2020-10-22 10:13:14 +00:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
from rest_framework import serializers
|
2020-11-02 02:24:05 +00:00
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2020-10-22 10:13:14 +00:00
|
|
|
|
|
|
|
|
|
from assets.models import SystemUser
|
|
|
|
|
from applications.models import Application
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
|
'ApplicationGrantedSerializer',
|
|
|
|
|
'ApplicationSystemUserSerializer'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ApplicationSystemUserSerializer(serializers.ModelSerializer):
|
|
|
|
|
"""
|
|
|
|
|
查看授权的应用系统用户的数据结构,这个和SystemUserSerializer不同,字段少
|
|
|
|
|
"""
|
|
|
|
|
class Meta:
|
|
|
|
|
model = SystemUser
|
|
|
|
|
only_fields = (
|
|
|
|
|
'id', 'name', 'username', 'priority', 'protocol', 'login_mode'
|
|
|
|
|
)
|
|
|
|
|
fields = list(only_fields)
|
|
|
|
|
read_only_fields = fields
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ApplicationGrantedSerializer(serializers.ModelSerializer):
|
|
|
|
|
"""
|
|
|
|
|
被授权应用的数据结构
|
|
|
|
|
"""
|
2020-11-02 02:24:05 +00:00
|
|
|
|
category_display = serializers.ReadOnlyField(source='get_category_display', label=_('Category'))
|
|
|
|
|
type_display = serializers.ReadOnlyField(source='get_type_display', label=_('Type'))
|
|
|
|
|
|
2020-10-22 10:13:14 +00:00
|
|
|
|
class Meta:
|
|
|
|
|
model = Application
|
|
|
|
|
only_fields = [
|
2020-11-05 03:23:32 +00:00
|
|
|
|
'id', 'name', 'domain', 'category', 'type', 'attrs', 'comment', 'org_id'
|
2020-10-22 10:13:14 +00:00
|
|
|
|
]
|
2020-11-02 02:24:05 +00:00
|
|
|
|
fields = only_fields + ['category_display', 'type_display', 'org_name']
|
2020-10-22 10:13:14 +00:00
|
|
|
|
read_only_fields = fields
|