Browse Source

feat(ticket): 申请资产工单添加`actions`字段

pull/4462/head
xinwen 4 years ago committed by 老广
parent
commit
1a9d9e4145
  1. 6
      apps/tickets/api/request_asset_perm.py
  2. 6
      apps/tickets/serializers/request_asset_perm.py

6
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))

6
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',

Loading…
Cancel
Save