Only allow lockout admins to access tool, category

This commit is contained in:
Tanner Collin 2018-09-13 23:02:51 -06:00
parent e1c776698e
commit 61ceff77e3

View File

@ -3,13 +3,22 @@ from rest_framework import viewsets, permissions
from . import models, serializers from . import models, serializers
class IsLockoutAdmin(permissions.BasePermission):
def has_permission(self, request, view):
try:
return request.user.profile.lockout_admin
except AttributeError:
return False
class CategoryViewSet(viewsets.ModelViewSet): class CategoryViewSet(viewsets.ModelViewSet):
queryset = models.Category.objects.all().order_by('id') queryset = models.Category.objects.all().order_by('id')
serializer_class = serializers.CategorySerializer serializer_class = serializers.CategorySerializer
permission_classes = (IsLockoutAdmin,)
class ToolViewSet(viewsets.ModelViewSet): class ToolViewSet(viewsets.ModelViewSet):
queryset = models.Tool.objects.all().order_by('id') queryset = models.Tool.objects.all().order_by('id')
serializer_class = serializers.ToolSerializer serializer_class = serializers.ToolSerializer
permission_classes = (IsLockoutAdmin,)
class ToolDataViewSet(viewsets.ReadOnlyModelViewSet): class ToolDataViewSet(viewsets.ReadOnlyModelViewSet):
queryset = models.Category.objects.all().order_by('id') queryset = models.Category.objects.all().order_by('id')