mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2025-08-11 00:44:27 +02:00
Restrict ticket selection for dependencies and parents
When adding a dependent or parent ticket, the choice field in the ticket selection form excludes: - All existing dependencies of the current ticket. - All existing parent tickets of the current ticket. - The current ticket itself. The first two prevent immediate circular references: A dependency cannot be a parent and vice versa. Deeper circular references are not covered by this: a ticket can still be its own grandchild. They also prevent current behavior of throwing an `IntegrityException` when selecting a dependency or parent. The third one prevents also a quirky behavior: until now, specifying the ticket itself as parent or dependency just does not save the dependency and does not issue a warning either.
This commit is contained in:
@ -591,6 +591,12 @@ class TicketDependencyForm(forms.ModelForm):
|
||||
model = TicketDependency
|
||||
exclude = ('ticket',)
|
||||
|
||||
def __init__(self, ticket, *args, **kwargs):
|
||||
super(TicketDependencyForm,self).__init__(*args, **kwargs)
|
||||
|
||||
# Exclude duplicate tickets, myself, existing dependencies and parents
|
||||
self.fields['depends_on'].queryset = Ticket.objects.exclude(status=Ticket.DUPLICATE_STATUS).exclude(id=ticket.id).exclude(depends_on__ticket=ticket).exclude(ticketdependency__depends_on=ticket)
|
||||
|
||||
class TicketResolvesForm(forms.ModelForm):
|
||||
''' Adds this ticket as a dependency for a different ticket '''
|
||||
|
||||
@ -599,6 +605,12 @@ class TicketResolvesForm(forms.ModelForm):
|
||||
#exclude = ('depends_on',)
|
||||
fields = ('ticket',)
|
||||
|
||||
def __init__(self, ticket, *args, **kwargs):
|
||||
super(TicketResolvesForm,self).__init__(*args, **kwargs)
|
||||
|
||||
# Exclude duplicate tickets, myself, existing dependencies and parents
|
||||
self.fields['ticket'].queryset = Ticket.objects.exclude(status=Ticket.DUPLICATE_STATUS).exclude(id=ticket.id).exclude(depends_on__ticket=ticket).exclude(ticketdependency__depends_on=ticket)
|
||||
|
||||
|
||||
class MultipleTicketSelectForm(forms.Form):
|
||||
tickets = forms.ModelMultipleChoiceField(
|
||||
|
Reference in New Issue
Block a user