From 811593dbb1e9e30573e74b2844adf2ce64310d00 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Tue, 23 Jun 2015 20:26:05 +0300 Subject: [PATCH 1/7] Crate New Task UI Tweaks --- templates/views/newTask.html | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/templates/views/newTask.html b/templates/views/newTask.html index 56354bf..aa62983 100644 --- a/templates/views/newTask.html +++ b/templates/views/newTask.html @@ -27,6 +27,12 @@ +
+
+
+ Submit +
+
@@ -55,8 +61,8 @@
-
- Add Component +
+ Add To Task
From 7a4f669f90803039ac92b598b1e2b6ceabafe109 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Tue, 23 Jun 2015 20:32:29 +0300 Subject: [PATCH 2/7] Typo in projectsController --- templates/js/controllers/projectsController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/js/controllers/projectsController.js b/templates/js/controllers/projectsController.js index f074dc3..7336919 100644 --- a/templates/js/controllers/projectsController.js +++ b/templates/js/controllers/projectsController.js @@ -1,5 +1,5 @@ angular.module('SeHub') -.controller('projectsContoller', ['$scope', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope', function ($scope, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService ,$rootScope) +.controller('projectsController', ['$scope', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope', function ($scope, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService ,$rootScope) { console.log("in projects controller"); From 88906c30a89266220814760a2098b181158d08f7 Mon Sep 17 00:00:00 2001 From: Matan Bar Yosef Date: Tue, 23 Jun 2015 20:34:26 +0300 Subject: [PATCH 3/7] - my classes fixed buttons --- templates/js/controllers/myClassesController.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/js/controllers/myClassesController.js b/templates/js/controllers/myClassesController.js index 8ca5128..879dcbb 100644 --- a/templates/js/controllers/myClassesController.js +++ b/templates/js/controllers/myClassesController.js @@ -30,12 +30,14 @@ angular.module('SeHub') $scope.createCourseClicked = function() { $scope.isNewCourse = true; + $scope.showMyClass = false; console.log("create course Clicked!!"); } $scope.showMyCourses = function() { $scope.showMyClass = true; + $scope.isNewCourse = false; } $scope.submitNewClassClicked = function() From 868b7fad8aabc1a28126941f5df9705f7f49eeb2 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Wed, 24 Jun 2015 00:50:59 +0300 Subject: [PATCH 4/7] some organizing --- SE_API/CampusRoutes.py | 22 ++++++++++++++++++++-- SE_API/CourseRoutes.py | 8 +++++--- SE_API/ProjectRoutes.py | 24 +++++++++++++++++++++--- SE_API/TaskRoutes.py | 26 +++++++++++++++++++++++--- 4 files changed, 69 insertions(+), 11 deletions(-) diff --git a/SE_API/CampusRoutes.py b/SE_API/CampusRoutes.py index ebfa72a..3c25394 100644 --- a/SE_API/CampusRoutes.py +++ b/SE_API/CampusRoutes.py @@ -22,11 +22,14 @@ from SE_API.Validation_Utils import * from SE_API.Respones_Utils import * from SE_API.Email_Utils import * - - campus_routes = Blueprint("campus_routes", __name__) auto = Autodoc() + +#---------------------------------------------------------- +# POST +#---------------------------------------------------------- + @campus_routes.route('/api/campuses/create/', methods=['POST']) @auto.doc() def create_campus(token): @@ -85,6 +88,13 @@ def create_campus(token): +#---------------------------------------------------------- +# PUT +#---------------------------------------------------------- + +#---------------------------------------------------------- +# GET +#---------------------------------------------------------- @campus_routes.route('/api/campuses/getAll/', methods=['GET']) @auto.doc() @@ -141,6 +151,10 @@ def get_campuses(token): return forbidden("Invalid Token") +#---------------------------------------------------------- +# DELETE +#---------------------------------------------------------- + @campus_routes.route('/api/campuses/deleteCampus//', methods=['DELETE']) @auto.doc() @@ -191,6 +205,10 @@ def deleteCampus(token,campusid): +#---------------------------------------------------------- +# DOCUMENTATION +#---------------------------------------------------------- + @campus_routes.route('/api/campuses/help') def documentation(): return auto.html() diff --git a/SE_API/CourseRoutes.py b/SE_API/CourseRoutes.py index b7af470..972b047 100644 --- a/SE_API/CourseRoutes.py +++ b/SE_API/CourseRoutes.py @@ -279,9 +279,6 @@ def getMessagesByCourseName(name): - - - @course_routes.route('/api/courses/deleteCourse//', methods=['DELETE']) @auto.doc() def deleteCourse(token,courseid): @@ -390,6 +387,11 @@ def deleteCoursesByCampus(token,campusName): return no_content() + +#---------------------------------------------------------- +# DOCUMENTATION +#---------------------------------------------------------- + @course_routes.route('/api/courses/help') def documentation(): return auto.html() \ No newline at end of file diff --git a/SE_API/ProjectRoutes.py b/SE_API/ProjectRoutes.py index 175a3a7..bf9d76a 100644 --- a/SE_API/ProjectRoutes.py +++ b/SE_API/ProjectRoutes.py @@ -21,11 +21,13 @@ from models.Project import Project from SE_API.Validation_Utils import * from SE_API.Respones_Utils import * - - project_routes = Blueprint("project_routes", __name__) auto = Autodoc() +#---------------------------------------------------------- +# POST +#---------------------------------------------------------- + @project_routes.route('/api/projects/create/', methods=['POST']) @auto.doc() def create_project(token): @@ -78,9 +80,14 @@ def create_project(token): status=201, mimetype="application/json") +#---------------------------------------------------------- +# PUT +#---------------------------------------------------------- - +#---------------------------------------------------------- +# GET +#---------------------------------------------------------- @project_routes.route('/api/projects/getProjectsByCourseName/', methods=["GET"]) @auto.doc() @@ -131,6 +138,12 @@ def getProjectsByCourseName(name): +#---------------------------------------------------------- +# DELETE +#---------------------------------------------------------- + + + @project_routes.route('/api/projects/deleteProject//', methods=['DELETE']) @auto.doc() def deleteProject(token,projectid): @@ -179,6 +192,11 @@ def deleteProject(token,projectid): + +#---------------------------------------------------------- +# DOCUMENTATION +#---------------------------------------------------------- + @project_routes.route('/api/projects/help') def documentation(): return auto.html() \ No newline at end of file diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index ad3b990..ab36b2e 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -25,11 +25,15 @@ from SE_API.Validation_Utils import * from SE_API.Respones_Utils import * - - task_routes = Blueprint("task_routes", __name__) auto = Autodoc() + + +#---------------------------------------------------------- +# POST +#---------------------------------------------------------- + @task_routes.route('/api/tasks/create/', methods=['POST']) @auto.doc() def create_task(token): @@ -140,8 +144,13 @@ def create_task(token): return created() +#---------------------------------------------------------- +# PUT +#---------------------------------------------------------- - +#---------------------------------------------------------- +# GET +#---------------------------------------------------------- @task_routes.route('/api/tasks/getAllTasks/', methods=["GET"]) @@ -321,6 +330,12 @@ def getTaskComponents(taskId): +#---------------------------------------------------------- +# DELETE +#---------------------------------------------------------- + + + @task_routes.route('/api/tasks/deleteTask//', methods=['DELETE']) @auto.doc() def deleteTask(token,taskid): @@ -422,6 +437,11 @@ def deleteTaskComponents(token,taskid): + +#---------------------------------------------------------- +# DOCUMENTATION +#---------------------------------------------------------- + @task_routes.route('/api/tasks/help') def documentation(): return auto.html() From dc6070fe291b2877ff62da2826a1a5c08305df8b Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Wed, 24 Jun 2015 00:54:55 +0300 Subject: [PATCH 5/7] added functions: addUserToCampus, addUserToCourse also, getUserByToken now returns the campuses themselfs --- SE_API/UserRoutes.py | 369 +++++++++++++++++++++++++++++++++++++------ models/User.py | 5 +- 2 files changed, 324 insertions(+), 50 deletions(-) diff --git a/SE_API/UserRoutes.py b/SE_API/UserRoutes.py index d66fdea..56f05e4 100644 --- a/SE_API/UserRoutes.py +++ b/SE_API/UserRoutes.py @@ -16,6 +16,7 @@ from flask.ext.autodoc import Autodoc # DB Models from models.User import User +from models.Course import Course #Validation Utils Libs from SE_API.Validation_Utils import * @@ -25,55 +26,18 @@ from SE_API.Respones_Utils import * user_routes = Blueprint("user_routes", __name__) auto = Autodoc() -@user_routes.route('/api/users/getUserByToken/', defaults={'token': None}) -@user_routes.route('/api/users/getUserByToken/', methods=["GET"]) -@auto.doc() -def getUserByToken(token): - """ - >This Call will return a user by a given token -
- Route Parameters
- - seToken: 'seToken' -
-
- Payload
- - NONE -
-
- Response -
- 200 - JSON Example:
- - {
- 'username': 'DarkLord',
- 'name': 'Darth Vader',
- 'email': 'darkLord@death.planet,
- 'isLecturer': 'True',
- 'seToken': 'xxxxxx-xxxxx-xxxxx-xxxxxx',
- 'avatar_url': 'http://location.git.com/somthing'
- 'isFirstLogin': False,
- 'campuses_id_list': ['JCA','JCB','JCC'],
- 'classes_id_list': ['a','b','c']
- } -
-
- 403 - No User Found - """ - if token is None: - return no_content("Token Is Empty, No User Found") - - query = User.all() - query.filter("seToken =", token) - - for u in query.run(limit=5): - return Response(response=u.to_JSON(), - status=200, - mimetype="application/json") # Real response! - - return no_content("No User Found") -@user_routes.route('/api/users/updateUser/', methods=["POST"]) + +#---------------------------------------------------------- +# POST +#---------------------------------------------------------- + +#---------------------------------------------------------- +# PUT +#---------------------------------------------------------- + +@user_routes.route('/api/users/updateUser/', methods=["PUT"]) @auto.doc() def updateUser(token): """ @@ -129,7 +93,318 @@ def updateUser(token): db.save return ok("User updated") +@user_routes.route('/api/users/addUserToCourse/', methods=["PUT"]) +@auto.doc() +def addUserToCourse(token): + """ + >This Call will add a course to user course list +
+ Route Parameters
+ - seToken: 'seToken' +
+
+ Payload
+ - JSON Object, Example:
+ {
+ 'courseId': 1234567890
+ }
+
+ Response +
+ 200 - User updated +
+ 400 - Bad Request + """ + if not request.data: + return bad_request() + + try: + payload = json.loads(request.data) + except Exception as e: + return bad_request() + + #check user exists + user = get_user_by_token(token) + if user is None: + return bad_request("Not a user!") + + #check course Exists + course = Course.get_by_id(payload['coursesId']) + if course is None: + return bad_request("No such Course!") + + try: + user.courses_id_list.append(payload['coursesId']) + except Exception as e: + print e + return bad_request() + + db.put(user) + db.save + return Response(response=user.to_JSON(), + status=200, + mimetype="application/json") # Real response! + + + + +@user_routes.route('/api/users/addUserToCampus/', methods=["PUT"]) +@auto.doc() +def addUserToCampus(token): + """ + >This Call will add a Campus to user Campus list +
+ Route Parameters
+ - seToken: 'seToken' +
+
+ Payload
+ - JSON Object, Example:
+ {
+ 'campusId': 1234567890
+ }
+
+ Response +
+ 200 - User updated +
+ 400 - Bad Request + """ + + if not request.data: + return bad_request() + + try: + payload = json.loads(request.data) + except Exception as e: + print e + return bad_request() + + if not is_lecturer(token): #todo: change to lecturer id + return forbidden("Invalid token or not a lecturer!") + + user = get_user_by_token(token) + + #check Campus Exists + campus = Campus.get_by_id(payload['campusId']) + if campus is None: + return bad_request("No such Campus!") + + try: + if str(payload['campusId']) in user.campuses_id_list: + return accepted("Already a member of that campus") + + user.campuses_id_list.append(str(payload['campusId'])) + except Exception as e: + print e + return bad_request() + + + db.put(user) + db.save + return Response(response=user.to_JSON(), + status=200, + mimetype="application/json") # Real response! + + +#---------------------------------------------------------- +# GET +#---------------------------------------------------------- + + +@user_routes.route('/api/users/getUserByToken/', defaults={'token': None}) +@user_routes.route('/api/users/getUserByToken/', methods=["GET"]) +@auto.doc() +def getUserByToken(token): + """ + >This Call will return a user by a given token +
+ Route Parameters
+ - seToken: 'seToken' +
+
+ Payload
+ - NONE +
+
+ Response +
+ 200 - JSON Example:
+ + {
+ 'username': 'DarkLord',
+ 'name': 'Darth Vader',
+ 'email': 'darkLord@death.planet,
+ 'isLecturer': 'True',
+ 'seToken': 'xxxxxx-xxxxx-xxxxx-xxxxxx',
+ 'avatar_url': 'http://location.git.com/somthing'
+ 'isFirstLogin': False,
+ 'campuses_id_list': [{
+ 'master_user_id': 111,
+ 'id': 5629499534213120,
+ 'email_ending': "@post.jce.ac.il",
+ 'avatar_url': "https://yt3.ggpht.com/--ZkWxybWGOM/AAAAAAAAAAI/AAAAAAAAAAA/_nAICC_kzzI/s88-c-k-no/photo.jpg",
+ 'title': "JCE" + }],
+ 'courses_id_list': ['a','b','c']
+ } +
+
+ 403 - No User Found + """ + if token is None: + return no_content("Token Is Empty, No User Found") + + query = User.all() + query.filter("seToken =", token) + + for u in query.run(limit=5): + for index, c in enumerate(u.campuses_id_list): + c = json.loads(Campus.get_by_id(int(c)).to_JSON()) + u.campuses_id_list[index] = c + + return Response(response=u.to_JSON(), + status=200, + mimetype="application/json") # Real response! + + + + + + return no_content("No User Found") + + + +#---------------------------------------------------------- +# DELETE +#---------------------------------------------------------- + +@user_routes.route('/api/users/removeUserFromCampus//', methods=["PUT"]) +@auto.doc() +def removeUserFromCampus(token, campusId): + """ + >This Call will remove a Campus from a user Campus list +
+ Route Parameters
+ - seToken: 'seToken' + - 'campusId': 1234567890
+
+
+ Payload
+ - NONE + {
+ }
+
+ Response +
+ 200 - User updated +
+ 400 - Bad Request + """ + + if not request.data: + return bad_request() + + try: + payload = json.loads(request.data) + except Exception as e: + return bad_request() + + if not is_lecturer(token): #todo: change to lecturer id + return forbidden("Invalid token or not a lecturer!") + + user = get_user_by_token(token) + + #check Campus Exists + campus = Campus.get_by_id(int(campusId)) + if campus is None: + return bad_request("No such Campus!") + + #check if user is owner of Campus + if user.key().id() != campus.master_user_id: + return forbidden("Lecturer is not owner of course") + + try: + user.campuses_id_list.remove(campusId) + except Exception as e: + print e + return bad_request("user is not listed to this campus") + + db.put(user) + db.save + return Response(response=user.to_JSON(), + status=200, + mimetype="application/json") # Real response! + + + + + +# @user_routes.route('/api/users/removeUserFromCourse//', methods=["PUT"]) +# @auto.doc() +# def removeUserFromCourse(token, courseId): +# """ +# >This Call will remove a Course from a user Campus list +#
+# Route Parameters
+# - seToken: 'seToken' +# - 'courseId': 1234567890
+#
+#
+# Payload
+# - NONE +# {
+# }
+#
+# Response +#
+# 200 - User updated +#
+# 400 - Bad Request +# """ +# +# if not request.data: +# return bad_request() +# +# try: +# payload = json.loads(request.data) +# except Exception as e: +# return bad_request() +# +# user = get_user_by_token(token) +# if user is None: +# return bad_request("No such user!") +# +# +# #check Course Exists +# course = Course.get_by_id(int(courseId)) +# if course is None: +# return bad_request("No such Course!") +# +# #check if user is owner of Campus +# if user.key().id() != course.master_id: +# return forbidden("Lecturer is not owner of course") +# +# try: +# user.campuses_id_list.remove(campusId) +# except Exception as e: +# print e +# return bad_request("user is not listed to this campus") +# +# db.put(user) +# db.save +# return Response(response=user.to_JSON(), +# status=200, +# mimetype="application/json") # Real response! +# +# + + + +#---------------------------------------------------------- +# DOCUMENTATION +#---------------------------------------------------------- @user_routes.route('/api/users/help') def documentation(): diff --git a/models/User.py b/models/User.py index 348266c..3aaa1cf 100644 --- a/models/User.py +++ b/models/User.py @@ -14,18 +14,17 @@ class User(db.Model): isFirstLogin = db.BooleanProperty(default=True) campusName = db.StringProperty(required=True, default=" ") campuses_id_list = db.StringListProperty(default=[]) - classes_id_list = db.StringListProperty(default=[]) + courses_id_list = db.StringListProperty(default=[]) def to_JSON(self): data = {'username' : self.username, 'name' : self.name, 'email' : self.email, 'isLecturer' : self.isLecturer, - 'seToken' : self.seToken, 'avatar_url' : self.avatar_url, 'isFirstLogin' : self.isFirstLogin, 'campusName': self.campusName, 'campuses_id_list': self.campuses_id_list, - 'classes_id_list': self.classes_id_list + 'courses_id_list': self.courses_id_list } return json.dumps(data) From 90909c7c2f028eec1553782be92e1aabd401da3b Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Wed, 24 Jun 2015 01:16:51 +0300 Subject: [PATCH 6/7] fix #61 --- SE_API/CampusRoutes.py | 2 ++ SE_API/Email_Utils.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/SE_API/CampusRoutes.py b/SE_API/CampusRoutes.py index 3c25394..6f73148 100644 --- a/SE_API/CampusRoutes.py +++ b/SE_API/CampusRoutes.py @@ -83,7 +83,9 @@ def create_campus(token): return bad_request() send_create_campus_request(user.email, user.name, campus.title) + db.put(campus) notify_se_hub_campus_request(campus, campus.title) + db.delete(campus) return ok() diff --git a/SE_API/Email_Utils.py b/SE_API/Email_Utils.py index 683f7e8..2939cc7 100644 --- a/SE_API/Email_Utils.py +++ b/SE_API/Email_Utils.py @@ -105,7 +105,7 @@ def notify_se_hub_campus_request(campus, campus_name): message.body = """ a new Campus request - """+str(campus.to_JSON()) + """ + str(campus.to_JSON()) message.html = """ From 72d3036c2add8929f782681aec541bde2bd629ae Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Wed, 24 Jun 2015 01:20:53 +0300 Subject: [PATCH 7/7] fix #62 --- SE_API/ProjectRoutes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SE_API/ProjectRoutes.py b/SE_API/ProjectRoutes.py index bf9d76a..5c12708 100644 --- a/SE_API/ProjectRoutes.py +++ b/SE_API/ProjectRoutes.py @@ -69,7 +69,7 @@ def create_project(token): #todo: check legality try: - project = Project(projectName=payload['projectName'], courseName=payload['courseName'], masterId=user.key().id(), gitRepository=payload['gitRepository'], membersId=[token]) + project = Project(projectName=payload['projectName'], courseName=payload['courseName'], master_id=user.key().id(), gitRepository=payload['gitRepository'], membersId=[token]) except Exception as e: print e return bad_request() @@ -77,7 +77,7 @@ def create_project(token): db.put(project) db.save return Response(response=project.to_JSON(), - status=201, + status=200, mimetype="application/json") #----------------------------------------------------------