You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jumpserver/apps/perms/serializers.py

48 lines
1.3 KiB

8 years ago
# -*- coding: utf-8 -*-
#
from rest_framework import serializers
from .models import AssetPermission
from common.fields import StringManyToManyField
8 years ago
7 years ago
class AssetPermissionCreateUpdateSerializer(serializers.ModelSerializer):
8 years ago
class Meta:
model = AssetPermission
exclude = ('created_by', 'date_created')
7 years ago
class AssetPermissionListSerializer(serializers.ModelSerializer):
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()
7 years ago
class Meta:
model = AssetPermission
7 years ago
fields = '__all__'
@staticmethod
def get_inherit(obj):
if hasattr(obj, 'inherit'):
return obj.inherit
else:
return None
class AssetPermissionUpdateUserSerializer(serializers.ModelSerializer):
class Meta:
model = AssetPermission
fields = ['id', 'users']
class AssetPermissionUpdateAssetSerializer(serializers.ModelSerializer):
class Meta:
model = AssetPermission
fields = ['id', 'assets']