mirror of https://github.com/jumpserver/jumpserver
parent
3749a0c6a1
commit
8247f24d3f
|
@ -34,10 +34,10 @@ class TicketViewSet(CommonApiMixin, viewsets.ModelViewSet):
|
|||
model = Ticket
|
||||
filterset_class = filters.TicketFilter
|
||||
search_fields = [
|
||||
'title', 'type', 'status', 'applicant_display'
|
||||
'title', 'type', 'status'
|
||||
]
|
||||
ordering_fields = (
|
||||
'title', 'applicant_display', 'status', 'state',
|
||||
'title', 'status', 'state',
|
||||
'action_display', 'date_created', 'serial_num',
|
||||
)
|
||||
ordering = ('-date_created',)
|
||||
|
@ -67,7 +67,8 @@ class TicketViewSet(CommonApiMixin, viewsets.ModelViewSet):
|
|||
|
||||
@action(detail=False, methods=[POST], permission_classes=[RBACPermission, ])
|
||||
def open(self, request, *args, **kwargs):
|
||||
return super().create(request, *args, **kwargs)
|
||||
with tmp_to_root_org():
|
||||
return super().create(request, *args, **kwargs)
|
||||
|
||||
@action(detail=True, methods=[PUT], permission_classes=[IsAssignee, ])
|
||||
def approve(self, request, *args, **kwargs):
|
||||
|
|
|
@ -189,7 +189,7 @@ class StatusMixin:
|
|||
assignees_display.append(str(i.assignee))
|
||||
if state != StepState.pending and state == i.state:
|
||||
processor = i.assignee
|
||||
if state != StepState.closed:
|
||||
if state == StepState.closed:
|
||||
processor = self.applicant
|
||||
step_info = {
|
||||
'state': state,
|
||||
|
|
|
@ -26,15 +26,9 @@ class ApplyApplicationSerializer(BaseApplyAssetApplicationSerializer, TicketAppl
|
|||
extra_kwargs = {}
|
||||
extra_kwargs.update(ticket_extra_kwargs)
|
||||
|
||||
def validate_apply_applications(self, apply_applications):
|
||||
type = self.initial_data.get('apply_type')
|
||||
org_id = self.initial_data.get('org_id')
|
||||
application_ids = [app.id for app in apply_applications]
|
||||
with tmp_to_org(org_id):
|
||||
applications = Application.objects.filter(
|
||||
id__in=application_ids, type=type
|
||||
).values_list('id', flat=True)
|
||||
return list(applications)
|
||||
def validate_apply_applications(self, applications):
|
||||
tp = self.initial_data.get('apply_type')
|
||||
return self.filter_many_to_many_field(Application, applications, type=tp)
|
||||
|
||||
|
||||
class ApplyApplicationDisplaySerializer(ApplyApplicationSerializer):
|
||||
|
|
|
@ -4,6 +4,7 @@ from rest_framework import serializers
|
|||
from perms.serializers.base import ActionsField
|
||||
from perms.models import AssetPermission
|
||||
from orgs.utils import tmp_to_org
|
||||
from assets.models import Asset, Node
|
||||
|
||||
from tickets.models import ApplyAssetTicket
|
||||
from .ticket import TicketApplySerializer
|
||||
|
@ -34,6 +35,12 @@ class ApplyAssetSerializer(BaseApplyAssetApplicationSerializer, TicketApplySeria
|
|||
}
|
||||
extra_kwargs.update(ticket_extra_kwargs)
|
||||
|
||||
def validate_apply_nodes(self, nodes):
|
||||
return self.filter_many_to_many_field(Node, nodes)
|
||||
|
||||
def validate_apply_assets(self, assets):
|
||||
return self.filter_many_to_many_field(Asset, assets)
|
||||
|
||||
def validate(self, attrs):
|
||||
attrs = super().validate(attrs)
|
||||
if not attrs.get('apply_nodes') and not attrs.get('apply_assets'):
|
||||
|
|
|
@ -3,6 +3,7 @@ from django.db.models import Model
|
|||
from django.utils.translation import ugettext as _
|
||||
from rest_framework import serializers
|
||||
|
||||
from assets.models import SystemUser
|
||||
from orgs.utils import tmp_to_org
|
||||
from tickets.models import Ticket
|
||||
|
||||
|
@ -37,6 +38,16 @@ class DefaultPermissionName(object):
|
|||
class BaseApplyAssetApplicationSerializer(serializers.Serializer):
|
||||
permission_model: Model
|
||||
|
||||
def filter_many_to_many_field(self, model, values: list, **kwargs):
|
||||
org_id = self.initial_data.get('org_id')
|
||||
ids = [instance.id for instance in values]
|
||||
with tmp_to_org(org_id):
|
||||
qs = model.objects.filter(id__in=ids, **kwargs).values_list('id', flat=True)
|
||||
return list(qs)
|
||||
|
||||
def validate_apply_system_users(self, system_users):
|
||||
return self.filter_many_to_many_field(SystemUser, system_users)
|
||||
|
||||
def validate(self, attrs):
|
||||
attrs = super().validate(attrs)
|
||||
|
||||
|
|
Loading…
Reference in New Issue