jumpserver/apps/perms/serializers.py

54 lines
1.4 KiB
Python
Raw Normal View History

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 = [
'id', 'node', 'user_group', 'system_user',
2018-02-01 09:14:15 +00:00
'is_active', 'date_expired'
]
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)
2018-02-01 09:14:15 +00:00
class Meta:
model = NodePermission
fields = '__all__'
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