2016-10-19 11:30:55 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
|
2016-11-10 08:59:50 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from rest_framework import serializers
|
|
|
|
from common.utils import get_object_or_none
|
2018-02-01 09:14:15 +00:00
|
|
|
from common.fields import StringIDField
|
|
|
|
from .models import AssetPermission, NodePermission
|
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-02-01 09:14:15 +00:00
|
|
|
model = NodePermission
|
|
|
|
fields = [
|
|
|
|
'node', 'user_group', 'system_user',
|
|
|
|
'is_active', 'date_expired'
|
|
|
|
]
|
2017-12-19 11:38:09 +00:00
|
|
|
|
|
|
|
|
2018-02-01 09:14:15 +00:00
|
|
|
class AssetPermissionListSerializer(serializers.ModelSerializer):
|
|
|
|
node = StringIDField(read_only=True)
|
|
|
|
user_group = StringIDField(read_only=True)
|
|
|
|
system_user = StringIDField(read_only=True)
|
2017-12-19 11:38:09 +00:00
|
|
|
|
2018-02-01 09:14:15 +00:00
|
|
|
class Meta:
|
|
|
|
model = NodePermission
|
|
|
|
fields = '__all__'
|
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']
|
|
|
|
|
2016-11-10 08:59:50 +00:00
|
|
|
|
2018-02-01 09:14:15 +00:00
|
|
|
class UserAssetPermissionCreateUpdateSerializer(AssetPermissionCreateUpdateSerializer):
|
2016-11-10 08:59:50 +00:00
|
|
|
is_inherited = serializers.SerializerMethodField()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_is_inherited(obj):
|
|
|
|
if getattr(obj, 'inherited', ''):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|