From 43f30b37da5f77f9569e1237e49c54a33b1dfaef Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Wed, 15 Sep 2021 21:00:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=A8=E6=88=B7=E6=89=8B=E6=9C=BA?= =?UTF-8?q?=E5=8F=B7=E6=B2=A1=E6=9C=89=E6=A0=A1=E9=AA=8C=20(#6875)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: xinwen Co-authored-by: Jiangjie.Bai <32935519+BaiJiangJie@users.noreply.github.com> --- apps/common/validators.py | 11 +++++ apps/locale/zh/LC_MESSAGES/django.po | 60 +++++++++++++++------------- apps/users/serializers/user.py | 2 + 3 files changed, 45 insertions(+), 28 deletions(-) diff --git a/apps/common/validators.py b/apps/common/validators.py index 0ce334552..c22ea69da 100644 --- a/apps/common/validators.py +++ b/apps/common/validators.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- # +import re + from django.core.validators import RegexValidator from django.utils.translation import ugettext_lazy as _ from rest_framework.validators import ( @@ -32,3 +34,12 @@ class NoSpecialChars: raise serializers.ValidationError( _("Should not contains special characters") ) + + +class PhoneValidator: + pattern = re.compile(r"^1[356789]\d{9}$") + message = _('The mobile phone number format is incorrect') + + def __call__(self, value): + if not self.pattern.match(value): + raise serializers.ValidationError(self.message) diff --git a/apps/locale/zh/LC_MESSAGES/django.po b/apps/locale/zh/LC_MESSAGES/django.po index 830ccace5..507c4781a 100644 --- a/apps/locale/zh/LC_MESSAGES/django.po +++ b/apps/locale/zh/LC_MESSAGES/django.po @@ -2138,18 +2138,22 @@ msgstr "忽略时间" msgid "Invalid ip" msgstr "无效IP" -#: common/validators.py:13 +#: common/validators.py:15 msgid "Special char not allowed" msgstr "不能包含特殊字符" -#: common/validators.py:25 +#: common/validators.py:27 msgid "This field must be unique." msgstr "字段必须唯一" -#: common/validators.py:33 +#: common/validators.py:35 msgid "Should not contains special characters" msgstr "不能包含特殊字符" +#: common/validators.py:41 +msgid "The mobile phone number format is incorrect" +msgstr "手机号格式不正确" + #: jumpserver/context_processor.py:20 msgid "JumpServer Open Source Bastion Host" msgstr "JumpServer 开源堡垒机" @@ -2400,7 +2404,7 @@ msgstr "组织审计员" msgid "GLOBAL" msgstr "全局组织" -#: orgs/models.py:434 users/models/user.py:614 users/serializers/user.py:36 +#: orgs/models.py:434 users/models/user.py:614 users/serializers/user.py:37 #: users/templates/users/_select_user_modal.html:15 msgid "Role" msgstr "角色" @@ -2487,15 +2491,15 @@ msgstr "来自工单" #: perms/serializers/application/permission.py:18 #: perms/serializers/application/permission.py:38 #: perms/serializers/asset/permission.py:42 -#: perms/serializers/asset/permission.py:68 users/serializers/user.py:77 +#: perms/serializers/asset/permission.py:68 users/serializers/user.py:78 msgid "Is valid" msgstr "账户是否有效" #: perms/serializers/application/permission.py:19 #: perms/serializers/application/permission.py:37 #: perms/serializers/asset/permission.py:43 -#: perms/serializers/asset/permission.py:67 users/serializers/user.py:28 -#: users/serializers/user.py:78 +#: perms/serializers/asset/permission.py:67 users/serializers/user.py:29 +#: users/serializers/user.py:79 msgid "Is expired" msgstr "是否过期" @@ -5263,7 +5267,7 @@ msgstr "" msgid "The old password is incorrect" msgstr "旧密码错误" -#: users/serializers/profile.py:36 users/serializers/user.py:138 +#: users/serializers/profile.py:36 users/serializers/user.py:140 msgid "Password does not match security rules" msgstr "密码不满足安全规则" @@ -5275,85 +5279,85 @@ msgstr "新密码不能是最近 {} 次的密码" msgid "The newly set password is inconsistent" msgstr "两次密码不一致" -#: users/serializers/profile.py:121 users/serializers/user.py:76 +#: users/serializers/profile.py:121 users/serializers/user.py:77 msgid "Is first login" msgstr "首次登录" -#: users/serializers/user.py:22 +#: users/serializers/user.py:23 #: xpack/plugins/change_auth_plan/models/base.py:32 #: xpack/plugins/change_auth_plan/serializers/base.py:24 msgid "Password strategy" msgstr "密码策略" -#: users/serializers/user.py:24 +#: users/serializers/user.py:25 msgid "MFA enabled" msgstr "是否开启多因子认证" -#: users/serializers/user.py:25 +#: users/serializers/user.py:26 msgid "MFA force enabled" msgstr "强制启用多因子认证" -#: users/serializers/user.py:26 +#: users/serializers/user.py:27 msgid "MFA level display" msgstr "多因子认证等级名称" -#: users/serializers/user.py:27 +#: users/serializers/user.py:28 msgid "Login blocked" msgstr "登录被阻塞" -#: users/serializers/user.py:29 +#: users/serializers/user.py:30 msgid "Can update" msgstr "是否可更新" -#: users/serializers/user.py:30 +#: users/serializers/user.py:31 msgid "Can delete" msgstr "是否可删除" -#: users/serializers/user.py:31 +#: users/serializers/user.py:32 msgid "Can public key authentication" msgstr "能否公钥认证" -#: users/serializers/user.py:33 users/serializers/user.py:83 +#: users/serializers/user.py:34 users/serializers/user.py:84 msgid "Organization role name" msgstr "组织角色名称" -#: users/serializers/user.py:79 +#: users/serializers/user.py:80 msgid "Avatar url" msgstr "头像路径" -#: users/serializers/user.py:81 +#: users/serializers/user.py:82 msgid "Groups name" msgstr "用户组名" -#: users/serializers/user.py:82 +#: users/serializers/user.py:83 msgid "Source name" msgstr "用户来源名" -#: users/serializers/user.py:84 +#: users/serializers/user.py:85 msgid "Super role name" msgstr "超级角色名称" -#: users/serializers/user.py:85 +#: users/serializers/user.py:86 msgid "Total role name" msgstr "汇总角色名称" -#: users/serializers/user.py:87 +#: users/serializers/user.py:88 msgid "Is wecom bound" msgstr "是否绑定了企业微信" -#: users/serializers/user.py:88 +#: users/serializers/user.py:89 msgid "Is dingtalk bound" msgstr "是否绑定了钉钉" -#: users/serializers/user.py:89 +#: users/serializers/user.py:90 msgid "Is feishu bound" msgstr "是否绑定了飞书" -#: users/serializers/user.py:112 +#: users/serializers/user.py:114 msgid "Role limit to {}" msgstr "角色只能为 {}" -#: users/serializers/user.py:232 +#: users/serializers/user.py:234 msgid "name not unique" msgstr "名称重复" diff --git a/apps/users/serializers/user.py b/apps/users/serializers/user.py index a6da38a37..82e9c1c50 100644 --- a/apps/users/serializers/user.py +++ b/apps/users/serializers/user.py @@ -6,6 +6,7 @@ from rest_framework import serializers from common.mixins import CommonBulkSerializerMixin from common.permissions import CanUpdateDeleteUser +from common.validators import PhoneValidator from orgs.models import ROLE as ORG_ROLE from ..models import User from ..const import SystemOrOrgRole, PasswordStrategy @@ -87,6 +88,7 @@ class UserSerializer(CommonBulkSerializerMixin, serializers.ModelSerializer): 'is_wecom_bound': {'label': _('Is wecom bound')}, 'is_dingtalk_bound': {'label': _('Is dingtalk bound')}, 'is_feishu_bound': {'label': _('Is feishu bound')}, + 'phone': {'validators': [PhoneValidator()]}, } def __init__(self, *args, **kwargs):