2020-06-08 15:40:41 -04:00
|
|
|
from django.contrib.auth.models import Group, User
|
2020-06-03 13:08:04 -04:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
|
|
|
|
from users.models import ObjectPermission
|
|
|
|
from utilities.api import ContentTypeField, SerializedPKRelatedField, ValidatedModelSerializer
|
2018-11-12 11:36:44 -05:00
|
|
|
from .nested_serializers import *
|
2017-03-09 14:26:39 -05:00
|
|
|
|
|
|
|
|
2020-06-03 13:08:04 -04:00
|
|
|
class ObjectPermissionSerializer(ValidatedModelSerializer):
|
|
|
|
object_types = ContentTypeField(
|
|
|
|
queryset=ContentType.objects.all(),
|
|
|
|
many=True
|
|
|
|
)
|
|
|
|
groups = SerializedPKRelatedField(
|
|
|
|
queryset=Group.objects.all(),
|
|
|
|
serializer=NestedGroupSerializer,
|
|
|
|
required=False,
|
|
|
|
many=True
|
|
|
|
)
|
|
|
|
users = SerializedPKRelatedField(
|
|
|
|
queryset=User.objects.all(),
|
|
|
|
serializer=NestedUserSerializer,
|
|
|
|
required=False,
|
|
|
|
many=True
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ObjectPermission
|
2020-07-08 13:34:57 -04:00
|
|
|
fields = ('id', 'name', 'enabled', 'object_types', 'groups', 'users', 'actions', 'constraints')
|