Add Micron asset picker to work package creator
Adds an optional read-only Micron asset catalog lookup for the WP creator, with searchable asset IDs, CSV import, and graceful fallback to manual asset entry when the catalog is absent or unreachable. This includes the backend /api/assets endpoint, SQL Server connector configuration, Docker network changes for outbound access, and UI updates/documentation to make the catalog read-only and clearly distinguish Micron-vetted assets from manual entries.
This commit is contained in:
@@ -25,7 +25,7 @@ from sqlalchemy import select, delete, func
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .db import Base, engine, get_db
|
||||
from . import models, auth, notify
|
||||
from . import models, auth, notify, assets_db
|
||||
|
||||
# Schema management:
|
||||
# • Local dev (SQLite) auto-creates tables for a zero-config run.
|
||||
@@ -1810,6 +1810,29 @@ def list_comments(
|
||||
return [c.to_dict() for c in rows]
|
||||
|
||||
|
||||
# ── Micron asset catalog (read-only lookup) ────────────────────────────────────
|
||||
# Backs the asset picker in the work package creator. This is a *lookup*, not a
|
||||
# resource this app owns: there is no POST, and nothing here ever writes to the
|
||||
# Micron database. It is deliberately not project-scoped by the app's own access
|
||||
# rules — the catalog is reference data, and any signed-in user who can build a
|
||||
# work package needs to be able to name the assets it covers. Authentication is
|
||||
# still required (the auth_gate middleware covers every /api/ path).
|
||||
@app.get("/api/assets")
|
||||
def list_assets(_user: models.User = Depends(auth.get_current_user)):
|
||||
"""The whole catalog, fetched once when the creator loads. Searching happens
|
||||
in the browser — there is no per-keystroke endpoint by design."""
|
||||
if not assets_db.configured():
|
||||
# Not an error — the suite is designed to run without Micron wired up.
|
||||
# The picker reads this and switches to manual entry.
|
||||
return {"configured": False, "assets": [], "detail": assets_db.status()["detail"]}
|
||||
try:
|
||||
return {"configured": True, "assets": assets_db.load()}
|
||||
except assets_db.AssetSourceError as exc:
|
||||
# 503, not 500: the suite is healthy, its upstream lookup is not. The
|
||||
# picker degrades to manual entry rather than blocking the package.
|
||||
raise HTTPException(status_code=503, detail=str(exc))
|
||||
|
||||
|
||||
# ── Local dev convenience: serve the static site from this app ──────────────────
|
||||
# In production NGINX serves html/ and only proxies /api/ here, so this app never
|
||||
# receives "/" requests, and the api Docker image doesn't even include html/ — so
|
||||
|
||||
Reference in New Issue
Block a user