You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GET api/customer/1/ Will give 403 error for any user whose id differs from 1. And that is fine.
Then if anon user goes to api/customer/1/favourite-product/ they will get 200 response with product payload, because permissions for product checked in ProductViewSet, which have no permissions for any role. But I think it is wrong and should return 403, since we have to check permission for customer first. We actually just told everybody what is customer's 1 favorite product!
I understand that permissions it is out of json api spec, but may be there is a nice way I can handle permissions with this lib correctly?
For now I do it like below:
A RelatedMixin class will get a related entity and will find corresponding a serializer for that. And all that stuff will happen after we check permissions for parent ("customer" in the case) entity
Permissions is not part of JSON API spec but certainly something addressed by DRF. Hence I like the idea to solve this issue for DJA specific case of related links.
Your approach outlined here also seems to make it easier to implement related links. Beside some details (can be later on discussed in the PR) this potentially needs two queries as when implementing ProductViewSet as its own view it could be reduced to one sql query. But I guess a small difference which can be neglected if it makes it easier to implement related links.
Feel free to open a PR and we can then discuss details there.
Let's say we have config like this:
views.py
urls.py
GET api/customer/1/
Will give 403 error for any user whose id differs from 1. And that is fine.Then if anon user goes to
api/customer/1/favourite-product/
they will get 200 response with product payload, because permissions for product checked inProductViewSet
, which have no permissions for any role. But I think it is wrong and should return 403, since we have to check permission for customer first. We actually just told everybody what is customer's 1 favorite product!I understand that permissions it is out of json api spec, but may be there is a nice way I can handle permissions with this lib correctly?
For now I do it like below:
A RelatedMixin class will get a related entity and will find corresponding a serializer for that. And all that stuff will happen after we check permissions for parent ("customer" in the case) entity
and then just make a view that will handle all Customer's related entities:
urls.py # Only one url route required for all related entities
What do you think about it ? If you like the idea I'm ready to come up with PR
The text was updated successfully, but these errors were encountered: