Beispiel #1
0
 def comment(self, id):
     loggedInUser = helper.getLoggedInUser()
     jsonData = helper.getRequestBody()
     if jsonData != "":
         theShift = Shift.read(id, userId=loggedInUser)
         if not theShift:
             return error("Shift does not exist.",
                          ResourceDoesNotExistError)
         if theShift.type != "shift":
             return error("Resource is not of type shift",
                          ResourceTypeError)
         from server.models.ssuser import SSUser
         theUser = SSUser.read(loggedInUser)
         theData = json.loads(jsonData)
         if theUser.canRead(theShift):
             from server.models.comment import Comment
             Comment.create(theUser.id, theShift.id, theData["text"],
                            theData.get("subscribe") or False)
             return data(Shift.read(theShift.id, theUser.id))
         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 testUnsubscribe(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private": False})
     # another user makes a comment
     newComment = Comment.create(self.fakebob.id,
                                 newShift.id,
                                 "1st comment!",
                                 subscribe=True)
     # subscribe fakejohn
     self.fakejohn.subscribe(newShift)
     # another user makes another comment
     newComment = Comment.create(self.fakebob.id, newShift.id,
                                 "2nd comment!")
     # check that fakejohn has one message
     messages = self.fakejohn.messages()
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].text,
                      "fakebob just commented on fakemary's shift!")
     # unsubscribe fakejohn
     self.fakejohn.unsubscribe(newShift)
     newComment = Comment.create(self.fakebob.id, newShift.id,
                                 "3rd comment!")
     # check that fakejohn still only has one message
     messages = self.fakejohn.messages()
     self.assertEqual(len(messages), 1)
     # check that fakemary has two messages
     messages = self.fakemary.messages()
     self.assertEqual(len(messages), 3)
     # check that fakebob has no messages
     messages = self.fakebob.messages()
     self.assertEqual(len(messages), 0)
     newShift.deleteThread()
Beispiel #3
0
 def comments(self, start=None, end=None, limit=25):
     from server.models.comment import Comment
     if not self.hasThread():
         return []
     db = core.connect(Comment.db(self.id))
     return Comment.joinData(
         core.objects(Comment.by_created(db, limit=limit)))
 def testSubscribe(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private":False})
     # make a comment
     newComment = Comment.create(
         self.fakejohn.id,
         newShift.id,
         "1st comment!",
         subscribe=True
         )
     # check that shift author is subscribed
     subscribers = newShift.subscribers()
     self.assertTrue(self.fakemary.id in subscribers)
     # check that commenter is subscribed
     self.assertTrue(self.fakejohn.id in subscribers)
     # check that there is a message in shift author message db
     messages = self.fakemary.messages()
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].text, "fakejohn just commented on your shift!")
     # check that there is _not_ a message in commenters message db
     messages = self.fakejohn.messages()
     self.assertEqual(len(messages), 0)
     newShift.deleteThread()
Beispiel #5
0
 def hasThread(self):
     from server.models.comment import Comment
     try:
         server = core.sharedServer()
         thread = server[Comment.db(self.id)]
         return thread != None
     except Exception:
         return False
Beispiel #6
0
 def hasThread(self):
     from server.models.comment import Comment
     try:
         server = core.sharedServer()
         thread = server[Comment.db(self.id)]
         return thread != None
     except Exception:
         return False
Beispiel #7
0
 def comments(self, start=None, end=None, limit=25):
     from server.models.comment import Comment
     db = core.connect("shiftspace/shared")
     if not start:
         start = [self.id]
     if not end:
         end = [self.id, {}]
     results = Comment.by_user_and_created(db, limit=limit)
     return core.objects(results[start:end])
Beispiel #8
0
 def comments(self, start=None, end=None, limit=25):
     from server.models.comment import Comment
     db = core.connect("shiftspace/shared")
     if not start:
         start = [self.id]
     if not end:
         end = [self.id, {}]
     results = Comment.by_user_and_created(db, limit=limit)
     return core.objects(results[start:end])
Beispiel #9
0
 def subscribe(self, aShift):
     from server.models.comment import Comment
     db = core.connect(Comment.db(aShift.id))
     if not self.isSubscribed(aShift):
         db.create({
             "_id": "user:%s" % self.id,
             "shiftId": aShift.id,
             "type": "subscription",
             "userId": self.id,
             })
Beispiel #10
0
 def subscribe(self, aShift):
     from server.models.comment import Comment
     db = core.connect(Comment.db(aShift.id))
     if not self.isSubscribed(aShift):
         db.create({
             "_id": "user:%s" % self.id,
             "shiftId": aShift.id,
             "type": "subscription",
             "userId": self.id,
         })
Beispiel #11
0
 def comment(self, id):
     loggedInUser = helper.getLoggedInUser()
     jsonData = helper.getRequestBody()
     if jsonData != "":
         theShift = Shift.read(id)
         if not theShift:
             return error("Resource does not exist.", ResourceDoesNotExistError)
         if theShift.type != "shift":
             return error("Resource is not of type shift", ResourceTypeError)
         from server.models.ssuser import SSUser
         theUser = SSUser.read(loggedInUser)
         theData = json.loads(jsonData)
         if theUser.canRead(theShift):
             from server.models.comment import Comment
             Comment.create(theUser.id, theShift.id, theData["text"], theData.get("subscribe") or False)
             return data(Shift.read(theShift.id, theUser.id))
         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 testUnsubscribe(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private":False})
     # another user makes a comment
     newComment = Comment.create(
         self.fakebob.id,
         newShift.id,
         "1st comment!",
         subscribe=True
         )
     # subscribe fakejohn
     self.fakejohn.subscribe(newShift)
     # another user makes another comment
     newComment = Comment.create(
         self.fakebob.id,
         newShift.id,
         "2nd comment!"
         )
     # check that fakejohn has one message
     messages = self.fakejohn.messages()
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].text, "fakebob just commented on fakemary's shift!")
     # unsubscribe fakejohn
     self.fakejohn.unsubscribe(newShift)
     newComment = Comment.create(
         self.fakebob.id,
         newShift.id,
         "3rd comment!"
         )
     # check that fakejohn still only has one message
     messages = self.fakejohn.messages()
     self.assertEqual(len(messages), 1)
     # check that fakemary has two messages
     messages = self.fakemary.messages()
     self.assertEqual(len(messages), 3)
     # check that fakebob has no messages
     messages = self.fakebob.messages()
     self.assertEqual(len(messages), 0)
     newShift.deleteThread()
 def testCreate(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private":False})
     # create new comment
     newComment = Comment.create(self.fakejohn.id, newShift.id, "1st comment!")
     # shift comment db should now exist
     self.assertNotEqual(core.connect(Comment.db(newShift.id)), None)
     # shift should have thread
     self.assertTrue(newShift.hasThread())
     # should be a comment count of 1 for shift
     count = newShift.commentCount()
     self.assertEqual(count, 1)
     # should be one message in fakemary's inbox from fakejohn
     messages = self.fakemary.messages()
     self.assertEqual(len(messages), 1)
     # delete the comment
     # TODO: separate fixture - David
     newComment.delete()
     # delete the thread
     newShift.deleteThread()
 def testCreate(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private": False})
     # create new comment
     newComment = Comment.create(self.fakejohn.id, newShift.id,
                                 "1st comment!")
     # shift comment db should now exist
     self.assertNotEqual(core.connect(Comment.db(newShift.id)), None)
     # shift should have thread
     self.assertTrue(newShift.hasThread())
     # should be a comment count of 1 for shift
     count = newShift.commentCount()
     self.assertEqual(count, 1)
     # should be one message in fakemary's inbox from fakejohn
     messages = self.fakemary.messages()
     self.assertEqual(len(messages), 1)
     # delete the comment
     # TODO: separate fixture - David
     newComment.delete()
     # delete the thread
     newShift.deleteThread()
 def testSubscribe(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private": False})
     # make a comment
     newComment = Comment.create(self.fakejohn.id,
                                 newShift.id,
                                 "1st comment!",
                                 subscribe=True)
     # check that shift author is subscribed
     subscribers = newShift.subscribers()
     self.assertTrue(self.fakemary.id in subscribers)
     # check that commenter is subscribed
     self.assertTrue(self.fakejohn.id in subscribers)
     # check that there is a message in shift author message db
     messages = self.fakemary.messages()
     self.assertEqual(len(messages), 1)
     self.assertEqual(messages[0].text,
                      "fakejohn just commented on your shift!")
     # check that there is _not_ a message in commenters message db
     messages = self.fakejohn.messages()
     self.assertEqual(len(messages), 0)
     newShift.deleteThread()
Beispiel #16
0
 def commentCount(self):
     from server.models.comment import Comment
     db = core.connect("shiftspace/shared")
     return core.value(Comment.count_by_shift(db, key=self.id))
Beispiel #17
0
 def subscribers(self):
     from server.models.comment import Comment
     db = core.connect(Comment.db(self.id))
     return core.values(Comment.all_subscribed(db))
Beispiel #18
0
 def deleteThread(self):
     from server.models.comment import Comment
     server = core.sharedServer()
     # TODO - use bulk API to delete all comment stubs - David
     del server[Comment.db(self.id)]
Beispiel #19
0
 def deleteThread(self):
     from server.models.comment import Comment
     server = core.sharedServer()
     # TODO - use bulk API to delete all comment stubs - David
     del server[Comment.db(self.id)]
Beispiel #20
0
 def comments(self, start=None, end=None, limit=25):
     from server.models.comment import Comment
     if not self.hasThread():
         return []
     db = core.connect(Comment.db(self.id))
     return Comment.joinData(core.objects(Comment.by_created(db, limit=limit)))
Beispiel #21
0
 def commentCount(self):
     from server.models.comment import Comment
     db = core.connect("shiftspace/shared")
     return core.value(Comment.count_by_shift(db, key=self.id))
Beispiel #22
0
 def subscribers(self):
     from server.models.comment import Comment
     db = core.connect(Comment.db(self.id))
     return core.values(Comment.all_subscribed(db))
Beispiel #23
0
 def unsubscribe(self, aShift):
     from server.models.comment import Comment
     db = core.connect(Comment.db(aShift.id))
     if self.isSubscribed(aShift):
         del db["user:%s" % self.id]
Beispiel #24
0
 def isSubscribed(self, aShift):
     from server.models.comment import Comment
     db = core.connect(Comment.db(aShift.id))
     return db.get("user:%s" % self.id) != None
Beispiel #25
0
 def isSubscribed(self, aShift):
     from server.models.comment import Comment
     db = core.connect(Comment.db(aShift.id))
     return db.get("user:%s" % self.id) != None
Beispiel #26
0
 def unsubscribe(self, aShift):
     from server.models.comment import Comment
     db = core.connect(Comment.db(aShift.id))
     if self.isSubscribed(aShift):
         del db["user:%s" % self.id]