Skip to main content

Module scope_guard

Module scope_guard 

Source
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 Transform registered on /buildings / /acps routes; it consults AppState::list_acps_use_case to 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 Unauthorized if no/invalid JWT
  • 403 AcpNotInScope { acp_id } if scope forged out of perimeter
  • 400 Validation if 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 ScopeGuard middleware. Handlers read it via req.extensions().get::<AcpScope>() (or via an extractor in a follow-up story).
ScopeGuard
ScopeGuard Actix middleware factory.
ScopeGuardMiddleware

Enums§

ScopeGuardError
Errors surfaced by ScopeGuard. Mapped to HTTP via ResponseError.

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_id triple to an AcpCaller. Same convention as acp_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-AcpId takes precedence over ?acp_id=. Returns Err(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_id et 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