2016-10-19 11:30:55 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
|
2016-11-10 08:59:50 +00:00
|
|
|
from rest_framework import serializers
|
2018-04-08 12:02:40 +00:00
|
|
|
from .models import AssetPermission
|
2018-04-10 12:29:06 +00:00
|
|
|
from common.fields import StringManyToManyField
|
2016-11-04 10:33:16 +00:00
|
|
|
|
|
|
|
|
2018-02-01 09:14:15 +00:00
|
|
|
class AssetPermissionCreateUpdateSerializer(serializers.ModelSerializer):
|
2016-11-04 10:33:16 +00:00
|
|
|
class Meta:
|
2018-04-08 12:02:40 +00:00
|
|
|
model = AssetPermission
|
2018-05-04 06:54:58 +00:00
|
|
|
exclude = ('created_by', 'date_created')
|
2017-12-19 11:38:09 +00:00
|
|
|
|
|
|
|
|
2018-02-01 09:14:15 +00:00
|
|
|
class AssetPermissionListSerializer(serializers.ModelSerializer):
|
2018-04-10 12:29:06 +00:00
|
|
|
users = StringManyToManyField(many=True, read_only=True)
|
|
|
|
user_groups = StringManyToManyField(many=True, read_only=True)
|
|
|
|
assets = StringManyToManyField(many=True, read_only=True)
|
|
|
|
nodes = StringManyToManyField(many=True, read_only=True)
|
|
|
|
system_users = StringManyToManyField(many=True, read_only=True)
|
|
|
|
inherit = serializers.SerializerMethodField()
|
|
|
|
|
2018-02-01 09:14:15 +00:00
|
|
|
class Meta:
|
2018-04-08 12:02:40 +00:00
|
|
|
model = AssetPermission
|
2018-02-01 09:14:15 +00:00
|
|
|
fields = '__all__'
|
2017-12-19 11:38:09 +00:00
|
|
|
|
2018-04-10 12:29:06 +00:00
|
|
|
@staticmethod
|
|
|
|
def get_inherit(obj):
|
|
|
|
if hasattr(obj, 'inherit'):
|
|
|
|
return obj.inherit
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2017-12-19 11:38:09 +00:00
|
|
|
|
|
|
|
class AssetPermissionUpdateUserSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = AssetPermission
|
|
|
|
fields = ['id', 'users']
|
|
|
|
|
|
|
|
|
|
|
|
class AssetPermissionUpdateAssetSerializer(serializers.ModelSerializer):
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = AssetPermission
|
|
|
|
fields = ['id', 'assets']
|
|
|
|
|