Пример #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)
Пример #2
0
 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()
Пример #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)))
Пример #4
0
 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()
Пример #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
Пример #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
Пример #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])
Пример #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])
Пример #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,
             })
Пример #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,
         })
Пример #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)
Пример #12
0
 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()
Пример #13
0
 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()
Пример #14
0
 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()
Пример #15
0
 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()
Пример #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))
Пример #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))
Пример #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)]
Пример #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)]
Пример #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)))
Пример #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))
Пример #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))
Пример #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]
Пример #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
Пример #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
Пример #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]