From 8e47d2ff0af9c1289362ef1f27062be2f2af0d33 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Sat, 1 Aug 2015 14:17:33 +0300 Subject: [PATCH 01/10] change in get user task by id --- SE_API/TaskRoutes.py | 141 +++++++++++++++++++++++-------------------- 1 file changed, 76 insertions(+), 65 deletions(-) diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index ee3bee6..a7ec923 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -353,7 +353,7 @@ def getTaskComponents(token, taskId): @task_routes.route('/api/tasks/getAllUserTasks/', methods=["GET"]) @auto.doc() -def getAllTasksByUser(token): +def getAllUserTasks(token): """ >This Call will return an array of all of the User's Tasks
@@ -491,70 +491,81 @@ def getAllTasksByUser(token): -# @task_routes.route('/api/tasks/getUserFullTasksById//', methods=["GET"]) -# @auto.doc() -# def getFullTasksById(token, taskId): -# """ -# >This Call will return an array of all components for a given task -#
-# Route Parameters
-# - SeToken: token
-# - taskId: 1234567890 -#
-#
-# Payload
-# - NONE -#
-#
-# Response -#
-# 200 - JSON Example:
-# -# [ -# {
-# 'taskId' : 7589454894, -# 'userId' : -1, -# 'type' : 'kindOfType', -# 'label' : 'kindOfLabel', -# 'isMandatory' : true, -# 'order' : 2 -# }
-# {
-# 'taskId' : 7589454894, -# 'userId' : yossi, -# 'type' : 'otherKindOfType', -# 'label' : 'otherKindOfLabel', -# 'isMandatory' : false, -# 'order' : 4 -# }
-# ] -#
-#
-# """ -# user = get_user_by_token(token) -# if user is None: -# return bad_request("Bad User Token") -# -# task = Task.get_by_id(int(taskId)) -# if task is None: -# return bad_request("Bad Task id") -# -# taskCompQuery = TaskComponent.all() -# taskCompQuery.filter("taskId = ", task.key().id()) -# -# if task.isPersonal: -# taskCompQuery.filter("userId = ", user.key().id()) -# else: -# taskCompQuery.filter("userId = ", user.key().id()) -# -# if taskCompQuery.count() == 0: -# #create componenets and Score for user -# -# -# for i in taskCompQuery.run(): -# print i.to_JSON() -# -# return no_content() +@task_routes.route('/api/tasks/getUserTaskById//', methods=["GET"]) +@auto.doc() +def getUserTaskById(token, taskId): + """ + >This Call will return an array of all components for a given task +
+ Route Parameters
+ - SeToken: token
+ - taskId: 1234567890 +
+
+ Payload
+ - NONE +
+
+ Response +
+ 200 - JSON Example:
+ + [ + {
+ 'taskId' : 7589454894, + 'userId' : -1, + 'type' : 'kindOfType', + 'label' : 'kindOfLabel', + 'isMandatory' : true, + 'order' : 2 + }
+ {
+ 'taskId' : 7589454894, + 'userId' : yossi, + 'type' : 'otherKindOfType', + 'label' : 'otherKindOfLabel', + 'isMandatory' : false, + 'order' : 4 + }
+ ] +
+
+ """ + user = get_user_by_token(token) + if user is None: + return bad_request("Bad User Token") + + task = Task.get_by_id(int(taskId)) + if task is None: + return bad_request("Bad Task id") + + + taskCompQuery = TaskComponent.all() + taskCompQuery.filter("taskId = ", task.key().id()) + + if task.isPersonal: + taskCompQuery.filter("userId = ", user.key().id()) + else: + taskCompQuery.filter("userId = ", user.key().id())#TODO: fix to project + + #check if never created a personalized task and if so, create it + if taskCompQuery.count() == 0: + taskCompQuery = TaskComponent.all().filter("taskId = ", task.key().id()).filter("userId = ", -1) + for tc in taskCompQuery.run(): + tcNew = TaskComponent(taskId=tc.taskId, userId=user.key().id(), type=tc.type, label=tc.label, isMandatory=tc.isMandatory, order=tc.order) + db.put(tcNew) + + grade = TaskGrade(grade=0, taskId=task.key().id(), userId=user.key().id()) + db.put(grade) + + + + + + + + db.save + return no_content() From 69d757554fbd7d6787c9a340e8b37027c96c4d99 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Sat, 1 Aug 2015 15:25:20 +0300 Subject: [PATCH 02/10] added some comments --- SE_API/UserRoutes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/SE_API/UserRoutes.py b/SE_API/UserRoutes.py index 09de2df..0a746ad 100644 --- a/SE_API/UserRoutes.py +++ b/SE_API/UserRoutes.py @@ -579,6 +579,7 @@ def removeUserFromCampus(token, userId, campusId): if requestingUser.key().id() != userToRemove.key().id(): return forbidden("No permission to delete user") + #remove campus from user campus list try: userToRemove.campuses_id_list.remove(campusId) except Exception as e: From fd32392b42274437e69266899d5cde5527c58c75 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Sat, 1 Aug 2015 16:52:11 +0300 Subject: [PATCH 03/10] bug fix --- SE_API/UserRoutes.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/SE_API/UserRoutes.py b/SE_API/UserRoutes.py index 0a746ad..ca473b2 100644 --- a/SE_API/UserRoutes.py +++ b/SE_API/UserRoutes.py @@ -322,16 +322,15 @@ def getUserById(token, id): if u is None: return no_content('No user Found') + 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(), + return Response(response=u.to_JSON(), status=200, mimetype="application/json") # Real response! - return no_content("No User Found") - @user_routes.route('/api/users/getUsersByCampus//', methods=["GET"]) From 4b08085d6388aa308b99e56d2a899ca0f31f969e Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Sat, 1 Aug 2015 16:52:33 +0300 Subject: [PATCH 04/10] added update foe user project list when joining --- SE_API/ProjectRoutes.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SE_API/ProjectRoutes.py b/SE_API/ProjectRoutes.py index fc5bf90..943f8bf 100644 --- a/SE_API/ProjectRoutes.py +++ b/SE_API/ProjectRoutes.py @@ -145,7 +145,9 @@ def joinProject(token, projectId): return bad_request("User is already member in Project") project.membersId.append(str(user.key().id())) + user.projects_id_list.append(str(project.key().id())) + db.put(user) db.put(project) db.save From ad3b232f5ddb98997c0bda32aa39dcffce39da26 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Sat, 1 Aug 2015 17:17:53 +0300 Subject: [PATCH 05/10] added: when user is removed from course he is also removed from projects inside course #126 --- SE_API/UserRoutes.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SE_API/UserRoutes.py b/SE_API/UserRoutes.py index ca473b2..1e8440c 100644 --- a/SE_API/UserRoutes.py +++ b/SE_API/UserRoutes.py @@ -646,6 +646,13 @@ def removeUserFromCourse(token, userId, courseId): except Exception as e: return bad_request("user is not listed to this course") + #remove user from all projects in course + projects = Project.all().filter("courseId =", course.key().id()) + for p in projects: + if p.key().id() in userToRemove.projects_id_list: + userToRemove.projects_id_list.remove(p.key().id()) + p.membersId.remove(userToRemove.key().id()) + db.put(p) db.put(userToRemove) From a3e97009ff292e516ba7eba3bd0e2ce1ba5c8e0c Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Sat, 1 Aug 2015 18:01:14 +0300 Subject: [PATCH 06/10] For Matan - Random Avatar --- SE_API/API.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SE_API/API.py b/SE_API/API.py index 340b5f8..c98b2fe 100644 --- a/SE_API/API.py +++ b/SE_API/API.py @@ -208,7 +208,8 @@ def login(): debug = True # Change In Production if debug: - counter = 300 + import random + counter = random.randrange(300,400) @auto.doc() @app.route('/debug/login') From c826b06f02861ef33f40c06019c9960dfa4d5036 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Sun, 2 Aug 2015 12:34:20 +0300 Subject: [PATCH 07/10] added getAllFutureTasks --- SE_API/TaskRoutes.py | 71 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index a7ec923..e9f2363 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -218,9 +218,9 @@ def getAllTasksByCourse(token, courseId): return no_content() -@task_routes.route('/api/tasks/getAllFutureTasks//', methods=["GET"]) +@task_routes.route('/api/tasks/getAllFutureCampusTasks//', methods=["GET"]) @auto.doc() -def getAllFutureTasks(token, courseId): +def getAllFutureCampusTasks(token, courseId): """ >This Call will return an array of all Future Tasks in a course, ordered by date
@@ -284,6 +284,73 @@ def getAllFutureTasks(token, courseId): else: return no_content() +@task_routes.route('/api/tasks/getAllFutureTasks/', methods=["GET"]) +@auto.doc() +def getAllFutureCampusTasks(token): + """ + >This Call will return an array of all Future Tasks ordered by date +
+ Route Parameters
+ - SeToken: token
+
+
+ Payload
+ - NONE +
+
+ Response +
+ 200 - JSON Example:
+ + {
+ 'title' : 'Task1',
+ 'courseName' : 'advance Math',
+ 'description' : 'prepare by sunday',
+ 'dueDate' : { + 'year' : 2015, + 'month' : 12, + 'day' : 23 + }
+ 'isPersonal' : true,
+ 'task_id' : 589689456894
+ }
+
+
+ """ + + user = get_user_by_token + if user is None: + return bad_request("Bad User Token") + + arr = [] + + for courseId in user.courses_id_list: + query = Task.all() + + try: + query.filter("courseId = ", int(courseId)) + except Exception as e: + return bad_request("Bad id format") + + for t in query.run(): + taskDic =dict(json.loads(t.to_JSON())) + #add a key 'forSortDate' for sorting dates + taskTime = datetime.datetime(taskDic['dueDate']['year'], taskDic['dueDate']['month'], taskDic['dueDate']['day']) + if taskTime >= datetime.date.today(): + taskDic['forSortDate'] = taskTime + arr.append(taskDic) + + #sort array by date, and remove added key + arr = sorted(arr, key=itemgetter('forSortDate'), reverse=False) + for i in arr: + del i['forSortDate'] + + if len(arr) != 0: + return Response(response=json.dumps(arr), + status=200, + mimetype="application/json") + else: + return no_content() @task_routes.route('/api/tasks/getTaskComponents//', methods=["GET"]) From dc41da5007f2471f27e9d3cc0f726342140803ae Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Sun, 2 Aug 2015 12:35:06 +0300 Subject: [PATCH 08/10] removing all users from project when it is deleted by creator --- SE_API/ProjectRoutes.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/SE_API/ProjectRoutes.py b/SE_API/ProjectRoutes.py index 943f8bf..a2d1383 100644 --- a/SE_API/ProjectRoutes.py +++ b/SE_API/ProjectRoutes.py @@ -372,12 +372,22 @@ def deleteProject(token,projectId): if p is None: return bad_request("no such Project") - if p.master_id == user.key().id(): - db.delete(p) - db.save - return accepted("Project deleted") + if p.master_id != user.key().id(): + return forbidden("user is not owner of Project") + + #remove all users related to project + for uId in p.membersId: + user = User.get_by_id(uId) + if user is None: + return bad_request("trying to remove a user from project failed") + user.projects_id_list.remove(p.key().id()) + db.put(user) + + + db.delete(p) + db.save + return accepted("Project deleted") - return forbidden("user is not owner of Project") From 2b0fc51b8b230a17d7e4094ae0690c3898d78b83 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Sun, 2 Aug 2015 12:53:10 +0300 Subject: [PATCH 09/10] fix --- SE_API/TaskRoutes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SE_API/TaskRoutes.py b/SE_API/TaskRoutes.py index e9f2363..c587901 100644 --- a/SE_API/TaskRoutes.py +++ b/SE_API/TaskRoutes.py @@ -286,7 +286,7 @@ def getAllFutureCampusTasks(token, courseId): @task_routes.route('/api/tasks/getAllFutureTasks/', methods=["GET"]) @auto.doc() -def getAllFutureCampusTasks(token): +def getAllFutureTasks(token): """ >This Call will return an array of all Future Tasks ordered by date
From b853793bbbfeffd780b4fd82ce5e594bda3dd8c4 Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Sun, 2 Aug 2015 13:11:22 +0300 Subject: [PATCH 10/10] fix --- models/Message.py | 2 +- models/Task.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models/Message.py b/models/Message.py index 67906f9..1a64564 100644 --- a/models/Message.py +++ b/models/Message.py @@ -8,7 +8,7 @@ from models.Course import Course class Message(db.Model): groupId = db.IntegerProperty(required=True) - message = db.StringProperty(required=True) + message = db.StringProperty(required=True, multiline=True) msgDate = db.DateTimeProperty(required=True) master_id = db.IntegerProperty(required=True) isProject = db.BooleanProperty(default=False) diff --git a/models/Task.py b/models/Task.py index 5449fa2..1dd422a 100644 --- a/models/Task.py +++ b/models/Task.py @@ -15,7 +15,7 @@ class Task(db.Model): data = {'title' : self.title, 'courseId' : self.courseId, 'description' : self.description, - 'dueDate' : { + 'dueDate' : { 'year': self.dueDate.year, 'month': self.dueDate.month, 'day': self.dueDate.day