diff --git a/helpdesk/settings.py b/helpdesk/settings.py
index ccc7b033..96026068 100644
--- a/helpdesk/settings.py
+++ b/helpdesk/settings.py
@@ -66,6 +66,9 @@ HELPDESK_FOLLOWUP_MOD = getattr(settings, 'HELPDESK_FOLLOWUP_MOD', False)
# show custom welcome message in dashboard?
HELPDESK_CUSTOM_WELCOME = getattr(settings, 'HELPDESK_CUSTOM_WELCOME', False)
+# auto-subscribe user to ticket if (s)he responds to a ticket?
+HELPDESK_AUTO_SUBSCRIBE_ON_TICKET_RESPONSE = getattr(settings, 'HELPDESK_AUTO_SUBSCRIBE_ON_TICKET_RESPONSE', False)
+
''' options for public pages '''
diff --git a/helpdesk/templates/helpdesk/ticket_desc_table.html b/helpdesk/templates/helpdesk/ticket_desc_table.html
index deac9058..cdde594e 100644
--- a/helpdesk/templates/helpdesk/ticket_desc_table.html
+++ b/helpdesk/templates/helpdesk/ticket_desc_table.html
@@ -34,7 +34,7 @@
{% trans "Copies To" %} |
- {% for ticketcc in ticket.ticketcc_set.all %}{{ ticketcc.display }}{% if not forloop.last %}, {% endif %}{% endfor %} {% trans "Manage" %}{% trans "Click here to add / remove people who should receive an e-mail whenever this ticket is updated." %} |
+ {{ ticketcc_string }} {% trans "Manage" %}{% trans "Click here to add / remove people who should receive an e-mail whenever this ticket is updated." %}{% if SHOW_SUBSCRIBE %}, {% trans "Subscribe" %}{% trans "Click here to subscribe yourself to this ticket, if you want to receive an e-mail whenever this ticket is updated." %}{% endif %} |
{% if tags_enabled %}
diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py
index e1e410b7..f0f4205f 100644
--- a/helpdesk/views/staff.py
+++ b/helpdesk/views/staff.py
@@ -151,12 +151,13 @@ def followup_edit(request, ticket_id, followup_id):
'public': followup.public,
'new_status': followup.new_status,
})
-
+ ticketcc_string, SHOW_SUBSCRIBE = return_ticketccstring_and_show_subscribe(request.user, ticket)
return render_to_response('helpdesk/followup_edit.html',
RequestContext(request, {
'followup': followup,
'ticket': ticket,
'form': form,
+ 'ticketcc_string': ticketcc_string,
}))
elif request.method == 'POST':
form = EditFollowUpForm(request.POST)
@@ -211,6 +212,13 @@ def view_ticket(request, ticket_id):
}
return update_ticket(request, ticket_id)
+ if request.GET.has_key('subscribe'):
+ # Allow the user to subscribe him/herself to the ticket whilst viewing it.
+ ticketcc_string, SHOW_SUBSCRIBE = return_ticketccstring_and_show_subscribe(request.user, ticket)
+ if SHOW_SUBSCRIBE:
+ subscribe_staff_member_to_ticket(ticket, request.user)
+ return HttpResponseRedirect(reverse('helpdesk_view', args=[ticket.id]))
+
if request.GET.has_key('close') and ticket.status == Ticket.RESOLVED_STATUS:
if not ticket.assigned_to:
owner = 0
@@ -229,6 +237,8 @@ def view_ticket(request, ticket_id):
return update_ticket(request, ticket_id)
+
+ ticketcc_string, SHOW_SUBSCRIBE = return_ticketccstring_and_show_subscribe(request.user, ticket)
return render_to_response('helpdesk/ticket.html',
RequestContext(request, {
'ticket': ticket,
@@ -236,10 +246,56 @@ def view_ticket(request, ticket_id):
'priorities': Ticket.PRIORITY_CHOICES,
'preset_replies': PreSetReply.objects.filter(Q(queues=ticket.queue) | Q(queues__isnull=True)),
'tags_enabled': HAS_TAG_SUPPORT,
+ 'ticketcc_string': ticketcc_string,
+ 'SHOW_SUBSCRIBE': SHOW_SUBSCRIBE,
}))
view_ticket = staff_member_required(view_ticket)
+def return_ticketccstring_and_show_subscribe(user, ticket):
+ ''' used in view_ticket() and followup_edit()'''
+ # create the ticketcc_string and check whether current user is already
+ # subscribed
+ username = user.username.upper()
+ useremail = user.email.upper()
+ strings_to_check = list()
+ strings_to_check.append(username)
+ strings_to_check.append(useremail)
+
+ ticketcc_string = ''
+ all_ticketcc = ticket.ticketcc_set.all()
+ counter_all_ticketcc = len(all_ticketcc) - 1
+ SHOW_SUBSCRIBE = True
+ for i, ticketcc in enumerate(all_ticketcc):
+ ticketcc_this_entry = str(ticketcc.display)
+ ticketcc_string = ticketcc_string + ticketcc_this_entry
+ if i < counter_all_ticketcc:
+ ticketcc_string = ticketcc_string + ', '
+ if strings_to_check.__contains__(ticketcc_this_entry.upper()):
+ SHOW_SUBSCRIBE = False
+
+ # check whether current user is a submitter or assigned to ticket
+ assignedto_username = str(ticket.assigned_to).upper()
+ submitter_email = ticket.submitter_email.upper()
+ strings_to_check = list()
+ strings_to_check.append(assignedto_username)
+ strings_to_check.append(submitter_email)
+ if strings_to_check.__contains__(username) or strings_to_check.__contains__(useremail):
+ SHOW_SUBSCRIBE = False
+
+ return ticketcc_string, SHOW_SUBSCRIBE
+
+
+def subscribe_staff_member_to_ticket(ticket, user):
+ ''' used in view_ticket() and update_ticket() '''
+ ticketcc = TicketCC()
+ ticketcc.ticket = ticket
+ ticketcc.user = user
+ ticketcc.can_view = True
+ ticketcc.can_update = True
+ ticketcc.save()
+
+
def update_ticket(request, ticket_id, public=False):
if not (public or (request.user.is_authenticated() and request.user.is_active and (request.user.is_staff or helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE))):
return HttpResponseForbidden(_('Sorry, you need to login to do that.'))
@@ -468,6 +524,12 @@ def update_ticket(request, ticket_id, public=False):
ticket.save()
+ # auto subscribe user if enabled
+ if helpdesk_settings.HELPDESK_AUTO_SUBSCRIBE_ON_TICKET_RESPONSE:
+ ticketcc_string, SHOW_SUBSCRIBE = return_ticketccstring_and_show_subscribe(request.user, ticket)
+ if SHOW_SUBSCRIBE:
+ subscribe_staff_member_to_ticket(ticket, request.user)
+
return return_to_ticket(request.user, helpdesk_settings, ticket)