From 6ef420427dbf15c1ac3b216e5b2282561a9464b9 Mon Sep 17 00:00:00 2001 From: Ross Poulton Date: Mon, 21 Jan 2008 01:02:12 +0000 Subject: [PATCH] * Added support for e-maling a queue "CC" address (two options here, one for new tickets only, one for all queue activity) * Added support for e-mailing submitter when a ticket is closed * Added facility to e-mail owner when someone else acts on their ticket --- forms.py | 16 +++++++- models.py | 10 +++++ templates/helpdesk/emails/cc_assigned.html | 10 +++++ templates/helpdesk/emails/cc_assigned.txt | 7 ++++ templates/helpdesk/emails/cc_closed.html | 12 ++++++ templates/helpdesk/emails/cc_closed.txt | 7 ++++ templates/helpdesk/emails/cc_newticket.html | 10 +++++ templates/helpdesk/emails/cc_newticket.txt | 7 ++++ templates/helpdesk/emails/cc_resolved.html | 18 ++++++++ templates/helpdesk/emails/cc_resolved.txt | 13 ++++++ templates/helpdesk/emails/cc_updated.html | 18 ++++++++ templates/helpdesk/emails/cc_updated.txt | 13 ++++++ templates/helpdesk/emails/owner_assigned.html | 15 +++++++ templates/helpdesk/emails/owner_assigned.txt | 9 ++++ templates/helpdesk/emails/owner_closed.html | 12 ++++++ templates/helpdesk/emails/owner_closed.txt | 7 ++++ templates/helpdesk/emails/owner_resolved.html | 18 ++++++++ templates/helpdesk/emails/owner_resolved.txt | 13 ++++++ templates/helpdesk/emails/owner_updated.html | 18 ++++++++ templates/helpdesk/emails/owner_updated.txt | 13 ++++++ .../helpdesk/emails/submitter_closed.html | 14 +++++++ .../helpdesk/emails/submitter_closed.txt | 9 ++++ views.py | 41 +++++++++++++++++++ 23 files changed, 309 insertions(+), 1 deletion(-) create mode 100644 templates/helpdesk/emails/cc_assigned.html create mode 100644 templates/helpdesk/emails/cc_assigned.txt create mode 100644 templates/helpdesk/emails/cc_closed.html create mode 100644 templates/helpdesk/emails/cc_closed.txt create mode 100644 templates/helpdesk/emails/cc_newticket.html create mode 100644 templates/helpdesk/emails/cc_newticket.txt create mode 100644 templates/helpdesk/emails/cc_resolved.html create mode 100644 templates/helpdesk/emails/cc_resolved.txt create mode 100644 templates/helpdesk/emails/cc_updated.html create mode 100644 templates/helpdesk/emails/cc_updated.txt create mode 100644 templates/helpdesk/emails/owner_assigned.html create mode 100644 templates/helpdesk/emails/owner_assigned.txt create mode 100644 templates/helpdesk/emails/owner_closed.html create mode 100644 templates/helpdesk/emails/owner_closed.txt create mode 100644 templates/helpdesk/emails/owner_resolved.html create mode 100644 templates/helpdesk/emails/owner_resolved.txt create mode 100644 templates/helpdesk/emails/owner_updated.html create mode 100644 templates/helpdesk/emails/owner_updated.txt create mode 100644 templates/helpdesk/emails/submitter_closed.html create mode 100644 templates/helpdesk/emails/submitter_closed.txt diff --git a/forms.py b/forms.py index e0ef0a4a..2d28769d 100644 --- a/forms.py +++ b/forms.py @@ -97,10 +97,19 @@ class TicketForm(forms.Form): 'queue': q, } + from helpdesk.lib import send_multipart_mail + if t.submitter_email: - from helpdesk.lib import send_multipart_mail send_multipart_mail('helpdesk/emails/submitter_newticket', context, '%s %s' % (t.ticket, t.title), t.submitter_email, q.from_address) + if t.assigned_to != user: + send_multipart_mail('helpdesk/emails/owner_assigned', context, '%s %s (Opened)' % (t.ticket, t.title), t.assigned_to.email, q.from_address) + + if q.new_ticket_cc: + send_multipart_mail('helpdesk/emails/cc_newticket', context, '%s %s (Opened)' % (t.ticket, t.title), q.updated_ticket_cc, q.from_address) + elif q.updated_ticket_cc and q.updated_ticket_cc != q.new_ticket_cc: + send_multipart_mail('helpdesk/emails/cc_newticket', context, '%s %s (Opened)' % (t.ticket, t.title), q.updated_ticket_cc, q.from_address) + return t class PublicTicketForm(forms.Form): @@ -159,4 +168,9 @@ class PublicTicketForm(forms.Form): from helpdesk.lib import send_multipart_mail send_multipart_mail('helpdesk/emails/submitter_newticket', context, '%s %s' % (t.ticket, t.title), t.submitter_email, q.from_address) + if q.new_ticket_cc: + send_multipart_mail('helpdesk/emails/cc_newticket', context, '%s %s (Opened)' % (t.ticket, t.title), q.updated_ticket_cc, q.from_address) + elif q.updated_ticket_cc and q.updated_ticket_cc != q.new_ticket_cc: + send_multipart_mail('helpdesk/emails/cc_newticket', context, '%s %s (Opened)' % (t.ticket, t.title), q.updated_ticket_cc, q.from_address) + return t diff --git a/models.py b/models.py index 34500c49..da1e1f15 100644 --- a/models.py +++ b/models.py @@ -56,6 +56,9 @@ class Queue(models.Model): return '%s <%s>' % (self.title, self.email_address) from_address = property(_from_address) + new_ticket_cc = models.EmailField(blank=True, null=True, help_text='If an e-mail address is entered here, then it will receive notification of all new tickets created for this queue') + updated_ticket_cc = models.EmailField(blank=True, null=True, help_text='If an e-mail address is entered here, then it will receive notification of all activity (new tickets, closed tickets, updates, reassignments, etc) for this queue') + email_box_type = models.CharField(maxlength=5, choices=(('pop3', 'POP 3'),('imap', 'IMAP')), blank=True, null=True, help_text='E-Mail Server Type - Both POP3 and IMAP are supported. Select your email server type here.') email_box_host = models.CharField(maxlength=200, blank=True, null=True, help_text='Your e-mail server address - either the domain name or IP address. May be "localhost".') email_box_port = models.IntegerField(blank=True, null=True, help_text='Port number to use for accessing e-mail. Default for POP3 is "110", and for IMAP is "143". This may differ on some servers.') @@ -174,6 +177,13 @@ class Ticket(models.Model): return "http://%s%s?ticket=%s&email=%s" % (site.domain, reverse('helpdesk_public_view'), self.ticket_for_url, self.submitter_email) ticket_url = property(_get_ticket_url) + def _get_staff_url(self): + from django.contrib.sites.models import Site + from django.core.urlresolvers import reverse + site = Site.objects.get_current() + return "http://%s%s" % (site.domain, reverse('helpdesk_view', args=[self.id])) + staff_url = property(_get_staff_url) + class Admin: list_display = ('title', 'status', 'assigned_to', 'submitter_email',) date_hierarchy = 'created' diff --git a/templates/helpdesk/emails/cc_assigned.html b/templates/helpdesk/emails/cc_assigned.html new file mode 100644 index 00000000..c0875b1b --- /dev/null +++ b/templates/helpdesk/emails/cc_assigned.html @@ -0,0 +1,10 @@ +{% extends "helpdesk/emails/base.html" %} + +{% block header %}Ticket Re-Assigned{% endblock %} + +{% block content %} +

Hello,

+ +

This is a courtesy e-mail to let you know that ticket {{ ticket.ticket }} ({{ ticket.title }}) has been {% if ticket.assigned_to %}assigned to {{ ticket.assigned_to %}{% else %}unassigned{% endif %}.

+ +{% endblock %} diff --git a/templates/helpdesk/emails/cc_assigned.txt b/templates/helpdesk/emails/cc_assigned.txt new file mode 100644 index 00000000..f4bcb2c3 --- /dev/null +++ b/templates/helpdesk/emails/cc_assigned.txt @@ -0,0 +1,7 @@ +Hello, + +This is a courtesy e-mail to let you know that ticket {{ ticket.ticket }} ("{{ ticket.title }}") has been {% if ticket.assigned_to %}assigned to {{ ticket.assigned_to }}{% else %}unassigned{% endif %} + +You can view this online at {{ ticket.staff_url }}. + +{% include "helpdesk/emails/text_footer.txt" %} diff --git a/templates/helpdesk/emails/cc_closed.html b/templates/helpdesk/emails/cc_closed.html new file mode 100644 index 00000000..6a234c56 --- /dev/null +++ b/templates/helpdesk/emails/cc_closed.html @@ -0,0 +1,12 @@ +{% extends "helpdesk/emails/base.html" %} + +{% block header %}Ticket Closed{% endblock %} + +{% block content %} +

Hello,

+ +

Ticket {{ ticket.title }} ("{{ ticket.title }}") has been closed.

+ +

If you wish to view this ticket online, you can visit {{ ticket.get_staff_url }}.

+ +{% endblock %} diff --git a/templates/helpdesk/emails/cc_closed.txt b/templates/helpdesk/emails/cc_closed.txt new file mode 100644 index 00000000..2c2a3145 --- /dev/null +++ b/templates/helpdesk/emails/cc_closed.txt @@ -0,0 +1,7 @@ +Hello, + +Ticket {{ ticket.title }} ("{{ ticket.title }}") has been closed. + +If you wish to view this ticket online, you can visit {{ ticket.get_staff_url }}. + +{% include "helpdesk/emails/text_footer.txt" %} diff --git a/templates/helpdesk/emails/cc_newticket.html b/templates/helpdesk/emails/cc_newticket.html new file mode 100644 index 00000000..56b098d8 --- /dev/null +++ b/templates/helpdesk/emails/cc_newticket.html @@ -0,0 +1,10 @@ +{% extends "helpdesk/emails/base.html" %} + +{% block header %}Ticket Re-Assigned{% endblock %} + +{% block content %} +

Hello,

+ +

This is a courtesy e-mail to let you know that ticket {{ ticket.ticket }} ({{ ticket.title }}) has been opened.

+ +{% endblock %} diff --git a/templates/helpdesk/emails/cc_newticket.txt b/templates/helpdesk/emails/cc_newticket.txt new file mode 100644 index 00000000..ff692d3f --- /dev/null +++ b/templates/helpdesk/emails/cc_newticket.txt @@ -0,0 +1,7 @@ +Hello, + +This is a courtesy e-mail to let you know that ticket {{ ticket.ticket }} ("{{ ticket.title }}") has been opened. + +You can view this online at {{ ticket.staff_url }}. + +{% include "helpdesk/emails/text_footer.txt" %} diff --git a/templates/helpdesk/emails/cc_resolved.html b/templates/helpdesk/emails/cc_resolved.html new file mode 100644 index 00000000..7a29a2a1 --- /dev/null +++ b/templates/helpdesk/emails/cc_resolved.html @@ -0,0 +1,18 @@ +{% extends "helpdesk/emails/base.html" %} + +{% block header %}Ticket Resolution{% endblock %} + +{% block content %} +

Hello,

+ +

Ticket {{ ticket.ticket }} ({{ ticket.title }}) has been resolved.

+ +

The following resolution was added:

+ +
{{ resolution }}
+ +

This resolution has been e-mailed to the submitter, who will verify it before you can close this ticket.

+ +

If you wish to view this ticket online, you can visit {{ ticket.get_staff_url }}.

+ +{% endblock %} diff --git a/templates/helpdesk/emails/cc_resolved.txt b/templates/helpdesk/emails/cc_resolved.txt new file mode 100644 index 00000000..923f5092 --- /dev/null +++ b/templates/helpdesk/emails/cc_resolved.txt @@ -0,0 +1,13 @@ +Hello, + +Ticket {{ ticket.ticket }} ({{ ticket.title }}) has been resolved. + +The following resolution was added: + +{{ resolution }} + +This resolution has been e-mailed to the submitter, who will verify it before you can close this ticket. + +If you wish to view this ticket online, you can visit {{ ticket.get_staff_url }}. + +{% include "helpdesk/emails/text_footer.txt" %} diff --git a/templates/helpdesk/emails/cc_updated.html b/templates/helpdesk/emails/cc_updated.html new file mode 100644 index 00000000..f1b7bc25 --- /dev/null +++ b/templates/helpdesk/emails/cc_updated.html @@ -0,0 +1,18 @@ +{% extends "helpdesk/emails/base.html" %} + +{% block header %}Ticket Updated{% endblock %} + +{% block content %} +

Hello,

+ +

Ticket {{ ticket.ticket }} ({{ ticket.title }}) has been updated.

+ +

The following comment was added:

+ +
{{ comment }}
+ +

This information has {% if private %}not {% endif %} been e-mailed to the submitter.

+ +

If you wish to view this ticket online, you can visit {{ ticket.staff_url }}.

+ +{% endblock %} diff --git a/templates/helpdesk/emails/cc_updated.txt b/templates/helpdesk/emails/cc_updated.txt new file mode 100644 index 00000000..1b696654 --- /dev/null +++ b/templates/helpdesk/emails/cc_updated.txt @@ -0,0 +1,13 @@ +Hello, + +Ticket {{ ticket.ticket }} ({{ ticket.title }}) has been updated. + +The following comment was added: + +{{ comment }} + +This information has {% if private %}not {% endif %} been e-mailed to the submitter. + +If you wish to view this ticket online, you can visit {{ ticket.staff_url }}. + +{% include "helpdesk/emails/text_footer.txt" %} diff --git a/templates/helpdesk/emails/owner_assigned.html b/templates/helpdesk/emails/owner_assigned.html new file mode 100644 index 00000000..1e3f6836 --- /dev/null +++ b/templates/helpdesk/emails/owner_assigned.html @@ -0,0 +1,15 @@ +{% extends "helpdesk/emails/base.html" %} + +{% block header %}Ticket Assigned To You{% endblock %} + +{% block content %} +

Hello,

+ + +

This is a courtesy e-mail to let you know that a ticket has been assigned to you.

+ +

{% if ticket.submitter_email %}The ticket was submitted by {{ ticket.submitter_email }}, and the subject{% else %}The ticket subject{% endif%} is {{ ticket.title }}.

+ +

The ticket ID is {{ ticket.ticket }}. It's priority is {{ ticket.get_priority_display }}.

+ +{% endblock %} diff --git a/templates/helpdesk/emails/owner_assigned.txt b/templates/helpdesk/emails/owner_assigned.txt new file mode 100644 index 00000000..92630b4e --- /dev/null +++ b/templates/helpdesk/emails/owner_assigned.txt @@ -0,0 +1,9 @@ +Hello, + +This is a courtesy e-mail to let you know that a ticket has been assigned to you. + +{% if ticket.submitter_email %}The ticket was submitted by {{ ticket.submitter_email }}, and the subject{% else %}The ticket subject{% endif%} is {{ ticket.title }}. + +The ticket ID is {{ ticket.ticket }}, you can view it online at {{ ticket.staff_url }}. It's priority is {{ ticket.get_priority_display }}. + +{% include "helpdesk/emails/text_footer.txt" %} diff --git a/templates/helpdesk/emails/owner_closed.html b/templates/helpdesk/emails/owner_closed.html new file mode 100644 index 00000000..f034c882 --- /dev/null +++ b/templates/helpdesk/emails/owner_closed.html @@ -0,0 +1,12 @@ +{% extends "helpdesk/emails/base.html" %} + +{% block header %}Ticket Closed{% endblock %} + +{% block content %} +

Hello,

+ +

A ticket currently assigned to you with a subject of {{ ticket.title }} has been closed.

+ +

If you wish to view this ticket online, you can visit {{ ticket.get_staff_url }}.

+ +{% endblock %} diff --git a/templates/helpdesk/emails/owner_closed.txt b/templates/helpdesk/emails/owner_closed.txt new file mode 100644 index 00000000..271b2f79 --- /dev/null +++ b/templates/helpdesk/emails/owner_closed.txt @@ -0,0 +1,7 @@ +Hello, + +A ticket currently assigned to you with a subject of "{{ ticket.title }}" has been closed. + +If you wish to view this ticket online, you can visit {{ ticket.get_staff_url }}. + +{% include "helpdesk/emails/text_footer.txt" %} diff --git a/templates/helpdesk/emails/owner_resolved.html b/templates/helpdesk/emails/owner_resolved.html new file mode 100644 index 00000000..52a3b830 --- /dev/null +++ b/templates/helpdesk/emails/owner_resolved.html @@ -0,0 +1,18 @@ +{% extends "helpdesk/emails/base.html" %} + +{% block header %}Ticket Resolution{% endblock %} + +{% block content %} +

Hello,

+ +

A ticket currently assigned to you with a subject of {{ ticket.title }} has had a resolution added.

+ +

The following resolution was added to ticket {{ ticket.ticket }}:

+ +
{{ resolution }}
+ +

This resolution has been e-mailed to the submitter, who will verify it before you can close this ticket.

+ +

If you wish to view this ticket online, you can visit {{ ticket.get_staff_url }}.

+ +{% endblock %} diff --git a/templates/helpdesk/emails/owner_resolved.txt b/templates/helpdesk/emails/owner_resolved.txt new file mode 100644 index 00000000..d8530031 --- /dev/null +++ b/templates/helpdesk/emails/owner_resolved.txt @@ -0,0 +1,13 @@ +Hello, + +A ticket currently assigned to you with a subject of {{ ticket.title }} has had a resolution added. + +The following resolution was added to ticket {{ ticket.ticket }}: + +{{ resolution }} + +This resolution has been e-mailed to the submitter, who will verify it before you can close this ticket. + +If you wish to view this ticket online, you can visit {{ ticket.get_staff_url }}. + +{% include "helpdesk/emails/text_footer.txt" %} diff --git a/templates/helpdesk/emails/owner_updated.html b/templates/helpdesk/emails/owner_updated.html new file mode 100644 index 00000000..bc350217 --- /dev/null +++ b/templates/helpdesk/emails/owner_updated.html @@ -0,0 +1,18 @@ +{% extends "helpdesk/emails/base.html" %} + +{% block header %}Ticket Updated{% endblock %} + +{% block content %} +

Hello,

+ +

Ticket {{ ticket.ticket }} ({{ ticket.title }}), which is assigned to you, has been updated.

+ +

The following comment was added to ticket {{ ticket.ticket }}:

+ +
{{ comment }}
+ +

This information has {% if private %}not {% endif %} been e-mailed to the submitter.

+ +

If you wish to view this ticket online, you can visit {{ ticket.staff_url }}.

+ +{% endblock %} diff --git a/templates/helpdesk/emails/owner_updated.txt b/templates/helpdesk/emails/owner_updated.txt new file mode 100644 index 00000000..ce5f4657 --- /dev/null +++ b/templates/helpdesk/emails/owner_updated.txt @@ -0,0 +1,13 @@ +Hello, + +Ticket {{ ticket.ticket }} ({{ ticket.title }}), which is assigned to you, has been updated. + +The following comment was added to ticket {{ ticket.ticket }}: + +{{ comment }} + +This information has {% if private %}not {% endif %} been e-mailed to the submitter. + +If you wish to view this ticket online, you can visit {{ ticket.staff_url }}. + +{% include "helpdesk/emails/text_footer.txt" %} diff --git a/templates/helpdesk/emails/submitter_closed.html b/templates/helpdesk/emails/submitter_closed.html new file mode 100644 index 00000000..234d5e17 --- /dev/null +++ b/templates/helpdesk/emails/submitter_closed.html @@ -0,0 +1,14 @@ +{% extends "helpdesk/emails/base.html" %} + +{% block header %}Your Ticket Has Been Closed{% endblock %} + +{% block content %} +

Hello,

+ +

You recently logged a ticket with a subject of {{ ticket.title }} with us. This e-mail is to confirm that this ticket has been closed.

+ +

If you believe that further work is required on this ticket, please let us know by replying to this e-mail and keeping the subject intact.

+ +

If you wish to view this ticket online, you can visit {{ ticket.get_ticket_url }}.

+ +{% endblock %} diff --git a/templates/helpdesk/emails/submitter_closed.txt b/templates/helpdesk/emails/submitter_closed.txt new file mode 100644 index 00000000..2c44779c --- /dev/null +++ b/templates/helpdesk/emails/submitter_closed.txt @@ -0,0 +1,9 @@ +Hello, + +You recently logged a ticket with a subject of "{{ ticket.title }}" with us. This e-mail is to confirm that this ticket has been closed. + +If you believe that further work is required on this ticket, please let us know by replying to this e-mail and keeping the subject intact. + +If you wish to view this ticket online, you can visit {{ ticket.get_ticket_url }}. + +{% include "helpdesk/emails/text_footer.txt" %} diff --git a/views.py b/views.py index 98bca6b2..477f14d5 100644 --- a/views.py +++ b/views.py @@ -137,11 +137,14 @@ def update_ticket(request, ticket_id): if public: f.public = True + reassigned = False + if owner: if owner != 0 and (ticket.assigned_to and owner != ticket.assigned_to.id) or not ticket.assigned_to: new_user = User.objects.get(id=owner) f.title = 'Assigned to %s' % new_user.username ticket.assigned_to = new_user + reassigned = True else: f.title = 'Unassigned' ticket.assigned_to = None @@ -186,11 +189,49 @@ def update_ticket(request, ticket_id): if f.new_status == Ticket.RESOLVED_STATUS: template = 'helpdesk/emails/submitter_resolved' subject = '%s %s (Resolved)' % (ticket.ticket, ticket.title) + elif f.new_status == Ticket.CLOSED_STATUS: + template = 'helpdesk/emails/submitter_closed' + subject = '%s %s (Closed)' % (ticket.ticket, ticket.title) else: template = 'helpdesk/emails/submitter_updated' subject = '%s %s (Updated)' % (ticket.ticket, ticket.title) send_multipart_mail(template, context, subject, ticket.submitter_email, ticket.queue.from_address) + if ticket.assigned_to and request.user != ticket.assigned_to: + # We only send e-mails to staff members if the ticket is updated by + # another user. + if reassigned: + template_staff = 'helpdesk/emails/owner_assigned' + subject = '%s %s (Assigned)' % (ticket.ticket, ticket.title) + elif f.new_status == Ticket.RESOLVED_STATUS: + template_staff = 'helpdesk/emails/owner_resolved' + subject = '%s %s (Resolved)' % (ticket.ticket, ticket.title) + elif f.new_status == Ticket.CLOSED_STATUS: + template_staff = 'helpdesk/emails/owner_closed' + subject = '%s %s (Closed)' % (ticket.ticket, ticket.title) + else: + template_staff = 'helpdesk/emails/owner_updated' + subject = '%s %s (Updated)' % (ticket.ticket, ticket.title) + + send_multipart_mail(template_staff, context, subject, ticket.submitter_email, ticket.queue.from_address) + + + if q.updated_ticket_cc: + if reassigned: + template_cc = 'helpdesk/emails/cc_assigned' + subject = '%s %s (Assigned)' % (ticket.ticket, ticket.title) + elif f.new_status == Ticket.RESOLVED_STATUS: + template_cc = 'helpdesk/emails/cc_resolved' + subject = '%s %s (Resolved)' % (ticket.ticket, ticket.title) + elif f.new_status == Ticket.CLOSED_STATUS: + template_cc = 'helpdesk/emails/cc_closed' + subject = '%s %s (Closed)' % (ticket.ticket, ticket.title) + else: + template_cc = 'helpdesk/emails/cc_updated' + subject = '%s %s (Updated)' % (ticket.ticket, ticket.title) + + send_multipart_mail(template_cc, context, q.updated_ticket_cc, t.submitter_email, q.from_address) + ticket.save() return HttpResponseRedirect(ticket.get_absolute_url())