Improve ticket CC handling. By @kotowicz in

4bf79ccf46.
This commit is contained in:
Ross Poulton 2012-08-07 23:41:43 +10:00
parent 2f1b74316f
commit a21050082a
3 changed files with 68 additions and 2 deletions

View File

@ -69,6 +69,8 @@ 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 '''

View File

@ -34,7 +34,7 @@
<tr class='{% cycle rowcolors %}'>
<th>{% trans "Copies To" %}</th>
<td>{% for ticketcc in ticket.ticketcc_set.all %}{{ ticketcc.display }}{% if not forloop.last %}, {% endif %}{% endfor %} <strong><a class='tooltip' href='{% url helpdesk_ticket_cc ticket.id %}'>{% trans "Manage" %}<span>{% trans "Click here to add / remove people who should receive an e-mail whenever this ticket is updated." %}</span></a></strong></td>
<td>{{ ticketcc_string }} <strong><a class='tooltip' href='{% url helpdesk_ticket_cc ticket.id %}'>{% trans "Manage" %}<span>{% trans "Click here to add / remove people who should receive an e-mail whenever this ticket is updated." %}</span></a></strong>{% if SHOW_SUBSCRIBE %}, <strong><a class='tooltip' href='?subscribe'>{% trans "Subscribe" %}<span>{% trans "Click here to subscribe yourself to this ticket, if you want to receive an e-mail whenever this ticket is updated." %}</span></a></strong>{% endif %}</td>
</tr>
{% if tags_enabled %}

View File

@ -155,12 +155,15 @@ 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)
@ -215,6 +218,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
@ -242,6 +252,8 @@ def view_ticket(request, ticket_id):
# TODO: shouldn't this template get a form to begin with?
form = TicketForm(initial={'due_date':ticket.due_date})
ticketcc_string, SHOW_SUBSCRIBE = return_ticketccstring_and_show_subscribe(request.user, ticket)
return render_to_response('helpdesk/ticket.html',
RequestContext(request, {
'ticket': ticket,
@ -250,9 +262,54 @@ 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))):
@ -495,8 +552,15 @@ 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)
def return_to_ticket(user, helpdesk_settings, ticket):
''' Helpder function for update_ticket '''