Files
govoplan-reporting/src/govoplan_reporting/backend/acl.py
T

30 lines
984 B
Python

from __future__ import annotations
from govoplan_core.auth import has_scope
from govoplan_core.core.modules import AccessDecision
class ReportingScopeAclProvider:
def __init__(self, resource_type: str) -> None:
self.resource_type = resource_type
def can_read(self, principal: object, resource_id: str) -> bool:
del resource_id
return has_scope(principal, "reporting:definition:read")
def can_write(self, principal: object, resource_id: str) -> bool:
del resource_id
return has_scope(principal, "reporting:definition:write")
def explain(self, principal: object, resource_id: str) -> AccessDecision:
del resource_id
allowed = self.can_read(principal, "")
return AccessDecision(
allowed=allowed,
reason=None if allowed else "Missing scope: reporting:definition:read",
requirements=("reporting:definition:read",),
)
__all__ = ["ReportingScopeAclProvider"]