diff --git a/apps/assets/forms/user.py b/apps/assets/forms/user.py index 3d67b434b..b50639684 100644 --- a/apps/assets/forms/user.py +++ b/apps/assets/forms/user.py @@ -6,6 +6,7 @@ from django.utils.translation import gettext_lazy as _ from common.utils import validate_ssh_private_key, ssh_pubkey_gen, get_logger from orgs.mixins.forms import OrgModelForm from ..models import AdminUser, SystemUser +from ..const import GENERAL_LIMIT_SPECIAL_CHARACTERS_HELP_TEXT logger = get_logger(__file__) __all__ = [ @@ -98,6 +99,7 @@ class SystemUserForm(OrgModelForm, PasswordAndKeyAuthForm): }), } help_texts = { + 'name': GENERAL_LIMIT_SPECIAL_CHARACTERS_HELP_TEXT, 'auto_push': _('Auto push system user to asset'), 'priority': _('1-100, High level will be using login asset as default, ' 'if user was granted more than 2 system user'), diff --git a/apps/assets/serializers/system_user.py b/apps/assets/serializers/system_user.py index eea93360b..3194f2fb6 100644 --- a/apps/assets/serializers/system_user.py +++ b/apps/assets/serializers/system_user.py @@ -1,3 +1,4 @@ +import re from rest_framework import serializers from django.utils.translation import ugettext_lazy as _ @@ -6,6 +7,10 @@ from common.serializers import AdaptedBulkListSerializer from common.utils import ssh_pubkey_gen from orgs.mixins.serializers import BulkOrgResourceModelSerializer from ..models import SystemUser +from ..const import ( + GENERAL_LIMIT_SPECIAL_CHARACTERS_PATTERN, + GENERAL_LIMIT_SPECIAL_CHARACTERS_ERROR_MSG +) from .base import AuthSerializer, AuthSerializerMixin @@ -33,6 +38,15 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer): 'created_by': {'read_only': True}, } + @staticmethod + def validate_name(name): + pattern = GENERAL_LIMIT_SPECIAL_CHARACTERS_PATTERN + res = re.match(pattern, name) + if res is None: + msg = GENERAL_LIMIT_SPECIAL_CHARACTERS_ERROR_MSG + raise serializers.ValidationError(msg) + return name + def validate_auto_push(self, value): login_mode = self.initial_data.get("login_mode") protocol = self.initial_data.get("protocol")