From 00a18d8f549511d6475a9eb40eb05e574405c20c Mon Sep 17 00:00:00 2001 From: bbe Date: Fri, 30 Oct 2020 20:19:50 +0100 Subject: [PATCH] Restrict possible tickets to merge to the ones that haven't been already merged. Also check that all selected tickets are within the same queue. --- helpdesk/forms.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/helpdesk/forms.py b/helpdesk/forms.py index bb9072a0..d6779c69 100644 --- a/helpdesk/forms.py +++ b/helpdesk/forms.py @@ -515,14 +515,17 @@ class TicketDependencyForm(forms.ModelForm): class MultipleTicketSelectForm(forms.Form): tickets = forms.ModelMultipleChoiceField( label=_('Tickets to merge'), - queryset=Ticket.objects.all(), + 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')) + 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