コード例 #1
0
    def test_user_group(self):
        """
        Test the association of access to a group
        """
        # pylint: disable=E1101
        user = User("login", "password")
        group1 = Group('Reader')
        group2 = Group('Writer')

        self.session.add(user)
        self.session.add(group1)
        self.session.add(group2)
        self.session.commit()

        user = self.session.query(User).all()[0]
        self.assertEquals(user.groups, [])

        user.groups.append(group1)
        self.session.commit()
        user = self.session.query(User).all()[0]
        self.assertEquals(user.groups, [group1])

        user.groups.append(group2)
        self.session.commit()
        user = self.session.query(User).all()[0]
        self.assertEquals(user.groups, [group1, group2])

        user.groups.remove(group2)
        self.session.commit()
        user = self.session.query(User).all()[0]
        self.assertEquals(user.groups, [group1])
コード例 #2
0
    def test_group_basic(self):
        """
        Test all access to the bdd for Group
         - Insert
         - Select
         - Update
         - Delete
        """
        # pylint: disable=E1101
        self.session.add(Group("reader"))
        self.session.commit()
        gp1 = self.session.query(Group).filter_by(name="reader").scalar()
        self.assertEquals(gp1.name, "reader")

        self.session.add(Group("Editor"))
        self.session.commit()

        self.assertEquals(self.session.query(Group).count(), 2)

        gp1 = self.session.query(Group).filter_by(name="reader").scalar()
        gp1.name = "Reader"
        self.session.commit()

        gp1 = self.session.query(Group).filter_by(name="Reader").scalar()
        self.assertEquals(gp1.name, "Reader")

        self.session.delete(gp1)
        self.session.commit()

        self.assertEquals(self.session.query(Group).count(), 1)
コード例 #3
0
 def group_delete(self):
     """
     Delete a group
     """
     uid = int(self.request.matchdict.get('uid', -1))
     entry = Group.by_uid(uid)
     if entry:
         # pylint: disable=E1101
         Group.get_session().delete(entry)
         Group.get_session().commit()
     return HTTPFound(location=self.request.route_url('group_list'))
コード例 #4
0
 def __iter__(self):
     """
     Get a iterator of ACL
     """
     for group in Group.all():
         for right in group.rights:
             yield(Allow, group.name, right.name)
コード例 #5
0
 def __iter__(self):
     """
     Get a iterator of ACL
     """
     for group in Group.all():
         for right in group.rights:
             yield (Allow, group.name, right.name)
コード例 #6
0
    def test_group_right(self):
        """
        Test the association of right to a group
        """
        acc1 = Right('read')
        acc2 = Right('write')
        gp1 = Group('Reader')

        # pylint: disable=E1101
        self.session.add(acc1)
        self.session.add(acc2)
        self.session.add(gp1)
        self.session.commit()

        gp1 = self.session.query(Group).filter_by(name="Reader").scalar()
        self.assertEquals(gp1.rights, [])

        gp1.rights.append(acc1)
        self.session.commit()
        gp1 = self.session.query(Group).filter_by(name="Reader").scalar()
        self.assertEquals(gp1.rights, [acc1])

        gp1.rights.append(acc2)
        self.session.commit()
        gp1 = self.session.query(Group).filter_by(name="Reader").scalar()
        self.assertEquals(gp1.rights, [acc1, acc2])

        gp1.rights.remove(acc2)
        self.session.commit()
        gp1 = self.session.query(Group).filter_by(name="Reader").scalar()
        self.assertEquals(gp1.rights, [acc1])
コード例 #7
0
    def group_list(self):
        """
        Get the list of all groups
        """
        new = self.request.matchdict.get('new', False)
        if new:
            new = True
        forms = []
        group_list = Group.all()
        right_list = Right.all()
        if new:
            group_list.append(Group())

        for group in group_list:
            forms.append(GroupForm(self.request.POST, GroupRightAccess(group),
                                   prefix=group.name, request=self.request))

        if self.request.method == 'POST':
            error = False
            session = Group.get_session()
            for k, group in enumerate(group_list):
                try:
                    # pylint: disable=E1101
                    with session.begin_nested():
                        if forms[k].validate():
                            forms[k].populate_obj(GroupRightAccess(group))
                            if group.uid is None:
                                # pylint: disable=E1101
                                session.add(group)
                        else:
                            error = True
                    session.commit()
                except IntegrityError:
                    msg = "Nom déjà existant"
                    errors = forms[k].errors.get('name', [])
                    errors.append(msg)
                    forms[k].errors['name'] = errors
                    error = True
            if not error:
                # pylint: disable=E1101
                return HTTPFound(location=self.request.route_url('group_list'))

        return {'tags' : Tag.all(),
                'title': 'Liste des groupes',
                'right_list': right_list,
                'group_list': group_list,
                'forms': forms}
コード例 #8
0
 def __len__(self):
     """
     Get the number of ACL
     """
     size = 0
     for group in Group.all():
         size += len(group.rights)
     return size
コード例 #9
0
 def __len__(self):
     """
     Get the number of ACL
     """
     size = 0
     for group in Group.all():
         size += len(group.rights)
     return size
コード例 #10
0
    def user_list(self):
        """
        Get the list of all users
        """
        new = self.request.matchdict.get('new', False)
        if new:
            new = True

        user_list = User.all()
        group_list = Group.all()
        forms = []
        if new:
            user_list.append(User())

        for user in user_list:
            forms.append(
                UserForm(self.request.POST,
                         UserGroupAccess(user),
                         prefix=user.login,
                         request=self.request))

        if self.request.method == 'POST':
            error = False
            session = User.get_session()
            for k, user in enumerate(user_list):
                try:
                    # pylint: disable=E1101
                    with session.begin_nested():
                        if forms[k].validate():
                            forms[k].populate_obj(UserGroupAccess(user))
                            if user.uid is None:
                                # pylint: disable=E1101
                                session.add(user)
                        else:
                            error = True
                    session.commit()
                except IntegrityError:
                    errors = forms[k].errors.get('login', [])
                    errors.append("Login déjà existant")
                    forms[k].errors['login'] = errors
                    error = True
            if not error:
                # pylint: disable=E1101
                return HTTPFound(location=self.request.route_url('user_list'))

        return {
            'tags': Tag.all(),
            'title': 'Liste des utilisateurs',
            'user_list': user_list,
            'group_list': group_list,
            'forms': forms
        }
コード例 #11
0
ファイル: user.py プロジェクト: SabatierBoris/CecileWebSite
    def user_list(self):
        """
        Get the list of all users
        """
        new = self.request.matchdict.get('new', False)
        if new:
            new = True

        user_list = User.all()
        group_list = Group.all()
        forms = []
        if new:
            user_list.append(User())

        for user in user_list:
            forms.append(UserForm(self.request.POST, UserGroupAccess(user),
                                  prefix=user.login, request=self.request))

        if self.request.method == 'POST':
            error = False
            session = User.get_session()
            for k, user in enumerate(user_list):
                try:
                    # pylint: disable=E1101
                    with session.begin_nested():
                        if forms[k].validate():
                            forms[k].populate_obj(UserGroupAccess(user))
                            if user.uid is None:
                                # pylint: disable=E1101
                                session.add(user)
                        else:
                            error = True
                    session.commit()
                except IntegrityError:
                    errors = forms[k].errors.get('login', [])
                    errors.append("Login déjà existant")
                    forms[k].errors['login'] = errors
                    error = True
            if not error:
                # pylint: disable=E1101
                return HTTPFound(location=self.request.route_url('user_list'))

        return {'tags' : Tag.all(),
                'title': 'Liste des utilisateurs',
                'user_list': user_list,
                'group_list': group_list,
                'forms': forms}