django-revproxy icon indicating copy to clipboard operation
django-revproxy copied to clipboard

django authentication and permissions

Open nimaansary opened this issue 4 years ago • 1 comments

I want to check user permissions and then give him access! how can i add middleware to django-revproxy

nimaansary avatar Aug 27 '20 06:08 nimaansary

I think this can easily be done by overriding get_request_headers and raising a PermissionDenied exception if the user does not have permission

class YourView(ProxyView):
    
    def get_request_headers(self):
          if not hasattr(self.request, 'user') or not self.request.user.has_perm("myapp.permission_code"):
                raise PermissionDenied()
          return super().get_request_headers()

nl-emmanuellodovice avatar Oct 27 '20 12:10 nl-emmanuellodovice