mirror of https://github.com/jumpserver/jumpserver
feat: 工单多种审批
parent
d34c7edb00
commit
75b76170f9
|
@ -0,0 +1,87 @@
|
||||||
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
|
from . import const
|
||||||
|
from notifications.notifications import UserMessage
|
||||||
|
from common.utils import get_logger
|
||||||
|
|
||||||
|
logger = get_logger(__file__)
|
||||||
|
|
||||||
|
EMAIL_TEMPLATE = '''
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{title}
|
||||||
|
<a href={ticket_detail_url}>
|
||||||
|
<strong>{ticket_detail_url_description}</strong>
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<div>
|
||||||
|
{body}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
class BaseTicketMessage(UserMessage):
|
||||||
|
|
||||||
|
@property
|
||||||
|
def subject(self):
|
||||||
|
return _(self.title).format(self.ticket.title, self.ticket.get_type_display())
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ticket_detail_url(self):
|
||||||
|
return urljoin(settings.SITE_URL, const.TICKET_DETAIL_URL.format(id=str(self.ticket.id)))
|
||||||
|
|
||||||
|
def get_text_msg(self) -> dict:
|
||||||
|
message = """
|
||||||
|
{title}: {ticket_detail_url} -> {ticket_detail_url_description}
|
||||||
|
{body}
|
||||||
|
""".format(
|
||||||
|
title=self.content_title,
|
||||||
|
ticket_detail_url=self.ticket_detail_url,
|
||||||
|
ticket_detail_url_description=_('click here to review'),
|
||||||
|
body=self.ticket.body
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
'subject': self.subject,
|
||||||
|
'message': message
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_html_msg(self) -> dict:
|
||||||
|
message = EMAIL_TEMPLATE.format(
|
||||||
|
title=self.content_title,
|
||||||
|
ticket_detail_url=self.ticket_detail_url,
|
||||||
|
ticket_detail_url_description=_('click here to review'),
|
||||||
|
body=self.ticket.body.replace('\n', '<br/>'),
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
'subject': self.subject,
|
||||||
|
'message': message
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TicketAppliedToAssignee(BaseTicketMessage):
|
||||||
|
title = 'New Ticket - {} ({})'
|
||||||
|
|
||||||
|
def __init__(self, user, ticket):
|
||||||
|
self.ticket = ticket
|
||||||
|
super().__init__(user)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def content_title(self):
|
||||||
|
return _('Your has a new ticket, applicant - {}').format(str(self.ticket.applicant_display))
|
||||||
|
|
||||||
|
|
||||||
|
class TicketProcessedToApplicant(BaseTicketMessage):
|
||||||
|
title = 'Ticket has processed - {} ({})'
|
||||||
|
|
||||||
|
def __init__(self, user, ticket, processor):
|
||||||
|
self.ticket = ticket
|
||||||
|
self.processor = processor
|
||||||
|
super().__init__(user)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def content_title(self):
|
||||||
|
return _('Your ticket has been processed, processor - {}').format(str(self.processor))
|
|
@ -1,66 +1,32 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
from urllib.parse import urljoin
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.translation import ugettext as _
|
|
||||||
|
|
||||||
from common.utils import get_logger
|
from common.utils import get_logger
|
||||||
from common.tasks import send_mail_async
|
from .notifications import TicketAppliedToAssignee, TicketProcessedToApplicant
|
||||||
from . import const
|
|
||||||
|
|
||||||
logger = get_logger(__file__)
|
logger = get_logger(__file__)
|
||||||
|
|
||||||
EMAIL_TEMPLATE = '''
|
|
||||||
<div>
|
|
||||||
<p>
|
|
||||||
{title}
|
|
||||||
<a href={ticket_detail_url}>
|
|
||||||
<strong>{ticket_detail_url_description}</strong>
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
<div>
|
|
||||||
{body}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
def send_ticket_applied_mail_to_assignees(ticket):
|
def send_ticket_applied_mail_to_assignees(ticket):
|
||||||
assignees = ticket.current_node.first().ticket_assignees.all()
|
assignees = ticket.current_node.first().ticket_assignees.all()
|
||||||
if not assignees:
|
if not assignees:
|
||||||
logger.debug("Not found assignees, ticket: {}({}), assignees: {}".format(
|
logger.debug("Not found assignees, ticket: {}({}), assignees: {}".format(ticket, str(ticket.id), assignees))
|
||||||
ticket, str(ticket.id), assignees)
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
ticket_detail_url = urljoin(settings.SITE_URL, const.TICKET_DETAIL_URL.format(id=str(ticket.id)))
|
for assignee in assignees:
|
||||||
subject = _('New Ticket - {} ({})').format(ticket.title, ticket.get_type_display())
|
instance = TicketAppliedToAssignee(assignee, ticket)
|
||||||
message = EMAIL_TEMPLATE.format(
|
if settings.DEBUG:
|
||||||
title=_('Your has a new ticket, applicant - {}').format(str(ticket.applicant_display)),
|
logger.debug(instance)
|
||||||
ticket_detail_url=ticket_detail_url,
|
instance.publish_async()
|
||||||
ticket_detail_url_description=_('click here to review'),
|
|
||||||
body=ticket.body.replace('\n', '<br/>'),
|
|
||||||
)
|
|
||||||
if settings.DEBUG:
|
|
||||||
logger.debug(message)
|
|
||||||
recipient_list = [i.assignee.email for i in assignees]
|
|
||||||
send_mail_async.delay(subject, message, recipient_list, html_message=message)
|
|
||||||
|
|
||||||
|
|
||||||
def send_ticket_processed_mail_to_applicant(ticket, processor):
|
def send_ticket_processed_mail_to_applicant(ticket, processor):
|
||||||
if not ticket.applicant:
|
if not ticket.applicant:
|
||||||
logger.error("Not found applicant: {}({})".format(ticket.title, ticket.id))
|
logger.error("Not found applicant: {}({})".format(ticket.title, ticket.id))
|
||||||
return
|
return
|
||||||
processor_display = str(processor)
|
|
||||||
ticket_detail_url = urljoin(settings.SITE_URL, const.TICKET_DETAIL_URL.format(id=str(ticket.id)))
|
instance = TicketProcessedToApplicant(ticket.applicant, ticket, processor)
|
||||||
subject = _('Ticket has processed - {} ({})').format(ticket.title, processor_display)
|
|
||||||
message = EMAIL_TEMPLATE.format(
|
|
||||||
title=_('Your ticket has been processed, processor - {}').format(processor_display),
|
|
||||||
ticket_detail_url=ticket_detail_url,
|
|
||||||
ticket_detail_url_description=_('click here to review'),
|
|
||||||
body=ticket.body.replace('\n', '<br/>'),
|
|
||||||
)
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
logger.debug(message)
|
logger.debug(instance)
|
||||||
recipient_list = [ticket.applicant.email, ]
|
instance.publish_async()
|
||||||
send_mail_async.delay(subject, message, recipient_list, html_message=message)
|
|
||||||
|
|
Loading…
Reference in New Issue