2018-02-07 15:25:15 +00:00
|
|
|
|
from rest_framework import serializers
|
2019-05-21 08:24:01 +00:00
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2020-03-12 08:24:38 +00:00
|
|
|
|
from django.db.models import Count
|
2019-05-21 08:24:01 +00:00
|
|
|
|
|
2019-12-05 07:09:25 +00:00
|
|
|
|
from common.mixins.serializers import BulkSerializerMixin
|
2019-08-01 09:10:02 +00:00
|
|
|
|
from common.utils import ssh_pubkey_gen
|
2021-12-20 10:24:16 +00:00
|
|
|
|
from common.validators import alphanumeric_re, alphanumeric_cn_re, alphanumeric_win_re
|
2019-08-21 12:27:21 +00:00
|
|
|
|
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
2020-03-12 08:24:38 +00:00
|
|
|
|
from ..models import SystemUser, Asset
|
2021-07-23 08:41:02 +00:00
|
|
|
|
from .utils import validate_password_contains_left_double_curly_bracket
|
2020-03-12 08:24:38 +00:00
|
|
|
|
from .base import AuthSerializerMixin
|
2018-02-07 15:25:15 +00:00
|
|
|
|
|
2019-12-05 07:09:25 +00:00
|
|
|
|
__all__ = [
|
2021-09-12 13:00:51 +00:00
|
|
|
|
'SystemUserSerializer', 'MiniSystemUserSerializer',
|
2019-12-05 07:09:25 +00:00
|
|
|
|
'SystemUserSimpleSerializer', 'SystemUserAssetRelationSerializer',
|
2020-03-12 08:24:38 +00:00
|
|
|
|
'SystemUserNodeRelationSerializer', 'SystemUserTaskSerializer',
|
|
|
|
|
'SystemUserUserRelationSerializer', 'SystemUserWithAuthInfoSerializer',
|
2021-09-09 08:04:54 +00:00
|
|
|
|
'SystemUserTempAuthSerializer', 'RelationMixin',
|
2019-12-05 07:09:25 +00:00
|
|
|
|
]
|
|
|
|
|
|
2018-02-07 15:25:15 +00:00
|
|
|
|
|
2019-07-08 07:35:20 +00:00
|
|
|
|
class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
2018-02-07 15:25:15 +00:00
|
|
|
|
"""
|
|
|
|
|
系统用户
|
|
|
|
|
"""
|
2019-07-08 07:35:20 +00:00
|
|
|
|
auto_generate_key = serializers.BooleanField(initial=True, required=False, write_only=True)
|
2021-07-14 08:22:27 +00:00
|
|
|
|
type_display = serializers.ReadOnlyField(source='get_type_display', label=_('Type display'))
|
2021-07-13 08:57:23 +00:00
|
|
|
|
ssh_key_fingerprint = serializers.ReadOnlyField(label=_('SSH key fingerprint'))
|
2021-10-25 08:23:53 +00:00
|
|
|
|
applications_amount = serializers.IntegerField(
|
|
|
|
|
source='apps_amount', read_only=True, label=_('Apps amount')
|
|
|
|
|
)
|
2018-02-07 15:25:15 +00:00
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
model = SystemUser
|
2021-04-29 11:10:45 +00:00
|
|
|
|
fields_mini = ['id', 'name', 'username']
|
2021-12-30 02:47:46 +00:00
|
|
|
|
fields_write_only = ['password', 'public_key', 'private_key', 'passphrase']
|
2021-04-29 11:10:45 +00:00
|
|
|
|
fields_small = fields_mini + fields_write_only + [
|
2021-09-09 08:04:54 +00:00
|
|
|
|
'token', 'ssh_key_fingerprint',
|
|
|
|
|
'type', 'type_display', 'protocol', 'is_asset_protocol',
|
|
|
|
|
'login_mode', 'login_mode_display', 'priority',
|
|
|
|
|
'sudo', 'shell', 'sftp_root', 'home', 'system_groups', 'ad_domain',
|
2021-04-29 11:10:45 +00:00
|
|
|
|
'username_same_with_user', 'auto_push', 'auto_generate_key',
|
2021-11-05 08:11:29 +00:00
|
|
|
|
'su_enabled', 'su_from',
|
2021-09-09 08:04:54 +00:00
|
|
|
|
'date_created', 'date_updated', 'comment', 'created_by',
|
2019-05-21 08:24:01 +00:00
|
|
|
|
]
|
2021-10-25 06:58:59 +00:00
|
|
|
|
fields_m2m = ['cmd_filters', 'assets_amount', 'applications_amount', 'nodes']
|
2021-04-29 11:10:45 +00:00
|
|
|
|
fields = fields_small + fields_m2m
|
2019-05-21 08:24:01 +00:00
|
|
|
|
extra_kwargs = {
|
2021-07-23 08:41:02 +00:00
|
|
|
|
'password': {
|
|
|
|
|
"write_only": True,
|
2021-11-23 02:20:16 +00:00
|
|
|
|
'trim_whitespace': False,
|
2021-07-23 08:41:02 +00:00
|
|
|
|
"validators": [validate_password_contains_left_double_curly_bracket]
|
|
|
|
|
},
|
2022-01-18 06:21:27 +00:00
|
|
|
|
'cmd_filters': {"required": False, 'label': _('Command filter')},
|
2019-06-25 06:32:25 +00:00
|
|
|
|
'public_key': {"write_only": True},
|
|
|
|
|
'private_key': {"write_only": True},
|
2020-08-07 03:52:34 +00:00
|
|
|
|
'token': {"write_only": True},
|
2020-11-11 02:27:18 +00:00
|
|
|
|
'nodes_amount': {'label': _('Nodes amount')},
|
|
|
|
|
'assets_amount': {'label': _('Assets amount')},
|
2019-05-21 08:24:01 +00:00
|
|
|
|
'login_mode_display': {'label': _('Login mode display')},
|
2019-06-19 08:45:14 +00:00
|
|
|
|
'created_by': {'read_only': True},
|
2020-11-13 06:46:25 +00:00
|
|
|
|
'ad_domain': {'required': False, 'allow_blank': True, 'label': _('Ad domain')},
|
2021-11-05 08:11:29 +00:00
|
|
|
|
'is_asset_protocol': {'label': _('Is asset protocol')},
|
|
|
|
|
'su_from': {'help_text': _('Only ssh and automatic login system users are supported')}
|
2019-05-21 08:24:01 +00:00
|
|
|
|
}
|
2018-02-07 15:25:15 +00:00
|
|
|
|
|
2019-07-08 07:35:20 +00:00
|
|
|
|
def validate_auto_push(self, value):
|
2021-07-13 01:07:57 +00:00
|
|
|
|
login_mode = self.get_initial_value("login_mode")
|
|
|
|
|
protocol = self.get_initial_value("protocol")
|
2019-07-08 07:35:20 +00:00
|
|
|
|
|
2021-07-08 06:23:18 +00:00
|
|
|
|
if login_mode == SystemUser.LOGIN_MANUAL:
|
|
|
|
|
value = False
|
|
|
|
|
elif protocol not in SystemUser.SUPPORT_PUSH_PROTOCOLS:
|
2019-07-08 07:35:20 +00:00
|
|
|
|
value = False
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
def validate_auto_generate_key(self, value):
|
2021-07-13 01:07:57 +00:00
|
|
|
|
login_mode = self.get_initial_value("login_mode")
|
|
|
|
|
protocol = self.get_initial_value("protocol")
|
2019-07-08 07:35:20 +00:00
|
|
|
|
|
|
|
|
|
if self.context["request"].method.lower() != "post":
|
|
|
|
|
value = False
|
|
|
|
|
elif self.instance:
|
|
|
|
|
value = False
|
|
|
|
|
elif login_mode == SystemUser.LOGIN_MANUAL:
|
|
|
|
|
value = False
|
2021-07-08 06:23:18 +00:00
|
|
|
|
elif protocol not in SystemUser.SUPPORT_PUSH_PROTOCOLS:
|
2019-07-08 07:35:20 +00:00
|
|
|
|
value = False
|
|
|
|
|
return value
|
|
|
|
|
|
2020-03-12 08:24:38 +00:00
|
|
|
|
def validate_username_same_with_user(self, username_same_with_user):
|
|
|
|
|
if not username_same_with_user:
|
|
|
|
|
return username_same_with_user
|
2021-07-13 01:07:57 +00:00
|
|
|
|
protocol = self.get_initial_value("protocol", "ssh")
|
2020-03-12 08:24:38 +00:00
|
|
|
|
queryset = SystemUser.objects.filter(
|
2021-07-08 06:23:18 +00:00
|
|
|
|
protocol=protocol,
|
|
|
|
|
username_same_with_user=True
|
2020-03-12 08:24:38 +00:00
|
|
|
|
)
|
|
|
|
|
if self.instance:
|
|
|
|
|
queryset = queryset.exclude(id=self.instance.id)
|
|
|
|
|
exists = queryset.exists()
|
|
|
|
|
if not exists:
|
|
|
|
|
return username_same_with_user
|
|
|
|
|
error = _("Username same with user with protocol {} only allow 1").format(protocol)
|
|
|
|
|
raise serializers.ValidationError(error)
|
|
|
|
|
|
2019-07-08 07:35:20 +00:00
|
|
|
|
def validate_username(self, username):
|
2021-10-14 14:27:02 +00:00
|
|
|
|
protocol = self.get_initial_value("protocol")
|
2019-07-08 07:35:20 +00:00
|
|
|
|
if username:
|
2021-12-20 10:24:16 +00:00
|
|
|
|
if protocol == SystemUser.Protocol.telnet:
|
2021-10-14 14:27:02 +00:00
|
|
|
|
regx = alphanumeric_cn_re
|
2021-12-20 10:24:16 +00:00
|
|
|
|
elif protocol == SystemUser.Protocol.rdp:
|
|
|
|
|
regx = alphanumeric_win_re
|
|
|
|
|
else:
|
|
|
|
|
regx = alphanumeric_re
|
2021-10-14 14:27:02 +00:00
|
|
|
|
if not regx.match(username):
|
|
|
|
|
raise serializers.ValidationError(_('Special char not allowed'))
|
2019-07-08 07:35:20 +00:00
|
|
|
|
return username
|
2021-07-08 06:23:18 +00:00
|
|
|
|
|
2021-10-14 14:27:02 +00:00
|
|
|
|
username_same_with_user = self.get_initial_value("username_same_with_user")
|
2021-07-12 04:46:55 +00:00
|
|
|
|
if username_same_with_user:
|
|
|
|
|
return ''
|
|
|
|
|
|
2021-10-14 14:27:02 +00:00
|
|
|
|
login_mode = self.get_initial_value("login_mode")
|
2021-12-23 03:13:32 +00:00
|
|
|
|
if login_mode == SystemUser.LOGIN_AUTO and protocol != SystemUser.Protocol.vnc \
|
|
|
|
|
and protocol != SystemUser.Protocol.redis:
|
2019-07-08 07:35:20 +00:00
|
|
|
|
msg = _('* Automatic login mode must fill in the username.')
|
|
|
|
|
raise serializers.ValidationError(msg)
|
|
|
|
|
return username
|
|
|
|
|
|
2021-05-13 16:17:47 +00:00
|
|
|
|
def validate_home(self, home):
|
2021-07-13 01:07:57 +00:00
|
|
|
|
username_same_with_user = self.get_initial_value("username_same_with_user")
|
2021-05-13 16:17:47 +00:00
|
|
|
|
if username_same_with_user:
|
|
|
|
|
return ''
|
|
|
|
|
return home
|
|
|
|
|
|
2021-10-22 06:27:54 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
def validate_sftp_root(value):
|
2020-03-12 08:24:38 +00:00
|
|
|
|
if value in ['home', 'tmp']:
|
|
|
|
|
return value
|
|
|
|
|
if not value.startswith('/'):
|
|
|
|
|
error = _("Path should starts with /")
|
|
|
|
|
raise serializers.ValidationError(error)
|
|
|
|
|
return value
|
|
|
|
|
|
2021-10-22 06:27:54 +00:00
|
|
|
|
def validate_password(self, password):
|
|
|
|
|
super().validate_password(password)
|
2021-12-30 02:47:46 +00:00
|
|
|
|
auto_gen_key = self.get_initial_value('auto_generate_key', False)
|
|
|
|
|
private_key = self.get_initial_value('private_key')
|
|
|
|
|
login_mode = self.get_initial_value('login_mode')
|
2021-10-22 06:27:54 +00:00
|
|
|
|
|
|
|
|
|
if not self.instance and not auto_gen_key and not password and \
|
|
|
|
|
not private_key and login_mode == SystemUser.LOGIN_AUTO:
|
|
|
|
|
raise serializers.ValidationError(_("Password or private key required"))
|
|
|
|
|
return password
|
|
|
|
|
|
2021-11-05 08:11:29 +00:00
|
|
|
|
def validate_su_from(self, su_from: SystemUser):
|
|
|
|
|
# self: su enabled
|
|
|
|
|
su_enabled = self.get_initial_value('su_enabled', default=False)
|
|
|
|
|
if not su_enabled:
|
|
|
|
|
return
|
|
|
|
|
if not su_from:
|
|
|
|
|
error = _('This field is required.')
|
|
|
|
|
raise serializers.ValidationError(error)
|
|
|
|
|
# self: protocol ssh
|
|
|
|
|
protocol = self.get_initial_value('protocol', default=SystemUser.Protocol.ssh.value)
|
|
|
|
|
if protocol not in [SystemUser.Protocol.ssh.value]:
|
|
|
|
|
error = _('Only ssh protocol system users are allowed')
|
|
|
|
|
raise serializers.ValidationError(error)
|
|
|
|
|
# su_from: protocol same
|
|
|
|
|
if su_from.protocol != protocol:
|
|
|
|
|
error = _('The protocol must be consistent with the current user: {}').format(protocol)
|
|
|
|
|
raise serializers.ValidationError(error)
|
|
|
|
|
# su_from: login model auto
|
|
|
|
|
if su_from.login_mode != su_from.LOGIN_AUTO:
|
|
|
|
|
error = _('Only system users with automatic login are allowed')
|
|
|
|
|
raise serializers.ValidationError(error)
|
|
|
|
|
return su_from
|
|
|
|
|
|
2021-10-22 06:27:54 +00:00
|
|
|
|
def _validate_admin_user(self, attrs):
|
2021-07-13 01:07:57 +00:00
|
|
|
|
if self.instance:
|
|
|
|
|
tp = self.instance.type
|
|
|
|
|
else:
|
|
|
|
|
tp = attrs.get('type')
|
2021-07-08 06:23:18 +00:00
|
|
|
|
if tp != SystemUser.Type.admin:
|
|
|
|
|
return attrs
|
|
|
|
|
attrs['protocol'] = SystemUser.Protocol.ssh
|
|
|
|
|
attrs['login_mode'] = SystemUser.LOGIN_AUTO
|
|
|
|
|
attrs['username_same_with_user'] = False
|
|
|
|
|
attrs['auto_push'] = False
|
|
|
|
|
return attrs
|
|
|
|
|
|
2021-10-22 06:27:54 +00:00
|
|
|
|
def _validate_gen_key(self, attrs):
|
2021-12-30 02:47:46 +00:00
|
|
|
|
username = attrs.get('username', 'manual')
|
|
|
|
|
auto_gen_key = attrs.pop('auto_generate_key', False)
|
|
|
|
|
protocol = attrs.get('protocol')
|
2019-12-19 07:28:17 +00:00
|
|
|
|
|
2021-07-08 06:23:18 +00:00
|
|
|
|
if protocol not in SystemUser.SUPPORT_PUSH_PROTOCOLS:
|
2019-12-19 07:28:17 +00:00
|
|
|
|
return attrs
|
|
|
|
|
|
2021-07-08 06:23:18 +00:00
|
|
|
|
# 自动生成
|
|
|
|
|
if auto_gen_key and not self.instance:
|
2019-07-08 07:35:20 +00:00
|
|
|
|
password = SystemUser.gen_password()
|
2021-12-30 02:47:46 +00:00
|
|
|
|
attrs['password'] = password
|
2021-07-08 06:23:18 +00:00
|
|
|
|
if protocol == SystemUser.Protocol.ssh:
|
2019-07-08 07:35:20 +00:00
|
|
|
|
private_key, public_key = SystemUser.gen_key(username)
|
2021-12-30 02:47:46 +00:00
|
|
|
|
attrs['private_key'] = private_key
|
|
|
|
|
attrs['public_key'] = public_key
|
2021-07-08 06:23:18 +00:00
|
|
|
|
# 如果设置了private key,没有设置public key则生成
|
2021-12-30 02:47:46 +00:00
|
|
|
|
elif attrs.get('private_key'):
|
|
|
|
|
private_key = attrs['private_key']
|
|
|
|
|
password = attrs.get('password')
|
2021-07-08 06:23:18 +00:00
|
|
|
|
public_key = ssh_pubkey_gen(private_key, password=password, username=username)
|
2021-12-30 02:47:46 +00:00
|
|
|
|
attrs['public_key'] = public_key
|
2019-07-08 07:35:20 +00:00
|
|
|
|
return attrs
|
|
|
|
|
|
2021-10-22 06:27:54 +00:00
|
|
|
|
def _validate_login_mode(self, attrs):
|
|
|
|
|
if 'login_mode' in attrs:
|
|
|
|
|
login_mode = attrs['login_mode']
|
|
|
|
|
else:
|
|
|
|
|
login_mode = self.instance.login_mode if self.instance else SystemUser.LOGIN_AUTO
|
|
|
|
|
|
|
|
|
|
if login_mode == SystemUser.LOGIN_MANUAL:
|
|
|
|
|
attrs['password'] = ''
|
|
|
|
|
attrs['private_key'] = ''
|
|
|
|
|
attrs['public_key'] = ''
|
|
|
|
|
|
|
|
|
|
return attrs
|
|
|
|
|
|
2021-07-08 06:23:18 +00:00
|
|
|
|
def validate(self, attrs):
|
2021-10-22 06:27:54 +00:00
|
|
|
|
attrs = self._validate_admin_user(attrs)
|
|
|
|
|
attrs = self._validate_gen_key(attrs)
|
|
|
|
|
attrs = self._validate_login_mode(attrs)
|
2021-07-08 06:23:18 +00:00
|
|
|
|
return attrs
|
|
|
|
|
|
2019-07-04 07:36:57 +00:00
|
|
|
|
@classmethod
|
|
|
|
|
def setup_eager_loading(cls, queryset):
|
|
|
|
|
""" Perform necessary eager loading of data. """
|
2021-12-30 02:47:46 +00:00
|
|
|
|
queryset = queryset \
|
2021-10-25 06:58:59 +00:00
|
|
|
|
.annotate(assets_amount=Count("assets")) \
|
2021-10-20 11:45:37 +00:00
|
|
|
|
.prefetch_related('nodes', 'cmd_filters')
|
2019-07-04 07:36:57 +00:00
|
|
|
|
return queryset
|
|
|
|
|
|
2018-02-07 15:25:15 +00:00
|
|
|
|
|
2021-09-12 13:00:51 +00:00
|
|
|
|
class MiniSystemUserSerializer(serializers.ModelSerializer):
|
|
|
|
|
class Meta:
|
|
|
|
|
model = SystemUser
|
|
|
|
|
fields = SystemUserSerializer.Meta.fields_mini
|
|
|
|
|
|
|
|
|
|
|
2020-03-12 08:24:38 +00:00
|
|
|
|
class SystemUserWithAuthInfoSerializer(SystemUserSerializer):
|
|
|
|
|
class Meta(SystemUserSerializer.Meta):
|
2021-04-29 11:10:45 +00:00
|
|
|
|
fields_mini = ['id', 'name', 'username']
|
|
|
|
|
fields_write_only = ['password', 'public_key', 'private_key']
|
|
|
|
|
fields_small = fields_mini + fields_write_only + [
|
|
|
|
|
'protocol', 'login_mode', 'login_mode_display', 'priority',
|
|
|
|
|
'sudo', 'shell', 'ad_domain', 'sftp_root', 'token',
|
|
|
|
|
"username_same_with_user", 'auto_push', 'auto_generate_key',
|
|
|
|
|
'comment',
|
2020-03-16 08:59:45 +00:00
|
|
|
|
]
|
2021-04-29 11:10:45 +00:00
|
|
|
|
fields = fields_small
|
2020-03-12 08:24:38 +00:00
|
|
|
|
extra_kwargs = {
|
|
|
|
|
'nodes_amount': {'label': _('Node')},
|
|
|
|
|
'assets_amount': {'label': _('Asset')},
|
|
|
|
|
'login_mode_display': {'label': _('Login mode display')},
|
|
|
|
|
'created_by': {'read_only': True},
|
|
|
|
|
}
|
2020-01-07 07:53:53 +00:00
|
|
|
|
|
2018-03-09 04:53:08 +00:00
|
|
|
|
|
2018-02-07 15:25:15 +00:00
|
|
|
|
class SystemUserSimpleSerializer(serializers.ModelSerializer):
|
|
|
|
|
"""
|
|
|
|
|
系统用户最基本信息的数据结构
|
|
|
|
|
"""
|
2021-09-12 13:00:51 +00:00
|
|
|
|
|
2018-02-07 15:25:15 +00:00
|
|
|
|
class Meta:
|
|
|
|
|
model = SystemUser
|
2018-12-18 09:28:45 +00:00
|
|
|
|
fields = ('id', 'name', 'username')
|
|
|
|
|
|
|
|
|
|
|
2019-12-05 07:09:25 +00:00
|
|
|
|
class RelationMixin(BulkSerializerMixin, serializers.Serializer):
|
2021-07-14 03:31:09 +00:00
|
|
|
|
systemuser_display = serializers.ReadOnlyField(label=_("System user name"))
|
2021-07-14 10:51:24 +00:00
|
|
|
|
org_name = serializers.ReadOnlyField(label=_("Org name"))
|
2019-12-05 07:09:25 +00:00
|
|
|
|
|
|
|
|
|
def get_field_names(self, declared_fields, info):
|
|
|
|
|
fields = super().get_field_names(declared_fields, info)
|
2021-07-14 10:51:24 +00:00
|
|
|
|
fields.extend(['systemuser', "systemuser_display", "org_name"])
|
2019-12-05 07:09:25 +00:00
|
|
|
|
return fields
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SystemUserAssetRelationSerializer(RelationMixin, serializers.ModelSerializer):
|
2021-07-14 03:31:09 +00:00
|
|
|
|
asset_display = serializers.ReadOnlyField(label=_('Asset hostname'))
|
2019-12-05 07:09:25 +00:00
|
|
|
|
|
2021-07-08 06:23:18 +00:00
|
|
|
|
class Meta:
|
2019-12-05 07:09:25 +00:00
|
|
|
|
model = SystemUser.assets.through
|
|
|
|
|
fields = [
|
2021-07-12 12:11:53 +00:00
|
|
|
|
"id", "asset", "asset_display", 'systemuser', 'systemuser_display',
|
2021-07-13 09:43:36 +00:00
|
|
|
|
"connectivity", 'date_verified', 'org_id'
|
2019-12-05 07:09:25 +00:00
|
|
|
|
]
|
2021-07-08 06:23:18 +00:00
|
|
|
|
use_model_bulk_create = True
|
|
|
|
|
model_bulk_create_kwargs = {
|
|
|
|
|
'ignore_conflicts': True
|
|
|
|
|
}
|
2019-12-05 07:09:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SystemUserNodeRelationSerializer(RelationMixin, serializers.ModelSerializer):
|
|
|
|
|
node_display = serializers.SerializerMethodField()
|
|
|
|
|
|
2021-07-08 06:23:18 +00:00
|
|
|
|
class Meta:
|
2019-12-05 07:09:25 +00:00
|
|
|
|
model = SystemUser.nodes.through
|
|
|
|
|
fields = [
|
|
|
|
|
'id', 'node', "node_display",
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
def get_node_display(self, obj):
|
2020-09-29 09:13:32 +00:00
|
|
|
|
return obj.node.full_value
|
2020-03-12 08:24:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SystemUserUserRelationSerializer(RelationMixin, serializers.ModelSerializer):
|
|
|
|
|
user_display = serializers.ReadOnlyField()
|
|
|
|
|
|
2021-07-08 06:23:18 +00:00
|
|
|
|
class Meta:
|
2020-03-12 08:24:38 +00:00
|
|
|
|
model = SystemUser.users.through
|
|
|
|
|
fields = [
|
|
|
|
|
'id', "user", "user_display",
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SystemUserTaskSerializer(serializers.Serializer):
|
|
|
|
|
ACTION_CHOICES = (
|
|
|
|
|
("test", "test"),
|
|
|
|
|
("push", "push"),
|
|
|
|
|
)
|
|
|
|
|
action = serializers.ChoiceField(choices=ACTION_CHOICES, write_only=True)
|
|
|
|
|
asset = serializers.PrimaryKeyRelatedField(
|
|
|
|
|
queryset=Asset.objects, allow_null=True, required=False, write_only=True
|
|
|
|
|
)
|
2020-12-08 09:29:22 +00:00
|
|
|
|
assets = serializers.PrimaryKeyRelatedField(
|
|
|
|
|
queryset=Asset.objects, allow_null=True, required=False, write_only=True,
|
|
|
|
|
many=True
|
|
|
|
|
)
|
2020-03-12 08:24:38 +00:00
|
|
|
|
task = serializers.CharField(read_only=True)
|
2021-05-31 07:01:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SystemUserTempAuthSerializer(SystemUserSerializer):
|
|
|
|
|
instance_id = serializers.CharField()
|
|
|
|
|
|
|
|
|
|
class Meta(SystemUserSerializer.Meta):
|
|
|
|
|
fields = ['instance_id', 'username', 'password']
|