Skip to content

Commit

Permalink
Merge pull request #284 from nofusscomputing/ticket-categories
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-nfc authored Sep 14, 2024
2 parents 9d8c894 + c81e319 commit a373247
Show file tree
Hide file tree
Showing 69 changed files with 3,509 additions and 102 deletions.
12 changes: 12 additions & 0 deletions app/api/serializers/assistance/request.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from rest_framework.fields import empty

from api.serializers.core.ticket import TicketSerializer

from core.models.ticket.ticket import Ticket
Expand All @@ -16,6 +18,7 @@ class Meta:
'id',
'assigned_teams',
'assigned_users',
'category',
'created',
'modified',
'status',
Expand Down Expand Up @@ -47,3 +50,12 @@ class Meta:
'ticket_type',
'url',
]


def __init__(self, instance=None, data=empty, **kwargs):

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

self.fields.fields['category'].queryset = self.fields.fields['category'].queryset.filter(
request = True
)
1 change: 1 addition & 0 deletions app/api/serializers/core/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class Meta:
'id',
'assigned_teams',
'assigned_users',
'category',
'created',
'modified',
'status',
Expand Down
44 changes: 44 additions & 0 deletions app/api/serializers/core/ticket_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from django.urls import reverse

from rest_framework import serializers
from rest_framework.fields import empty

from api.serializers.core.ticket_comment import TicketCommentSerializer

from core.forms.validate_ticket import TicketValidation
from core.models.ticket.ticket_category import TicketCategory



class TicketCategorySerializer(
serializers.ModelSerializer,
):

url = serializers.HyperlinkedIdentityField(
view_name="API:_api_ticket_category-detail", format="html"
)


class Meta:

model = TicketCategory

fields = '__all__'

read_only_fields = [
'id',
'url',
]


def __init__(self, instance=None, data=empty, **kwargs):

if instance is not None:

if hasattr(instance, 'id'):

self.fields.fields['parent'].queryset = self.fields.fields['parent'].queryset.exclude(
id=instance.id
)

super().__init__(instance=instance, data=data, **kwargs)
42 changes: 42 additions & 0 deletions app/api/serializers/core/ticket_comment_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from django.urls import reverse

from rest_framework import serializers
from rest_framework.fields import empty


from core.models.ticket.ticket_comment_category import TicketCommentCategory



class TicketCommentCategorySerializer(
serializers.ModelSerializer,
):

url = serializers.HyperlinkedIdentityField(
view_name="API:_api_ticket_comment_category-detail", format="html"
)


class Meta:

model = TicketCommentCategory

fields = '__all__'

read_only_fields = [
'id',
'url',
]


def __init__(self, instance=None, data=empty, **kwargs):

if instance is not None:

if hasattr(instance, 'id'):

self.fields.fields['parent'].queryset = self.fields.fields['parent'].queryset.exclude(
id=instance.id
)

super().__init__(instance=instance, data=data, **kwargs)
12 changes: 12 additions & 0 deletions app/api/serializers/itim/change.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from rest_framework.fields import empty

from api.serializers.core.ticket import TicketSerializer

from core.models.ticket.ticket import Ticket
Expand All @@ -16,6 +18,7 @@ class Meta:
'id',
'assigned_teams',
'assigned_users',
'category',
'created',
'modified',
'status',
Expand Down Expand Up @@ -47,3 +50,12 @@ class Meta:
'ticket_type',
'url',
]


def __init__(self, instance=None, data=empty, **kwargs):

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

self.fields.fields['category'].queryset = self.fields.fields['category'].queryset.filter(
project_task = True
)
12 changes: 12 additions & 0 deletions app/api/serializers/itim/incident.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from rest_framework.fields import empty

from api.serializers.core.ticket import TicketSerializer

from core.models.ticket.ticket import Ticket
Expand All @@ -16,6 +18,7 @@ class Meta:
'id',
'assigned_teams',
'assigned_users',
'category',
'created',
'modified',
'status',
Expand Down Expand Up @@ -47,3 +50,12 @@ class Meta:
'ticket_type',
'url',
]


def __init__(self, instance=None, data=empty, **kwargs):

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

self.fields.fields['category'].queryset = self.fields.fields['category'].queryset.filter(
incident = True
)
12 changes: 12 additions & 0 deletions app/api/serializers/itim/problem.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from rest_framework.fields import empty

from api.serializers.core.ticket import TicketSerializer

from core.models.ticket.ticket import Ticket
Expand All @@ -16,6 +18,7 @@ class Meta:
'id',
'assigned_teams',
'assigned_users',
'category',
'created',
'modified',
'status',
Expand Down Expand Up @@ -47,3 +50,12 @@ class Meta:
'ticket_type',
'url',
]


def __init__(self, instance=None, data=empty, **kwargs):

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

self.fields.fields['category'].queryset = self.fields.fields['category'].queryset.filter(
problem = True
)
12 changes: 12 additions & 0 deletions app/api/serializers/project_management/project_task.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from rest_framework.fields import empty

from api.serializers.core.ticket import TicketSerializer

from core.models.ticket.ticket import Ticket
Expand All @@ -16,6 +18,7 @@ class Meta:
'id',
'assigned_teams',
'assigned_users',
'category',
'created',
'modified',
'status',
Expand Down Expand Up @@ -47,3 +50,12 @@ class Meta:
'ticket_type',
'url',
]


def __init__(self, instance=None, data=empty, **kwargs):

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

self.fields.fields['category'].queryset = self.fields.fields['category'].queryset.filter(
project_task = True
)
10 changes: 9 additions & 1 deletion app/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

from api.views import assistance, itim, project_management
from api.views.assistance import request_ticket
from api.views.core import ticket_comments as core_ticket_comments
from api.views.core import (
ticket_categories,
ticket_comment_categories,
ticket_comments as core_ticket_comments
)
from api.views.itim import change_ticket, incident_ticket, problem_ticket
from api.views.project_management import projects, project_task

Expand Down Expand Up @@ -44,6 +48,10 @@
router.register('project_management/projects/(?P<project_id>[0-9]+)/tasks', project_task.View, basename='_api_project_tasks')
router.register('project_management/projects/(?P<project_id>[0-9]+)/tasks/(?P<ticket_id>[0-9]+)/comments', core_ticket_comments.View, basename='_api_project_tasks_comments')

router.register('settings/ticket_categories', ticket_categories.View, basename='_api_ticket_category')

router.register('settings/ticket_comment_categories', ticket_comment_categories.View, basename='_api_ticket_comment_category')

router.register('software', software.SoftwareViewSet, basename='software')


Expand Down
79 changes: 79 additions & 0 deletions app/api/views/core/ticket_categories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from django.shortcuts import get_object_or_404

from drf_spectacular.utils import extend_schema, OpenApiResponse

from rest_framework import generics, viewsets

from access.mixin import OrganizationMixin

from api.serializers.core.ticket_category import TicketCategory, TicketCategorySerializer
from api.views.mixin import OrganizationPermissionAPI



class View(OrganizationMixin, viewsets.ModelViewSet):

permission_classes = [
OrganizationPermissionAPI
]

queryset = TicketCategory.objects.all()

serializer_class = TicketCategorySerializer


@extend_schema(
summary='Create a ticket category',
request = TicketCategorySerializer,
responses = {
201: OpenApiResponse(description='Ticket category created', response=TicketCategorySerializer),
403: OpenApiResponse(description='User tried to edit field they dont have access to'),
}
)
def create(self, request, *args, **kwargs):

return super().create(request, *args, **kwargs)


@extend_schema(
summary='Fetch all of a tickets category',
methods=["GET"],
responses = {
200: OpenApiResponse(description='Success', response=TicketCategorySerializer),
}
)
def list(self, request, *args, **kwargs):

return super().list(request, *args, **kwargs)


@extend_schema(
summary='Fetch the selected ticket category',
methods=["GET"],
responses = {
200: OpenApiResponse(description='Success', response=TicketCategorySerializer),
}
)
def retrieve(self, request, *args, **kwargs):

return super().retrieve(request, *args, **kwargs)


@extend_schema(
summary='Update a ticket category',
methods=["PUT"],
responses = {
200: OpenApiResponse(description='Ticket comment updated', response=TicketCategorySerializer),
403: OpenApiResponse(description='User tried to edit field they dont have access to'),
}
)
def update(self, request, *args, **kwargs):

return super().update(request, *args, **kwargs)


def get_view_name(self):
if self.detail:
return "Ticket Category"

return 'Ticket Categories'
Loading

0 comments on commit a373247

Please sign in to comment.