Skip to content

Commit

Permalink
Add RolesMixin to group view set
Browse files Browse the repository at this point in the history
re #9604
  • Loading branch information
mdellweg committed Dec 9, 2021
1 parent eff385d commit 1e8203f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/9604.feature
@@ -0,0 +1 @@
Added object specific endpoints ``{list,add}_roles``, ``remove_roles`` and ``my_permissions`` to tasks and groups viewsets.
17 changes: 17 additions & 0 deletions pulpcore/app/migrations/0083_alter_group_options.py
@@ -0,0 +1,17 @@
# Generated by Django 3.2.9 on 2021-12-06 16:28

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('core', '0082_add_manage_roles_permissions'),
]

operations = [
migrations.AlterModelOptions(
name='group',
options={'permissions': [('manage_roles_group', 'Can manage role assignments on group')]},
),
]
3 changes: 3 additions & 0 deletions pulpcore/app/models/access_policy.py
Expand Up @@ -307,3 +307,6 @@ class Group(LifecycleModelMixin, BaseGroup, AutoAddObjPermsMixin):

class Meta:
proxy = True
permissions = [
("manage_roles_group", "Can manage role assignments on group"),
]
12 changes: 10 additions & 2 deletions pulpcore/app/viewsets/user.py
Expand Up @@ -19,7 +19,7 @@

from pulpcore.app.models import Group
from pulpcore.app.models.role import GroupRole, Role, UserRole
from pulpcore.app.viewsets import BaseFilterSet, NamedModelViewSet, NAME_FILTER_OPTIONS
from pulpcore.app.viewsets import BaseFilterSet, NamedModelViewSet, RolesMixin, NAME_FILTER_OPTIONS
from pulpcore.app.serializers import (
GroupSerializer,
GroupUserSerializer,
Expand Down Expand Up @@ -107,6 +107,7 @@ class GroupViewSet(
mixins.RetrieveModelMixin,
mixins.ListModelMixin,
mixins.DestroyModelMixin,
RolesMixin,
):
"""
ViewSet for Group.
Expand Down Expand Up @@ -138,7 +139,7 @@ class GroupViewSet(
"condition": "has_model_perms:core.add_group",
},
{
"action": ["retrieve"],
"action": ["retrieve", "my_permissions"],
"principal": "authenticated",
"effect": "allow",
"condition": "has_model_or_obj_perms:core.view_group",
Expand All @@ -155,6 +156,12 @@ class GroupViewSet(
"effect": "allow",
"condition": "has_model_or_obj_perms:core.delete_group",
},
{
"action": ["list_roles", "add_role", "remove_role"],
"principal": "authenticated",
"effect": "allow",
"condition": ["has_model_or_obj_perms:auth.manage_roles_group"],
},
],
"creation_hooks": [
{
Expand All @@ -172,6 +179,7 @@ class GroupViewSet(
"core.view_group",
"core.change_group",
"core.delete_group",
"core.manage_roles_group",
],
"core.group_viewer": [
"core.view_group",
Expand Down

0 comments on commit 1e8203f

Please sign in to comment.