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