fix: 解决一些工单已知问题 (#8501)

Co-authored-by: feng626 <1304903146@qq.com>
pull/8504/head
fit2bot 2022-06-28 17:19:33 +08:00 committed by GitHub
parent b619ebf423
commit b33e376c90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 18 deletions

View File

@ -1,8 +1,10 @@
from django_filters import rest_framework as filters
from django.db.models import Subquery, OuterRef
from common.drf.filters import BaseFilterSet
from tickets.models import (
Ticket, ApplyAssetTicket, ApplyApplicationTicket,
Ticket, TicketStep, ApplyAssetTicket, ApplyApplicationTicket,
ApplyLoginTicket, ApplyLoginAssetTicket, ApplyCommandTicket
)
@ -17,7 +19,13 @@ class TicketFilter(BaseFilterSet):
)
def filter_assignees_id(self, queryset, name, value):
return queryset.filter(ticket_steps__ticket_assignees__assignee__id=value)
step_qs = TicketStep.objects.filter(
level=OuterRef("approval_step")
).values_list('id', flat=True)
return queryset.filter(
ticket_steps__id__in=Subquery(step_qs),
ticket_steps__ticket_assignees__assignee__id=value
)
class ApplyAssetTicketFilter(BaseFilterSet):

View File

@ -55,10 +55,7 @@ class BaseHandler:
def _send_processed_mail_to_applicant(self, step=None):
applicant = self.ticket.applicant
if self.ticket.status == TicketStatus.closed:
processor = applicant
else:
processor = step.processor if step else self.ticket.processor
processor = step.processor if step else applicant
logger.debug('Send processed mail to applicant: {}'.format(applicant))
send_ticket_processed_mail_to_applicant(self.ticket, processor)

View File

@ -13,6 +13,7 @@ from common.utils.timezone import as_current_tz
from common.mixins.models import CommonModelMixin
from common.db.encoder import ModelJSONFieldEncoder
from orgs.models import Organization
from orgs.utils import tmp_to_org
from tickets.const import (
TicketType, TicketStatus, TicketState,
TicketLevel, StepState, StepStatus
@ -336,14 +337,15 @@ class Ticket(StatusMixin, CommonModelMixin):
m2m_fields.add(name)
snapshot = {}
for field in rel_fields:
value = getattr(self, field)
with tmp_to_org(self.org_id):
for field in rel_fields:
value = getattr(self, field)
if field in m2m_fields:
value = [str(v) for v in value.all()]
else:
value = str(value) if value else ''
snapshot[field] = value
if field in m2m_fields:
value = [str(v) for v in value.all()]
else:
value = str(value) if value else ''
snapshot[field] = value
self.rel_snapshot.update(snapshot)
if save:

View File

@ -1,7 +1,7 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from .general import Ticket, SubTicketManager
from .general import Ticket
__all__ = ['ApplyLoginTicket']

View File

@ -23,7 +23,9 @@ class ApplyApplicationSerializer(BaseApplyAssetApplicationSerializer, TicketAppl
fields = TicketApplySerializer.Meta.fields + writeable_fields + ['apply_permission_name']
read_only_fields = list(set(fields) - set(writeable_fields))
ticket_extra_kwargs = TicketApplySerializer.Meta.extra_kwargs
extra_kwargs = {}
extra_kwargs = {
'apply_system_users': {'required': True},
}
extra_kwargs.update(ticket_extra_kwargs)
def validate_apply_applications(self, applications):

View File

@ -31,7 +31,8 @@ class ApplyAssetSerializer(BaseApplyAssetApplicationSerializer, TicketApplySeria
ticket_extra_kwargs = TicketApplySerializer.Meta.extra_kwargs
extra_kwargs = {
'apply_nodes': {'required': False, 'help_text': asset_or_node_help_text},
'apply_assets': {'required': False, 'help_text': asset_or_node_help_text}
'apply_assets': {'required': False, 'help_text': asset_or_node_help_text},
'apply_system_users': {'required': True},
}
extra_kwargs.update(ticket_extra_kwargs)

View File

@ -7,11 +7,17 @@ from django.shortcuts import redirect, reverse
from django.core.cache import cache
from django.utils.translation import ugettext as _
from tickets.models import Ticket
from orgs.utils import tmp_to_root_org
from tickets.models import (
Ticket, ApplyAssetTicket, ApplyApplicationTicket,
ApplyLoginTicket, ApplyLoginAssetTicket, ApplyCommandTicket
)
from tickets.const import TicketType
from tickets.errors import AlreadyClosed
from common.utils import get_logger, FlashMessageUtil
logger = get_logger(__name__)
__all__ = ['TicketDirectApproveView']
@ -19,6 +25,14 @@ class TicketDirectApproveView(TemplateView):
template_name = 'tickets/approve_check_password.html'
redirect_field_name = 'next'
TICKET_SUB_MODEL_MAP = {
TicketType.apply_asset: ApplyAssetTicket,
TicketType.apply_application: ApplyApplicationTicket,
TicketType.login_confirm: ApplyLoginTicket,
TicketType.login_asset_confirm: ApplyLoginAssetTicket,
TicketType.command_confirm: ApplyCommandTicket,
}
@property
def message_data(self):
return {
@ -84,7 +98,10 @@ class TicketDirectApproveView(TemplateView):
return self.redirect_message_response(redirect_url=self.login_url)
try:
ticket_id = ticket_info.get('ticket_id')
ticket = Ticket.all().get(id=ticket_id)
with tmp_to_root_org():
ticket = Ticket.all().get(id=ticket_id)
ticket_sub_model = self.TICKET_SUB_MODEL_MAP[ticket.type]
ticket = ticket_sub_model.objects.get(id=ticket_id)
if not ticket.has_current_assignee(user):
raise Exception(_("This user is not authorized to approve this ticket"))
getattr(ticket, action)(user)