2025-04-14 12:11:23 +00:00
|
|
|
|
# coding=utf-8
|
|
|
|
|
|
"""
|
|
|
|
|
|
@project: MaxKB
|
|
|
|
|
|
@Author:虎虎
|
|
|
|
|
|
@file: user.py
|
|
|
|
|
|
@date:2025/4/14 19:25
|
|
|
|
|
|
@desc:
|
|
|
|
|
|
"""
|
|
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2025-04-17 06:27:58 +00:00
|
|
|
|
from drf_spectacular.utils import extend_schema
|
2025-04-14 12:11:23 +00:00
|
|
|
|
from rest_framework.request import Request
|
2025-04-17 06:27:58 +00:00
|
|
|
|
from rest_framework.views import APIView
|
2025-04-14 12:11:23 +00:00
|
|
|
|
|
2025-04-17 06:27:58 +00:00
|
|
|
|
from common.auth.authenticate import TokenAuth
|
2025-04-15 12:37:38 +00:00
|
|
|
|
from common.auth.authentication import has_permissions
|
2025-04-17 09:16:45 +00:00
|
|
|
|
from common.constants.permission_constants import PermissionConstants, Permission, Group, Operate
|
2025-04-14 12:11:23 +00:00
|
|
|
|
from common.result import result
|
2025-04-17 02:35:02 +00:00
|
|
|
|
from users.api.user import UserProfileAPI, TestWorkspacePermissionUserApi
|
2025-04-27 08:26:40 +00:00
|
|
|
|
from users.serializers.user import UserProfileSerializer, UserManageSerializer
|
2025-04-14 12:11:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserProfileView(APIView):
|
|
|
|
|
|
authentication_classes = [TokenAuth]
|
|
|
|
|
|
|
|
|
|
|
|
@extend_schema(methods=['GET'],
|
|
|
|
|
|
description=_("Get current user information"),
|
|
|
|
|
|
operation_id=_("Get current user information"),
|
|
|
|
|
|
tags=[_("User management")],
|
|
|
|
|
|
responses=UserProfileAPI.get_response())
|
|
|
|
|
|
def get(self, request: Request):
|
|
|
|
|
|
return result.success(UserProfileSerializer().profile(request.user))
|
2025-04-15 12:37:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestPermissionsUserView(APIView):
|
|
|
|
|
|
authentication_classes = [TokenAuth]
|
|
|
|
|
|
|
|
|
|
|
|
@extend_schema(methods=['GET'],
|
|
|
|
|
|
description=_("Get current user information"),
|
2025-04-17 06:27:58 +00:00
|
|
|
|
operation_id="测试",
|
2025-04-15 12:37:38 +00:00
|
|
|
|
tags=[_("User management")],
|
|
|
|
|
|
responses=UserProfileAPI.get_response())
|
|
|
|
|
|
@has_permissions(PermissionConstants.USER_EDIT)
|
|
|
|
|
|
def get(self, request: Request):
|
|
|
|
|
|
return result.success(UserProfileSerializer().profile(request.user))
|
2025-04-17 02:35:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestWorkspacePermissionUserView(APIView):
|
|
|
|
|
|
authentication_classes = [TokenAuth]
|
|
|
|
|
|
|
|
|
|
|
|
@extend_schema(methods=['GET'],
|
|
|
|
|
|
description="针对工作空间下权限校验",
|
|
|
|
|
|
operation_id="针对工作空间下权限校验",
|
|
|
|
|
|
tags=[_("User management")],
|
|
|
|
|
|
responses=UserProfileAPI.get_response(),
|
|
|
|
|
|
parameters=TestWorkspacePermissionUserApi.get_parameters())
|
|
|
|
|
|
@has_permissions(PermissionConstants.USER_EDIT.get_workspace_permission())
|
|
|
|
|
|
def get(self, request: Request, workspace_id):
|
|
|
|
|
|
return result.success(UserProfileSerializer().profile(request.user))
|
2025-04-27 08:26:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserManage(APIView):
|
|
|
|
|
|
authentication_classes = [TokenAuth]
|
|
|
|
|
|
|
|
|
|
|
|
@extend_schema(methods=['POST'],
|
|
|
|
|
|
description=_("Create user"),
|
|
|
|
|
|
operation_id=_("Create user"),
|
|
|
|
|
|
tags=[_("User management")],
|
|
|
|
|
|
request=UserProfileAPI.get_request(),
|
|
|
|
|
|
responses=UserProfileAPI.get_response())
|
|
|
|
|
|
@has_permissions(PermissionConstants.USER_CREATE)
|
|
|
|
|
|
def post(self, request: Request):
|
|
|
|
|
|
return result.success(UserManageSerializer().save(request.data))
|