Ejemplo n.º 1
0
    def load_usergroups(self, usersgroupsauthorisor):

        dbusers = self._storage_engine.session.query(AuthoriseUser)
        for dbuser in dbusers:
            user = User(dbuser.name)
            dbuserroles = self._storage_engine.session.query(UserRole).filter(
                UserRole.user == dbuser.name)
            for dbuserrole in dbuserroles:
                user.add_role(dbuserrole.role)
            dbusergroups = self._storage_engine.session.query(
                UserGroup).filter(UserGroup.user == dbuser.name)
            for dbusergroup in dbusergroups:
                user.add_group(dbusergroup.group)
            usersgroupsauthorisor.users[user.userid] = user

        groups = self._storage_engine.session.query(AuthoriseGroup)
        for dbgroup in groups:
            group = Group(dbgroup.name)
            groupusers = self._storage_engine.session.query(GroupUser).filter(
                GroupUser.group == dbgroup.name)
            for dbgroupuser in groupusers:
                group.add_user(dbgroupuser.user)
            groupgroups = self._storage_engine.session.query(
                GroupGroup).filter(GroupGroup.group == dbgroup.name)
            for dbgroupgroup in groupgroups:
                group.add_group(dbgroupgroup.subgroup)
            grouproles = self._storage_engine.session.query(GroupRole).filter(
                GroupRole.group == dbgroup.name)
            for dbgrouprole in grouproles:
                group.add_role(dbgrouprole.role)
            usersgroupsauthorisor.groups[group.groupid] = group

        self._combine_users_and_groups(usersgroupsauthorisor)
Ejemplo n.º 2
0
    def combine_users_and_groups(self, usergroups):

        for user_id in usergroups.users.keys():
            user = usergroups.users[user_id]

            new_groups = []
            for group_id in user.groups:
                if group_id in usergroups.groups:
                    group = usergroups.groups[group_id]
                    new_groups.append(group)
                else:
                    YLogger.error(self, "Unknown group id [%s] in user [%s]", group_id, user_id)
            user.add_groups(new_groups[:])

        for group_id in usergroups.groups.keys():
            group = usergroups.groups[group_id]

            new_groups = []
            for sub_group_id in group.groups:
                if sub_group_id in usergroups.groups:
                    new_group = usergroups.groups[sub_group_id]
                    new_groups.append(new_group)
                else:
                    YLogger.error(self, "Unknown group id [%s] in group [%s]", sub_group_id, group_id)
            group.add_groups(new_groups[:])

            for sub_user_id in group.users:
                if sub_user_id not in usergroups.users:
                    new_user = User(sub_user_id)
                    for role in group.roles:
                        new_user.add_role(role)
                    usergroups.users[new_user.userid] = new_user
                else:
                    YLogger.error(self, "Duplicate user id [%s] in group [%s]", sub_user_id, group_id)