style: Updated the overall UI of the provisining pages
This commit is contained in:
@@ -46,6 +46,7 @@ def _doc_to_inventory_item(doc) -> DeviceInventoryItem:
|
||||
created_at=created_str,
|
||||
owner=data.get("owner"),
|
||||
assigned_to=data.get("assigned_to"),
|
||||
device_name=data.get("device_name") or None,
|
||||
)
|
||||
|
||||
|
||||
@@ -217,6 +218,47 @@ def get_stats() -> ManufacturingStats:
|
||||
return ManufacturingStats(counts=counts, recent_activity=recent)
|
||||
|
||||
|
||||
PROTECTED_STATUSES = {"sold", "claimed"}
|
||||
|
||||
|
||||
def delete_device(sn: str, force: bool = False) -> None:
|
||||
"""Delete a device by serial number.
|
||||
|
||||
Raises PermissionError if the device is sold/claimed and force is not set.
|
||||
The frontend uses force=True only after the user confirms by typing the SN.
|
||||
"""
|
||||
db = get_db()
|
||||
docs = list(db.collection(COLLECTION).where("serial_number", "==", sn).limit(1).stream())
|
||||
if not docs:
|
||||
raise NotFoundError("Device")
|
||||
|
||||
data = docs[0].to_dict() or {}
|
||||
status = data.get("mfg_status", "manufactured")
|
||||
|
||||
if status in PROTECTED_STATUSES and not force:
|
||||
raise PermissionError(
|
||||
f"Device {sn} has status '{status}' and cannot be deleted without explicit confirmation."
|
||||
)
|
||||
|
||||
docs[0].reference.delete()
|
||||
|
||||
|
||||
def delete_unprovisioned_devices() -> list[str]:
|
||||
"""Delete all devices with status 'manufactured' (never flashed/provisioned).
|
||||
|
||||
Returns the list of deleted serial numbers.
|
||||
"""
|
||||
db = get_db()
|
||||
docs = list(db.collection(COLLECTION).where("mfg_status", "==", "manufactured").stream())
|
||||
deleted = []
|
||||
for doc in docs:
|
||||
data = doc.to_dict() or {}
|
||||
sn = data.get("serial_number", "")
|
||||
doc.reference.delete()
|
||||
deleted.append(sn)
|
||||
return deleted
|
||||
|
||||
|
||||
def get_firmware_url(sn: str) -> str:
|
||||
"""Return the FastAPI download URL for the latest stable firmware for this device's hw_type."""
|
||||
from firmware.service import get_latest
|
||||
|
||||
Reference in New Issue
Block a user