def process_view(self, request, view_func, view_args, view_kwargs): """ The process_view() hook allows us to examine the request before view_func is called""" # Special override flag if self.OVERRIDE: return None # Url exception(s) exc_pattern = settings.INDIVO_ACCESS_CONTROL_EXCEPTION if exc_pattern and re.match(exc_pattern, request.path): return None if hasattr(view_func, 'resolve'): resolved_func = view_func.resolve(request) if not resolved_func: return view_func.resolution_error_response else: view_func = resolved_func try: if view_func and hasattr(request, 'principal') and request.principal: access_rule = AccessRule.lookup(view_func) if access_rule and access_rule.check(request.principal, ** view_kwargs): return None # Accept except: logging.debug( 'indivo.middlewares.Authorization: access_rule.check() was unsuccessful' ) raise PermissionDenied logging.debug( 'indivo.middlewares.Authorization: There is no principal') raise PermissionDenied
def process_view(self, request, view_func, view_args, view_kwargs): """ The process_view() hook allows us to examine the request before view_func is called""" # Special override flag if self.OVERRIDE: return None # Url exception(s) exc_pattern= settings.INDIVO_ACCESS_CONTROL_EXCEPTION if exc_pattern and re.match(exc_pattern, request.path): return None if hasattr(view_func, 'resolve'): resolved_func = view_func.resolve(request) if not resolved_func: return view_func.resolution_error_response else: view_func = resolved_func try: if view_func and hasattr(request, 'principal') and request.principal: access_rule = AccessRule.lookup(view_func) if access_rule and access_rule.check(request.principal, **view_kwargs): return None # Accept except: logging.debug('indivo.middlewares.Authorization: access_rule.check() was unsuccessful') raise PermissionDenied logging.debug('indivo.middlewares.Authorization: There is no principal') raise PermissionDenied
def get_access_rule(self, view_func): return AccessRule.lookup(view_func)
def _get_access_rule(self): return AccessRule.lookup(self.view_func) if self.view_func else None