Issue #90: Users can receive multiple e-mails.

If an e-mail address is used in the 'Queue CC' set up and then that 
e-mail address is used as a submitter for a ticket, they received two 
emails. Worse, if that user was ALSO the 'assigned to' person for that 
ticket, they got THREE emails! 
This fix will ensure a particular email goes to an address only once.
Thanks to Andreas Kotowicz for this patch.
This commit is contained in:
Ross Poulton 2009-08-11 09:02:48 +00:00
parent 06fe35e944
commit b492bd5bd2
3 changed files with 38 additions and 13 deletions

View File

@ -134,6 +134,8 @@ class TicketForm(forms.Form):
'queue': q,
}
messages_sent_to = []
if t.submitter_email:
send_templated_mail(
'newticket_submitter',
@ -143,8 +145,9 @@ class TicketForm(forms.Form):
fail_silently=True,
files=files,
)
messages_sent_to.append(t.submitter_email)
if t.assigned_to and t.assigned_to != user and getattr(t.assigned_to.usersettings.settings, 'email_on_ticket_assign', False):
if t.assigned_to and t.assigned_to != user and getattr(t.assigned_to.usersettings.settings, 'email_on_ticket_assign', False) and t.assigned_to.email and t.assigned_to.email not in messages_sent_to:
send_templated_mail(
'assigned_owner',
context,
@ -153,8 +156,9 @@ class TicketForm(forms.Form):
fail_silently=True,
files=files,
)
messages_sent_to.append(t.assigned_to.email)
if q.new_ticket_cc:
if q.new_ticket_cc and q.new_ticket_cc not in messages_sent_to:
send_templated_mail(
'newticket_cc',
context,
@ -163,8 +167,9 @@ class TicketForm(forms.Form):
fail_silently=True,
files=files,
)
messages_sent_to.append(q.new_ticket_cc)
if q.updated_ticket_cc and q.updated_ticket_cc != q.new_ticket_cc:
if q.updated_ticket_cc and q.updated_ticket_cc != q.new_ticket_cc and q.updated_ticket_cc not in messages_sent_to:
send_templated_mail(
'newticket_cc',
context,
@ -272,6 +277,8 @@ class PublicTicketForm(forms.Form):
'queue': q,
}
messages_sent_to = []
send_templated_mail(
'newticket_submitter',
context,
@ -280,8 +287,9 @@ class PublicTicketForm(forms.Form):
fail_silently=True,
files=files,
)
messages_sent_to.append(t.submitter_email)
if q.new_ticket_cc:
if q.new_ticket_cc and q.new_ticket_cc not in messages_sent_to:
send_templated_mail(
'newticket_cc',
context,
@ -290,8 +298,9 @@ class PublicTicketForm(forms.Form):
fail_silently=True,
files=files,
)
messages_sent_to.append(q.new_ticket_cc)
if q.updated_ticket_cc and q.updated_ticket_cc != q.new_ticket_cc:
if q.updated_ticket_cc and q.updated_ticket_cc != q.new_ticket_cc and q.updated_ticket_cc not in messages_sent_to:
send_templated_mail(
'newticket_cc',
context,

View File

@ -197,6 +197,8 @@ class API:
'comment': f.comment,
}
messages_sent_to = []
if public and ticket.submitter_email:
send_templated_mail(
'updated_submitter',
@ -205,8 +207,9 @@ class API:
sender=ticket.queue.from_address,
fail_silently=True,
)
messages_sent_to.append(ticket.submitter_email)
if ticket.queue.updated_ticket_cc:
if ticket.queue.updated_ticket_cc and ticket.queue.updated_ticket_cc not in messages_sent_to:
send_templated_mail(
'updated_cc',
context,
@ -214,8 +217,9 @@ class API:
sender=ticket.queue.from_address,
fail_silently=True,
)
messages_sent_to.append(ticket.queue.updated_ticket_cc)
if ticket.assigned_to and self.request.user != ticket.assigned_to and getattr(ticket.assigned_to.usersettings.settings, 'email_on_ticket_apichange', False):
if ticket.assigned_to and self.request.user != ticket.assigned_to and getattr(ticket.assigned_to.usersettings.settings, 'email_on_ticket_apichange', False) and ticket.assigned_to.email and ticket.assigned_to.email not in messages_sent_to:
send_templated_mail(
'updated_owner',
context,
@ -258,6 +262,8 @@ class API:
subject = '%s %s (Resolved)' % (ticket.ticket, ticket.title)
messages_sent_to = []
if ticket.submitter_email:
send_templated_mail(
'resolved_submitter',
@ -266,8 +272,9 @@ class API:
sender=ticket.queue.from_address,
fail_silently=True,
)
messages_sent_to.append(ticket.submitter_email)
if ticket.queue.updated_ticket_cc:
if ticket.queue.updated_ticket_cc and ticket.queue.updated_ticket_cc not in messages_sent_to:
send_templated_mail(
'resolved_cc',
context,
@ -275,8 +282,9 @@ class API:
sender=ticket.queue.from_address,
fail_silently=True,
)
messages_sent_to.append(ticket.queue.updated_ticket_cc)
if ticket.assigned_to and self.request.user != ticket.assigned_to and getattr(ticket.assigned_to.usersettings.settings, 'email_on_ticket_apichange', False):
if ticket.assigned_to and self.request.user != ticket.assigned_to and getattr(ticket.assigned_to.usersettings.settings, 'email_on_ticket_apichange', False) and ticket.assigned_to.email and ticket.assigned_to.email not in messages_sent_to:
send_templated_mail(
'resolved_resolved',
context,

View File

@ -233,6 +233,8 @@ def update_ticket(request, ticket_id, public=False):
if f.new_status == Ticket.RESOLVED_STATUS:
ticket.resolution = comment
messages_sent_to = []
if ticket.submitter_email and public and (f.comment or (f.new_status in (Ticket.RESOLVED_STATUS, Ticket.CLOSED_STATUS))):
context.update(
resolution=ticket.resolution,
@ -254,8 +256,9 @@ def update_ticket(request, ticket_id, public=False):
fail_silently=True,
files=files,
)
messages_sent_to.append(ticket.submitter_email)
if ticket.assigned_to and request.user != ticket.assigned_to and ticket.assigned_to.email:
if ticket.assigned_to and request.user != ticket.assigned_to and ticket.assigned_to.email and ticket.assigned_to.email not in messages_sent_to:
# We only send e-mails to staff members if the ticket is updated by
# another user. The actual template varies, depending on what has been
# changed.
@ -277,8 +280,9 @@ def update_ticket(request, ticket_id, public=False):
fail_silently=True,
files=files,
)
messages_sent_to.append(ticket.assigned_to.email)
if ticket.queue.updated_ticket_cc:
if ticket.queue.updated_ticket_cc and ticket.queue.updated_ticket_cc not in messages_sent_to:
if reassigned:
template_cc = 'assigned_cc'
elif f.new_status == Ticket.RESOLVED_STATUS:
@ -347,6 +351,8 @@ def mass_update(request):
'resolution': t.resolution,
}
messages_sent_to = []
if t.submitter_email:
send_templated_mail(
'closed_submitter',
@ -355,8 +361,9 @@ def mass_update(request):
sender=t.queue.from_address,
fail_silently=True,
)
messages_sent_to.append(t.submitter_email)
if t.assigned_to and request.user != t.assigned_to and t.assigned_to.email:
if t.assigned_to and request.user != t.assigned_to and t.assigned_to.email and t.assigned_to.email not in messages_sent_to:
send_templated_mail(
'closed_owner',
context,
@ -364,8 +371,9 @@ def mass_update(request):
sender=t.queue.from_address,
fail_silently=True,
)
messages_sent_to.append(t.assigned_to.email)
if t.queue.updated_ticket_cc:
if t.queue.updated_ticket_cc and t.queue.updated_ticket_cc not in messages_sent_to:
send_templated_mail(
'closed_cc',
context,