Phase 2: core domain, policy engine, packet API, Clerical screen
Migration 0003: projects, aliases, renumbers, units, packets and every child table, change orders, assets, documents, ITPs, station limits, department weld flag. Policy package: Principal, PacketState, Action rules, custody, preconditions, CO hold, order of checks, can/blocked/holder on reads. docs/POLICY.md with the tightenings table for Seth. Write pipeline: FOR UPDATE, CAS on status and dept, If-Match row versions, server-assigned numbers, field CAS, version bump, packet log, audit, NOTIFY, signatures, IT reasons, filed lock and HMAC seal. API: /api/packets (header, transitions, work orders, pages, docs, move, remove, BOM, shorts, welds, heat tags, heat table, stage, checklist, clock, warehouse stage, Q.C., change orders, log, seal), /api/projects, /api/units, /api/assets, /_blob. Frontend: Clerical home, projects and units, packet page with pdf.js and QR codes, hand draft, heat map, send to warehouse, department or Q.C. Tests: policy matrix, API, concurrency, schema, projects; Playwright Clerical draft scenario. Verified on docker-1 with the CI stack and the Samba DC. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
"""Units: the picker list, read, field edits, renumber (new lot) and soft delete.
|
||||
|
||||
New units are made through POST /api/projects/{id}/units. Same access rules as projects: reads need any
|
||||
session; edits need Clerical; renumber and delete need clerical_supervisor; admin with an it_reason.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from ..domain import projects as dom
|
||||
from .deps import Db, Principal, current_principal, get_db
|
||||
from .projects import TEXT, FieldCas, ReasonBody, authorize
|
||||
|
||||
router = APIRouter(prefix="/api/units", tags=["units"])
|
||||
|
||||
|
||||
class RenumberUnit(BaseModel):
|
||||
lot: str = Field(max_length=40)
|
||||
reason: str | None = Field(None, max_length=TEXT)
|
||||
it_reason: str | None = Field(None, max_length=TEXT)
|
||||
|
||||
|
||||
@router.get("")
|
||||
def list_units(
|
||||
p: Principal = Depends(current_principal), # noqa: B008
|
||||
d: Db = Depends(get_db), # noqa: B008
|
||||
project_id: int | None = Query(None),
|
||||
q: str = Query("", max_length=200),
|
||||
status: str = Query("active", max_length=20),
|
||||
) -> list[dict[str, Any]]:
|
||||
return dom.list_units(d.conn, project_id=project_id, q=q, status=status)
|
||||
|
||||
|
||||
@router.get("/{unit_id}")
|
||||
def unit_detail(
|
||||
unit_id: int,
|
||||
p: Principal = Depends(current_principal), # noqa: B008
|
||||
d: Db = Depends(get_db), # noqa: B008
|
||||
) -> dict[str, Any]:
|
||||
return dom.unit_detail(d.conn, unit_id)
|
||||
|
||||
|
||||
@router.patch("/{unit_id}")
|
||||
def update_unit(
|
||||
unit_id: int,
|
||||
body: FieldCas,
|
||||
p: Principal = Depends(current_principal), # noqa: B008
|
||||
d: Db = Depends(get_db), # noqa: B008
|
||||
) -> dict[str, Any]:
|
||||
who = authorize(p, supervisor=False, it_reason=body.it_reason)
|
||||
return dom.update_unit(d.conn, who, unit_id, body.values, body.base)
|
||||
|
||||
|
||||
@router.post("/{unit_id}/renumber")
|
||||
def renumber_unit(
|
||||
unit_id: int,
|
||||
body: RenumberUnit,
|
||||
p: Principal = Depends(current_principal), # noqa: B008
|
||||
d: Db = Depends(get_db), # noqa: B008
|
||||
) -> dict[str, Any]:
|
||||
who = authorize(p, supervisor=True, it_reason=body.it_reason)
|
||||
return dom.renumber_unit(d.conn, who, unit_id, body.lot, body.reason)
|
||||
|
||||
|
||||
@router.delete("/{unit_id}")
|
||||
def remove_unit(
|
||||
unit_id: int,
|
||||
body: ReasonBody,
|
||||
p: Principal = Depends(current_principal), # noqa: B008
|
||||
d: Db = Depends(get_db), # noqa: B008
|
||||
) -> dict[str, Any]:
|
||||
who = authorize(p, supervisor=True, it_reason=body.it_reason)
|
||||
return dom.remove_unit(d.conn, who, unit_id, body.reason)
|
||||
Reference in New Issue
Block a user