예제 #1
0
 def testBasicPublish(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private": False})
     # should exist in user/public db
     theShift = Shift.load(core.connect(SSUser.publicDb(self.fakemary.id)),
                           newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
     self.assertTrue(not theShift.publishData.draft)
     self.assertTrue(not theShift.publishData.private)
     # should exist in shiftspace/public db
     theShift = Shift.load(core.connect("shiftspace/public"), newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
     self.assertTrue(not theShift.publishData.draft)
     self.assertTrue(not theShift.publishData.private)
     # should exist in shiftspace/shared db
     theShift = Shift.load(core.connect("shiftspace/shared"), newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
     self.assertTrue(not theShift.publishData.draft)
     self.assertTrue(not theShift.publishData.private)
     # should _not_ exist in user/private db
     theShift = Shift.load(core.connect(SSUser.privateDb(self.fakemary.id)),
                           newShift.id)
     self.assertEqual(theShift, None)
예제 #2
0
    def update(self, fields, updateDbs=True):
        from server.models.ssuser import SSUser
        if fields.get("content"):
            self.content = fields.get("content")
        if fields.get("summary"):
            self.summary = self.content["summary"] = fields.get("summary")
        if fields.get("broken"):
            self.broken = fields.get("broken")
        if fields.get("dbs"):
            self.dbs = list(set(self.dbs.extend(fields.get("dbs"))))
        self.modified = datetime.now()
        
        # update the correct user db
        if self.publishData.private:
            db = SSUser.privateDb(self.createdBy)
        else:
            db = SSUser.publicDb(self.createdBy)
        
        self.store(core.connect(db))
        core.replicate(db, "shiftspace/shared")
        
        # update followers and groups
        if updateDbs:
            for db in self.publishData.dbs:
                dbtype, dbid = db.split("/")
                if dbtype == "group":
                    from server.models.group import Group
                    Group.read(dbid).updateShift(self)

        return Shift.joinData(self, self.createdBy)
예제 #3
0
    def update(self, fields, updateDbs=True):
        from server.models.ssuser import SSUser
        if fields.get("content"):
            self.content = fields.get("content")
        if fields.get("summary"):
            self.summary = self.content["summary"] = fields.get("summary")
        if fields.get("broken"):
            self.broken = fields.get("broken")
        if fields.get("dbs"):
            self.dbs = list(set(self.dbs.extend(fields.get("dbs"))))
        self.modified = datetime.now()

        # update the correct user db
        if self.publishData.private:
            db = SSUser.privateDb(self.createdBy)
        else:
            db = SSUser.publicDb(self.createdBy)

        self.store(core.connect(db))
        core.replicate(db, "shiftspace/shared")

        # update followers and groups
        if updateDbs:
            for db in self.publishData.dbs:
                dbtype, dbid = db.split("/")
                if dbtype == "group":
                    from server.models.group import Group
                    Group.read(dbid).updateShift(self)

        return Shift.joinData(self, self.createdBy)
예제 #4
0
 def delete(self):
     from server.models.ssuser import SSUser
     db = core.connect(SSUser.privateDb(self.createdBy))
     if db.get(self.id):
         del db[self.id]
     else:
         db = core.connect(SSUser.publicDb(self.createdBy))
         if db.get(self.id):
             del db[self.id]
     core.replicate(db.name, "shiftspace/shared")
예제 #5
0
 def delete(self):
     from server.models.ssuser import SSUser
     db = core.connect(SSUser.privateDb(self.createdBy))
     if db.get(self.id):
         del db[self.id]
     else:
         db = core.connect(SSUser.publicDb(self.createdBy))
         if db.get(self.id):
             del db[self.id]
     core.replicate(db.name, "shiftspace/shared")
예제 #6
0
 def read(cls, id, userId=None):
     from server.models.ssuser import SSUser
     if userId != None:
         # then try the user public
         db = core.connect(SSUser.publicDb(userId))
         theShift = Shift.load(db, id)
         if not theShift:
             # then user private
             db = core.connect(SSUser.privateDb(userId))
             theShift = Shift.load(db, id)
     else:
         theShift = Shift.load(core.connect("shiftspace/shared"), id)
     if theShift:
         return Shift.joinData(theShift, theShift.createdBy)
예제 #7
0
 def testBasicPublish(self):
     json = shiftJson()
     json["createdBy"] = self.fakemary.id
     newShift = Shift.create(json)
     newShift.publish({"private":False})
     # should exist in user/public db
     theShift = Shift.load(core.connect(SSUser.publicDb(self.fakemary.id)), newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
     # should exist in master/public db 
     theShift = Shift.load(core.connect("shiftspace/public"), newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
     # should exist in shiftspace/shared db
     theShift = Shift.load(core.connect("shiftspace/shared"), newShift.id)
     self.assertEqual(theShift.summary, newShift.summary)
     # should _not_ exist in user/private db
     theShift = Shift.load(core.connect(SSUser.privateDb(self.fakemary.id)), newShift.id)
     self.assertEqual(theShift, None)
예제 #8
0
 def read(cls, id, userId=None, proxy=False):
     from server.models.ssuser import SSUser
     theShift = None
     # then try the user public
     if userId:
         db = core.connect(SSUser.publicDb(userId))
         theShift = Shift.load(db, id)
         if not theShift:
             # then user private
             db = core.connect(SSUser.privateDb(userId))
             theShift = Shift.load(db, id)
     else:
         db = core.connect("shiftspace/public")
         theShift = Shift.load(db, id)
     if userId and not theShift:
         theUser = SSUser.read(userId)
         aShift = Shift.load(core.connect("shiftspace/shared"), id)
         if theUser.canRead(aShift):
             theShift = aShift
     if proxy:
         theShift = Shift.load(core.connect("shiftspace/shared"), id)
     if theShift:
         return Shift.joinData(theShift, theShift.createdBy)
예제 #9
0
 def read(cls, id, userId=None, proxy=False):
     from server.models.ssuser import SSUser
     theShift = None
     # then try the user public
     if userId:
         db = core.connect(SSUser.publicDb(userId))
         theShift = Shift.load(db, id)
         if not theShift:
             # then user private
             db = core.connect(SSUser.privateDb(userId))
             theShift = Shift.load(db, id)
     else:
         db = core.connect("shiftspace/public")
         theShift = Shift.load(db, id)
     if userId and not theShift:
         theUser = SSUser.read(userId)
         aShift = Shift.load(core.connect("shiftspace/shared"), id)
         if theUser.canRead(aShift):
             theShift = aShift
     if proxy:
         theShift = Shift.load(core.connect("shiftspace/shared"), id)
     if theShift:
         return Shift.joinData(theShift, theShift.createdBy)
예제 #10
0
    def publish(self, publishData=None):
        from server.models.ssuser import SSUser
        
        if publishData == None:
            return self
        
        db = core.connect(SSUser.privateDb(self.createdBy))
        dbs = []
        author = SSUser.read(self.createdBy)
        oldPublishData = dict(self.items())["publishData"]
        allowed = []
        
        # get the private status
        isPrivate = True
        if publishData and publishData.get("private") != None:
            isPrivate = publishData.get("private")
        else:
            isPrivate = self.isPrivate()
        
        # get the dbs being published to
        publishDbs = (publishData and publishData.get("dbs")) or []

        # get the list of dbs the user is actually allowed to publish to
        allowed = []
        if (publishData and isPrivate and len(publishDbs) > 0):
            from server.models.group import Group
            allowedGroups = author.writeable()
            allowed = list(set(allowedGroups).intersection(set(publishDbs)))
        
        # upate the private setting, the shift is no longer draft
        self.publishData.private = isPrivate
        self.publishData.draft = False
        
        # publish or update a copy to group/x, group/y, ...
        newGroupDbs = [s for s in allowed if s.split("/")[0] == "group"]
        oldGroupDbs = [s for s in oldPublishData.get("dbs") if s.split("/")[0] == "group"]
        newGroupDbs = list(set(newGroupDbs).difference(set(oldGroupDbs)))
        if newGroupDbs and len(newGroupDbs) > 0:
            dbs.extend(list(set(newGroupDbs)))

        # publish to any user we haven't published to before
        newUserDbs = [s for s in publishDbs if s.split("/")[0] == "user"]
        if newUserDbs and len(newUserDbs) > 0:
            userDbs = list(set(newUserDbs))
            dbs.extend(userDbs)
            self.shareWith([s.split("/")[1] for s in userDbs])

        self.publishData.dbs = dbs
        # store the human readable version
        targets = publishData.get("targets")
        if targets:
            self.publishData.targets = targets

        # update/add to group dbs
        self.updateInGroups(oldGroupDbs)
        self.addToGroups(newGroupDbs)
        
        # if public shift
        # create in user/public, delete from user/private
        # replicate shiftspace/public to shiftspace/shared
        if not isPrivate:
            publicdb = SSUser.publicDb(self.createdBy)
            if Shift.load(core.connect(publicdb), self.id):
                self.updateIn(publicdb)
            else:
                # TODO: copyTo should probably just be store - David
                self.copyTo(publicdb)
                privatedb = core.connect(SSUser.privateDb(self.createdBy))
                del privatedb[self.id]
                # we need to delete the private copy out of shiftspace/shared
                shared = core.connect("shiftspace/shared")
                del shared[self.id]
            # TODO: check that we have to force it in order to have it ready for replication - David
            db = core.connect(publicdb)
            core.replicate(publicdb, "shiftspace/public")
            core.replicate(publicdb, "shiftspace/shared")
        else:
            privatedb = SSUser.privateDb(self.createdBy)
            self.store(core.connect(privatedb))
            core.replicate(privatedb, "shiftspace/shared")
        
        return Shift.joinData(self, self.createdBy)
예제 #11
0
    def publish(self, publishData=None):
        from server.models.ssuser import SSUser

        if publishData == None:
            return self

        db = core.connect(SSUser.privateDb(self.createdBy))
        dbs = []
        author = SSUser.read(self.createdBy)
        oldPublishData = dict(self.items())["publishData"]
        allowed = []

        # get the private status
        isPrivate = True
        if publishData and publishData.get("private") != None:
            isPrivate = publishData.get("private")
        else:
            isPrivate = self.isPrivate()

        # get the dbs being published to
        publishDbs = (publishData and publishData.get("dbs")) or []

        # get the list of dbs the user is actually allowed to publish to
        allowed = []
        if (publishData and isPrivate and len(publishDbs) > 0):
            from server.models.group import Group
            allowedGroups = author.writeable()
            allowed = list(set(allowedGroups).intersection(set(publishDbs)))

        # upate the private setting, the shift is no longer draft
        self.publishData.private = isPrivate
        self.publishData.draft = False

        # publish or update a copy to group/x, group/y, ...
        newGroupDbs = [s for s in allowed if s.split("/")[0] == "group"]
        oldGroupDbs = [
            s for s in oldPublishData.get("dbs") if s.split("/")[0] == "group"
        ]
        newGroupDbs = list(set(newGroupDbs).difference(set(oldGroupDbs)))
        if newGroupDbs and len(newGroupDbs) > 0:
            dbs.extend(list(set(newGroupDbs)))

        # publish to any user we haven't published to before
        newUserDbs = [s for s in publishDbs if s.split("/")[0] == "user"]
        if newUserDbs and len(newUserDbs) > 0:
            userDbs = list(set(newUserDbs))
            dbs.extend(userDbs)
            self.shareWith([s.split("/")[1] for s in userDbs])

        self.publishData.dbs = dbs
        # store the human readable version
        targets = publishData.get("targets")
        if targets:
            self.publishData.targets = targets

        # update/add to group dbs
        self.updateInGroups(oldGroupDbs)
        self.addToGroups(newGroupDbs)

        # if public shift
        # create in user/public, delete from user/private
        # replicate shiftspace/public to shiftspace/shared
        if not isPrivate:
            publicdb = SSUser.publicDb(self.createdBy)
            if Shift.load(core.connect(publicdb), self.id):
                self.updateIn(publicdb)
            else:
                # TODO: copyTo should probably just be store - David
                self.copyTo(publicdb)
                privatedb = core.connect(SSUser.privateDb(self.createdBy))
                del privatedb[self.id]
                # we need to delete the private copy out of shiftspace/shared
                shared = core.connect("shiftspace/shared")
                del shared[self.id]
            # TODO: check that we have to force it in order to have it ready for replication - David
            db = core.connect(publicdb)
            core.replicate(publicdb, "shiftspace/public")
            core.replicate(publicdb, "shiftspace/shared")
        else:
            privatedb = SSUser.privateDb(self.createdBy)
            self.store(core.connect(privatedb))
            core.replicate(privatedb, "shiftspace/shared")

        return Shift.joinData(self, self.createdBy)