mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
from django.contrib.auth.models import Group
|
|
from django.contrib.auth.models import Permission
|
|
from django.contrib.auth.models import User
|
|
from rest_framework import serializers
|
|
|
|
|
|
class UserSerializer(serializers.ModelSerializer):
|
|
|
|
groups = serializers.SlugRelatedField(
|
|
many=True,
|
|
queryset=Group.objects.all(),
|
|
slug_field="name",
|
|
)
|
|
user_permissions = serializers.SlugRelatedField(
|
|
many=True,
|
|
queryset=Permission.objects.all(),
|
|
slug_field="codename",
|
|
)
|
|
inherited_permissions = serializers.SerializerMethodField()
|
|
|
|
class Meta:
|
|
model = User
|
|
fields = (
|
|
"id",
|
|
"username",
|
|
"first_name",
|
|
"last_name",
|
|
"date_joined",
|
|
"is_staff",
|
|
"is_active",
|
|
"is_superuser",
|
|
"groups",
|
|
"user_permissions",
|
|
"inherited_permissions",
|
|
)
|
|
|
|
def get_inherited_permissions(self, obj):
|
|
return obj.get_group_permissions()
|
|
|
|
|
|
class GroupSerializer(serializers.ModelSerializer):
|
|
|
|
permissions = serializers.SlugRelatedField(
|
|
many=True,
|
|
queryset=Permission.objects.all(),
|
|
slug_field="codename",
|
|
)
|
|
|
|
class Meta:
|
|
model = Group
|
|
fields = (
|
|
"id",
|
|
"name",
|
|
"permissions",
|
|
)
|