Beispiel #1
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)
Beispiel #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)
Beispiel #3
0
    def create(cls, userId, groupId, otherId, level):
        from server.models.ssuser import SSUser
        from server.models.group import Group

        db = core.connect()
        if not groupId:
            raise MissingGroupError
        if not userId:
            raise MissingCreatorError
        if Permission.readByUserAndGroup(otherId, groupId):
            raise PermissionAlreadyExistsError

        adminable = [row.value for row in Permission.by_adminable(db, key=userId).rows]
        allowed = groupId in adminable
        if not allowed:
            theUser = SSUser.read(userId)
            allowed = theUser.isAdmin()
        if not allowed:
            theGroup = Group.read(groupId)
            allowed = theUser.isOwnerOf(theGroup)
        if not allowed:
            raise CreateEventPermissionError

        json = {
            "createdBy": userId,
            "userId": otherId,
            "groupId": groupId,
            "level": level
            }

        newPermission = Permission(**utils.clean(json))
        newPermission.store(db)
        return newPermission
Beispiel #4
0
 def addToGroups(self, groupDbs):
     from server.models.group import Group
     # NOTE - do we need to delete from user/private? - David 11/12/09
     for db in groupDbs:
         dbtype, dbid = db.split("/")
         theGroup = Group.read(dbid)
         theGroup.addShift(self)
Beispiel #5
0
 def addToGroups(self, groupDbs):
     from server.models.group import Group
     # NOTE - do we need to delete from user/private? - David 11/12/09
     for db in groupDbs:
         dbtype, dbid = db.split("/")
         theGroup = Group.read(dbid)
         theGroup.addShift(self)
Beispiel #6
0
    def create(cls, userId, groupId, otherId, level):
        from server.models.ssuser import SSUser
        from server.models.group import Group

        db = core.connect()
        if not groupId:
            raise MissingGroupError
        if not userId:
            raise MissingCreatorError
        if Permission.readByUserAndGroup(otherId, groupId):
            raise PermissionAlreadyExistsError

        adminable = [
            row.value for row in Permission.by_adminable(db, key=userId).rows
        ]
        allowed = groupId in adminable
        if not allowed:
            theUser = SSUser.read(userId)
            allowed = theUser.isAdmin()
        if not allowed:
            theGroup = Group.read(groupId)
            allowed = theUser.isOwnerOf(theGroup)
        if not allowed:
            raise CreateEventPermissionError

        json = {
            "createdBy": userId,
            "userId": otherId,
            "groupId": groupId,
            "level": level
        }

        newPermission = Permission(**utils.clean(json))
        newPermission.store(db)
        return newPermission
Beispiel #7
0
 def members(self, id):
     from server.models.ssuser import SSUser
     theGroup = Group.read(id)
     loggedInUser = helper.getLoggedInUser()
     theUser = SSUser.read(loggedInUser)
     if theUser.isAdminOf(theGroup):
         return data(theGroup.members())
     else:
         return error("You don't have permission to view this groups members", PermissionError)
Beispiel #8
0
 def join(self, id):
     from server.models.ssuser import SSUser
     theGroup = Group.read(id)
     loggedInUser = helper.getLoggedInUser()
     theUser = SSUser.read(loggedInUser)
     if theUser.canJoin(theGroup):
         theUser.join(theGroup)
         return data(theGroup)
     else:
         return error("Operation not permitted. You don't have permission to join this group.", PermissionError)
Beispiel #9
0
 def makeAdmin(self, id, userId):
     from server.models.ssuser import SSUser
     theGroup = Group.read(id)
     theUser = SSUser.read(helper.getLoggedInUser())
     if theUser.isAdminOf(theGroup):
         otherUser = SSUser.read(userId)
         theGroup.setPrivilege(otherUser, 3)
         return ack
     else:
         return error("You don't have permission to promote members of this group to admin.", PermissionError)
Beispiel #10
0
 def inviteUsers(self, id, users):
     from server.models.ssuser import SSUser
     loggedInUser = helper.getLoggedInUser()
     groupAdmin = SSUser.read(loggedInUser)
     theGroup = Group.read(id)
     if groupAdmin.isAdminOf(theGroup):
         db = core.connect()
         users = SSUser.all(db, keys=json.loads(users))
         for user in users:
             groupAdmin.inviteUser(theGroup, user)
         return data(theGroup)
     else:
         return error("Operation not permitted. You don't have permission to modify this group", PermissionError)
Beispiel #11
0
 def update(self, id):
     from server.models.ssuser import SSUser
     loggedInUser = helper.getLoggedInUser()
     theUser = SSUser.read(loggedInUser)
     theGroup = Group.read(id)
     jsonData = helper.getRequestBody()
     if jsonData != "":
         if theUser.isAdminOf(theGroup):
             groupData = json.loads(jsonData)
             return data(theGroup.update(groupData))
         else:
             return error("You don't have permission to update this group", PermissionError)
     else:
         return error("No data for group.", NoDataError)
Beispiel #12
0
 def info(self, id):
     from server.models.ssuser import SSUser
     # TODO: bulk call - David 12/13/2009
     theGroup = Group.read(id)
     memberCount = theGroup.memberCount()
     adminCount = theGroup.adminCount()
     shiftCount = theGroup.shiftCount()
     info = {
         "memberCount": memberCount,
         "adminCount": adminCount,
         "shiftCount": shiftCount
         }
     theUser = SSUser.read(helper.getLoggedInUser())
     info["isAdmin"] = theUser.isAdminOf(theGroup)
     return data(info)
Beispiel #13
0
 def updateInGroups(self, groupDbs):
     from server.models.group import Group
     for db in groupDbs:
         dbtype, dbid = db.split("/")
         theGroup = Group.read(dbid)
         theGroup.updateShift(self)
Beispiel #14
0
 def read(self, id):
     # return only public groups
     theGroup = Group.read(id)
     return data(theGroup)
Beispiel #15
0
 def updateInGroups(self, groupDbs):
     from server.models.group import Group
     for db in groupDbs:
         dbtype, dbid = db.split("/")
         theGroup = Group.read(dbid)
         theGroup.updateShift(self)