Skip to content

Commit

Permalink
Merge pull request #292 from nofusscomputing/project-milestone
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-nfc authored Sep 16, 2024
2 parents a373247 + d8654fa commit d5e344f
Show file tree
Hide file tree
Showing 48 changed files with 2,927 additions and 1,394 deletions.
3 changes: 2 additions & 1 deletion app/api/serializers/assistance/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from api.serializers.core.ticket import TicketSerializer

from core.models.ticket.ticket import Ticket
from core.models.ticket import Ticket



Expand Down Expand Up @@ -39,6 +39,7 @@ class Meta:
'opened_by',
'organization',
'project',
'milestone',
'subscribed_teams',
'subscribed_users',
'ticket_comments',
Expand Down
14 changes: 5 additions & 9 deletions app/api/serializers/core/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from api.serializers.core.ticket_comment import TicketCommentSerializer

from core.forms.validate_ticket import TicketValidation
from core.models.ticket.ticket import Ticket
from core.models.ticket import Ticket



Expand Down Expand Up @@ -153,23 +153,19 @@ def __init__(self, instance=None, data=empty, **kwargs):
self.fields.fields['status'].initial = Ticket.TicketStatus.All.NEW
self.fields.fields['status'].default = Ticket.TicketStatus.All.NEW

self.ticket_type_fields = self.Meta.fields

super().__init__(instance=instance, data=data, **kwargs)

self.fields['organization'].required = True


def is_valid(self, *, raise_exception=True) -> bool:

self.request = self._context['request']

is_valid = super().is_valid(raise_exception=raise_exception)

if self.instance:

self.original_object = self.Meta.model.objects.get(pk=self.instance.pk)

else:

self.original_object = None

self._ticket_type = str(self.fields['ticket_type'].choices[self._context['view']._ticket_type_value]).lower().replace(' ', '_')


Expand Down
3 changes: 2 additions & 1 deletion app/api/serializers/itim/change.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from api.serializers.core.ticket import TicketSerializer

from core.models.ticket.ticket import Ticket
from core.models.ticket import Ticket



Expand Down Expand Up @@ -39,6 +39,7 @@ class Meta:
'opened_by',
'organization',
'project',
'milestone',
'subscribed_teams',
'subscribed_users',
'ticket_comments',
Expand Down
3 changes: 2 additions & 1 deletion app/api/serializers/itim/incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from api.serializers.core.ticket import TicketSerializer

from core.models.ticket.ticket import Ticket
from core.models.ticket import Ticket



Expand Down Expand Up @@ -39,6 +39,7 @@ class Meta:
'opened_by',
'organization',
'project',
'milestone',
'subscribed_teams',
'subscribed_users',
'ticket_comments',
Expand Down
3 changes: 2 additions & 1 deletion app/api/serializers/itim/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from api.serializers.core.ticket import TicketSerializer

from core.models.ticket.ticket import Ticket
from core.models.ticket import Ticket



Expand Down Expand Up @@ -39,6 +39,7 @@ class Meta:
'opened_by',
'organization',
'project',
'milestone',
'subscribed_teams',
'subscribed_users',
'ticket_comments',
Expand Down
3 changes: 2 additions & 1 deletion app/api/serializers/project_management/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from api.serializers.core.ticket import TicketSerializer

from core.models.ticket.ticket import Ticket
from core.models.ticket import Ticket



Expand Down Expand Up @@ -39,6 +39,7 @@ class Meta:
'opened_by',
'organization',
'project',
'milestone',
'subscribed_teams',
'subscribed_users',
'ticket_comments',
Expand Down
2 changes: 1 addition & 1 deletion app/api/views/core/tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from api.serializers.project_management.project_task import ProjectTaskSerializer
from api.views.mixin import OrganizationPermissionAPI

from core.models.ticket.ticket import Ticket
from core.models.ticket import Ticket



Expand Down
2 changes: 1 addition & 1 deletion app/core/forms/related_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from core.forms.common import CommonModelForm

from core.models.ticket.ticket import RelatedTickets
from core.models.ticket import RelatedTickets


class RelatedTicketForm(CommonModelForm):
Expand Down
40 changes: 29 additions & 11 deletions app/core/forms/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from core.forms.common import CommonModelForm
from core.forms.validate_ticket import TicketValidation

from core.models.ticket.ticket import Ticket, RelatedTickets
from core.models.ticket import Ticket, RelatedTickets



Expand Down Expand Up @@ -50,7 +50,24 @@ def __init__(self, request, *args, **kwargs):
self.fields['opened_by'].widget = self.fields['opened_by'].hidden_widget()

self.fields['ticket_type'].widget = self.fields['ticket_type'].hidden_widget()
self.fields['organization'].widget = self.fields['organization'].hidden_widget()

self.fields['organization'].initial = self.initial['organization']

if self.instance.pk is not None:

self.fields['organization'].widget = self.fields['organization'].hidden_widget()

if self.instance.project is not None:

self.fields['milestone'].queryset = self.fields['milestone'].queryset.filter(
project=self.instance.project
)

else:

self.fields['milestone'].queryset = self.fields['milestone'].queryset.filter(
id=0
)


original_fields = self.fields.copy()
Expand Down Expand Up @@ -139,26 +156,31 @@ def __init__(self, request, *args, **kwargs):

ticket_type += self.Meta.model.tech_fields

fields_allowed = self.fields_allowed
self.ticket_type_fields = ticket_type

fields_allowed_by_permission = self.get_fields_allowed_by_permission

for field in fields_allowed: # Remove fields not intended for the ticket type
allowed_ticket_fields: list = []

if field not in ticket_type:
for field in fields_allowed_by_permission: # Remove fields not intended for the ticket type

self._fields_allowed.remove(field)

if field in ticket_type:

allowed_ticket_fields = allowed_ticket_fields + [ field ]


for field in original_fields: # Remove fields user cant edit unless field is hidden

if (
(
field not in self._fields_allowed and not self.fields[field].widget.is_hidden
field not in allowed_ticket_fields and not self.fields[field].widget.is_hidden
)
or
field not in ticket_type
):

# self.fields[field].widget = self.fields[field].hidden_widget()
del self.fields[field]


Expand All @@ -173,10 +195,6 @@ def is_valid(self) -> bool:

is_valid = super().is_valid()

if self.instance.pk:

self.original_object = self.Meta.model.objects.get(pk=self.instance.pk)

self.validate_ticket()

if self._ticket_type == 'change':
Expand Down
Loading

0 comments on commit d5e344f

Please sign in to comment.