2015-06-25 23:55:51 +03:00
|
|
|
from rest_framework import authentication, renderers
|
2022-06-08 15:41:26 +03:00
|
|
|
from rest_framework.permissions import BasePermission
|
2014-09-02 16:53:37 +04:00
|
|
|
from rest_framework.response import Response
|
2015-06-25 23:55:51 +03:00
|
|
|
from rest_framework.views import APIView
|
2022-06-08 15:41:26 +03:00
|
|
|
from rest_framework.viewsets import ModelViewSet
|
|
|
|
|
|
|
|
from ..models import BasicModelWithUsers
|
|
|
|
from .serializers import BasicSerializer
|
|
|
|
|
|
|
|
|
|
|
|
class OrganizationPermissions(BasePermission):
|
|
|
|
def has_object_permission(self, request, view, obj):
|
|
|
|
return request.user.is_staff or (request.user == obj.owner.organization_user.user)
|
2014-09-02 16:53:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
class MockView(APIView):
|
|
|
|
authentication_classes = (authentication.SessionAuthentication,)
|
2016-06-01 17:31:00 +03:00
|
|
|
renderer_classes = (renderers.BrowsableAPIRenderer, renderers.JSONRenderer)
|
2014-09-02 16:53:37 +04:00
|
|
|
|
|
|
|
def get(self, request):
|
|
|
|
return Response({'a': 1, 'b': 2, 'c': 3})
|
2022-06-08 15:41:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
class BasicModelWithUsersViewSet(ModelViewSet):
|
|
|
|
queryset = BasicModelWithUsers.objects.all()
|
|
|
|
serializer_class = BasicSerializer
|
|
|
|
permission_classes = [OrganizationPermissions]
|
|
|
|
# permission_classes = [IsAuthenticated, OrganizationPermissions]
|
|
|
|
renderer_classes = (renderers.BrowsableAPIRenderer, renderers.JSONRenderer)
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
qs = super().get_queryset().filter(users=self.request.user)
|
|
|
|
return qs
|