示例#1
0
文件: user.py 项目: ljxia/shiftserver
 def update(self, userName):
     if not user.read(userName):
         return error("User %s does not exist" % userName, UserDoesNotExistError)
     loggedInUser = helper.getLoggedInUser()
     if loggedInUser and user.canUpdate(user.idForName(userName),
                                        loggedInUser["_id"]):
         theData = json.loads(helper.getRequestBody())
         theData["_id"] = user.idForName(userName)
         return data(user.update(theData))
     else:
         return error("Operation not permitted. You don't have permission to update this account.")
示例#2
0
文件: user.py 项目: ljxia/shiftserver
 def delete(self, userName):
     if not user.read(userName):
         return error("User %s does not exist" % userName, UserDoesNotExistError)
     loggedInUser = helper.getLoggedInUser()
     if loggedInUser and user.canDelete(user.idForName(userName),
                                        loggedInUser["_id"]):
         if user.idForName(userName) == loggedInUser["_id"]:
             helper.setLoggedInUser(None)
         user.delete(userName)
         return ack
     else:
         return error("Operation not permitted. You don't have permission to delete this account.")
示例#3
0
 def setPermission(self, id, userName, level):
     loggedInUser = helper.getLoggedInUser()
     if stream.canAdmin(id, loggedInUser["_id"]):
         permission.updateForUser(user.idForName(userName), id, level)
         return ack
     else:
         return error("Operation not permitted. You don't have permission to view permssions on this stream.", PermissionError)
示例#4
0
文件: user.py 项目: ljxia/shiftserver
 def comments(self, userName):
     loggedInUser = helper.getLoggedInUser()
     userId = loggedInUser["_id"]
     if user.isAdmin(userId) or user.idForName(userName) == userId:
         return data(user.comments(userId))
     else:
         return error("You don't have permission to view this user's comments.", PermissionError)
示例#5
0
文件: user.py 项目: ljxia/shiftserver
 def messages(self, userName):
     loggedInUser = helper.getLoggedInUser()
     messageStream = user.messageStream(user.idForName(userName))
     if stream.canRead(messageStream, loggedInUser["_id"]):
         return data(event.joinData(event.eventsForStream(messageStream)))
     else:
         return error("You do not have permission to view this user's messages.", PermissionError)
示例#6
0
文件: user.py 项目: ljxia/shiftserver
 def read(self, userName):
     if not user.read(userName):
         return error("User %s does not exist" % userName, UserDoesNotExistError)
     loggedInUser = helper.getLoggedInUser()
     if loggedInUser and user.canReadFull(user.idForName(userName),
                                          loggedInUser["_id"]):
         return data(user.readFull(userName).copy())
     else:
         return data(user.read(userName).copy())
示例#7
0
文件: user.py 项目: ljxia/shiftserver
 def unfollow(self, userName):
     loggedInUser = helper.getLoggedInUser()
     follower = loggedInUser["_id"]
     followed = user.idForName(userName)
     if follower == followed:
         return error("You cannot unfollow yourself.", FollowError)
     else:
         user.unfollow(follower, followed)
         return ack
示例#8
0
 def add(self, id, userName):
     loggedInUser = helper.getLoggedInUser()
     if stream.canAdmin(id, loggedInUser["_id"]):
         otherId = user.idForName(userName)
         if user.isSubscribed(otherId, id):
             return error("User %s is already subscribed to that stream." % userName, AlreadySubscribedError)
         else:
             stream.invite(id, loggedInUser["_id"], otherId)
             return ack
     else:
         return error("Operation not permitted. You don't have permission to subscribe to this stream.", PermissionError)