mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-20 11:00:35 +00:00
@@ -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)
|
||||
|
Reference in New Issue
Block a user