From 9a6939b5642ea446230152fe0a046d69363a058e Mon Sep 17 00:00:00 2001 From: Sam Splunks <72095718+samsplunks@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:02:44 +0000 Subject: [PATCH] Attach send_new_ticket_webhook to the new_ticket_done signal --- helpdesk/forms.py | 9 +++++++++ helpdesk/models.py | 2 -- helpdesk/signals.py | 5 ++++- helpdesk/webhooks.py | 8 ++++++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/helpdesk/forms.py b/helpdesk/forms.py index e63072cd..eb77c2e6 100644 --- a/helpdesk/forms.py +++ b/helpdesk/forms.py @@ -36,6 +36,7 @@ from helpdesk.settings import ( CUSTOMFIELD_TO_FIELD_DICT ) from helpdesk.validators import validate_file_extension +from helpdesk.signals import new_ticket_done import logging @@ -418,6 +419,10 @@ class TicketForm(AbstractTicketForm): followup.save() files = self._attach_files_to_follow_up(followup) + + # emit signal when the TicketForm.save is done + new_ticket_done.send(sender="TicketForm", ticket=ticket) + self._send_messages(ticket=ticket, queue=queue, followup=followup, @@ -507,6 +512,10 @@ class PublicTicketForm(AbstractTicketForm): followup.save() files = self._attach_files_to_follow_up(followup) + + # emit signal when the PublicTicketForm.save is done + new_ticket_done.send(sender="PublicTicketForm", ticket=ticket) + self._send_messages(ticket=ticket, queue=queue, followup=followup, diff --git a/helpdesk/models.py b/helpdesk/models.py index a9ce9a1b..c95f100c 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -644,8 +644,6 @@ class Ticket(models.Model): if self.queue.enable_notifications_on_email_events: for cc in self.ticketcc_set.all(): send('ticket_cc', cc.email_address) - if "new_ticket_cc" in roles: - send_new_ticket_webhook(self) return recipients def _get_assigned_to(self): diff --git a/helpdesk/signals.py b/helpdesk/signals.py index 0f3ed823..0f72ef20 100644 --- a/helpdesk/signals.py +++ b/helpdesk/signals.py @@ -1,4 +1,7 @@ import django.dispatch -# create a signal for ticket updates +# create a signal for *TicketForm +new_ticket_done = django.dispatch.Signal() + +# create a signal for ticket_update view update_ticket_done = django.dispatch.Signal() \ No newline at end of file diff --git a/helpdesk/webhooks.py b/helpdesk/webhooks.py index c1050581..1770e753 100644 --- a/helpdesk/webhooks.py +++ b/helpdesk/webhooks.py @@ -4,7 +4,7 @@ import logging from django.dispatch import receiver from . import settings -from .signals import update_ticket_done +from .signals import new_ticket_done, update_ticket_done logger = logging.getLogger(__name__) @@ -32,7 +32,6 @@ def notify_followup_webhooks(followup): except requests.exceptions.Timeout: logger.error('Timeout while sending followup webhook to %s', url) - # listener is loaded via app.py HelpdeskConfig.ready() @receiver(update_ticket_done) def notify_followup_webhooks_receiver(sender, followup, **kwargs): @@ -59,3 +58,8 @@ def send_new_ticket_webhook(ticket): requests.post(url, json=data, timeout=settings.HELPDESK_WEBHOOK_TIMEOUT) except requests.exceptions.Timeout: logger.error('Timeout while sending new ticket webhook to %s', url) + +# listener is loaded via app.py HelpdeskConfig.ready() +@receiver(new_ticket_done) +def send_new_ticket_webhook_receiver(sender, ticket, **kwargs): + send_new_ticket_webhook(ticket) \ No newline at end of file