-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move RBAC docs to proper place Start on views with RoleDefinition first Fix summary_fields that I broke
- Loading branch information
1 parent
9436a1c
commit 858d130
Showing
7 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...base/rbac/migrations/0002_roledefinition_created_by_roledefinition_created_on_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Generated by Django 4.2.8 on 2024-01-23 02:11 | ||
|
||
import django.db.models.deletion | ||
import django.utils.timezone | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('dab_rbac', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='roledefinition', | ||
name='created_by', | ||
field=models.ForeignKey( | ||
default=None, editable=False, | ||
help_text='The user who created this resource', | ||
null=True, on_delete=django.db.models.deletion.DO_NOTHING, | ||
related_name='%(app_label)s_%(class)s_created+', to=settings.AUTH_USER_MODEL | ||
), | ||
), | ||
migrations.AddField( | ||
model_name='roledefinition', | ||
name='created_on', | ||
field=models.DateTimeField(default=django.utils.timezone.now, editable=False, help_text='The date/time this resource was created'), | ||
preserve_default=False | ||
), | ||
migrations.AddField( | ||
model_name='roledefinition', | ||
name='modified_by', | ||
field=models.ForeignKey( | ||
default=None, editable=False, | ||
help_text='The user who last modified this resource', null=True, | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
related_name='%(app_label)s_%(class)s_modified+', | ||
to=settings.AUTH_USER_MODEL | ||
), | ||
), | ||
migrations.AddField( | ||
model_name='roledefinition', | ||
name='modified_on', | ||
field=models.DateTimeField(default=django.utils.timezone.now, editable=False, help_text='The date/time this resource was created'), | ||
preserve_default=False | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from rest_framework.routers import SimpleRouter | ||
|
||
from ansible_base.rbac import views | ||
|
||
router = SimpleRouter() | ||
|
||
router.register(r'role_definitions', views.RoleDefinitionViewSet) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from rest_framework import serializers | ||
|
||
from ansible_base.lib.serializers.common import CommonModelSerializer | ||
from ansible_base.rbac.models import RoleDefinition | ||
from ansible_base.rbac.permission_registry import permission_registry # careful for circular imports | ||
|
||
|
||
class RoleDefinitionSerializer(CommonModelSerializer): | ||
reverse_url_name = 'roledefinition-detail' | ||
permissions = serializers.SlugRelatedField(many=True, slug_field='codename', queryset=permission_registry.permission_model.objects.all()) | ||
|
||
class Meta: | ||
model = RoleDefinition | ||
fields = '__all__' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.urls import include, path | ||
|
||
from ansible_base.rbac.router import router | ||
|
||
api_version_urls = [ | ||
path('', include(router.urls)), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from rest_framework import permissions | ||
from rest_framework.viewsets import ModelViewSet | ||
|
||
from ansible_base.rbac.models import RoleDefinition | ||
from ansible_base.rbac.serializers import RoleDefinitionSerializer | ||
|
||
|
||
class RoleDefinitionViewSet(ModelViewSet): | ||
""" | ||
As per docs, RoleDefinition is interacted with like a normal model. | ||
""" | ||
|
||
queryset = RoleDefinition.objects.all() | ||
serializer_class = RoleDefinitionSerializer | ||
permission_classes = [permissions.IsAuthenticated] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters