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 comment(self, id): loggedInUser = helper.getLoggedInUser() jsonData = helper.getRequestBody() if jsonData != "": theData = json.loads(jsonData) if shift.canComment(id, loggedInUser["_id"]): theUser = user.readById(loggedInUser["_id"]) theShift = shift.read(id) event.create({ "meta": "comment", "objectRef": "shift:%s" % id, "streamId": shift.commentStream(id), "displayString": "%s just commented on your %s on %s" % (theUser["userName"], theShift["space"]["name"], theShift["href"]), "createdBy": loggedInUser["_id"], "content": { "href": theShift["href"], "domain": theShift["domain"], "text": theData["text"] } }) return ack else: return error("Operation not permitted. You don't have permission to comment on this shift.", PermissionError) else: return error("No data for comment.", NoDataError)
def unnotify(self, id): loggedInUser = helper.getLoggedInUser() userId = loggedInUser["_id"] if shift.commentStream(id) in user.readById(userId)["notify"]: user.removeNotification(userId, id) return ack else: return error("You are not getting notification from this stream.", NotBeingNotifiedError)
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)