2025-06-04 05:05:39 +00:00
|
|
|
|
# coding=utf-8
|
|
|
|
|
|
"""
|
|
|
|
|
|
@project: MaxKB
|
|
|
|
|
|
@Author:虎虎
|
|
|
|
|
|
@file: application_version.py.py
|
|
|
|
|
|
@date:2025/6/3 15:46
|
|
|
|
|
|
@desc:
|
|
|
|
|
|
"""
|
|
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
from drf_spectacular.utils import extend_schema
|
|
|
|
|
|
from rest_framework.request import Request
|
|
|
|
|
|
from rest_framework.views import APIView
|
|
|
|
|
|
|
2025-06-04 12:14:52 +00:00
|
|
|
|
from application.api.application_version import ApplicationVersionListAPI, ApplicationVersionPageAPI, \
|
|
|
|
|
|
ApplicationVersionAPI, ApplicationVersionOperateAPI
|
2025-06-04 05:05:39 +00:00
|
|
|
|
from application.serializers.application_version import ApplicationVersionSerializer
|
|
|
|
|
|
from common import result
|
|
|
|
|
|
from common.auth import TokenAuth
|
|
|
|
|
|
from common.auth.authentication import has_permissions
|
|
|
|
|
|
from common.constants.permission_constants import PermissionConstants
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ApplicationVersionView(APIView):
|
|
|
|
|
|
authentication_classes = [TokenAuth]
|
|
|
|
|
|
|
|
|
|
|
|
@extend_schema(
|
2025-06-04 12:14:52 +00:00
|
|
|
|
methods=['GET'],
|
|
|
|
|
|
description=_("Get the application version list"),
|
|
|
|
|
|
summary=_("Get the application version list"),
|
|
|
|
|
|
operation_id=_("Get the application version list"), # type: ignore
|
|
|
|
|
|
parameters=ApplicationVersionListAPI.get_parameters(),
|
|
|
|
|
|
responses=ApplicationVersionListAPI.get_response(),
|
2025-06-04 05:05:39 +00:00
|
|
|
|
tags=[_('Application/Version')] # type: ignore
|
|
|
|
|
|
)
|
2025-06-04 12:14:52 +00:00
|
|
|
|
@has_permissions(PermissionConstants.APPLICATION_READ.get_workspace_application_permission())
|
2025-06-04 05:05:39 +00:00
|
|
|
|
def get(self, request: Request, workspace_id, application_id: str):
|
|
|
|
|
|
return result.success(
|
|
|
|
|
|
ApplicationVersionSerializer.Query(
|
2025-06-04 12:14:52 +00:00
|
|
|
|
data={'workspace_id': workspace_id}).list(
|
|
|
|
|
|
{'name': request.query_params.get("name"), 'application_id': application_id}))
|
2025-06-04 05:05:39 +00:00
|
|
|
|
|
|
|
|
|
|
class Page(APIView):
|
|
|
|
|
|
authentication_classes = [TokenAuth]
|
|
|
|
|
|
|
|
|
|
|
|
@extend_schema(
|
2025-06-04 12:14:52 +00:00
|
|
|
|
methods=['GET'],
|
2025-06-04 05:05:39 +00:00
|
|
|
|
description=_("Get the list of application versions by page"),
|
|
|
|
|
|
summary=_("Get the list of application versions by page"),
|
|
|
|
|
|
operation_id=_("Get the list of application versions by page"), # type: ignore
|
2025-06-04 12:14:52 +00:00
|
|
|
|
parameters=ApplicationVersionPageAPI.get_parameters(),
|
|
|
|
|
|
responses=ApplicationVersionPageAPI.get_response(),
|
2025-06-04 05:05:39 +00:00
|
|
|
|
tags=[_('Application/Version')] # type: ignore
|
|
|
|
|
|
)
|
2025-06-04 12:14:52 +00:00
|
|
|
|
@has_permissions(PermissionConstants.APPLICATION_READ.get_workspace_application_permission())
|
|
|
|
|
|
def get(self, request: Request, workspace_id: str, application_id: str, current_page: int, page_size: int):
|
2025-06-04 05:05:39 +00:00
|
|
|
|
return result.success(
|
|
|
|
|
|
ApplicationVersionSerializer.Query(
|
2025-06-04 12:14:52 +00:00
|
|
|
|
data={'workspace_id': workspace_id}).page(
|
|
|
|
|
|
{'name': request.query_params.get("name"), 'application_id': application_id},
|
2025-06-04 05:05:39 +00:00
|
|
|
|
current_page, page_size))
|
|
|
|
|
|
|
|
|
|
|
|
class Operate(APIView):
|
|
|
|
|
|
authentication_classes = [TokenAuth]
|
|
|
|
|
|
|
|
|
|
|
|
@extend_schema(
|
|
|
|
|
|
methods=['GET'],
|
|
|
|
|
|
description=_("Get application version details"),
|
|
|
|
|
|
summary=_("Get application version details"),
|
|
|
|
|
|
operation_id=_("Get application version details"), # type: ignore
|
2025-06-04 12:14:52 +00:00
|
|
|
|
parameters=ApplicationVersionOperateAPI.get_parameters(),
|
|
|
|
|
|
responses=ApplicationVersionOperateAPI.get_response(),
|
2025-06-04 05:05:39 +00:00
|
|
|
|
tags=[_('Application/Version')] # type: ignore
|
|
|
|
|
|
)
|
2025-06-04 12:14:52 +00:00
|
|
|
|
@has_permissions(PermissionConstants.APPLICATION_EDIT.get_workspace_application_permission())
|
|
|
|
|
|
def get(self, request: Request, workspace_id: str, application_id: str, work_flow_version_id: str):
|
2025-06-04 05:05:39 +00:00
|
|
|
|
return result.success(
|
|
|
|
|
|
ApplicationVersionSerializer.Operate(
|
|
|
|
|
|
data={'user_id': request.user,
|
|
|
|
|
|
'application_id': application_id, 'work_flow_version_id': work_flow_version_id}).one())
|
|
|
|
|
|
|
|
|
|
|
|
@extend_schema(
|
|
|
|
|
|
methods=['PUT'],
|
|
|
|
|
|
description=_("Modify application version information"),
|
|
|
|
|
|
summary=_("Modify application version information"),
|
|
|
|
|
|
operation_id=_("Modify application version information"), # type: ignore
|
2025-06-04 12:14:52 +00:00
|
|
|
|
parameters=ApplicationVersionOperateAPI.get_parameters(),
|
|
|
|
|
|
request=None,
|
|
|
|
|
|
responses=ApplicationVersionOperateAPI.get_response(),
|
2025-06-04 05:05:39 +00:00
|
|
|
|
tags=[_('Application/Version')] # type: ignore
|
|
|
|
|
|
)
|
2025-06-04 12:14:52 +00:00
|
|
|
|
def put(self, request: Request, workspace_id: str, application_id: str, work_flow_version_id: str):
|
2025-06-04 05:05:39 +00:00
|
|
|
|
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))
|