diff --git a/helpdesk/templates/helpdesk/ticket_cc_add.html b/helpdesk/templates/helpdesk/ticket_cc_add.html index 07ee9f0f..b3bffd17 100644 --- a/helpdesk/templates/helpdesk/ticket_cc_add.html +++ b/helpdesk/templates/helpdesk/ticket_cc_add.html @@ -1,72 +1,104 @@ -{% extends "helpdesk/base.html" %}{% load i18n %} +{% extends "helpdesk/base.html" %} + +{% load i18n %} {% block helpdesk_title %}{% trans "Add Ticket CC" %}{% endblock %} {% block helpdesk_breadcrumb %} -
The following people will receive an e-mail whenever {{ ticket_title }} is updated. Some people can also view or edit the ticket via the public ticket views.
+The following people will receive an e-mail whenever {{ ticket_title }} is updated. Some people can also view or edit the ticket via the public ticket views.
-You can add a new recipient to the list or delete any of the items below as required.
{% endblocktrans %} +You can add a new recipient to the list or delete any of the items below as required.
{% endblocktrans %} -{% trans "E-Mail Address or Helpdesk User" %} | +{% trans "View?" %} | +{% trans "Update?" %} | +{% trans "Delete" %} | +
---|---|---|---|
{{ person.display }} | ++ {% if person.can_view %} + + {% else %} + + {% endif %} + | ++ {% if person.can_update %} + + {% else %} + + {% endif %} + | ++ + + + | +
+ + + +
{% endblock %} diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py index 9fa1b869..d24c109e 100644 --- a/helpdesk/views/staff.py +++ b/helpdesk/views/staff.py @@ -1508,21 +1508,27 @@ def ticket_cc_add(request, ticket_id): ticket = get_object_or_404(Ticket, id=ticket_id) ticket_perm_check(request, ticket) + form = None if request.method == 'POST': form = TicketCCForm(request.POST) if form.is_valid(): - ticketcc = form.save(commit=False) - ticketcc.ticket = ticket - ticketcc.save() - return HttpResponseRedirect(reverse('helpdesk:ticket_cc', - kwargs={'ticket_id': ticket.id})) - else: - form_email = TicketCCEmailForm() - form_user = TicketCCUserForm() + user = form.cleaned_data.get('user') + email = form.cleaned_data.get('email') + if user and ticket.ticketcc_set.filter(user=user).exists(): + form.add_error('user', _('Impossible to add twice the same user')) + elif email and ticket.ticketcc_set.filter(email=email).exists(): + form.add_error('email', _('Impossible to add twice the same email address')) + else: + ticketcc = form.save(commit=False) + ticketcc.ticket = ticket + ticketcc.save() + return HttpResponseRedirect(reverse('helpdesk:ticket_cc', kwargs={'ticket_id': ticket.id})) + return render(request, 'helpdesk/ticket_cc_add.html', { 'ticket': ticket, - 'form_email': form_email, - 'form_user': form_user, + 'form': form, + 'form_email': TicketCCEmailForm(), + 'form_user': TicketCCUserForm(), }) @@ -1531,13 +1537,14 @@ ticket_cc_add = staff_member_required(ticket_cc_add) @helpdesk_staff_member_required def ticket_cc_del(request, ticket_id, cc_id): + ticket = get_object_or_404(Ticket, id=ticket_id) cc = get_object_or_404(TicketCC, ticket__id=ticket_id, id=cc_id) if request.method == 'POST': cc.delete() - return HttpResponseRedirect(reverse('helpdesk:ticket_cc', - kwargs={'ticket_id': cc.ticket.id})) - return render(request, 'helpdesk/ticket_cc_del.html', {'cc': cc}) + return HttpResponseRedirect(reverse('helpdesk:ticket_cc', kwargs={'ticket_id': cc.ticket.id})) + + return render(request, 'helpdesk/ticket_cc_del.html', {'ticket': ticket, 'cc': cc}) ticket_cc_del = staff_member_required(ticket_cc_del)