From dc41da5007f2471f27e9d3cc0f726342140803ae Mon Sep 17 00:00:00 2001 From: aranzaiger Date: Sun, 2 Aug 2015 12:35:06 +0300 Subject: [PATCH] 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")