Пример #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)
Пример #2
0
    def test_groups(self):
        group = Group("sysadmin")
        self.assertEqual("sysadmin", group.groupid)

        self.assertFalse(group.has_role("admin2"))
        group.roles.append("admin2")
        self.assertTrue(group.has_role("admin2"))

        self.assertEqual([], group.users)
        self.assertFalse(group.has_user("keith"))
        self.assertFalse(group.has_user("fred"))
        user = User("keith")
        group.add_user(user)
        self.assertEqual([user], group.users)
        self.assertTrue(group.has_user("keith"))
        self.assertFalse(group.has_user("fred"))

        group.add_user(user)
        self.assertEqual([user], group.users)