2025-04-14 12:11:23 +00:00
|
|
|
|
# coding=utf-8
|
|
|
|
|
|
"""
|
|
|
|
|
|
@project: MaxKB
|
|
|
|
|
|
@Author:虎虎
|
|
|
|
|
|
@file: user.py
|
|
|
|
|
|
@date:2025/4/14 19:23
|
|
|
|
|
|
@desc:
|
|
|
|
|
|
"""
|
2025-04-17 02:35:02 +00:00
|
|
|
|
from drf_spectacular.types import OpenApiTypes
|
|
|
|
|
|
from drf_spectacular.utils import OpenApiParameter
|
|
|
|
|
|
|
2025-04-14 12:11:23 +00:00
|
|
|
|
from common.mixins.api_mixin import APIMixin
|
|
|
|
|
|
from common.result import ResultSerializer
|
2025-04-28 09:36:56 +00:00
|
|
|
|
from users.serializers.user import UserProfileResponse, CreateUserSerializer, UserManageSerializer, \
|
|
|
|
|
|
UserInstanceSerializer
|
|
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
from rest_framework import serializers
|
2025-04-14 12:11:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ApiUserProfileResponse(ResultSerializer):
|
|
|
|
|
|
def get_data(self):
|
|
|
|
|
|
return UserProfileResponse()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserProfileAPI(APIMixin):
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_response():
|
|
|
|
|
|
return ApiUserProfileResponse
|
2025-04-17 02:35:02 +00:00
|
|
|
|
|
2025-04-27 08:26:40 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_request():
|
|
|
|
|
|
return CreateUserSerializer
|
|
|
|
|
|
|
2025-04-28 09:36:56 +00:00
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_parameters():
|
|
|
|
|
|
return [OpenApiParameter(
|
|
|
|
|
|
name="user_id",
|
|
|
|
|
|
description=_('User ID'),
|
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
|
location=OpenApiParameter.PATH,
|
|
|
|
|
|
required=True,
|
|
|
|
|
|
)]
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-15 04:07:07 +00:00
|
|
|
|
class WorkspaceUserAPI(APIMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_parameters():
|
|
|
|
|
|
return [OpenApiParameter(
|
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
|
description=_('Workspace ID'),
|
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
|
location=OpenApiParameter.PATH,
|
|
|
|
|
|
required=True,
|
|
|
|
|
|
)]
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_response():
|
|
|
|
|
|
return WorkspaceUserListResponse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WorkspaceUser(serializers.Serializer):
|
|
|
|
|
|
id = serializers.CharField(required=True, label=_('id'))
|
|
|
|
|
|
username = serializers.CharField(required=True, label=_('Username'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WorkspaceUserListResponse(ResultSerializer):
|
|
|
|
|
|
def get_data(self):
|
|
|
|
|
|
return serializers.ListSerializer(child=WorkspaceUser())
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-13 06:39:47 +00:00
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-28 09:36:56 +00:00
|
|
|
|
class EditUserApi(APIMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_parameters():
|
|
|
|
|
|
return [OpenApiParameter(
|
|
|
|
|
|
name="user_id",
|
|
|
|
|
|
description=_('User ID'),
|
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
|
location=OpenApiParameter.PATH,
|
|
|
|
|
|
required=True,
|
|
|
|
|
|
)]
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_request():
|
|
|
|
|
|
return UserManageSerializer.UserEditInstance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DeleteUserApi(APIMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_parameters():
|
|
|
|
|
|
return [OpenApiParameter(
|
|
|
|
|
|
name="user_id",
|
|
|
|
|
|
description=_('User ID'),
|
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
|
location=OpenApiParameter.PATH,
|
|
|
|
|
|
required=True,
|
|
|
|
|
|
)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChangeUserPasswordApi(APIMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_request():
|
|
|
|
|
|
return UserManageSerializer.RePasswordInstance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserListResponse(ResultSerializer):
|
|
|
|
|
|
def get_data(self):
|
|
|
|
|
|
return serializers.ListSerializer(child=UserInstanceSerializer())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserPageApi(APIMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_parameters():
|
|
|
|
|
|
return [OpenApiParameter(
|
|
|
|
|
|
name="email_or_username",
|
|
|
|
|
|
description=_('Email or Username'),
|
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
|
location=OpenApiParameter.QUERY,
|
|
|
|
|
|
required=False,
|
|
|
|
|
|
)]
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_response():
|
|
|
|
|
|
return UserListResponse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserListApi(APIMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_parameters():
|
|
|
|
|
|
return [OpenApiParameter(
|
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
|
description=_('Workspace ID'),
|
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
|
location=OpenApiParameter.PATH,
|
|
|
|
|
|
required=False,
|
|
|
|
|
|
)]
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_response():
|
|
|
|
|
|
return UserListResponse
|
|
|
|
|
|
|
2025-04-17 02:35:02 +00:00
|
|
|
|
|
|
|
|
|
|
class TestWorkspacePermissionUserApi(APIMixin):
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
def get_parameters():
|
|
|
|
|
|
return [OpenApiParameter(
|
|
|
|
|
|
# 参数的名称是done
|
|
|
|
|
|
name="workspace_id",
|
|
|
|
|
|
# 对参数的备注
|
|
|
|
|
|
description="工作空间id",
|
|
|
|
|
|
# 指定参数的类型
|
|
|
|
|
|
type=OpenApiTypes.STR,
|
|
|
|
|
|
location=OpenApiParameter.PATH,
|
|
|
|
|
|
# 指定必须给
|
|
|
|
|
|
required=True,
|
|
|
|
|
|
)]
|