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.
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
"""Authorization for spending a workspace's shared wallet on GPU renders.
|
|
|
|
The render (``POST /render/jobs``) and film shot-render routes accept an optional
|
|
``workspace_id``; when present the wallet hold is taken against that team's
|
|
shared pool. Membership is the spend gate (every member may spend, mirroring the
|
|
reels path's ``_resolve_workspace_pool``), so this helper MUST run before any
|
|
``WalletServiceGateway`` is built with a caller-supplied workspace id.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from loguru import logger
|
|
|
|
from app.models.exception import HttpException
|
|
|
|
|
|
def resolve_spend_workspace(
|
|
session: Any, user_id: str, workspace_id: str | None, request_id: str
|
|
) -> str | None:
|
|
"""Return the validated workspace id, ``None`` for the personal wallet.
|
|
|
|
* blank / missing id -> ``None`` (personal wallet);
|
|
* workspaces layer unavailable -> ``503``;
|
|
* caller not a member (or unknown workspace, which has no membership) ->
|
|
``403`` with no existence leak.
|
|
"""
|
|
normalized = str(workspace_id or "").strip()
|
|
if not normalized:
|
|
return None
|
|
try:
|
|
from app.services import workspaces as ws_service
|
|
except Exception as exc: # pragma: no cover - import guard
|
|
logger.error(f"workspaces service unavailable, request_id: {request_id}: {exc}")
|
|
raise HttpException(
|
|
task_id=request_id, status_code=503,
|
|
message=f"{request_id}: workspaces service is not available",
|
|
) from exc
|
|
if ws_service.get_membership(session, normalized, user_id) is None:
|
|
raise HttpException(
|
|
task_id=request_id, status_code=403,
|
|
message=f"{request_id}: not a member of this workspace",
|
|
)
|
|
return normalized
|