Skip to content

API Reference parrot_formdesigner.core.tenant

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.core.tenant

View source

Tenant declaration and authorization shared by the API and UI layers.

This is the single enforcement point for the "client declares its tenant" requirement: a per-route decorator composed into existing route chains, never an aiohttp middleware. A decorator is attached to specific handlers at registration time, so it is structurally incapable of observing unrelated requests.

Public API:

requires_tenant(*, public: bool = False) -> decorator
declared_tenant(request) -> str
enforce_membership_unless_public(request, form, tenant) -> None
assert_body_tenant_matches(body, tenant) -> None

Alias TenantConflictError

Re-exported from parrot_formdesigner.core.tenant_errors.TenantConflictError.

Alias TenantForbiddenError

Re-exported from parrot_formdesigner.core.tenant_errors.TenantForbiddenError.

Alias TenantNotDeclaredError

Re-exported from parrot_formdesigner.core.tenant_errors.TenantNotDeclaredError.

Function assert_body_tenant_matches

Raise 400 when a POST/PUT/PATCH body declares a conflicting tenant.

The body tenant key is an optional cross-check, never required and never authoritative — the URL is authoritative on every verb.

assert_body_tenant_matches(body: dict, tenant: str) -> None

Parameter Type Default Description
body dict The parsed request body.
tenant str The URL-declared (and already validated) tenant.

Raises:

  • TenantConflictError — body["tenant"] is truthy and differs from tenant.

Function declared_tenant

Return the tenant validated by :func:requires_tenant for this request.

declared_tenant(request: web.Request) -> str

Parameter Type Default Description
request web.Request Incoming HTTP request.

Returns: str — The validated tenant slug.

Raises:

  • RuntimeError — request["tenant"] is absent — the route was mounted without :func:requires_tenant. This is a programming error, never a runtime fallback.

Function enforce_membership_unless_public

Close the authorization gap on shared public/private routes.

requires_tenant(public=True) skips membership authorization at the decorator level, because it runs BEFORE the handler resolves the form and therefore cannot know whether this SPECIFIC form_uid is actually public — the same route (GET /forms/{form_uid}, etc.) serves both public and private forms. Call this immediately after the form has been resolved and tenant-scoped (:func:declared_tenant + the registry's tenant-scoped lookup), so a private form on a public-mode route still requires the caller to be a tenant member (or superuser) — exactly as if the route had been tenant="required". A truly public form (form.is_public) is exempt, matching the route's original intent.

enforce_membership_unless_public(request: web.Request, form: Any, tenant: str) -> None

Parameter Type Default Description
request web.Request Incoming HTTP request.
form Any The already-resolved, tenant-scoped form.
tenant str The declared tenant for this request.

Raises:

  • TenantForbiddenError — form.is_public is falsy and the caller is not a member of tenant (and not a superuser).

Attribute logger

Function requires_tenant

Decorator: validate + authorize the URL-declared tenant.

Applied at route-registration time to forms handlers only. Never registered as an aiohttp middleware.

requires_tenant(*, public: bool = False) -> Callable[[_Handler], _Handler]

Parameter Type Default Description
public bool False When True, skip the authorization step (public-form routes, where is_public is the grant), but the tenant is still mandatory.

Returns: Callable[[_Handler], _Handler] — A decorator that wraps a handler with the checks above.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally