Skip to content

Commit

Permalink
minor: resolve #1664 conversations
Browse files Browse the repository at this point in the history
  • Loading branch information
narasux committed Apr 24, 2024
1 parent 7f44428 commit 866631a
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
TenantDepartmentUpdateInputSLZ,
)
from .tenants import (
RequiredTenantUserFieldOutputSLZ,
TenantListOutputSLZ,
TenantRequiredUserFieldOutputSLZ,
TenantRetrieveOutputSLZ,
)
from .users import (
Expand All @@ -51,7 +51,7 @@
# 租户
"TenantListOutputSLZ",
"TenantRetrieveOutputSLZ",
"TenantRequiredUserFieldOutputSLZ",
"RequiredTenantUserFieldOutputSLZ",
# 租户部门
"TenantDepartmentListInputSLZ",
"TenantDepartmentListOutputSLZ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,24 @@


class TenantUserInfoSLZ(serializers.Serializer):
"""批量创建时校验用户信息用,该模式邮箱,手机号等均为必填字段"""

username = serializers.CharField(help_text="用户名", validators=[validate_data_source_user_username])
full_name = serializers.CharField(help_text="姓名")
email = serializers.EmailField(help_text="邮箱", required=False, default="", allow_blank=True)
phone = serializers.CharField(help_text="手机号", required=False, default="", allow_blank=True)
phone_country_code = serializers.CharField(
help_text="手机国际区号", required=False, default=settings.DEFAULT_PHONE_COUNTRY_CODE, allow_blank=True
)
extras = serializers.JSONField(help_text="自定义字段", default=dict)
email = serializers.EmailField(help_text="邮箱")
phone = serializers.CharField(help_text="手机号")
phone_country_code = serializers.CharField(help_text="手机国际区号")
extras = serializers.JSONField(help_text="自定义字段")

def validate_extras(self, extras: Dict[str, Any]) -> Dict[str, Any]:
return validate_user_extras(extras, self.context["custom_fields"], self.context["data_source_id"])

def validate(self, attrs: Dict[str, Any]) -> Dict[str, Any]:
# 如果提供了手机号,则校验手机号是否合法
if attrs["phone"]:
try:
validate_phone_with_country_code(phone=attrs["phone"], country_code=attrs["phone_country_code"])
except ValueError as e:
raise ValidationError(str(e))
# 校验手机号是否合法
try:
validate_phone_with_country_code(phone=attrs["phone"], country_code=attrs["phone_country_code"])
except ValueError as e:
raise ValidationError(str(e))

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

return attrs

Expand Down Expand Up @@ -82,7 +81,7 @@ def _parse_user_infos(
field_count = len(required_field_names)
user_infos: List[Dict[str, Any]] = []
for idx, raw_info in enumerate(raw_user_infos, start=1):
# raw_info 格式是以空格为分隔符的用户信息字符串
# 注:raw_info 格式是以空格为分隔符的用户信息字符串
# 形式如:tiga 迪迦 [email protected] +8613612356789 male shenzhen running,swimming
# 字段对应:username full_name email phone gender region sport_hobbies
data: List[str] = [s for s in raw_info.split(" ") if s]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_data_source(self, obj: Tenant) -> Dict[str, Any] | None:
return TenantDataSourceSLZ(data_source).data


class TenantRequiredUserFieldOutputSLZ(serializers.Serializer):
class RequiredTenantUserFieldOutputSLZ(serializers.Serializer):
name = serializers.CharField(help_text="字段名称")
display_name = serializers.CharField(help_text="字段展示名")
tips = serializers.CharField(help_text="提示信息")
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def validate_department_id(self, department_id: int) -> int:
department_id
and not TenantDepartment.objects.filter(tenant_id=self.context["tenant_id"], id=department_id).exists()
):
raise ValidationError("部门不存在")
raise ValidationError(_("部门不存在"))

return department_id

Expand Down
6 changes: 3 additions & 3 deletions src/bk-user/bkuser/apis/web/organization/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# 租户用户 - 快速录入必填字段
path(
"tenants/required-user-fields/",
views.TenantRequiredUserFieldListApi.as_view(),
views.RequiredTenantUserFieldListApi.as_view(),
name="organization.tenant.required_user_field.list",
),
# 租户部门列表
Expand All @@ -49,13 +49,13 @@
views.TenantDepartmentSearchApi.as_view(),
name="organization.tenant_department.search",
),
# 数据源部门列表
# 可选租户部门列表(下拉框数据用)
path(
"tenants/optional-departments/",
views.OptionalTenantDepartmentListApi.as_view(),
name="organization.optional_department.list",
),
# 数据源用户列表
# 可选租户用户列表(下拉框数据用)
path(
"tenants/optional-leaders/",
views.OptionalTenantUserListApi.as_view(),
Expand Down
4 changes: 2 additions & 2 deletions src/bk-user/bkuser/apis/web/organization/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .tenants import (
CollaborativeTenantListApi,
CurrentTenantRetrieveApi,
TenantRequiredUserFieldListApi,
RequiredTenantUserFieldListApi,
)
from .users import (
OptionalTenantUserListApi,
Expand All @@ -40,7 +40,7 @@
# 租户
"CurrentTenantRetrieveApi",
"CollaborativeTenantListApi",
"TenantRequiredUserFieldListApi",
"RequiredTenantUserFieldListApi",
# 租户部门
"TenantDepartmentListCreateApi",
"TenantDepartmentUpdateDestroyApi",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def post(self, request, *args, **kwargs):
]
TenantUser.objects.bulk_create(tenant_users)

return Response(status=status.HTTP_201_CREATED)
return Response(status=status.HTTP_204_NO_CONTENT)


class TenantUserBatchCopyApi(CurrentUserTenantMixin, generics.CreateAPIView):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,9 @@ def get_queryset(self) -> QuerySet[TenantDepartment]:
slz.is_valid(raise_exception=True)
params = slz.validated_data

cur_tenant_id = self.get_current_tenant_id()
queryset = TenantDepartment.objects.filter(
data_source__owner_tenant_id=self.get_current_tenant_id()
tenant_id=cur_tenant_id, data_source__owner_tenant_id=cur_tenant_id
).select_related("data_source_department")
if kw := params.get("keyword"):
queryset = queryset.filter(data_source_department__name__icontains=kw)
Expand Down
8 changes: 4 additions & 4 deletions src/bk-user/bkuser/apis/web/organization/views/tenants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

from bkuser.apis.web.mixins import CurrentUserTenantMixin
from bkuser.apis.web.organization.serializers import (
RequiredTenantUserFieldOutputSLZ,
TenantListOutputSLZ,
TenantRequiredUserFieldOutputSLZ,
TenantRetrieveOutputSLZ,
)
from bkuser.apps.permission.constants import PermAction
Expand Down Expand Up @@ -79,7 +79,7 @@ def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)


class TenantRequiredUserFieldListApi(CurrentUserTenantMixin, generics.ListAPIView):
class RequiredTenantUserFieldListApi(CurrentUserTenantMixin, generics.ListAPIView):
"""租户用户必填字段(快速录入用)"""

permission_classes = [IsAuthenticated, perm_class(PermAction.MANAGE_TENANT)]
Expand All @@ -89,7 +89,7 @@ class TenantRequiredUserFieldListApi(CurrentUserTenantMixin, generics.ListAPIVie
@swagger_auto_schema(
tags=["organization.tenant"],
operation_description="快速录入租户用户必填字段",
responses={status.HTTP_200_OK: TenantRequiredUserFieldOutputSLZ(many=True)},
responses={status.HTTP_200_OK: RequiredTenantUserFieldOutputSLZ(many=True)},
)
def get(self, request, *args, **kwargs):
cur_tenant_id = self.get_current_tenant_id()
Expand All @@ -110,4 +110,4 @@ def get(self, request, *args, **kwargs):

field_infos.append({"name": f.name, "display_name": f.display_name, "tips": tips})

return Response(TenantRequiredUserFieldOutputSLZ(field_infos, many=True).data, status=status.HTTP_200_OK)
return Response(RequiredTenantUserFieldOutputSLZ(field_infos, many=True).data, status=status.HTTP_200_OK)

0 comments on commit 866631a

Please sign in to comment.