My API allows access (any request) to certain objects only when a user is authenticated and certain other conditions are satisfied.
class SomethingViewSet(viewsets.ModelViewSet):
queryset = Something.objects.filter(query_hiding_non_authorized_objects)
serializer_class = SomethingSerializer
permission_classes = (permissions.IsAuthenticated, SomePermission)
If a user attempts to view a non-authorized object DRF returns a 403 error, however, this gives away that an object with the requested id exists. How can I return 404 errors in these cases?
Note: I also use a custom queryset to hide non-authorized objects from being listed.
ModelViewSet. If I had a permission checking the user is the owner of the object, then it return 403, as expected. But if I narrow theget_querysetto only display objects owned, then I have, as expected, a 404 on theListretrieval. But also a 404 when trying to access an existing object not owned. On the last one, I'd expect a 403...