Skip to content

Commit

Permalink
Merge pull request #895 from Benbb96/merging-tickets-feature
Browse files Browse the repository at this point in the history
New feature:  Merging tickets
  • Loading branch information
gwasser committed Nov 1, 2020
2 parents b7070db + 177ba8f commit c9fa0c8
Show file tree
Hide file tree
Showing 20 changed files with 2,113 additions and 1,108 deletions.
8 changes: 7 additions & 1 deletion helpdesk/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,15 @@ def create_object_from_email_message(message, ticket_id, payload, files, logger)
if previous_followup is None and ticket_id is not None:
try:
ticket = Ticket.objects.get(id=ticket_id)
new = False
except Ticket.DoesNotExist:
ticket = None
else:

This comment has been minimized.

Copy link
@alligatorbait

alligatorbait Nov 4, 2020

Contributor

This block looks to be indented at a level deeper than the initial if on line 337.

This comment has been minimized.

Copy link
@Benbb96

Benbb96 Nov 4, 2020

Member

Yes, it is intended. I used the optional else statement of the try-catch in order to isolate the exception of a not existing ticket.
So we don't bother checking for a merged ticket if no match was found.

This comment has been minimized.

Copy link
@gwasser

gwasser via email Nov 4, 2020

Author Member
new = False
# Check if the ticket has been merged to another ticket
if ticket.merged_to:
logger.info("Ticket has been merged to %s" % ticket.merged_to.ticket)
# Use the ticket in which it was merged to for next operations
ticket = ticket.merged_to

# New issue, create a new <Ticket> instance
if ticket is None:
Expand Down
21 changes: 20 additions & 1 deletion helpdesk/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""
import logging

from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django import forms
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
Expand Down Expand Up @@ -510,3 +510,22 @@ class TicketDependencyForm(forms.ModelForm):
class Meta:
model = TicketDependency
exclude = ('ticket',)


class MultipleTicketSelectForm(forms.Form):
tickets = forms.ModelMultipleChoiceField(
label=_('Tickets to merge'),
queryset=Ticket.objects.filter(merged_to=None),
widget=forms.SelectMultiple(attrs={'class': 'form-control'})
)

def clean_tickets(self):
tickets = self.cleaned_data.get('tickets')
if len(tickets) < 2:
raise ValidationError(_('Please choose at least 2 tickets.'))
if len(tickets) > 4:
raise ValidationError(_('Impossible to merge more than 4 tickets...'))
queues = tickets.order_by('queue').distinct().values_list('queue', flat=True)
if len(queues) != 1:
raise ValidationError(_('All selected tickets must share the same queue in order to be merged.'))
return tickets
2 changes: 1 addition & 1 deletion helpdesk/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def ticket_template_context(ticket):
for field in ('title', 'created', 'modified', 'submitter_email',
'status', 'get_status_display', 'on_hold', 'description',
'resolution', 'priority', 'get_priority_display',
'last_escalation', 'ticket', 'ticket_for_url',
'last_escalation', 'ticket', 'ticket_for_url', 'merged_to',
'get_status', 'ticket_url', 'staff_url', '_get_assigned_to'
):
attr = getattr(ticket, field, None)
Expand Down
Binary file modified helpdesk/locale/fr/LC_MESSAGES/django.mo
Binary file not shown.

0 comments on commit c9fa0c8

Please sign in to comment.