diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index bb768c73..6680beeb 100644 Binary files a/osinaweb/db.sqlite3 and b/osinaweb/db.sqlite3 differ diff --git a/osinaweb/support/__pycache__/models.cpython-310.pyc b/osinaweb/support/__pycache__/models.cpython-310.pyc index 5f8acdc0..2c2fd1bd 100644 Binary files a/osinaweb/support/__pycache__/models.cpython-310.pyc and b/osinaweb/support/__pycache__/models.cpython-310.pyc differ diff --git a/osinaweb/support/__pycache__/views.cpython-310.pyc b/osinaweb/support/__pycache__/views.cpython-310.pyc index 106d5e11..2c1e1988 100644 Binary files a/osinaweb/support/__pycache__/views.cpython-310.pyc and b/osinaweb/support/__pycache__/views.cpython-310.pyc differ diff --git a/osinaweb/support/models.py b/osinaweb/support/models.py index 6ccdb3bb..d856cb83 100644 --- a/osinaweb/support/models.py +++ b/osinaweb/support/models.py @@ -128,6 +128,19 @@ class Ticket(models.Model): else: return f"last seen on {last_seen_time.strftime('%b %d at %I:%M %p')}" + def get_all_ticket_staff(self): + ticket_staff = TicketStaff.objects.filter(ticket=self).select_related('staff') + latest_department = TicketDepartment.objects.filter(ticket=self).order_by('-date_added').first() + if latest_department: + department_staff = latest_department.department.get_staff() + else: + department_staff = [] + + all_staff = list(ticket_staff.values_list('staff', flat=True)) + list(department_staff) + + return all_staff + + diff --git a/osinaweb/support/views.py b/osinaweb/support/views.py index afd58c17..bf81a558 100644 --- a/osinaweb/support/views.py +++ b/osinaweb/support/views.py @@ -7,21 +7,13 @@ from django.http import Http404 # Create your views here. def ticket_room(request, ticket_number): ticket = get_object_or_404(Ticket, ticket_number=ticket_number) - + print(ticket.get_all_ticket_staff()) if request.user.is_superuser: base_template = "main.html" elif hasattr(request.user, 'customerprofile') and request.user.customerprofile == ticket.customer: base_template = "customer_main.html" - elif hasattr(request.user, 'staffprofile'): - latest_department = TicketDepartment.objects.filter(ticket=ticket).order_by('-date_added').first() - ticket_department_staffs = latest_department.department.get_staff() - ticket_staffs = TicketStaff.objects.filter(ticket=ticket) - if any(request.user.staffprofile == staff.staff for staff in ticket_staffs): - base_template = "main.html" - elif request.user.staffprofile in ticket_department_staffs: + elif hasattr(request.user, 'staffprofile') and request.user.staffprofile in ticket.get_all_ticket_staff(): base_template = "main.html" - else: - raise Http404("You are not authorized to view this ticket.") else: raise Http404("You are not authorized to view this ticket.") @@ -33,7 +25,7 @@ def ticket_room(request, ticket_number): last_ticket_status = TicketStatus.objects.filter(ticket=ticket).last() - connections = TicketConnection.objects.all().order_by('-id') + connections = TicketConnection.objects.filter(terminated=False).order_by('-id') context = { 'base_template': base_template,