Skip to content

Commit 4eed42b

Browse files
committed
refactor: user add default password
1 parent c3581be commit 4eed42b

File tree

6 files changed

+42
-1
lines changed

6 files changed

+42
-1
lines changed

apps/locales/en_US/LC_MESSAGES/django.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3311,3 +3311,6 @@ msgstr ""
33113311
#: apps/users/views/user.py:139
33123312
msgid "Get user paginated list"
33133313
msgstr ""
3314+
3315+
msgid "Get default password"
3316+
msgstr ""

apps/locales/zh_CN/LC_MESSAGES/django.po

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3489,3 +3489,5 @@ msgstr "修改密码"
34893489
msgid "Get user paginated list"
34903490
msgstr "获取用户分页列表"
34913491

3492+
msgid "Get default password"
3493+
msgstr "获取默认密码"

apps/locales/zh_Hant/LC_MESSAGES/django.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3489,3 +3489,6 @@ msgstr "修改密碼"
34893489
msgid "Get user paginated list"
34903490
msgstr "獲取用戶分頁列表"
34913491

3492+
msgid "Get default password"
3493+
msgstr "獲取默認密碼"
3494+

apps/users/api/user.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ def get_parameters():
4343
)]
4444

4545

46+
class UserPasswordResponse(APIMixin):
47+
48+
@staticmethod
49+
def get_response():
50+
return PasswordResponse
51+
52+
53+
class Password(serializers.Serializer):
54+
password = serializers.CharField(required=True, label=_('Password'))
55+
56+
57+
class PasswordResponse(ResultSerializer):
58+
def get_data(self):
59+
return Password()
60+
61+
4662
class EditUserApi(APIMixin):
4763
@staticmethod
4864
def get_parameters():

apps/users/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
path('workspace/<str:workspace_id>/user/profile', views.TestWorkspacePermissionUserView.as_view(),
1212
name="test_workspace_id_permission"),
1313
path("user_manage", views.UserManage.as_view(), name="user_manage"),
14+
path("user_manage/password", views.UserManage.Password.as_view()),
1415
path("user_manage/<str:user_id>", views.UserManage.Operate.as_view(), name="user_manage_operate"),
1516
path("user_manage/<str:user_id>/re_password", views.UserManage.RePassword.as_view(),
1617
name="user_manage_re_password"),

apps/users/views/user.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
from common.auth.authentication import has_permissions
1616
from common.constants.permission_constants import PermissionConstants, Permission, Group, Operate
1717
from common.result import result
18+
from maxkb.const import CONFIG
1819
from models_provider.api.model import DefaultModelResponse
1920
from users.api.user import UserProfileAPI, TestWorkspacePermissionUserApi, DeleteUserApi, EditUserApi, \
20-
ChangeUserPasswordApi, UserPageApi, UserListApi
21+
ChangeUserPasswordApi, UserPageApi, UserListApi, UserPasswordResponse
2122
from users.serializers.user import UserProfileSerializer, UserManageSerializer
2223

24+
default_password = CONFIG.get('default_password', 'MaxKB@123..')
25+
2326

2427
class UserProfileView(APIView):
2528
authentication_classes = [TokenAuth]
@@ -77,6 +80,19 @@ class UserManage(APIView):
7780
def post(self, request: Request):
7881
return result.success(UserManageSerializer().save(request.data))
7982

83+
class Password(APIView):
84+
authentication_classes = [TokenAuth]
85+
86+
@extend_schema(methods=['Get'],
87+
summary=_("Get default password"),
88+
description=_("Get default password"),
89+
operation_id=_("Get default password"), # type: ignore
90+
tags=[_("User management")], # type: ignore
91+
responses=UserPasswordResponse.get_response())
92+
@has_permissions(PermissionConstants.USER_CREATE)
93+
def get(self, request: Request):
94+
return result.success(data={'password': default_password})
95+
8096
class Operate(APIView):
8197
authentication_classes = [TokenAuth]
8298

0 commit comments

Comments
 (0)