Example #1
0
    def test_by_group_name_wrong_groupname(self, db_session):
        add_group(db_session)
        queried_group = GroupService.by_group_name(
            "not existing group", db_session=db_session
        )

        assert queried_group is None
    def by_group_name(cls, group_name, db_session=None):
        """ fetch group by name

        .. deprecated:: 0.8

        """
        db_session = get_db_session(db_session)
        return GroupService.by_group_name(group_name=group_name,
                                          db_session=db_session)
    def test_resources_with_possible_perms(self, db_session):
        self.set_up_user_group_and_perms(db_session)
        perms = GroupService.resources_with_possible_perms(self.group)
        second = [
            PermissionTuple(
                None, "group_perm", "group", self.group, self.resource, False, True
            )
        ]

        check_one_in_other(perms, second)
    def resources_with_possible_perms(self, perm_names=None, resource_ids=None,
                                      resource_types=None,
                                      db_session=None):
        """

        .. deprecated:: 0.8

        :param perm_names:
        :param resource_ids:
        :param resource_types:
        :param db_session:
        :return:
        """
        db_session = get_db_session(db_session, self)
        return GroupService.resources_with_possible_perms(
            self, perm_names=perm_names, resource_ids=resource_ids,
            resource_types=resource_types, db_session=db_session)
    def get_user_paginator(self, page=1, item_count=None, items_per_page=50,
                           user_ids=None, GET_params=None, db_session=None):
        """

        .. deprecated:: 0.8

        :param page:
        :param item_count:
        :param items_per_page:
        :param user_ids:
        :param GET_params:
        :param db_session:
        :return:
        """
        return GroupService.get_user_paginator(
            self, page=page, item_count=item_count,
            items_per_page=items_per_page,
            user_ids=user_ids, GET_params=GET_params)
Example #6
0
    def test_user_paginator_usernames(self, db_session):
        user1 = add_user(db_session, "user1", "email1")
        user2 = add_user(db_session, "user2", "email2")
        user3 = add_user(db_session, "user3", "email3")

        group = add_group(db_session)
        group.users.append(user1)
        group.users.append(user2)
        group.users.append(user3)

        # TODO: users count when filtering on names?
        paginator = GroupService.get_user_paginator(group, 1, user_ids=[1, 3])

        assert paginator.page == 1
        assert paginator.first_item == 1
        assert paginator.last_item == 2
        assert paginator.items == [user1, user3]
        assert paginator.item_count == 2
        assert paginator.page_count == 1
Example #7
0
    def test_user_paginator(self, db_session):
        user1 = add_user(db_session, "user1", "email1")
        user2 = add_user(db_session, "user2", "email2")

        group = add_group(db_session)
        group.users.append(user1)
        group.users.append(user2)
        users_count = len(group.users)
        get_params = {"foo": "bar", "baz": "xxx"}

        paginator = GroupService.get_user_paginator(
            group, 1, users_count, GET_params=get_params
        )

        assert paginator.page == 1
        assert paginator.first_item == 1
        assert paginator.last_item == 2
        assert paginator.items == [user1, user2]
        assert paginator.items == [user1, user2]
        assert paginator.items == [user1, user2]
        assert paginator.items == [user1, user2]
    def test_resources_with_possible_perms_group2(self, db_session):
        self.set_up_user_group_and_perms(db_session)
        resource3 = add_resource_b(db_session, 3, "other resource")
        self.group2.resources.append(resource3)
        group_permission2 = GroupResourcePermission(
            perm_name="group_perm2", group_id=self.group2.id
        )
        self.resource2.group_permissions.append(group_permission2)

        perms = GroupService.resources_with_possible_perms(self.group2)
        second = [
            PermissionTuple(
                None, "group_perm", "group", self.group2, self.resource, False, True
            ),
            PermissionTuple(
                None, "group_perm2", "group", self.group2, self.resource2, False, True
            ),
            PermissionTuple(
                None, ALL_PERMISSIONS, "group", self.group2, resource3, True, True
            ),
        ]

        check_one_in_other(perms, second)
Example #9
0
 def test_get(self, db_session):
     group1 = add_group(db_session, "group1")
     group = GroupService.get(group_id=group1.id, db_session=db_session)
     assert group.id == group1.id
Example #10
0
    def test_by_group_name(self, db_session):
        added_group = add_group(db_session)
        queried_group = GroupService.by_group_name("group", db_session=db_session)

        assert added_group == queried_group
Example #11
0
def unique_groupname_validator(form, field):
    group = GroupService.by_group_name(field.data)
    mod_group = getattr(form, "_modified_group", None)
    if group and (not mod_group or mod_group.id != group.id):
        raise wtforms.ValidationError(
            "This group name already exists in system")