Exemple #1
0
def create_groups(community_name):
    """Create groups for a particular Community instance using its name

    :param community_name: string name of community
    :return: list of community Group objects
    """
    community_groups = []
    for key, group_name in groups_templates.items():
        group, created = Group.objects.get_or_create(
            name=group_name.format(community_name))
        community_groups.append(group)
    return community_groups
Exemple #2
0
def create_groups(community_name):
    """Create groups for a particular Community instance using its name

    :param community_name: string name of community
    :return: list of community Group objects
    """
    community_groups = []
    for key, group_name in groups_templates.items():
        group, created = Group.objects.get_or_create(
            name=group_name.format(community_name))
        community_groups.append(group)
    return community_groups
Exemple #3
0
    def test_create_groups(self):
        """Test the creation of groups according to a name"""
        name = "Foo"
        groups = create_groups(name)
        expected_group_names = []
        for key, group_name in groups_templates.items():
            expected_group_names.append(group_name.format(name))
        group_names = []
        for group in groups:
            group_names.append(group.name)
        self.assertCountEqual(list(expected_group_names), group_names)

        community_groups = Group.objects.filter(name__startswith=name)
        self.assertCountEqual(community_groups, groups)
Exemple #4
0
def assign_permissions(community, groups):
    """Assign row-level permissions to community groups and community object

    :param community: Community object
    :param groups: list of Group objects
    """
    for key, group_name in groups_templates.items():
        group = next(g for g in groups
                     if g.name == group_name.format(community.name))
        for perm in group_permissions[key]:
            if perm.endswith('tag') or perm.endswith('resourcetype'):
                group.permissions.add(Permission.objects.get(codename=perm))
                group.save()
            else:
                assign_perm(perm, group, community)
Exemple #5
0
def assign_permissions(community, groups):
    """Assign row-level permissions to community groups and community object

    :param community: Community object
    :param groups: list of Group objects
    """
    for key, group_name in groups_templates.items():
        group = next(
            g for g in groups if g.name == group_name.format(community.name))
        for perm in group_permissions[key]:
            if perm.endswith('tag') or perm.endswith('resourcetype'):
                group.permissions.add(Permission.objects.get(codename=perm))
                group.save()
            else:
                assign_perm(perm, group, community)
Exemple #6
0
    def test_rename_groups(self):
        """Test the renaming of groups according to a new name"""
        old_name = "Foo"
        new_name = "Bar"
        create_groups(old_name)
        groups = rename_groups(old_name, new_name)
        expected_group_names = []
        for key, group_name in groups_templates.items():
            expected_group_names.append(group_name.format(new_name))
        group_names = []
        for group in groups:
            group_names.append(group.name)
        self.assertCountEqual(expected_group_names, group_names)

        community_groups = Group.objects.filter(name__startswith=new_name)
        self.assertCountEqual(community_groups, groups)
        old_community_groups = Group.objects.filter(name__startswith=old_name)
        self.assertSequenceEqual(old_community_groups, [])