I'd like to validate whether users have permission to update a "shared_with" field , right now I'm doing it with a direct call to .has_perm, but this seems to not scalable, anyone know what's the best practice in this case?
views.py:
class MyViewSet(viewsets.ModelViewSet):
@staticmethod
def _check_sharing_permission(request: Request):
if request.data.get('shared_with') and not
request.user.has_perm(CAN_SHARE_PERMISSION_CODENAME):
raise PermissionDenied('you shall not pass!')
def update(self, request, *args, **kwargs):
self._check_sharing_permission(request)
return super().update(request, *args, **kwargs)