From 1840609d535001d1f156b9e605b9332951db9a22 Mon Sep 17 00:00:00 2001 From: ibuler Date: Mon, 12 Jul 2021 12:46:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=94=A8=E6=88=B7=E6=97=A0=E6=B3=95=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix: 修复动态系统用户 --- apps/assets/models/user.py | 7 +------ apps/assets/serializers/system_user.py | 9 ++++----- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/apps/assets/models/user.py b/apps/assets/models/user.py index fcdb9e244..3f8849188 100644 --- a/apps/assets/models/user.py +++ b/apps/assets/models/user.py @@ -215,7 +215,7 @@ class SystemUser(ProtocolMixin, AuthMixin, BaseUser): def __str__(self): username = self.username if self.username_same_with_user: - username = 'dynamic' + username = '*' return '{0.name}({1})'.format(self, username) @property @@ -270,11 +270,6 @@ class SystemUser(ProtocolMixin, AuthMixin, BaseUser): assets = Asset.objects.filter(id__in=asset_ids) return assets - def save(self, *args, **kwargs): - if self.username_same_with_user: - self.username = '*' - return super().save(*args, **kwargs) - class Meta: ordering = ['name'] unique_together = [('name', 'org_id')] diff --git a/apps/assets/serializers/system_user.py b/apps/assets/serializers/system_user.py index abb70c47c..381b46592 100644 --- a/apps/assets/serializers/system_user.py +++ b/apps/assets/serializers/system_user.py @@ -97,13 +97,12 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer): protocol = self.initial_data.get("protocol") username_same_with_user = self.initial_data.get("username_same_with_user") - if login_mode == SystemUser.LOGIN_AUTO and \ - protocol != SystemUser.Protocol.vnc: + if username_same_with_user: + return '' + + if login_mode == SystemUser.LOGIN_AUTO and protocol != SystemUser.Protocol.vnc: msg = _('* Automatic login mode must fill in the username.') raise serializers.ValidationError(msg) - - if username_same_with_user: - username = '*' return username def validate_home(self, home):