Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
"""Pure team spend-role policy (no DB): which workspace role may do what.
|
|
|
|
Governs three shared-pool capabilities (PRODUCT_ROADMAP.md C — team roles on
|
|
spend):
|
|
|
|
* ``topup`` — add credit to the workspace wallet (owner/admin)
|
|
* ``manage_policy`` — set the workspace budget / BYOK consent / spend role (owner/admin)
|
|
* ``spend`` — draw the shared pool to fund a job (>= the workspace's
|
|
configurable ``min_spend_role``, default ``member``)
|
|
|
|
Kept side-effect free so the matrix is unit-testable; the service resolves the
|
|
caller's role and enforces it.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
# Higher rank = more privilege. Unknown roles rank 0 (no privilege).
|
|
_RANK = {"owner": 3, "admin": 2, "member": 1}
|
|
|
|
TOPUP = "topup"
|
|
MANAGE_POLICY = "manage_policy"
|
|
SPEND = "spend"
|
|
|
|
# Actions that always require an admin-or-owner.
|
|
_ADMIN_ACTIONS = {TOPUP, MANAGE_POLICY}
|
|
|
|
VALID_MIN_SPEND_ROLES = ("owner", "admin", "member")
|
|
|
|
|
|
def rank(role: str | None) -> int:
|
|
return _RANK.get(str(role or "").strip().lower(), 0)
|
|
|
|
|
|
def can(action: str, role: str | None, *, min_spend_role: str = "member") -> bool:
|
|
"""Whether ``role`` may perform ``action`` on the workspace shared pool.
|
|
|
|
``topup`` / ``manage_policy`` require admin+. ``spend`` requires at least the
|
|
workspace's ``min_spend_role`` (an operator can restrict spending to admins).
|
|
"""
|
|
caller = rank(role)
|
|
if caller <= 0:
|
|
return False
|
|
if action in _ADMIN_ACTIONS:
|
|
return caller >= _RANK["admin"]
|
|
if action == SPEND:
|
|
floor = rank(min_spend_role) or _RANK["member"]
|
|
return caller >= floor
|
|
return False
|
|
|
|
|
|
def normalize_min_spend_role(value: str | None) -> str:
|
|
"""Coerce a requested min-spend role to a valid one (default 'member')."""
|
|
role = str(value or "").strip().lower()
|
|
return role if role in VALID_MIN_SPEND_ROLES else "member"
|