refactor: user add default password
Some checks are pending
sync2gitee / repo-sync (push) Waiting to run

This commit is contained in:
wxg0103 2025-05-13 14:39:47 +08:00
parent c3581be9bd
commit 4eed42b6a0
6 changed files with 42 additions and 1 deletions

View File

@ -3311,3 +3311,6 @@ msgstr ""
#: apps/users/views/user.py:139
msgid "Get user paginated list"
msgstr ""
msgid "Get default password"
msgstr ""

View File

@ -3489,3 +3489,5 @@ msgstr "修改密码"
msgid "Get user paginated list"
msgstr "获取用户分页列表"
msgid "Get default password"
msgstr "获取默认密码"

View File

@ -3489,3 +3489,6 @@ msgstr "修改密碼"
msgid "Get user paginated list"
msgstr "獲取用戶分頁列表"
msgid "Get default password"
msgstr "獲取默認密碼"

View File

@ -43,6 +43,22 @@ class UserProfileAPI(APIMixin):
)]
class UserPasswordResponse(APIMixin):
@staticmethod
def get_response():
return PasswordResponse
class Password(serializers.Serializer):
password = serializers.CharField(required=True, label=_('Password'))
class PasswordResponse(ResultSerializer):
def get_data(self):
return Password()
class EditUserApi(APIMixin):
@staticmethod
def get_parameters():

View File

@ -11,6 +11,7 @@ urlpatterns = [
path('workspace/<str:workspace_id>/user/profile', views.TestWorkspacePermissionUserView.as_view(),
name="test_workspace_id_permission"),
path("user_manage", views.UserManage.as_view(), name="user_manage"),
path("user_manage/password", views.UserManage.Password.as_view()),
path("user_manage/<str:user_id>", views.UserManage.Operate.as_view(), name="user_manage_operate"),
path("user_manage/<str:user_id>/re_password", views.UserManage.RePassword.as_view(),
name="user_manage_re_password"),

View File

@ -15,11 +15,14 @@ from common.auth.authenticate import TokenAuth
from common.auth.authentication import has_permissions
from common.constants.permission_constants import PermissionConstants, Permission, Group, Operate
from common.result import result
from maxkb.const import CONFIG
from models_provider.api.model import DefaultModelResponse
from users.api.user import UserProfileAPI, TestWorkspacePermissionUserApi, DeleteUserApi, EditUserApi, \
ChangeUserPasswordApi, UserPageApi, UserListApi
ChangeUserPasswordApi, UserPageApi, UserListApi, UserPasswordResponse
from users.serializers.user import UserProfileSerializer, UserManageSerializer
default_password = CONFIG.get('default_password', 'MaxKB@123..')
class UserProfileView(APIView):
authentication_classes = [TokenAuth]
@ -77,6 +80,19 @@ class UserManage(APIView):
def post(self, request: Request):
return result.success(UserManageSerializer().save(request.data))
class Password(APIView):
authentication_classes = [TokenAuth]
@extend_schema(methods=['Get'],
summary=_("Get default password"),
description=_("Get default password"),
operation_id=_("Get default password"), # type: ignore
tags=[_("User management")], # type: ignore
responses=UserPasswordResponse.get_response())
@has_permissions(PermissionConstants.USER_CREATE)
def get(self, request: Request):
return result.success(data={'password': default_password})
class Operate(APIView):
authentication_classes = [TokenAuth]