From ab1024fbf4e73086ad0b246f8efce651a6d19e4b Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Mon, 28 Feb 2022 20:22:14 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=20super=20ticket=20?= =?UTF-8?q?=E7=9A=84=E7=8A=B6=E6=80=81=20(#7714)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: token 系统用户增加 protocol * fix: 修复清除orphan session时同时清除对应的 session_task * perf: 修改 connection token api * fix: 修复无法获取系统角色绑定的问题 * perf: 增加 db terminal 及 magnus 组件 * perf: 修改 migrations * fix: 修复AUTHENTICATION_BACKENDS相关的逻辑 * fix: 修改判断backend认证逻辑 * fix: 修复资产账号查看密码跳过mfa * fix: 修复用户组授权权限错误 * feat: 支持COS对象存储 * feat: 升级依赖 jms_storage==0.0.42 * fix: 修复 koko api 问题 * feat: 修改存储翻译信息 * perf: 修改 ticket 权限 * fix: 修复获取资产授权系统用户 get_queryset * perf: 抽取 ticket * perf: 修改 cmd filter 的权限 * fix: 修改 ticket perm * perf: 修改工单的api Co-authored-by: Eric Co-authored-by: Jiangjie.Bai Co-authored-by: ibuler Co-authored-by: 小冯 Co-authored-by: feng626 <1304903146@qq.com> --- apps/acls/api/login_asset_check.py | 8 ++--- apps/acls/urls/api_urls.py | 1 - apps/assets/api/cmd_filter.py | 7 +--- apps/assets/urls/api_urls.py | 1 - apps/tickets/api/__init__.py | 2 +- apps/tickets/api/common.py | 43 ------------------------ apps/tickets/api/super_ticket.py | 20 +++++++++++ apps/tickets/models/ticket.py | 2 +- apps/tickets/serializers/__init__.py | 1 + apps/tickets/serializers/super_ticket.py | 12 +++++++ apps/tickets/urls/api_urls.py | 1 + 11 files changed, 39 insertions(+), 59 deletions(-) delete mode 100644 apps/tickets/api/common.py create mode 100644 apps/tickets/api/super_ticket.py create mode 100644 apps/tickets/serializers/super_ticket.py diff --git a/apps/acls/api/login_asset_check.py b/apps/acls/api/login_asset_check.py index 49044509e..fc5f4157f 100644 --- a/apps/acls/api/login_asset_check.py +++ b/apps/acls/api/login_asset_check.py @@ -3,11 +3,10 @@ from rest_framework.generics import CreateAPIView from common.utils import reverse, lazyproperty from orgs.utils import tmp_to_org -from tickets.api import GenericTicketStatusRetrieveCloseAPI from ..models import LoginAssetACL from .. import serializers -__all__ = ['LoginAssetCheckAPI', 'LoginAssetConfirmStatusAPI'] +__all__ = ['LoginAssetCheckAPI'] class LoginAssetCheckAPI(CreateAPIView): @@ -51,7 +50,7 @@ class LoginAssetCheckAPI(CreateAPIView): org_id=self.serializer.org.id ) confirm_status_url = reverse( - view_name='api-acls:login-asset-confirm-status', + view_name='api-tickets:super-ticket-status', kwargs={'pk': str(ticket.id)} ) ticket_detail_url = reverse( @@ -76,6 +75,3 @@ class LoginAssetCheckAPI(CreateAPIView): serializer.is_valid(raise_exception=True) return serializer - -class LoginAssetConfirmStatusAPI(GenericTicketStatusRetrieveCloseAPI): - pass diff --git a/apps/acls/urls/api_urls.py b/apps/acls/urls/api_urls.py index 24fbc11b0..c4040ff45 100644 --- a/apps/acls/urls/api_urls.py +++ b/apps/acls/urls/api_urls.py @@ -12,7 +12,6 @@ router.register(r'login-asset-acls', api.LoginAssetACLViewSet, 'login-asset-acl' urlpatterns = [ path('login-asset/check/', api.LoginAssetCheckAPI.as_view(), name='login-asset-check'), - path('login-asset-confirm//status/', api.LoginAssetConfirmStatusAPI.as_view(), name='login-asset-confirm-status') ] urlpatterns += router.urls diff --git a/apps/assets/api/cmd_filter.py b/apps/assets/api/cmd_filter.py index 1c73d6d0b..c9fad91a0 100644 --- a/apps/assets/api/cmd_filter.py +++ b/apps/assets/api/cmd_filter.py @@ -8,13 +8,11 @@ from django.shortcuts import get_object_or_404 from common.utils import reverse from common.utils import lazyproperty from orgs.mixins.api import OrgBulkModelViewSet -from tickets.api import GenericTicketStatusRetrieveCloseAPI from ..models import CommandFilter, CommandFilterRule from .. import serializers __all__ = [ 'CommandFilterViewSet', 'CommandFilterRuleViewSet', 'CommandConfirmAPI', - 'CommandConfirmStatusAPI' ] @@ -62,7 +60,7 @@ class CommandConfirmAPI(CreateAPIView): @staticmethod def get_response_data(ticket): confirm_status_url = reverse( - view_name='api-assets:command-confirm-status', + view_name='api-tickets:super-ticket-status', kwargs={'pk': str(ticket.id)} ) ticket_detail_url = reverse( @@ -85,6 +83,3 @@ class CommandConfirmAPI(CreateAPIView): serializer.is_valid(raise_exception=True) return serializer - -class CommandConfirmStatusAPI(GenericTicketStatusRetrieveCloseAPI): - pass diff --git a/apps/assets/urls/api_urls.py b/apps/assets/urls/api_urls.py index b92903d02..fee5b9a9c 100644 --- a/apps/assets/urls/api_urls.py +++ b/apps/assets/urls/api_urls.py @@ -68,7 +68,6 @@ urlpatterns = [ path('gateways//test-connective/', api.GatewayTestConnectionApi.as_view(), name='test-gateway-connective'), path('cmd-filters/command-confirm/', api.CommandConfirmAPI.as_view(), name='command-confirm'), - path('cmd-filters/command-confirm//status/', api.CommandConfirmStatusAPI.as_view(), name='command-confirm-status') ] diff --git a/apps/tickets/api/__init__.py b/apps/tickets/api/__init__.py index 4aad8f12a..0342771e0 100644 --- a/apps/tickets/api/__init__.py +++ b/apps/tickets/api/__init__.py @@ -2,5 +2,5 @@ # from .ticket import * from .comment import * -from .common import * +from .super_ticket import * from .relation import * diff --git a/apps/tickets/api/common.py b/apps/tickets/api/common.py deleted file mode 100644 index c45791ced..000000000 --- a/apps/tickets/api/common.py +++ /dev/null @@ -1,43 +0,0 @@ -from django.shortcuts import get_object_or_404 -from rest_framework.response import Response -from rest_framework.generics import RetrieveDestroyAPIView - -from common.utils import lazyproperty -from orgs.utils import tmp_to_root_org -from ..models import Ticket - - -__all__ = ['GenericTicketStatusRetrieveCloseAPI'] - - -class GenericTicketStatusRetrieveCloseAPI(RetrieveDestroyAPIView): - queryset = Ticket.objects.all() - - def retrieve(self, request, *args, **kwargs): - if self.ticket.state_open: - status = 'await' - elif self.ticket.state_approve: - status = 'approved' - else: - status = 'rejected' - data = { - 'status': status, - 'action': self.ticket.state, - 'processor': str(self.ticket.processor) - } - return Response(data=data, status=200) - - def destroy(self, request, *args, **kwargs): - if self.ticket.status_open: - self.ticket.close(processor=self.ticket.applicant) - data = { - 'action': self.ticket.state, - 'status': self.ticket.status, - 'processor': str(self.ticket.processor) - } - return Response(data=data, status=200) - - @lazyproperty - def ticket(self): - with tmp_to_root_org(): - return get_object_or_404(Ticket, pk=self.kwargs['pk']) diff --git a/apps/tickets/api/super_ticket.py b/apps/tickets/api/super_ticket.py new file mode 100644 index 000000000..bf96a6cc9 --- /dev/null +++ b/apps/tickets/api/super_ticket.py @@ -0,0 +1,20 @@ +from rest_framework.generics import RetrieveDestroyAPIView + +from orgs.utils import tmp_to_root_org +from ..serializers import SuperTicketSerializer +from ..models import SuperTicket + + +__all__ = ['SuperTicketStatusAPI'] + + +class SuperTicketStatusAPI(RetrieveDestroyAPIView): + serializer_class = SuperTicketSerializer + + def get_queryset(self): + with tmp_to_root_org(): + return SuperTicket.objects.all() + + def perform_destroy(self, instance): + ticket = self.get_object() + ticket.close(processor=ticket.applicant) diff --git a/apps/tickets/models/ticket.py b/apps/tickets/models/ticket.py index f09c444eb..d3ee162bd 100644 --- a/apps/tickets/models/ticket.py +++ b/apps/tickets/models/ticket.py @@ -17,7 +17,7 @@ from tickets.signals import post_change_ticket_action from tickets.handler import get_ticket_handler from tickets.errors import AlreadyClosed -__all__ = ['Ticket', 'TicketStep', 'TicketAssignee'] +__all__ = ['Ticket', 'TicketStep', 'TicketAssignee', 'SuperTicket'] class TicketStep(CommonModelMixin): diff --git a/apps/tickets/serializers/__init__.py b/apps/tickets/serializers/__init__.py index 340fd1496..853feafd1 100644 --- a/apps/tickets/serializers/__init__.py +++ b/apps/tickets/serializers/__init__.py @@ -3,3 +3,4 @@ from .ticket import * from .comment import * from .relation import * +from .super_ticket import * \ No newline at end of file diff --git a/apps/tickets/serializers/super_ticket.py b/apps/tickets/serializers/super_ticket.py new file mode 100644 index 000000000..a59bc51fb --- /dev/null +++ b/apps/tickets/serializers/super_ticket.py @@ -0,0 +1,12 @@ +from rest_framework.serializers import ModelSerializer + +from ..models import SuperTicket + + +__all__ = ['SuperTicketSerializer'] + + +class SuperTicketSerializer(ModelSerializer): + class Meta: + model = SuperTicket + fields = ['id', 'status', 'state', 'processor'] diff --git a/apps/tickets/urls/api_urls.py b/apps/tickets/urls/api_urls.py index 94d0f1cbb..bc6bb7f54 100644 --- a/apps/tickets/urls/api_urls.py +++ b/apps/tickets/urls/api_urls.py @@ -16,5 +16,6 @@ router.register('ticket-session-relation', api.TicketSessionRelationViewSet, 'ti urlpatterns = [ path('tickets//session/', api.TicketSessionApi.as_view(), name='ticket-sesion'), + path('super-tickets//status/', api.SuperTicketStatusAPI.as_view(), name='super-ticket-status'), ] urlpatterns += router.urls