2024-10-23 09:01:19 +00:00
|
|
|
|
# coding=utf-8
|
|
|
|
|
|
"""
|
|
|
|
|
|
@project: MaxKB
|
|
|
|
|
|
@Author:虎
|
|
|
|
|
|
@file: application_version_views.py
|
|
|
|
|
|
@date:2024/10/15 16:49
|
|
|
|
|
|
@desc:
|
|
|
|
|
|
"""
|
|
|
|
|
|
from drf_yasg.utils import swagger_auto_schema
|
|
|
|
|
|
from rest_framework.decorators import action
|
|
|
|
|
|
from rest_framework.request import Request
|
|
|
|
|
|
from rest_framework.views import APIView
|
|
|
|
|
|
|
|
|
|
|
|
from application.serializers.application_version_serializers import ApplicationVersionSerializer
|
|
|
|
|
|
from application.swagger_api.application_version_api import ApplicationVersionApi
|
|
|
|
|
|
from common.auth import has_permissions, TokenAuth
|
|
|
|
|
|
from common.constants.permission_constants import PermissionConstants, CompareConstants, ViewPermission, RoleConstants, \
|
|
|
|
|
|
Permission, Group, Operate
|
2025-03-19 07:45:10 +00:00
|
|
|
|
from common.log.log import log
|
2024-10-23 09:01:19 +00:00
|
|
|
|
from common.response import result
|
2025-01-13 11:05:08 +00:00
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2024-10-23 09:01:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ApplicationVersionView(APIView):
|
|
|
|
|
|
authentication_classes = [TokenAuth]
|
|
|
|
|
|
|
|
|
|
|
|
@action(methods=['GET'], detail=False)
|
2025-01-13 11:05:08 +00:00
|
|
|
|
@swagger_auto_schema(operation_summary=_("Get the application list"),
|
|
|
|
|
|
operation_id=_("Get the application list"),
|
2024-10-23 09:01:19 +00:00
|
|
|
|
manual_parameters=ApplicationVersionApi.Query.get_request_params_api(),
|
|
|
|
|
|
responses=result.get_api_array_response(ApplicationVersionApi.get_response_body_api()),
|
2025-01-13 11:05:08 +00:00
|
|
|
|
tags=[_('Application/Version')])
|
2024-10-23 09:01:19 +00:00
|
|
|
|
@has_permissions(PermissionConstants.APPLICATION_READ, compare=CompareConstants.AND)
|
2025-03-19 07:45:10 +00:00
|
|
|
|
@log(menu='Application', operate="Get the application list")
|
2024-10-23 09:01:19 +00:00
|
|
|
|
def get(self, request: Request, application_id: str):
|
|
|
|
|
|
return result.success(
|
|
|
|
|
|
ApplicationVersionSerializer.Query(
|
|
|
|
|
|
data={'name': request.query_params.get('name'), 'user_id': request.user.id,
|
|
|
|
|
|
'application_id': application_id}).list())
|
|
|
|
|
|
|
|
|
|
|
|
class Page(APIView):
|
|
|
|
|
|
authentication_classes = [TokenAuth]
|
|
|
|
|
|
|
|
|
|
|
|
@action(methods=['GET'], detail=False)
|
2025-01-13 11:05:08 +00:00
|
|
|
|
@swagger_auto_schema(operation_summary=_("Get the list of application versions by page"),
|
|
|
|
|
|
operation_id=_("Get the list of application versions by page"),
|
2024-10-23 09:01:19 +00:00
|
|
|
|
manual_parameters=result.get_page_request_params(
|
|
|
|
|
|
ApplicationVersionApi.Query.get_request_params_api()),
|
|
|
|
|
|
responses=result.get_page_api_response(ApplicationVersionApi.get_response_body_api()),
|
2025-01-13 11:05:08 +00:00
|
|
|
|
tags=[_('Application/Version')])
|
2024-10-23 09:01:19 +00:00
|
|
|
|
@has_permissions(PermissionConstants.APPLICATION_READ, compare=CompareConstants.AND)
|
2025-03-19 07:45:10 +00:00
|
|
|
|
@log(menu='Application', operate="Get the list of application versions by page")
|
2024-10-23 09:01:19 +00:00
|
|
|
|
def get(self, request: Request, application_id: str, current_page: int, page_size: int):
|
|
|
|
|
|
return result.success(
|
|
|
|
|
|
ApplicationVersionSerializer.Query(
|
|
|
|
|
|
data={'name': request.query_params.get('name'), 'user_id': request.user,
|
|
|
|
|
|
'application_id': application_id}).page(
|
|
|
|
|
|
current_page, page_size))
|
|
|
|
|
|
|
|
|
|
|
|
class Operate(APIView):
|
|
|
|
|
|
authentication_classes = [TokenAuth]
|
|
|
|
|
|
|
|
|
|
|
|
@action(methods=['GET'], detail=False)
|
2025-01-13 11:05:08 +00:00
|
|
|
|
@swagger_auto_schema(operation_summary=_("Get application version details"),
|
|
|
|
|
|
operation_id=_("Get application version details"),
|
2024-10-23 09:01:19 +00:00
|
|
|
|
manual_parameters=ApplicationVersionApi.Operate.get_request_params_api(),
|
|
|
|
|
|
responses=result.get_api_response(ApplicationVersionApi.get_response_body_api()),
|
2025-01-13 11:05:08 +00:00
|
|
|
|
tags=[_('Application/Version')])
|
2024-10-23 09:01:19 +00:00
|
|
|
|
@has_permissions(PermissionConstants.APPLICATION_READ, compare=CompareConstants.AND)
|
2025-03-19 07:45:10 +00:00
|
|
|
|
@log(menu='Application', operate="Get application version details")
|
2024-10-23 09:01:19 +00:00
|
|
|
|
def get(self, request: Request, application_id: str, work_flow_version_id: str):
|
|
|
|
|
|
return result.success(
|
|
|
|
|
|
ApplicationVersionSerializer.Operate(
|
|
|
|
|
|
data={'user_id': request.user,
|
|
|
|
|
|
'application_id': application_id, 'work_flow_version_id': work_flow_version_id}).one())
|
|
|
|
|
|
|
|
|
|
|
|
@action(methods=['PUT'], detail=False)
|
2025-01-13 11:05:08 +00:00
|
|
|
|
@swagger_auto_schema(operation_summary=_("Modify application version information"),
|
|
|
|
|
|
operation_id=_("Modify application version information"),
|
2024-10-23 09:01:19 +00:00
|
|
|
|
manual_parameters=ApplicationVersionApi.Operate.get_request_params_api(),
|
|
|
|
|
|
request_body=ApplicationVersionApi.Edit.get_request_body_api(),
|
|
|
|
|
|
responses=result.get_api_response(ApplicationVersionApi.get_response_body_api()),
|
2025-01-13 11:05:08 +00:00
|
|
|
|
tags=[_('Application/Version')])
|
2024-10-23 09:01:19 +00:00
|
|
|
|
@has_permissions(ViewPermission(
|
|
|
|
|
|
[RoleConstants.ADMIN, RoleConstants.USER],
|
|
|
|
|
|
[lambda r, keywords: Permission(group=Group.APPLICATION, operate=Operate.MANAGE,
|
|
|
|
|
|
dynamic_tag=keywords.get('application_id'))],
|
|
|
|
|
|
compare=CompareConstants.AND))
|
2025-03-19 07:45:10 +00:00
|
|
|
|
@log(menu='Application', operate="Modify application version information")
|
2024-10-23 09:01:19 +00:00
|
|
|
|
def put(self, request: Request, application_id: str, work_flow_version_id: str):
|
|
|
|
|
|
return result.success(
|
|
|
|
|
|
ApplicationVersionSerializer.Operate(
|
|
|
|
|
|
data={'application_id': application_id, 'work_flow_version_id': work_flow_version_id,
|
|
|
|
|
|
'user_id': request.user.id}).edit(
|
|
|
|
|
|
request.data))
|