From 1a9d9e4145815b28c71382c113c8bf7518e1fe8e Mon Sep 17 00:00:00 2001 From: xinwen Date: Wed, 5 Aug 2020 19:42:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(ticket):=20=E7=94=B3=E8=AF=B7=E8=B5=84?= =?UTF-8?q?=E4=BA=A7=E5=B7=A5=E5=8D=95=E6=B7=BB=E5=8A=A0`actions`=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/tickets/api/request_asset_perm.py | 6 ++++-- apps/tickets/serializers/request_asset_perm.py | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/tickets/api/request_asset_perm.py b/apps/tickets/api/request_asset_perm.py index c12ea3070..5b62b8dcf 100644 --- a/apps/tickets/api/request_asset_perm.py +++ b/apps/tickets/api/request_asset_perm.py @@ -13,6 +13,7 @@ from common.utils.django import get_object_or_none from common.utils.timezone import dt_parser from common.drf.serializers import EmptySerializer from perms.models.asset_permission import AssetPermission, Asset +from perms.models import Action from assets.models.user import SystemUser from ..exceptions import ( ConfirmedAssetsChanged, ConfirmedSystemUserChanged, @@ -105,12 +106,14 @@ class RequestAssetPermTicketViewSet(JMSModelViewSet): def _create_asset_permission(self, instance: Ticket, assets, system_user): meta = instance.meta request = self.request + actions = meta.get('actions', Action.CONNECT) ap_kwargs = { 'name': _('From request ticket: {} {}').format(instance.user_display, instance.id), 'created_by': self.request.user.username, 'comment': _('{} request assets, approved by {}').format(instance.user_display, - instance.assignees_display) + instance.assignees_display), + 'actions': actions, } date_start = dt_parser(meta.get('date_start')) date_expired = dt_parser(meta.get('date_expired')) @@ -118,7 +121,6 @@ class RequestAssetPermTicketViewSet(JMSModelViewSet): ap_kwargs['date_start'] = date_start if date_expired: ap_kwargs['date_expired'] = date_expired - instance.perform_action(instance.ACTION.APPROVE, request.user, self._get_extra_comment(instance)) diff --git a/apps/tickets/serializers/request_asset_perm.py b/apps/tickets/serializers/request_asset_perm.py index 521d2582e..8827f482c 100644 --- a/apps/tickets/serializers/request_asset_perm.py +++ b/apps/tickets/serializers/request_asset_perm.py @@ -11,10 +11,14 @@ from orgs.utils import tmp_to_root_org from orgs.models import Organization, ROLE as ORG_ROLE from assets.models.asset import Asset from users.models.user import User +from perms.serializers import ActionsField +from perms.models import Action from ..models import Ticket class RequestAssetPermTicketSerializer(serializers.ModelSerializer): + actions = ActionsField(source='meta.actions', choices=Action.DB_CHOICES, + default=Action.CONNECT) ips = serializers.ListField(child=serializers.IPAddressField(), source='meta.ips', default=list, label=_('IP group')) hostname = serializers.CharField(max_length=256, source='meta.hostname', default='', @@ -42,7 +46,7 @@ class RequestAssetPermTicketSerializer(serializers.ModelSerializer): 'status', 'action', 'date_created', 'date_updated', 'system_user_waitlist_url', 'type', 'type_display', 'action_display', 'ips', 'confirmed_assets', 'date_start', 'date_expired', 'confirmed_system_user', 'hostname', - 'assets_waitlist_url', 'system_user', 'org_id' + 'assets_waitlist_url', 'system_user', 'org_id', 'actions' ] m2m_fields = [ 'user', 'user_display', 'assignees', 'assignees_display',