2018-02-07 15:25:15 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2019-05-21 08:24:01 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2018-03-27 10:34:41 +00:00
|
|
|
|
2021-07-08 06:23:18 +00:00
|
|
|
from ..models import SystemUser
|
2019-08-21 12:27:21 +00:00
|
|
|
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
2018-02-07 15:25:15 +00:00
|
|
|
|
2021-07-08 06:23:18 +00:00
|
|
|
from .base import AuthSerializerMixin
|
2018-03-27 10:34:41 +00:00
|
|
|
|
2018-02-07 15:25:15 +00:00
|
|
|
|
2019-07-08 07:35:20 +00:00
|
|
|
class AdminUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
2018-02-07 15:25:15 +00:00
|
|
|
"""
|
|
|
|
管理用户
|
|
|
|
"""
|
|
|
|
|
|
|
|
class Meta:
|
2021-07-08 06:23:18 +00:00
|
|
|
model = SystemUser
|
|
|
|
fields_mini = ['id', 'name', 'username']
|
2021-04-29 11:10:45 +00:00
|
|
|
fields_write_only = ['password', 'private_key', 'public_key']
|
|
|
|
fields_small = fields_mini + fields_write_only + [
|
|
|
|
'date_created', 'date_updated',
|
|
|
|
'comment', 'created_by'
|
2019-05-21 08:24:01 +00:00
|
|
|
]
|
2021-04-29 11:10:45 +00:00
|
|
|
fields_fk = ['assets_amount']
|
|
|
|
fields = fields_small + fields_fk
|
2019-07-12 10:31:55 +00:00
|
|
|
read_only_fields = ['date_created', 'date_updated', 'created_by', 'assets_amount']
|
2019-05-21 08:24:01 +00:00
|
|
|
|
|
|
|
extra_kwargs = {
|
2021-03-15 10:51:21 +00:00
|
|
|
'username': {"required": True},
|
2019-06-25 06:32:25 +00:00
|
|
|
'password': {"write_only": True},
|
|
|
|
'private_key': {"write_only": True},
|
|
|
|
'public_key': {"write_only": True},
|
2019-06-24 06:23:29 +00:00
|
|
|
'assets_amount': {'label': _('Asset')},
|
2019-05-21 08:24:01 +00:00
|
|
|
}
|
2018-02-07 15:25:15 +00:00
|
|
|
|
2021-07-08 06:23:18 +00:00
|
|
|
def create(self, validated_data):
|
|
|
|
data = {k: v for k, v in validated_data.items()}
|
|
|
|
data['protocol'] = 'ssh'
|
|
|
|
data['type'] = SystemUser.Type.admin
|
|
|
|
return super().create(data)
|