Exemplo n.º 1
0
    def __permissions_query(self, ctx, session):
        """
        get all the parts to build a query to get only the group which the user can have access
        """
        join_tables = [[
            self.users, False, self.users.c.id == self.groups.c.FK_users
        ],
                       [
                           self.shareGroup, True,
                           self.groups.c.id == self.shareGroup.c.FK_groups
                       ]]
        filters = None

        if ctx.userid <> 'root':
            # Filter on user groups
            user_id = self.__getOrCreateUser(ctx)
            filters = [
                self.users.c.login == ctx.userid,
                self.shareGroup.c.FK_users == user_id
            ]

            # get all usergroups ids
            ug_ids = []
            for user in self.__getUsers(getUserGroups(ctx.userid), 1, session):
                ug_ids.append(user.id)
            if ug_ids:
                filters.append(self.shareGroup.c.FK_users.in_(ug_ids))

            filters = or_(*filters)

        return (join_tables, filters)
Exemplo n.º 2
0
    def __getGroupInSessionFirstStep(self, ctx, session, ro = False):
        """
        return the query on groups, filtered on the context
        ie : only the group you can have access!
        """
        user_id = self.__getOrCreateUser(ctx)
        ug_ids = map(lambda x: x.id, self.__getUsers(getUserGroups(ctx.userid), 1, session)) # get all usergroups ids

        group = session.query(Groups).select_from(self.groups.join(self.users, self.groups.c.FK_users == self.users.c.id).outerjoin(self.shareGroup, self.groups.c.id == self.shareGroup.c.FK_groups))
        if ctx.userid == 'root' or ro:
            return group
        return group.filter(or_(self.users.c.login == ctx.userid, self.shareGroup.c.FK_users == user_id, self.shareGroup.c.FK_users.in_(ug_ids)))
Exemplo n.º 3
0
    def __getGroupInSessionFirstStep(self, ctx, session, ro=False):
        """
        return the query on groups, filtered on the context
        ie : only the group you can have access!
        """
        user_id = self.__getOrCreateUser(ctx)
        ug_ids = map(lambda x: x.id,
                     self.__getUsers(getUserGroups(ctx.userid), 1,
                                     session))  # get all usergroups ids

        group = session.query(Groups).select_from(
            self.groups.join(
                self.users,
                self.groups.c.FK_users == self.users.c.id).outerjoin(
                    self.shareGroup,
                    self.groups.c.id == self.shareGroup.c.FK_groups))
        if ctx.userid == 'root' or ro:
            return group
        return group.filter(
            or_(self.users.c.login == ctx.userid,
                self.shareGroup.c.FK_users == user_id,
                self.shareGroup.c.FK_users.in_(ug_ids)))
Exemplo n.º 4
0
    def __permissions_query(self, ctx, session):
        """
        get all the parts to build a query to get only the group which the user can have access
        """
        join_tables = [[self.users, False, self.users.c.id==self.groups.c.FK_users], 
                       [self.shareGroup, True, self.groups.c.id==self.shareGroup.c.FK_groups]]
        filters = None

        if ctx.userid<>'root':
            # Filter on user groups
            user_id = self.__getOrCreateUser(ctx)
            filters = [ self.users.c.login==ctx.userid, 
                        self.shareGroup.c.FK_users==user_id ]

            # get all usergroups ids
            ug_ids = []
            for user in self.__getUsers(getUserGroups(ctx.userid), 1, session):
                ug_ids.append(user.id)            
            if ug_ids:
                filters.append(self.shareGroup.c.FK_users.in_(ug_ids))

            filters = or_(*filters)

        return (join_tables, filters)