mirror of https://github.com/jumpserver/jumpserver
parent
f6a26ac165
commit
f772296dff
|
@ -51,8 +51,8 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
||||||
}
|
}
|
||||||
|
|
||||||
def validate_auto_push(self, value):
|
def validate_auto_push(self, value):
|
||||||
login_mode = self.initial_data.get("login_mode")
|
login_mode = self.get_initial_value("login_mode")
|
||||||
protocol = self.initial_data.get("protocol")
|
protocol = self.get_initial_value("protocol")
|
||||||
|
|
||||||
if login_mode == SystemUser.LOGIN_MANUAL:
|
if login_mode == SystemUser.LOGIN_MANUAL:
|
||||||
value = False
|
value = False
|
||||||
|
@ -61,8 +61,8 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def validate_auto_generate_key(self, value):
|
def validate_auto_generate_key(self, value):
|
||||||
login_mode = self.initial_data.get("login_mode")
|
login_mode = self.get_initial_value("login_mode")
|
||||||
protocol = self.initial_data.get("protocol")
|
protocol = self.get_initial_value("protocol")
|
||||||
|
|
||||||
if self.context["request"].method.lower() != "post":
|
if self.context["request"].method.lower() != "post":
|
||||||
value = False
|
value = False
|
||||||
|
@ -77,7 +77,7 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
||||||
def validate_username_same_with_user(self, username_same_with_user):
|
def validate_username_same_with_user(self, username_same_with_user):
|
||||||
if not username_same_with_user:
|
if not username_same_with_user:
|
||||||
return username_same_with_user
|
return username_same_with_user
|
||||||
protocol = self.initial_data.get("protocol", "ssh")
|
protocol = self.get_initial_value("protocol", "ssh")
|
||||||
queryset = SystemUser.objects.filter(
|
queryset = SystemUser.objects.filter(
|
||||||
protocol=protocol,
|
protocol=protocol,
|
||||||
username_same_with_user=True
|
username_same_with_user=True
|
||||||
|
@ -93,9 +93,9 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
||||||
def validate_username(self, username):
|
def validate_username(self, username):
|
||||||
if username:
|
if username:
|
||||||
return username
|
return username
|
||||||
login_mode = self.initial_data.get("login_mode")
|
login_mode = self.get_initial_value("login_mode")
|
||||||
protocol = self.initial_data.get("protocol")
|
protocol = self.get_initial_value("protocol")
|
||||||
username_same_with_user = self.initial_data.get("username_same_with_user")
|
username_same_with_user = self.get_initial_value("username_same_with_user")
|
||||||
|
|
||||||
if username_same_with_user:
|
if username_same_with_user:
|
||||||
return ''
|
return ''
|
||||||
|
@ -106,7 +106,7 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
||||||
return username
|
return username
|
||||||
|
|
||||||
def validate_home(self, home):
|
def validate_home(self, home):
|
||||||
username_same_with_user = self.initial_data.get("username_same_with_user")
|
username_same_with_user = self.get_initial_value("username_same_with_user")
|
||||||
if username_same_with_user:
|
if username_same_with_user:
|
||||||
return ''
|
return ''
|
||||||
return home
|
return home
|
||||||
|
@ -119,9 +119,11 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
||||||
raise serializers.ValidationError(error)
|
raise serializers.ValidationError(error)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@staticmethod
|
def validate_admin_user(self, attrs):
|
||||||
def validate_admin_user(attrs):
|
if self.instance:
|
||||||
tp = attrs.get('type')
|
tp = self.instance.type
|
||||||
|
else:
|
||||||
|
tp = attrs.get('type')
|
||||||
if tp != SystemUser.Type.admin:
|
if tp != SystemUser.Type.admin:
|
||||||
return attrs
|
return attrs
|
||||||
attrs['protocol'] = SystemUser.Protocol.ssh
|
attrs['protocol'] = SystemUser.Protocol.ssh
|
||||||
|
@ -132,9 +134,9 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
||||||
|
|
||||||
def validate_password(self, password):
|
def validate_password(self, password):
|
||||||
super().validate_password(password)
|
super().validate_password(password)
|
||||||
auto_gen_key = self.initial_data.get("auto_generate_key", False)
|
auto_gen_key = self.get_initial_value("auto_generate_key", False)
|
||||||
private_key = self.initial_data.get("private_key")
|
private_key = self.get_initial_value("private_key")
|
||||||
login_mode = self.initial_data.get("login_mode")
|
login_mode = self.get_initial_value("login_mode")
|
||||||
|
|
||||||
if not self.instance and not auto_gen_key and not password and \
|
if not self.instance and not auto_gen_key and not password and \
|
||||||
not private_key and login_mode == SystemUser.LOGIN_AUTO:
|
not private_key and login_mode == SystemUser.LOGIN_AUTO:
|
||||||
|
|
|
@ -293,7 +293,14 @@ class EagerLoadQuerySetFields:
|
||||||
|
|
||||||
|
|
||||||
class CommonSerializerMixin(DynamicFieldsMixin, DefaultValueFieldsMixin):
|
class CommonSerializerMixin(DynamicFieldsMixin, DefaultValueFieldsMixin):
|
||||||
pass
|
instance: None
|
||||||
|
initial_data: dict
|
||||||
|
|
||||||
|
def get_initial_value(self, attr, default=None):
|
||||||
|
if self.instance:
|
||||||
|
return getattr(self.instance, attr, default)
|
||||||
|
else:
|
||||||
|
return self.initial_data.get(attr)
|
||||||
|
|
||||||
|
|
||||||
class CommonBulkSerializerMixin(BulkSerializerMixin, CommonSerializerMixin):
|
class CommonBulkSerializerMixin(BulkSerializerMixin, CommonSerializerMixin):
|
||||||
|
|
Loading…
Reference in New Issue