2020-10-21 11:32:27 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
from rest_framework import serializers
|
|
|
|
|
|
|
|
from common.mixins import BulkSerializerMixin
|
2021-01-01 23:25:23 +00:00
|
|
|
from common.drf.serializers import AdaptedBulkListSerializer
|
2020-10-22 10:13:14 +00:00
|
|
|
from perms.models import ApplicationPermission
|
2020-10-21 11:32:27 +00:00
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
'ApplicationPermissionUserRelationSerializer',
|
|
|
|
'ApplicationPermissionUserGroupRelationSerializer',
|
|
|
|
'ApplicationPermissionApplicationRelationSerializer',
|
2020-10-22 09:05:47 +00:00
|
|
|
'ApplicationPermissionSystemUserRelationSerializer',
|
|
|
|
'ApplicationPermissionAllApplicationSerializer',
|
|
|
|
'ApplicationPermissionAllUserSerializer'
|
2020-10-21 11:32:27 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class RelationMixin(BulkSerializerMixin, serializers.Serializer):
|
|
|
|
applicationpermission_display = serializers.ReadOnlyField()
|
|
|
|
|
|
|
|
def get_field_names(self, declared_fields, info):
|
|
|
|
fields = super().get_field_names(declared_fields, info)
|
|
|
|
fields.extend(['applicationpermission', "applicationpermission_display"])
|
|
|
|
return fields
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
list_serializer_class = AdaptedBulkListSerializer
|
|
|
|
|
|
|
|
|
|
|
|
class ApplicationPermissionUserRelationSerializer(RelationMixin, serializers.ModelSerializer):
|
|
|
|
user_display = serializers.ReadOnlyField()
|
|
|
|
|
|
|
|
class Meta(RelationMixin.Meta):
|
|
|
|
model = ApplicationPermission.users.through
|
|
|
|
fields = [
|
|
|
|
'id', 'user', 'user_display',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class ApplicationPermissionUserGroupRelationSerializer(RelationMixin, serializers.ModelSerializer):
|
|
|
|
usergroup_display = serializers.ReadOnlyField()
|
|
|
|
|
|
|
|
class Meta(RelationMixin.Meta):
|
|
|
|
model = ApplicationPermission.user_groups.through
|
|
|
|
fields = [
|
|
|
|
'id', 'usergroup', "usergroup_display",
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class ApplicationPermissionApplicationRelationSerializer(RelationMixin, serializers.ModelSerializer):
|
|
|
|
application_display = serializers.ReadOnlyField()
|
|
|
|
|
|
|
|
class Meta(RelationMixin.Meta):
|
|
|
|
model = ApplicationPermission.applications.through
|
|
|
|
fields = [
|
|
|
|
'id', "application", "application_display",
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class ApplicationPermissionSystemUserRelationSerializer(RelationMixin, serializers.ModelSerializer):
|
|
|
|
systemuser_display = serializers.ReadOnlyField()
|
|
|
|
|
|
|
|
class Meta(RelationMixin.Meta):
|
|
|
|
model = ApplicationPermission.system_users.through
|
|
|
|
fields = [
|
|
|
|
'id', 'systemuser', 'systemuser_display'
|
|
|
|
]
|
|
|
|
|
2020-10-22 09:05:47 +00:00
|
|
|
|
|
|
|
class ApplicationPermissionAllApplicationSerializer(serializers.Serializer):
|
|
|
|
application = serializers.UUIDField(read_only=True, source='id')
|
|
|
|
application_display = serializers.SerializerMethodField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
only_fields = ['id', 'name']
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_application_display(obj):
|
|
|
|
return str(obj)
|
|
|
|
|
|
|
|
|
|
|
|
class ApplicationPermissionAllUserSerializer(serializers.Serializer):
|
|
|
|
user = serializers.UUIDField(read_only=True, source='id')
|
|
|
|
user_display = serializers.SerializerMethodField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
only_fields = ['id', 'username', 'name']
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_user_display(obj):
|
|
|
|
return str(obj)
|