-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d28aa8c
commit f942e1d
Showing
11 changed files
with
282 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
from copy import deepcopy | ||
import json | ||
import logging | ||
|
||
from django.contrib import messages | ||
from django.contrib.auth import get_user_model | ||
from django.contrib.auth.models import Group | ||
from django.core import serializers | ||
from django.core.exceptions import BadRequest | ||
from django.db.models import Q | ||
from django.http import Http404 | ||
from django.shortcuts import get_object_or_404 | ||
|
||
from rest_framework.authentication import SessionAuthentication | ||
from rest_framework.exceptions import PermissionDenied | ||
from rest_framework import generics | ||
from rest_framework.views import APIView | ||
from rest_framework.response import Response | ||
from rest_framework import permissions, viewsets | ||
|
||
from uni_ticket.dynamic_form import serialize_form | ||
from uni_ticket.models import Ticket, TicketAssignment, TicketCategory, TicketReply | ||
from uni_ticket.views.user import TicketAddNew, TicketClose, TicketDetail | ||
from uni_ticket.settings import TICKET_CREATE_BUTTON_NAME | ||
from uni_ticket.utils import user_is_manager, user_is_operator, visible_tickets_to_user | ||
|
||
from organizational_area.models import OrganizationalStructure | ||
from api_rest.authorizations import AuthorizationToken | ||
|
||
|
||
from .. serializers import ( | ||
GroupSerializer, | ||
OrganizationalStructureSerializer, | ||
TicketCategorySerializer, | ||
TicketSerializer, | ||
UserSerializer | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
# ViewSets define the view behavior. | ||
class UserViewSet(viewsets.ModelViewSet): | ||
permission_classes = [permissions.IsAdminUser] | ||
queryset = get_user_model().objects.all() | ||
serializer_class = UserSerializer | ||
|
||
|
||
class GroupViewSet(viewsets.ModelViewSet): | ||
""" | ||
API endpoint that allows groups to be viewed or edited. | ||
""" | ||
permission_classes = [permissions.IsAdminUser] | ||
queryset = Group.objects.all() | ||
serializer_class = GroupSerializer | ||
|
||
|
||
class uniTicketROGenericList(generics.ListAPIView): | ||
authentication_classes = [AuthorizationToken, SessionAuthentication] | ||
permission_classes = [permissions.IsAuthenticated] | ||
|
||
|
||
def message_level(level:int): | ||
levels = {v:k for k,v in messages.DEFAULT_LEVELS.items()} | ||
return levels.get(level, level) | ||
|
||
|
||
class TicketAPIBaseView(APIView): | ||
""" | ||
base class to port in the API all the legacy code | ||
""" | ||
|
||
# TODO: AgID MoDI also here? | ||
authentication_classes = [ | ||
AuthorizationToken, SessionAuthentication | ||
] | ||
permission_classes = [permissions.IsAuthenticated] | ||
|
||
def get_messages(self): | ||
return [ | ||
{ | ||
message_level(i.level): i.message | ||
for i in messages.get_messages(self.request) | ||
} | ||
] | ||
|
||
|
||
class TicketAPIStruttureList(uniTicketROGenericList): | ||
queryset = OrganizationalStructure.objects.filter(is_active=True) | ||
lookup_field = 'pk' | ||
serializer_class = OrganizationalStructureSerializer | ||
|
||
|
||
class TicketAPITicketCategoryList(uniTicketROGenericList): | ||
queryset = TicketCategory.objects.filter(is_active=True) | ||
lookup_field = 'pk' | ||
serializer_class = TicketCategorySerializer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import logging | ||
|
||
from django.contrib import messages | ||
from django.core import serializers | ||
from django.db.models import Q | ||
from django.http import Http404 | ||
from django.shortcuts import get_object_or_404 | ||
|
||
from rest_framework.authentication import SessionAuthentication | ||
from rest_framework.exceptions import PermissionDenied | ||
from rest_framework import generics | ||
from rest_framework.views import APIView | ||
from rest_framework.response import Response | ||
from rest_framework import permissions, viewsets | ||
|
||
from uni_ticket.models import Ticket, TicketAssignment, TicketCategory, TicketReply | ||
from uni_ticket.utils import user_is_manager, user_is_operator, visible_tickets_to_user | ||
|
||
from organizational_area.models import OrganizationalStructure | ||
from api_rest.authorizations import AuthorizationToken | ||
|
||
from . generic import * | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class TicketAPICounter(TicketAPIBaseView): | ||
def get(self, request, structure_slug, *args, **kwargs): | ||
structure = get_object_or_404(OrganizationalStructure, slug=structure_slug) | ||
if not user_is_manager(request.user, structure): raise PermissionDenied | ||
|
||
unassigned_tickets = TicketAssignment.get_ticket_per_structure(structure=structure, | ||
closed=False, | ||
taken=False) | ||
|
||
open_tickets = TicketAssignment.get_ticket_per_structure(structure=structure, | ||
closed=False, | ||
taken=True) | ||
|
||
my_open_tickets = TicketAssignment.get_ticket_per_structure(structure=structure, | ||
closed=False, | ||
taken=True, | ||
taken_by=request.user) | ||
ticket_ids = TicketAssignment.objects.filter( | ||
office__organizational_structure=structure, | ||
office__is_active=True, | ||
follow=True, | ||
ticket__is_closed=False | ||
).values_list('ticket__pk', flat=True).distinct() | ||
messages = TicketReply.get_unread_messages_count(ticket_ids=ticket_ids) | ||
|
||
return Response({'unassigned': len(unassigned_tickets), | ||
'open': len(open_tickets), | ||
'my_open': len(my_open_tickets), | ||
'new_messages': messages}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import logging | ||
|
||
from django.contrib import messages | ||
from django.core import serializers | ||
from django.db.models import Q | ||
from django.http import Http404 | ||
from django.shortcuts import get_object_or_404 | ||
|
||
from rest_framework.authentication import SessionAuthentication | ||
from rest_framework.exceptions import PermissionDenied | ||
from rest_framework import generics | ||
from rest_framework.views import APIView | ||
from rest_framework.response import Response | ||
from rest_framework import permissions, viewsets | ||
|
||
from uni_ticket.models import Ticket, TicketAssignment, TicketCategory, TicketReply | ||
from uni_ticket.utils import user_is_manager, user_is_operator, visible_tickets_to_user | ||
|
||
from organizational_area.models import OrganizationalStructure | ||
from api_rest.authorizations import AuthorizationToken | ||
|
||
from . generic import * | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class TicketAPICounter(TicketAPIBaseView): | ||
def get(self, request, structure_slug, *args, **kwargs): | ||
structure = get_object_or_404(OrganizationalStructure, slug=structure_slug) | ||
oe = user_is_operator(request.user, structure) | ||
if not oe: raise PermissionDenied | ||
|
||
unassigned_tickets = visible_tickets_to_user(user=request.user, | ||
structure=structure, | ||
office_employee=oe, | ||
closed=False, | ||
taken=False) | ||
|
||
open_tickets = visible_tickets_to_user(user=request.user, | ||
structure=structure, | ||
office_employee=oe, | ||
closed=False, | ||
taken=True) | ||
|
||
my_open_tickets = visible_tickets_to_user(user=request.user, | ||
structure=structure, | ||
office_employee=oe, | ||
closed=False, | ||
taken=True, | ||
taken_by=request.user) | ||
|
||
ticket_ids = visible_tickets_to_user( | ||
user=request.user, | ||
structure=structure, | ||
office_employee=oe, | ||
closed=False | ||
) | ||
|
||
messages = TicketReply.get_unread_messages_count(ticket_ids=ticket_ids) | ||
|
||
return Response({'unassigned': len(unassigned_tickets), | ||
'open': len(open_tickets), | ||
'my_open': len(my_open_tickets), | ||
'new_messages': messages}) |
Oops, something went wrong.