def may(self, pname: str) -> bool: if pname in self._permissions: return self._permissions[pname] they_may = may_with_roles(self.role_ids, pname) self._permissions[pname] = they_may is_rest_api_call = bool( endpoint) # we can't check if "is None" because it's a LocalProxy if is_rest_api_call: endpoint.remember_checked_permission(pname) if (endpoint.permissions_required is not None and not endpoint.permissions_required.validate( list(endpoint._used_permissions))): raise PermissionError( f"Required permissions not specified for endpoint.\n" f"Endpoint: {endpoint}\n" f"Required: {endpoint.permissions_required}\n" f"Triggered: {endpoint._used_permissions}\n", ) return they_may
def may(self, pname: str) -> bool: if pname in self._permissions: return self._permissions[pname] they_may = may_with_roles(self.role_ids, pname) self._permissions[pname] = they_may is_rest_api_call = bool( endpoint) # we can't check if "is None" because it's a LocalProxy if is_rest_api_call and endpoint.track_permissions: # We need to remember this, in oder to later check if the set of required permissions # actually fits the declared permission schema. endpoint.remember_checked_permission(pname) permission_not_declared = ( endpoint.permissions_required is not None and pname not in endpoint.permissions_required) if permission_not_declared: raise PermissionError( f"Required permissions not declared for this endpoint.\n" f"Endpoint: {endpoint}\n" f"Permission: {pname}\n" f"Used permission: {endpoint._used_permissions}\n" f"Declared: {endpoint.permissions_required}\n") return they_may
def may(self, pname: str) -> bool: if pname in self._permissions: return self._permissions[pname] he_may = may_with_roles(self.role_ids, pname) self._permissions[pname] = he_may return he_may