mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-12-26 08:39:08 +01:00
ADDED: Flag to enable notifications on every interaction that occurs over email.
This commit is contained in:
parent
1511e0e72c
commit
26fc6cb1de
@ -348,7 +348,7 @@ def create_object_from_email_message(message, ticket_id, payload, files, quiet):
|
||||
for email in ticket_cc_list :
|
||||
notifications_to_be_sent.append(email)
|
||||
|
||||
if len(notifications_to_be_sent):
|
||||
if queue.enable_notifications_on_email_events and len(notifications_to_be_sent):
|
||||
|
||||
send_templated_mail(
|
||||
notification_template,
|
||||
|
@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.1 on 2016-03-01 19:43
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('helpdesk', '0013_add_submitter_email_id_field_to_ticket'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='queue',
|
||||
name='enable_notifications_on_email_events',
|
||||
field=models.BooleanField(default=False, help_text='When an email arrives to either create a ticket or to interact with an existing discussion. Should email notifications be sent ? Note: the new_ticket_cc and updated_ticket_cc work independently of this feature', verbose_name='Notify contacts when email updates arrive'),
|
||||
),
|
||||
]
|
@ -112,6 +112,15 @@ class Queue(models.Model):
|
||||
'multiple addresses with a comma.'),
|
||||
)
|
||||
|
||||
enable_notifications_on_email_events = models.BooleanField(
|
||||
_('Notify contacts when email updates arrive'),
|
||||
blank=True,
|
||||
default=False,
|
||||
help_text=_('When an email arrives to either create a ticket or to '
|
||||
'interact with an existing discussion. Should email notifications be sent ? '
|
||||
'Note: the new_ticket_cc and updated_ticket_cc work independently of this feature'),
|
||||
)
|
||||
|
||||
email_box_type = models.CharField(
|
||||
_('E-Mail Box Type'),
|
||||
max_length=5,
|
||||
|
@ -123,22 +123,17 @@ class EmailInteractionsTestCase(TestCase):
|
||||
self.queue_public = Queue.objects.create(title='Mail Queue 1',
|
||||
slug='mq1',
|
||||
allow_public_submission=True,
|
||||
new_ticket_cc='new.public@example.com',
|
||||
updated_ticket_cc='update.public@example.com'
|
||||
new_ticket_cc='new.public.with.notifications@example.com',
|
||||
updated_ticket_cc='update.public.with.notifications@example.com',
|
||||
enable_notifications_on_email_events=True,
|
||||
)
|
||||
|
||||
self.queue_public_with_notification_enabled = Queue.objects.create(title='Mail Queue 2',
|
||||
self.queue_public_with_notifications_disabled = Queue.objects.create(title='Mail Queue 2',
|
||||
slug='mq2',
|
||||
allow_public_submission=True,
|
||||
new_ticket_cc='new.public.with.notifications@example.com',
|
||||
updated_ticket_cc='update.public.with.notifications@example.com'
|
||||
)
|
||||
|
||||
self.queue_public_with_notification_disabled = Queue.objects.create(title='Mail Queue 3',
|
||||
slug='mq3',
|
||||
allow_public_submission=True,
|
||||
new_ticket_cc='new.public.without.notifications@example.com',
|
||||
updated_ticket_cc='update.public.without.notifications@example.com'
|
||||
updated_ticket_cc='update.public.without.notifications@example.com',
|
||||
enable_notifications_on_email_events=False,
|
||||
)
|
||||
|
||||
self.ticket_data = {
|
||||
@ -508,3 +503,85 @@ class EmailInteractionsTestCase(TestCase):
|
||||
# the new and update queues (+2) and contacts on the cc_list (+1 as it's
|
||||
# treated as a list)
|
||||
self.assertEqual(email_count + 1 + 2 + 1, len(mail.outbox))
|
||||
|
||||
def test_create_ticket_from_email_to_a_notification_enabled_queue(self):
|
||||
|
||||
"""
|
||||
Ensure that when an email is sent to a Queue with notifications_enabled turned ON, all contacts
|
||||
on the TicketCC list are notified.
|
||||
"""
|
||||
|
||||
msg = email.message.Message()
|
||||
|
||||
message_id = uuid.uuid4().hex
|
||||
submitter_email = 'foo@bar.py'
|
||||
cc_list = ['bravo@example.net', 'charlie@foobar.com']
|
||||
|
||||
msg.__setitem__('Message-ID', message_id)
|
||||
msg.__setitem__('Subject', self.ticket_data['title'])
|
||||
msg.__setitem__('From', submitter_email)
|
||||
msg.__setitem__('To', self.queue_public.email_address)
|
||||
msg.__setitem__('Cc', ','.join(cc_list))
|
||||
msg.__setitem__('Content-Type', 'text/plain;')
|
||||
msg.set_payload(self.ticket_data['description'])
|
||||
|
||||
email_count = len(mail.outbox)
|
||||
|
||||
object_from_message(str(msg), self.queue_public, quiet=True)
|
||||
|
||||
followup = FollowUp.objects.get(message_id=message_id)
|
||||
ticket = Ticket.objects.get(id=followup.ticket.id)
|
||||
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
||||
|
||||
# As we have created an Ticket from an email, we notify the sender (+1),
|
||||
# the new and update queues (+2) and contacts on the cc_list (+1 as it's
|
||||
# treated as a list)
|
||||
self.assertEqual(email_count + 1 + 2 + 1, len(mail.outbox))
|
||||
|
||||
# Ensure that <TicketCC> is created
|
||||
for cc_email in cc_list:
|
||||
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
||||
self.assertTrue(ticket_cc.ticket, ticket)
|
||||
self.assertTrue(ticket_cc.email, cc_email)
|
||||
|
||||
def test_create_ticket_from_email_to_a_notification_disabled_queue(self):
|
||||
|
||||
"""
|
||||
Ensure that when an email is sent to a Queue with notifications_enabled turned OFF, only the
|
||||
new_ticket_cc and updated_ticket_cc contacts (if they are set) are notified. No contact
|
||||
from the TicketCC list should be notified.
|
||||
"""
|
||||
|
||||
msg = email.message.Message()
|
||||
|
||||
message_id = uuid.uuid4().hex
|
||||
submitter_email = 'foo@bar.py'
|
||||
cc_list = ['bravo@example.net', 'charlie@foobar.com']
|
||||
|
||||
msg.__setitem__('Message-ID', message_id)
|
||||
msg.__setitem__('Subject', self.ticket_data['title'])
|
||||
msg.__setitem__('From', submitter_email)
|
||||
msg.__setitem__('To', self.queue_public.email_address)
|
||||
msg.__setitem__('Cc', ','.join(cc_list))
|
||||
msg.__setitem__('Content-Type', 'text/plain;')
|
||||
msg.set_payload(self.ticket_data['description'])
|
||||
|
||||
email_count = len(mail.outbox)
|
||||
|
||||
object_from_message(str(msg), self.queue_public_with_notifications_disabled, quiet=True)
|
||||
|
||||
followup = FollowUp.objects.get(message_id=message_id)
|
||||
ticket = Ticket.objects.get(id=followup.ticket.id)
|
||||
self.assertEqual(ticket.ticket_for_url, "mq2-%s" % ticket.id)
|
||||
|
||||
# As we have created an Ticket from an email, we notify the sender (+1),
|
||||
# the new and update queues (+2) and that's all
|
||||
self.assertEqual(email_count + 1 + 2, len(mail.outbox))
|
||||
|
||||
# Ensure that <TicketCC> is created even if the Queue notifications are disabled
|
||||
# so when staff members interact with the <Ticket>, they get notified
|
||||
for cc_email in cc_list:
|
||||
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
||||
self.assertTrue(ticket_cc.ticket, ticket)
|
||||
self.assertTrue(ticket_cc.email, cc_email)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user