···7474 """
7575 For regular users with no team: return all open tickets that are created by the user
7676 """
7777+ if user.is_superuser:
7878+ return cls.objects.all()
7979+7780 user_teams = user.team_set.all()
7881 if not user_teams:
7982 return cls.objects.filter(user=user)
···103106 return cls._get_tickets(user).filter(status=cls.Status.CLOSED)
104107105108 def can_open(self, user):
109109+ if user.is_superuser:
110110+ return True
106111 return self.user == user or self.assigned_to == user or self.assigned_team in user.team_set.all() or self.assigned_team is None and user.team_set.filter(access_non_category_tickets=True).exists()
107112108113 def can_edit(self, user):
109109- assigned_and_write_access = self.assigned_team in user.team_set.filter(readonly_access=False)
114114+ if user.is_superuser:
115115+ return True
116116+ assigned_and_write_access = self.assigned_team in user.team_set.filter(readonly_access=False) or self.assigned_to == user
110117 unassigned_and_write_access = self.assigned_team is None and user.team_set.filter(access_non_category_tickets=True, readonly_access=False).exists()
111118 print(assigned_and_write_access, unassigned_and_write_access)
112119 return self.can_open(user) and (assigned_and_write_access or unassigned_and_write_access)
+8-7
ticketing/views.py
···2727@login_required
2828def show_ticket(request, ticket_id):
2929 ticket = get_object_or_404(Ticket, pk=ticket_id)
3030+ can_edit = ticket.can_edit(request.user)
3031 # comment_templates = Template.objects.filter(category=ticket.category)
31323233 if not ticket.can_open(request.user):
···3637 ), TemplateForm(), TeamAssignmentForm(), CategoryAssignmentForm()
37383839 if request.method == "POST":
3939- if 'apply_template' in request.POST and request.user.is_staff:
4040+ if 'apply_template' in request.POST and can_edit:
4041 template_form = TemplateForm(request.POST)
4142 if template_form.is_valid():
4243 template = template_form.cleaned_data["template_select"]
4344 form = CommentForm(initial={"text": template.content})
4444- elif 'assign_to_team' in request.POST and request.user.is_staff:
4545+ elif 'assign_to_team' in request.POST and can_edit:
4546 team_assignment_form = TeamAssignmentForm(request.POST)
4647 if team_assignment_form.is_valid():
4748 ticket.assign_to_team(
4849 team_assignment_form.cleaned_data["team_select"])
4949- elif 'assign_to_category' in request.POST and request.user.is_staff:
5050+ elif 'assign_to_category' in request.POST and can_edit:
5051 category_assignment_form = CategoryAssignmentForm(request.POST)
5152 if category_assignment_form.is_valid():
5253 ticket.category = category_assignment_form.cleaned_data["category_select"]
5354 ticket.save()
5454- elif 'assign_self' in request.POST and request.user.is_staff:
5555+ elif 'assign_self' in request.POST and can_edit:
5556 ticket.assigned_to = request.user
5657 ticket.save()
5757- elif 'reopen_ticket' in request.POST and request.user.is_staff:
5858+ elif 'reopen_ticket' in request.POST and can_edit:
5859 ticket.status = Ticket.Status.IN_PROGRESS
5960 ticket.save()
6061 else:
···6970 for file in form.cleaned_data["attachments"]:
7071 ticket.fileattachment_set.create(file=file)
71727272- if 'close' in request.POST and request.user.is_staff:
7373+ if 'close' in request.POST and can_edit:
7374 ticket.close_ticket()
74757576 comments = ticket.comment_set.all()
···7778 "ticket": ticket, "comments": comments, "attachments": [attachment.file for attachment in ticket.fileattachment_set.all()],
7879 "form": form, "template_form": template_form,
7980 "team_assignment_form": team_assignment_form, "category_assignment_form": category_assignment_form,
8080- "can_edit": ticket.can_edit(request.user)
8181+ "can_edit": can_edit
8182 }
8283 return render(request, "ticketing/ticket_detail.html", context)
8384