コード例 #1
0
ファイル: shift.py プロジェクト: omunroe-com/shiftspace
 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
ファイル: shift.py プロジェクト: electrikfreak/shiftspace
 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
ファイル: ssuser.py プロジェクト: gmatters/shiftspace
 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
ファイル: ssuser.py プロジェクト: omunroe-com/shiftspace
 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
ファイル: ssuser.py プロジェクト: gmatters/shiftspace
 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
ファイル: ssuser.py プロジェクト: omunroe-com/shiftspace
 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
ファイル: shift.py プロジェクト: gmatters/shiftspace
 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
ファイル: shift.py プロジェクト: electrikfreak/shiftspace
 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
ファイル: shift.py プロジェクト: electrikfreak/shiftspace
 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
ファイル: shift.py プロジェクト: electrikfreak/shiftspace
 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
ファイル: shift.py プロジェクト: electrikfreak/shiftspace
 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
ファイル: ssuser.py プロジェクト: omunroe-com/shiftspace
 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
ファイル: ssuser.py プロジェクト: gmatters/shiftspace
 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
ファイル: ssuser.py プロジェクト: omunroe-com/shiftspace
 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
ファイル: ssuser.py プロジェクト: gmatters/shiftspace
 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]