permissions.py 1.0 KB

1234567891011121314151617181920212223
  1. from django.shortcuts import get_object_or_404
  2. from rest_framework import permissions
  3. from tickets.models import Ticket, TicketList
  4. class UserCanReadTicketListPermission(permissions.BasePermission):
  5. def has_object_permission(serf, request, view, obj):
  6. return request.user.is_superuser or obj.group in request.user.groups.all()
  7. class UserTicketAccessPermission(permissions.BasePermission):
  8. def has_object_permission(self, request, view, obj):
  9. if request.method in permissions.SAFE_METHODS:
  10. return request.user.is_superuser or obj.ticket_list.group in request.user.groups.all() or obj.assigned_to == request.user
  11. return request.user.is_superuser or request.user.is_staff or obj.created_by == request.user
  12. class UserTicketStatusAccessPermission(permissions.BasePermission):
  13. def has_object_permission(self, request, view, obj):
  14. return request.user.is_superuser or obj.ticket_list.group in request.user.groups.all() or obj.assigned_to == request.user or obj.created_by == request.user