emile 10 months ago
parent 893acd6a8c
commit ee3e406cf3

Binary file not shown.

@ -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

@ -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,

Loading…
Cancel
Save