From 3b4f95239d07f0ebe27bf412b651189d49624f11 Mon Sep 17 00:00:00 2001 From: ycggyao Date: Fri, 29 Nov 2024 19:00:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E8=A1=A5=E5=85=85mongodb=20?= =?UTF-8?q?=E4=B8=8D=E5=85=81=E8=AE=B8=E5=88=9B=E5=BB=BA=E7=89=B9=E6=AE=8A?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=20#8309=20#=20Reviewed,=20transaction=20id:?= =?UTF-8?q?=2025427?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db_services/dbpermission/db_account/serializers.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dbm-ui/backend/db_services/dbpermission/db_account/serializers.py b/dbm-ui/backend/db_services/dbpermission/db_account/serializers.py index 99c2e36c6..0ab8e6c00 100644 --- a/dbm-ui/backend/db_services/dbpermission/db_account/serializers.py +++ b/dbm-ui/backend/db_services/dbpermission/db_account/serializers.py @@ -42,7 +42,15 @@ def check_username_valid(cls, account_type, user): # 不允许使用特殊账户名称 special_account_names = ACCOUNT_RULES_MAP.get(account_type, []) - if user in special_account_names: + # 检查是否为MongoDB类型,并尝试分割用户名 + second_part = None + if account_type == AccountType.MONGODB: + try: + first_part, second_part = user.split(".", 1) + except ValueError: + pass + + if second_part in special_account_names or user in special_account_names: raise serializers.ValidationError(_("不允许使用特殊账号名称[{}], 请重新更改账号名".format(user))) @classmethod