Expand description
scope_guard middleware — Story 1.3 (refonte UX multi-rôle ACP).
Reads the optional scope hint provided by the client (header
X-Scope-AcpId or query parameter ?acp_id=...), resolves the
caller’s effective AcpCaller from JWT, and injects an AcpScope
into the request extensions for downstream handlers to consume.
Refuses the request early (without hitting the handler) if the caller attempts to address an ACP outside their scope.
Design:
- The middleware is a thin
Transformregistered on/buildings//acpsroutes; it consultsAppState::list_acps_use_caseto verify the scope. - For routes that don’t need a forced ACP scope (e.g. admin listing “all”), the middleware is permissive: no scope hint → no restriction, the use-case will fall back to the role-derived default scope.
Error semantics (cf. architecture §6.3) :
- 401
Unauthorizedif no/invalid JWT - 403
AcpNotInScope { acp_id }if scope forged out of perimeter - 400
Validationif header/query are malformed and the role needs an explicit scope id (non-admin)
Structs§
- AcpScope
- Resolved scope context, injected into request extensions by the
ScopeGuardmiddleware. Handlers read it viareq.extensions().get::<AcpScope>()(or via an extractor in a follow-up story). - Scope
Guard ScopeGuardActix middleware factory.- Scope
Guard Middleware
Enums§
- Scope
Guard Error - Errors surfaced by
ScopeGuard. Mapped to HTTP viaResponseError.
Constants§
- SCOPE_
ACP_ HEADER - Header name accepted as a scope hint. Case-insensitive per HTTP RFC.
Functions§
- caller_
from_ role - Map a
UserRoleString + organization_id + user_idtriple to anAcpCaller. Same convention asacp_handlers::caller_from_user— duplicated here to keep the middleware free of handler imports. - extract_
requested_ acp_ id - Extract the requested ACP id from headers or query string.
Header
X-Scope-AcpIdtakes precedence over?acp_id=. ReturnsErr(Validation)if a value is present but malformed. - requires_
repository_ check - Decide whether the caller is allowed to attach the requested scope id, without hitting the DB. Returns:
- verify_
acp_ org_ access - Hotfix #603 — résout
building.acp_id -> acp.organization_idet applique l’isolation multi-tenant sur les GET-by-id (building, budget, expense, meeting, resolution, unit, work_report). - verify_
booking_ org_ access - verify_
building_ org_ access - Isolation multi-tenant sur les ÉCRITURES qui désignent un immeuble par le CORPS de la requête.
- verify_
call_ for_ funds_ org_ access - verify_
challenge_ org_ access - Vérifie le mandat de l’appelant sur l’organisation d’un défi.
- verify_
contribution_ org_ access - Vérifie le mandat de l’appelant sur l’ACP d’un appel de fonds.
- verify_
convocation_ org_ access - Vérifie le mandat de l’appelant sur l’ACP dont relève une convocation.
- verify_
document_ org_ access - Vérifie le mandat de l’appelant sur l’ACP dont relève un document.
- verify_
exchange_ org_ access - Vérifie le mandat de l’appelant sur l’organisation d’un échange local.
- verify_
expense_ org_ access - Vérifie le mandat de l’appelant sur l’ACP dont relève une dépense.
- verify_
meeting_ org_ access - Vérifie le mandat de l’appelant sur l’ACP dont relève une assemblée.
- verify_
notice_ org_ access - Vérifie le mandat de l’appelant sur l’immeuble d’une annonce.
- verify_
owner_ org_ access - Vérifie le mandat de l’appelant sur l’organisation d’un copropriétaire.
- verify_
poll_ org_ access - Vérifie le mandat de l’appelant sur l’organisation d’un sondage.
- verify_
quote_ org_ access - Vérifie le mandat de l’appelant sur l’ACP dont relève un lot.
- verify_
shared_ object_ org_ access - Vérifie le mandat de l’appelant sur l’ACP dont relève un objet partagé.
- verify_
skill_ org_ access - Vérifie le mandat de l’appelant sur l’ACP dont relève une compétence.
- verify_
technical_ spec_ org_ access - Vérifie le mandat de l’appelant sur l’ACP d’une fiche technique.
- verify_
ticket_ org_ access - Vérifie le mandat de l’appelant sur l’organisation d’un ticket.
- verify_
unit_ org_ access