def unfavorite(self, id): loggedInUser = helper.getLoggedInUser() loggedInId = loggedInUser["_id"] if shift.isPublic(id) or (shift.canRead(id, loggedInId)): return data(shift.unfavorite(id, loggedInId)) else: return error("Operation not permitted. You don't have permission to unfavorite this shift.", PermissionError)
def read(self, id): allowed = shift.isPublic(id) if not allowed: loggedInUser = helper.getLoggedInUser() if loggedInUser and shift.canRead(id, loggedInUser.get("_id")): return data(shift.read(id)) else: return error("Operation not permitted. You don't have permission to view this shift.", PermissionError) else: return data(shift.read(id))
def notify(self, id): loggedInUser = helper.getLoggedInUser() userId = loggedInUser["_id"] if shift.canRead(id, userId): if (not shift.commentStream(id) in user.readById(userId)["notify"]): user.addNotification(userId, shift.commentStream(id)) return ack else: return error("You are already getting notification from this stream", AlreadyBeingNotifiedError) else: return error("Operation not permitted. You don't have permission to be notified of events on this stream.", PermissionError)
def comments(self, id): loggedInUser = helper.getLoggedInUser() if shift.isPublic(id) or (shift.canRead(id, loggedInUser["_id"])): return data(event.eventsForStream(shift.commentStream(id))) else: return error("Operation not permitted. You don't have permission to view comments on this shift.", PermissionError)