Files
Atrium/backend/app/enums.py
T

114 lines
4.1 KiB
Python

"""Enum labels: the shared ones re-exported from dredd-core, Atrium's own below the divider.
`NodeRole` and `PrincipalType` are declared in **dredd-core** and back the org-tree columns core
owns; `SessionKind` and `TokenScope` describe credentials core's auth service issues. They are
re-exported here so every call site keeps importing `from ..enums import NodeRole` and nothing
downstream cares where the class is declared. (`ReviewPolicy` and `EncryptionMode` are also in
`dredd_core.enums` if this app grows a use for them — import them the same way.)
The `.value` strings are the canonical DB enum labels. `NodeRole` is ordered
(viewer < editor < approver < manager); that ordering is applied by core's authz resolver, so
compare roles through `services.authz`, never by string.
Native enum *types* are not created here: migration 0001 calls `create_enum_types(conn)` before
`Base.metadata.create_all(...)`, which builds core's types and this app's own from the model
metadata (the columns use `create_type=False`, so the types must exist first).
"""
from __future__ import annotations
from enum import StrEnum
from dredd_core.enums import NodeRole, PrincipalType, SessionKind, TokenScope
# NOTE: SessionKind and TokenScope back plain Text columns, NOT native PG enums — core's choice,
# and a deliberate one: a credential vocabulary that grows (a new scope, a new kind) then needs no
# type surgery on a live database.
# ── Atrium's own ────────────────────────────────────────────────────────
# `node.kind` is a plain text column: the set of kinds is this app's to define, which is why there
# is no `NodeKind` in dredd-core. Keep this StrEnum as the single place they are named, and keep
# `services/nodes.py` (CONTAINER_KINDS) in step with it.
class NodeKind(StrEnum):
"""The organizational tree. In Atrium it holds organizational units only — modules are catalog
rows, not nodes, so there is no leaf kind."""
workspace = "workspace" # top level — the organisation; a permission boundary
group = "group" # a department
folder = "folder" # a team or any grouping
# The marketplace vocabularies back plain Text columns guarded by CHECK constraints built from these
# very classes (see `models/marketplace.py`), not native PG enums: a status that grows ("deprecated")
# is then a constraint swap in a revision rather than enum-type surgery on a live database.
class ModuleStatus(StrEnum):
"""Where the module is in its life — the catalog's claim about the product."""
live = "live"
beta = "beta"
coming_soon = "coming_soon"
class Availability(StrEnum):
"""Who the administrator offers the module to — the instance's decision, separate from status."""
everyone = "everyone"
selected = "selected" # assigned organizational units and users only
off = "off"
class AccessRequestStatus(StrEnum):
pending = "pending"
approved = "approved"
declined = "declined"
# Skills and agents (`models/skills.py`): Text + CHECK for the same reason as the marketplace ones.
class SkillScope(StrEnum):
personal = "personal" # the owner's own; nobody else sees it, an administrator included
firm = "firm" # published to everybody on the instance
class CatalogStatus(StrEnum):
"""Shared by skills and agents. No `draft`: a draft is simply a personal skill."""
active = "active"
archived = "archived"
class SkillOrigin(StrEnum):
authored = "authored"
imported = "imported"
bundled = "bundled"
class AgentKind(StrEnum):
assistant = "assistant"
class PublishKind(StrEnum):
skill = "skill"
agent = "agent"
class PublishRequestStatus(StrEnum):
pending = "pending"
approved = "approved"
declined = "declined"
__all__ = [
# from dredd-core, unchanged
"NodeRole",
"PrincipalType",
"SessionKind",
"TokenScope",
# this app's own
"NodeKind",
"ModuleStatus",
"Availability",
"AccessRequestStatus",
"SkillScope",
"CatalogStatus",
"SkillOrigin",
"AgentKind",
"PublishKind",
"PublishRequestStatus",
]