From 2f1b74316f71c6e0b8aaf57fad297830854c2afd Mon Sep 17 00:00:00 2001 From: Ross Poulton Date: Tue, 7 Aug 2012 23:32:45 +1000 Subject: [PATCH] new option 'HELPDESK_SHOW_EDIT_BUTTON_FOLLOW_UP' which allows superusers to delete individual followups (so you don't have to go to the admin). (by @kotowicz in a2a5b10b2d44c861d2b0732660fb2736ee65e31b) --- helpdesk/settings.py | 3 +++ helpdesk/templates/helpdesk/ticket.html | 6 ++++++ helpdesk/urls.py | 4 ++++ helpdesk/views/staff.py | 23 ++++++++++++++++++----- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/helpdesk/settings.py b/helpdesk/settings.py index b707a8cb..783f332c 100644 --- a/helpdesk/settings.py +++ b/helpdesk/settings.py @@ -91,6 +91,9 @@ HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE = getattr(settings, 'HELPDESK_ALLOW_NON_S # show edit buttons in ticket follow ups. HELPDESK_SHOW_EDIT_BUTTON_FOLLOW_UP = getattr(settings, 'HELPDESK_SHOW_EDIT_BUTTON_FOLLOW_UP', True) +# show delete buttons in ticket follow ups if user is 'superuser' +HELPDESK_SHOW_DELETE_BUTTON_SUPERUSER_FOLLOW_UP = getattr(settings, 'HELPDESK_SHOW_DELETE_BUTTON_SUPERUSER_FOLLOW_UP', False) + # show ticket edit button on top of ticket description. HELPDESK_SHOW_EDIT_BUTTON_TICKET_TOP = getattr(settings, 'HELPDESK_SHOW_EDIT_BUTTON_TICKET_TOP', True) diff --git a/helpdesk/templates/helpdesk/ticket.html b/helpdesk/templates/helpdesk/ticket.html index b5c17080..5cf67f01 100644 --- a/helpdesk/templates/helpdesk/ticket.html +++ b/helpdesk/templates/helpdesk/ticket.html @@ -74,6 +74,9 @@ function googleTranslateElementInit() { Edit {% endif %} {% endif %} + {% if user.is_superuser and helpdesk_settings.HELPDESK_SHOW_DELETE_BUTTON_SUPERUSER_FOLLOW_UP %} + Delete + {% endif %} {% else %}
@@ -84,6 +87,9 @@ function googleTranslateElementInit() { Edit {% endif %} {% endif %} + {% if user.is_superuser and helpdesk_settings.HELPDESK_SHOW_DELETE_BUTTON_SUPERUSER_FOLLOW_UP %} + Delete + {% endif %}
{% endif %} {% if followup.comment %}{{ followup.comment|force_escape|urlizetrunc:50|num_to_link|linebreaksbr }}{% endif %} diff --git a/helpdesk/urls.py b/helpdesk/urls.py index 5a71557f..70e590a9 100644 --- a/helpdesk/urls.py +++ b/helpdesk/urls.py @@ -39,6 +39,10 @@ urlpatterns = patterns('helpdesk.views.staff', 'followup_edit', name='helpdesk_followup_edit'), + url(r'^tickets/(?P[0-9]+)/followup_delete/(?P[0-9]+)/$', + 'followup_delete', + name='helpdesk_followup_delete'), + url(r'^tickets/(?P[0-9]+)/edit/$', 'edit_ticket', name='helpdesk_edit'), diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py index 0afdaf9f..c29bff55 100644 --- a/helpdesk/views/staff.py +++ b/helpdesk/views/staff.py @@ -143,7 +143,7 @@ def delete_ticket(request, ticket_id): return HttpResponseRedirect(reverse('helpdesk_home')) delete_ticket = staff_member_required(delete_ticket) -def followup_edit(request, ticket_id, followup_id, ): +def followup_edit(request, ticket_id, followup_id): "Edit followup options with an ability to change the ticket." followup = get_object_or_404(FollowUp, id=followup_id) ticket = get_object_or_404(Ticket, id=ticket_id) @@ -155,7 +155,7 @@ def followup_edit(request, ticket_id, followup_id, ): 'public': followup.public, 'new_status': followup.new_status, }) - + return render_to_response('helpdesk/followup_edit.html', RequestContext(request, { 'followup': followup, @@ -178,14 +178,27 @@ def followup_edit(request, ticket_id, followup_id, ): new_followup.user = followup.user new_followup.save() # get list of old attachments & link them to new_followup - attachments = Attachment.objects.filter(followup = followup) + attachments = Attachment.objects.filter(followup = followup) for attachment in attachments: attachment.followup = new_followup attachment.save() # delete old followup - followup.delete() + followup.delete() return HttpResponseRedirect(reverse('helpdesk_view', args=[ticket.id])) - + + +def followup_delete(request, ticket_id, followup_id): + ''' followup delete for superuser''' + + ticket = get_object_or_404(Ticket, id=ticket_id) + if not request.user.is_superuser: + return HttpResponseRedirect(reverse('helpdesk_view', args=[ticket.id])) + + followup = get_object_or_404(FollowUp, id=followup_id) + followup.delete() + return HttpResponseRedirect(reverse('helpdesk_view', args=[ticket.id])) + + def view_ticket(request, ticket_id): ticket = get_object_or_404(Ticket, id=ticket_id)