Skip to content

API Reference parrot.handlers.studio._base._helpers

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

parrot.handlers.studio._base._helpers

View source

Studio base helpers — slug/path validation and the resolved caller identity.

Attribute STUDIO_SLUG_RE

Attribute SUPERUSER_GROUP

Class StudioUser

Resolved caller identity for a Studio request.

Parameter Type Default Description
user_id str
email str | None None
username str | None None
groups list[str] list()
is_superuser bool False
tenant str | None None
may_author bool True
may_administer bool False

Fields:

Field Type Default Description
user_id str The session's authenticated user id (always a string).
email str | None None Best-effort email from session userinfo, if present.
username str | None None Best-effort username from session userinfo, if present.
groups list[str] field(default_factory=list) Group memberships from session userinfo (empty list if none).
is_superuser bool False Derived admin/superuser flag — bypasses ownership checks in :meth:StudioBaseView._require_owner.
tenant str | None None Resolved tenant (opted-in hosts only).
may_author bool True Host authoring gate (opted-in hosts only).
may_administer bool False Host tenant-admin gate (opted-in hosts only).

Function is_valid_slug

Return True if value matches the Studio slug convention.

is_valid_slug(value: str) -> bool

Parameter Type Default Description
value str Candidate slug (agent name, skill name, draft name, ...).

Returns: bool — True when value matches ^[a-z0-9_-]+$ and is non-empty.

Function resolve_safe_path

Resolve relative under base_dir, rejecting traversal escapes.

Rejects absolute paths, .. segments, and symlink escapes — any path that would resolve outside base_dir once both are fully resolved. Used by file/draft-management Studio endpoints (TASK-2513/ TASK-2514) to keep on-disk writes sandboxed to their intended directory.

resolve_safe_path(base_dir: Path, relative: str) -> Path

Parameter Type Default Description
base_dir Path The directory the resolved path MUST stay inside.
relative str The caller-supplied relative path/filename.

Returns: Path — The resolved, safe Path.

Raises:

  • ValueError — relative is empty, absolute, contains a .. segment, or resolves outside base_dir (including via a symlink escape).

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