diff --git a/apps/assets/const.py b/apps/assets/const.py index c23b700ba..7786d8f13 100644 --- a/apps/assets/const.py +++ b/apps/assets/const.py @@ -4,11 +4,11 @@ from django.utils.translation import ugettext_lazy as _ -GENERAL_LIMIT_SPECIAL_CHARACTERS_HELP_TEXT = _( - 'Only Numbers、letters、 chinese and characters ( {} ) are allowed' -).format(" ".join(['.', '_', '@', '-'])) +GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_HELP_TEXT = _( + 'Cannot contain special characters: [ {} ]' +).format(" ".join(['/', '\\'])) -GENERAL_LIMIT_SPECIAL_CHARACTERS_PATTERN = r"^[\._@\w-]+$" +GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_PATTERN = r"[/\\]" -GENERAL_LIMIT_SPECIAL_CHARACTERS_ERROR_MSG = \ +GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_ERROR_MSG = \ _("* The contains characters that are not allowed") diff --git a/apps/assets/forms/asset.py b/apps/assets/forms/asset.py index b6e5d3a42..805f49f24 100644 --- a/apps/assets/forms/asset.py +++ b/apps/assets/forms/asset.py @@ -7,7 +7,7 @@ from common.utils import get_logger from orgs.mixins.forms import OrgModelForm from ..models import Asset, Node -from ..const import GENERAL_LIMIT_SPECIAL_CHARACTERS_HELP_TEXT +from ..const import GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_HELP_TEXT logger = get_logger(__file__) @@ -69,7 +69,7 @@ class AssetCreateForm(OrgModelForm): 'nodes': _("Node"), } help_texts = { - 'hostname': GENERAL_LIMIT_SPECIAL_CHARACTERS_HELP_TEXT, + 'hostname': GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_HELP_TEXT, 'admin_user': _( 'root or other NOPASSWD sudo privilege user existed in asset,' 'If asset is windows or other set any one, more see admin user left menu' @@ -116,7 +116,7 @@ class AssetUpdateForm(OrgModelForm): 'nodes': _("Node"), } help_texts = { - 'hostname': GENERAL_LIMIT_SPECIAL_CHARACTERS_HELP_TEXT, + 'hostname': GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_HELP_TEXT, 'admin_user': _( 'root or other NOPASSWD sudo privilege user existed in asset,' 'If asset is windows or other set any one, more see admin user left menu' diff --git a/apps/assets/forms/user.py b/apps/assets/forms/user.py index b50639684..21626f4f6 100644 --- a/apps/assets/forms/user.py +++ b/apps/assets/forms/user.py @@ -6,7 +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 +from ..const import GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_HELP_TEXT logger = get_logger(__file__) __all__ = [ @@ -99,7 +99,7 @@ class SystemUserForm(OrgModelForm, PasswordAndKeyAuthForm): }), } help_texts = { - 'name': GENERAL_LIMIT_SPECIAL_CHARACTERS_HELP_TEXT, + 'name': GENERAL_FORBIDDEN_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/asset.py b/apps/assets/serializers/asset.py index f198aee76..a24374c13 100644 --- a/apps/assets/serializers/asset.py +++ b/apps/assets/serializers/asset.py @@ -9,8 +9,8 @@ from orgs.mixins.serializers import BulkOrgResourceModelSerializer from common.serializers import AdaptedBulkListSerializer from ..models import Asset, Node, Label from ..const import ( - GENERAL_LIMIT_SPECIAL_CHARACTERS_PATTERN, - GENERAL_LIMIT_SPECIAL_CHARACTERS_ERROR_MSG + GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_PATTERN, + GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_ERROR_MSG ) from .base import ConnectivitySerializer @@ -98,10 +98,10 @@ class AssetSerializer(BulkOrgResourceModelSerializer): @staticmethod def validate_hostname(hostname): - pattern = GENERAL_LIMIT_SPECIAL_CHARACTERS_PATTERN - res = re.match(pattern, hostname) - if res is None: - msg = GENERAL_LIMIT_SPECIAL_CHARACTERS_ERROR_MSG + pattern = GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_PATTERN + res = re.search(pattern, hostname) + if res is not None: + msg = GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_ERROR_MSG raise serializers.ValidationError(msg) return hostname diff --git a/apps/assets/serializers/system_user.py b/apps/assets/serializers/system_user.py index 1340741e6..648af01a7 100644 --- a/apps/assets/serializers/system_user.py +++ b/apps/assets/serializers/system_user.py @@ -8,8 +8,8 @@ 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 + GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_PATTERN, + GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_ERROR_MSG ) from .base import AuthSerializer, AuthSerializerMixin @@ -41,10 +41,10 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer): @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 + pattern = GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_PATTERN + res = re.search(pattern, name) + if res is not None: + msg = GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_ERROR_MSG raise serializers.ValidationError(msg) return name diff --git a/apps/locale/zh/LC_MESSAGES/django.mo b/apps/locale/zh/LC_MESSAGES/django.mo index f6f15fd93..a6510ca5a 100644 Binary files a/apps/locale/zh/LC_MESSAGES/django.mo and b/apps/locale/zh/LC_MESSAGES/django.mo differ diff --git a/apps/locale/zh/LC_MESSAGES/django.po b/apps/locale/zh/LC_MESSAGES/django.po index 1b88cc884..fdc37654f 100644 --- a/apps/locale/zh/LC_MESSAGES/django.po +++ b/apps/locale/zh/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Jumpserver 0.3.3\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-10-24 18:31+0800\n" +"POT-Creation-Date: 2019-10-25 10:52+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: ibuler \n" "Language-Team: Jumpserver team\n" @@ -583,8 +583,8 @@ msgid "Test if the assets under the node are connectable: {}" msgstr "测试节点下资产是否可连接: {}" #: assets/const.py:8 -msgid "Only Numbers、letters、 chinese and characters ( {} ) are allowed" -msgstr "只允许包含数字、字母、中文和特殊字符( {} )" +msgid "Cannot contain special characters: [ {} ]" +msgstr "不能包含特殊字符:[ {} ]" #: assets/const.py:14 msgid "* The contains characters that are not allowed" diff --git a/apps/orgs/serializers.py b/apps/orgs/serializers.py index 8f4df1e10..3ac7da732 100644 --- a/apps/orgs/serializers.py +++ b/apps/orgs/serializers.py @@ -5,8 +5,8 @@ from rest_framework import serializers from users.models import User, UserGroup from assets.models import Asset, Domain, AdminUser, SystemUser, Label from assets.const import ( - GENERAL_LIMIT_SPECIAL_CHARACTERS_PATTERN, - GENERAL_LIMIT_SPECIAL_CHARACTERS_ERROR_MSG + GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_PATTERN, + GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_ERROR_MSG ) from perms.models import AssetPermission from common.serializers import AdaptedBulkListSerializer @@ -24,10 +24,10 @@ class OrgSerializer(ModelSerializer): @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 + pattern = GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_PATTERN + res = re.search(pattern, name) + if res is not None: + msg = GENERAL_FORBIDDEN_SPECIAL_CHARACTERS_ERROR_MSG raise serializers.ValidationError(msg) return name