Reformatting everything with black
This commit is contained in:
1 parent
7bd07f084a
commit
8185f1f8b3
48 files changed
+1000
-348
No files matched your search
@@ -35,7 +35,10 @@ async def create_attachment_point_name(
|
||||
):
|
||||
apn = await apn_crud.create(db, name=payload.name)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="AttachmentPointName",
|
||||
db,
|
||||
actor=actor,
|
||||
action="create",
|
||||
resource_type="AttachmentPointName",
|
||||
resource_id=apn.id,
|
||||
description=audit_crud.describe_create("AttachmentPointName", apn.id, apn.name),
|
||||
)
|
||||
@@ -67,7 +70,10 @@ async def update_attachment_point_name(
|
||||
changes = payload.model_dump(exclude_unset=True)
|
||||
apn = await apn_crud.update(db, apn, changes)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="AttachmentPointName",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="AttachmentPointName",
|
||||
resource_id=apn.id,
|
||||
description=audit_crud.describe_update("AttachmentPointName", apn.id, changes),
|
||||
)
|
||||
@@ -86,7 +92,10 @@ async def delete_attachment_point_name(
|
||||
name = apn.name
|
||||
await apn_crud.delete(db, apn)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="AttachmentPointName",
|
||||
db,
|
||||
actor=actor,
|
||||
action="delete",
|
||||
resource_type="AttachmentPointName",
|
||||
resource_id=apn_id,
|
||||
description=audit_crud.describe_delete("AttachmentPointName", apn_id, name),
|
||||
)
|
||||
@@ -40,7 +40,9 @@ async def list_attachment_points(
|
||||
return await attachment_point_crud.list_all(db, skip=skip, limit=limit)
|
||||
|
||||
|
||||
@router.post("", response_model=AttachmentPointRead, status_code=status.HTTP_201_CREATED)
|
||||
@router.post(
|
||||
"", response_model=AttachmentPointRead, status_code=status.HTTP_201_CREATED
|
||||
)
|
||||
async def create_attachment_point(
|
||||
payload: AttachmentPointCreate,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
@@ -59,7 +61,10 @@ async def create_attachment_point(
|
||||
)
|
||||
ap = await attachment_point_crud.create(db, **payload.model_dump())
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="AttachmentPoint",
|
||||
db,
|
||||
actor=actor,
|
||||
action="create",
|
||||
resource_type="AttachmentPoint",
|
||||
resource_id=ap.id,
|
||||
description=audit_crud.describe_create(
|
||||
"AttachmentPoint", ap.id, _connection_label(ap)
|
||||
@@ -93,7 +98,10 @@ async def update_attachment_point(
|
||||
changes = payload.model_dump(exclude_unset=True)
|
||||
ap = await attachment_point_crud.update(db, ap, changes)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="AttachmentPoint",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="AttachmentPoint",
|
||||
resource_id=ap.id,
|
||||
description=audit_crud.describe_update("AttachmentPoint", ap.id, changes),
|
||||
)
|
||||
@@ -112,7 +120,12 @@ async def delete_attachment_point(
|
||||
label = _connection_label(ap)
|
||||
await attachment_point_crud.delete(db, ap)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="AttachmentPoint",
|
||||
db,
|
||||
actor=actor,
|
||||
action="delete",
|
||||
resource_type="AttachmentPoint",
|
||||
resource_id=attachment_point_id,
|
||||
description=audit_crud.describe_delete("AttachmentPoint", attachment_point_id, label),
|
||||
description=audit_crud.describe_delete(
|
||||
"AttachmentPoint", attachment_point_id, label
|
||||
),
|
||||
)
|
||||
@@ -44,9 +44,14 @@ async def create_augmented_part(
|
||||
sub_part_type_id=payload.sub_part_type_id,
|
||||
)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="AugmentedPart",
|
||||
db,
|
||||
actor=actor,
|
||||
action="create",
|
||||
resource_type="AugmentedPart",
|
||||
resource_id=ap.id,
|
||||
description=audit_crud.describe_create("AugmentedPart", ap.id, ap.sku or ap.description),
|
||||
description=audit_crud.describe_create(
|
||||
"AugmentedPart", ap.id, ap.sku or ap.description
|
||||
),
|
||||
)
|
||||
return ap
|
||||
|
||||
@@ -58,7 +63,10 @@ async def sync_augmented_parts(
|
||||
):
|
||||
result = await augmented_part_sync.sync(db)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="AugmentedPart",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="AugmentedPart",
|
||||
resource_id=None,
|
||||
description=(
|
||||
f"Sync: {result.created} created, {result.deleted} deleted, "
|
||||
@@ -93,7 +101,10 @@ async def update_augmented_part(
|
||||
changes = payload.model_dump(exclude_unset=True)
|
||||
ap = await augmented_part_crud.update(db, ap, changes)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="AugmentedPart",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="AugmentedPart",
|
||||
resource_id=ap.id,
|
||||
description=audit_crud.describe_update("AugmentedPart", ap.id, changes),
|
||||
)
|
||||
@@ -112,7 +123,12 @@ async def delete_augmented_part(
|
||||
label = ap.sku or ap.description
|
||||
await augmented_part_crud.delete(db, ap)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="AugmentedPart",
|
||||
db,
|
||||
actor=actor,
|
||||
action="delete",
|
||||
resource_type="AugmentedPart",
|
||||
resource_id=augmented_part_id,
|
||||
description=audit_crud.describe_delete("AugmentedPart", augmented_part_id, label),
|
||||
description=audit_crud.describe_delete(
|
||||
"AugmentedPart", augmented_part_id, label
|
||||
),
|
||||
)
|
||||
@@ -25,7 +25,9 @@ async def list_clamp_connections(
|
||||
return await clamp_connection_crud.list_all(db, skip=skip, limit=limit)
|
||||
|
||||
|
||||
@router.post("", response_model=ClampConnectionRead, status_code=status.HTTP_201_CREATED)
|
||||
@router.post(
|
||||
"", response_model=ClampConnectionRead, status_code=status.HTTP_201_CREATED
|
||||
)
|
||||
async def create_clamp_connection(
|
||||
payload: ClampConnectionCreate,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
@@ -39,11 +41,19 @@ async def create_clamp_connection(
|
||||
max_in=payload.max_in,
|
||||
)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="ClampConnection",
|
||||
db,
|
||||
actor=actor,
|
||||
action="create",
|
||||
resource_type="ClampConnection",
|
||||
resource_id=cc.id,
|
||||
description=audit_crud.describe_create(
|
||||
"ClampConnection", cc.id,
|
||||
f"{cc.min_mm}–{cc.max_mm} mm" if cc.min_mm is not None else f"{cc.min_in}–{cc.max_in} in",
|
||||
"ClampConnection",
|
||||
cc.id,
|
||||
(
|
||||
f"{cc.min_mm}–{cc.max_mm} mm"
|
||||
if cc.min_mm is not None
|
||||
else f"{cc.min_in}–{cc.max_in} in"
|
||||
),
|
||||
),
|
||||
)
|
||||
return cc
|
||||
@@ -74,7 +84,10 @@ async def update_clamp_connection(
|
||||
changes = payload.model_dump(exclude_unset=True)
|
||||
cc = await clamp_connection_crud.update(db, cc, changes)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="ClampConnection",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="ClampConnection",
|
||||
resource_id=cc.id,
|
||||
description=audit_crud.describe_update("ClampConnection", cc.id, changes),
|
||||
)
|
||||
@@ -91,12 +104,18 @@ async def delete_clamp_connection(
|
||||
if cc is None:
|
||||
raise HTTPException(status_code=404, detail="Clamp connection not found")
|
||||
label = (
|
||||
f"{cc.min_mm}–{cc.max_mm} mm" if cc.min_mm is not None
|
||||
f"{cc.min_mm}–{cc.max_mm} mm"
|
||||
if cc.min_mm is not None
|
||||
else f"{cc.min_in}–{cc.max_in} in"
|
||||
)
|
||||
await clamp_connection_crud.delete(db, cc)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="ClampConnection",
|
||||
db,
|
||||
actor=actor,
|
||||
action="delete",
|
||||
resource_type="ClampConnection",
|
||||
resource_id=clamp_connection_id,
|
||||
description=audit_crud.describe_delete("ClampConnection", clamp_connection_id, label),
|
||||
description=audit_crud.describe_delete(
|
||||
"ClampConnection", clamp_connection_id, label
|
||||
),
|
||||
)
|
||||
@@ -51,7 +51,11 @@ async def update_config(
|
||||
):
|
||||
current = await config_crud.get(db)
|
||||
# Keep existing password if not provided in the update
|
||||
new_password = payload.password if payload.password is not None else (current.password if current else None)
|
||||
new_password = (
|
||||
payload.password
|
||||
if payload.password is not None
|
||||
else (current.password if current else None)
|
||||
)
|
||||
config = await config_crud.upsert(
|
||||
db,
|
||||
odata_url=payload.odata_url,
|
||||
@@ -59,7 +63,10 @@ async def update_config(
|
||||
password=new_password,
|
||||
)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="ImportedPartConfig",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="ImportedPartConfig",
|
||||
resource_id=1,
|
||||
description="Updated ImportedPart OData configuration",
|
||||
)
|
||||
@@ -81,10 +88,15 @@ async def refresh_imported_parts(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail="OData URL is not configured.",
|
||||
)
|
||||
records = await odata_service.fetch(config.odata_url, config.username, config.password)
|
||||
records = await odata_service.fetch(
|
||||
config.odata_url, config.username, config.password
|
||||
)
|
||||
created, updated = await imported_part_crud.upsert_bulk(db, records)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="ImportedPart",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="ImportedPart",
|
||||
resource_id=None,
|
||||
description=f"OData sync: {created} created, {updated} updated ({len(records)} total records)",
|
||||
)
|
||||
@@ -99,7 +111,9 @@ async def get_imported_part(
|
||||
):
|
||||
part = await imported_part_crud.get(db, inventory_id)
|
||||
if part is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Imported part not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Imported part not found"
|
||||
)
|
||||
return part
|
||||
|
||||
|
||||
@@ -111,10 +125,15 @@ async def delete_imported_part(
|
||||
):
|
||||
part = await imported_part_crud.get(db, inventory_id)
|
||||
if part is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Imported part not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Imported part not found"
|
||||
)
|
||||
await imported_part_crud.delete(db, part)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="ImportedPart",
|
||||
db,
|
||||
actor=actor,
|
||||
action="delete",
|
||||
resource_type="ImportedPart",
|
||||
resource_id=None,
|
||||
description=audit_crud.describe_delete("ImportedPart", 0, inventory_id),
|
||||
)
|
||||
+24
-7
@@ -34,9 +34,14 @@ async def create_iso_thread(
|
||||
depth_mm=payload.depth_mm,
|
||||
)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="IsoThread",
|
||||
db,
|
||||
actor=actor,
|
||||
action="create",
|
||||
resource_type="IsoThread",
|
||||
resource_id=thread.id,
|
||||
description=audit_crud.describe_create("IsoThread", thread.id, f"M{thread.diameter_mm}×{thread.pitch_mm}"),
|
||||
description=audit_crud.describe_create(
|
||||
"IsoThread", thread.id, f"M{thread.diameter_mm}×{thread.pitch_mm}"
|
||||
),
|
||||
)
|
||||
return thread
|
||||
|
||||
@@ -49,7 +54,9 @@ async def get_iso_thread(
|
||||
):
|
||||
thread = await iso_thread_crud.get(db, iso_thread_id)
|
||||
if thread is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="ISO thread not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="ISO thread not found"
|
||||
)
|
||||
return thread
|
||||
|
||||
|
||||
@@ -62,11 +69,16 @@ async def update_iso_thread(
|
||||
):
|
||||
thread = await iso_thread_crud.get(db, iso_thread_id)
|
||||
if thread is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="ISO thread not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="ISO thread not found"
|
||||
)
|
||||
changes = payload.model_dump(exclude_unset=True)
|
||||
thread = await iso_thread_crud.update(db, thread, changes)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="IsoThread",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="IsoThread",
|
||||
resource_id=thread.id,
|
||||
description=audit_crud.describe_update("IsoThread", thread.id, changes),
|
||||
)
|
||||
@@ -81,11 +93,16 @@ async def delete_iso_thread(
|
||||
):
|
||||
thread = await iso_thread_crud.get(db, iso_thread_id)
|
||||
if thread is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="ISO thread not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="ISO thread not found"
|
||||
)
|
||||
name = f"M{thread.diameter_mm}×{thread.pitch_mm}"
|
||||
await iso_thread_crud.delete(db, thread)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="IsoThread",
|
||||
db,
|
||||
actor=actor,
|
||||
action="delete",
|
||||
resource_type="IsoThread",
|
||||
resource_id=iso_thread_id,
|
||||
description=audit_crud.describe_delete("IsoThread", iso_thread_id, name),
|
||||
)
|
||||
@@ -6,7 +6,11 @@ from app.crud import audit as audit_crud
|
||||
from app.crud import manufacturer as manufacturer_crud
|
||||
from app.deps import require_permission
|
||||
from app.models.user import User
|
||||
from app.schemas.manufacturer import ManufacturerCreate, ManufacturerRead, ManufacturerUpdate
|
||||
from app.schemas.manufacturer import (
|
||||
ManufacturerCreate,
|
||||
ManufacturerRead,
|
||||
ManufacturerUpdate,
|
||||
)
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -34,7 +38,10 @@ async def create_manufacturer(
|
||||
logo_url=str(payload.logo_url) if payload.logo_url else None,
|
||||
)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="Manufacturer",
|
||||
db,
|
||||
actor=actor,
|
||||
action="create",
|
||||
resource_type="Manufacturer",
|
||||
resource_id=m.id,
|
||||
description=audit_crud.describe_create("Manufacturer", m.id, m.name),
|
||||
)
|
||||
@@ -49,7 +56,9 @@ async def get_manufacturer(
|
||||
):
|
||||
m = await manufacturer_crud.get(db, manufacturer_id)
|
||||
if m is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Manufacturer not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Manufacturer not found"
|
||||
)
|
||||
return m
|
||||
|
||||
|
||||
@@ -62,7 +71,9 @@ async def update_manufacturer(
|
||||
):
|
||||
m = await manufacturer_crud.get(db, manufacturer_id)
|
||||
if m is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Manufacturer not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Manufacturer not found"
|
||||
)
|
||||
data = payload.model_dump(exclude_unset=True)
|
||||
if "url" in data and data["url"] is not None:
|
||||
data["url"] = str(data["url"])
|
||||
@@ -70,7 +81,10 @@ async def update_manufacturer(
|
||||
data["logo_url"] = str(data["logo_url"])
|
||||
m = await manufacturer_crud.update(db, m, data)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="Manufacturer",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="Manufacturer",
|
||||
resource_id=m.id,
|
||||
description=audit_crud.describe_update("Manufacturer", m.id, data),
|
||||
)
|
||||
@@ -85,11 +99,16 @@ async def delete_manufacturer(
|
||||
):
|
||||
m = await manufacturer_crud.get(db, manufacturer_id)
|
||||
if m is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Manufacturer not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Manufacturer not found"
|
||||
)
|
||||
name = m.name
|
||||
await manufacturer_crud.delete(db, m)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="Manufacturer",
|
||||
db,
|
||||
actor=actor,
|
||||
action="delete",
|
||||
resource_type="Manufacturer",
|
||||
resource_id=manufacturer_id,
|
||||
description=audit_crud.describe_delete("Manufacturer", manufacturer_id, name),
|
||||
)
|
||||
+12
-3
@@ -29,7 +29,10 @@ async def create_part_colour(
|
||||
):
|
||||
pc = await part_colour_crud.create(db, name=payload.name)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="PartColour",
|
||||
db,
|
||||
actor=actor,
|
||||
action="create",
|
||||
resource_type="PartColour",
|
||||
resource_id=pc.id,
|
||||
description=audit_crud.describe_create("PartColour", pc.id, pc.name),
|
||||
)
|
||||
@@ -61,7 +64,10 @@ async def update_part_colour(
|
||||
changes = payload.model_dump(exclude_unset=True)
|
||||
pc = await part_colour_crud.update(db, pc, changes)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="PartColour",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="PartColour",
|
||||
resource_id=pc.id,
|
||||
description=audit_crud.describe_update("PartColour", pc.id, changes),
|
||||
)
|
||||
@@ -80,7 +86,10 @@ async def delete_part_colour(
|
||||
name = pc.name
|
||||
await part_colour_crud.delete(db, pc)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="PartColour",
|
||||
db,
|
||||
actor=actor,
|
||||
action="delete",
|
||||
resource_type="PartColour",
|
||||
resource_id=part_colour_id,
|
||||
description=audit_crud.describe_delete("PartColour", part_colour_id, name),
|
||||
)
|
||||
+21
-6
@@ -29,7 +29,10 @@ async def create_part_type(
|
||||
):
|
||||
pt = await part_type_crud.create(db, name=payload.name)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="PartType",
|
||||
db,
|
||||
actor=actor,
|
||||
action="create",
|
||||
resource_type="PartType",
|
||||
resource_id=pt.id,
|
||||
description=audit_crud.describe_create("PartType", pt.id, pt.name),
|
||||
)
|
||||
@@ -44,7 +47,9 @@ async def get_part_type(
|
||||
):
|
||||
pt = await part_type_crud.get(db, part_type_id)
|
||||
if pt is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Part type not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Part type not found"
|
||||
)
|
||||
return pt
|
||||
|
||||
|
||||
@@ -57,11 +62,16 @@ async def update_part_type(
|
||||
):
|
||||
pt = await part_type_crud.get(db, part_type_id)
|
||||
if pt is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Part type not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Part type not found"
|
||||
)
|
||||
changes = payload.model_dump(exclude_unset=True)
|
||||
pt = await part_type_crud.update(db, pt, changes)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="PartType",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="PartType",
|
||||
resource_id=pt.id,
|
||||
description=audit_crud.describe_update("PartType", pt.id, changes),
|
||||
)
|
||||
@@ -76,11 +86,16 @@ async def delete_part_type(
|
||||
):
|
||||
pt = await part_type_crud.get(db, part_type_id)
|
||||
if pt is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Part type not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Part type not found"
|
||||
)
|
||||
name = pt.name
|
||||
await part_type_crud.delete(db, pt)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="PartType",
|
||||
db,
|
||||
actor=actor,
|
||||
action="delete",
|
||||
resource_type="PartType",
|
||||
resource_id=part_type_id,
|
||||
description=audit_crud.describe_delete("PartType", part_type_id, name),
|
||||
)
|
||||
+12
-3
@@ -36,7 +36,10 @@ async def create_role(
|
||||
permission_ids=payload.permission_ids,
|
||||
)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="Role",
|
||||
db,
|
||||
actor=actor,
|
||||
action="create",
|
||||
resource_type="Role",
|
||||
resource_id=role.id,
|
||||
description=audit_crud.describe_create("Role", role.id, role.name),
|
||||
)
|
||||
@@ -80,7 +83,10 @@ async def update_role(
|
||||
changes = payload.model_dump(exclude_unset=True)
|
||||
role = await role_crud.update(db, role, changes)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="Role",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="Role",
|
||||
resource_id=role.id,
|
||||
description=audit_crud.describe_update("Role", role.id, changes),
|
||||
)
|
||||
@@ -101,7 +107,10 @@ async def delete_role(
|
||||
name = role.name
|
||||
await role_crud.delete(db, role)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="Role",
|
||||
db,
|
||||
actor=actor,
|
||||
action="delete",
|
||||
resource_type="Role",
|
||||
resource_id=role_id,
|
||||
description=audit_crud.describe_delete("Role", role_id, name),
|
||||
)
|
||||
+57
-13
@@ -1,22 +1,66 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app.api import attachment_point_names, attachment_points, audit_log, augmented_parts, auth, clamp_connections, imported_parts, iso_threads, manufacturers, part_colours, part_types, roles, scope_models, static_connections, sub_part_types, unc_threads, users
|
||||
from app.api import (
|
||||
attachment_point_names,
|
||||
attachment_points,
|
||||
audit_log,
|
||||
augmented_parts,
|
||||
auth,
|
||||
clamp_connections,
|
||||
imported_parts,
|
||||
iso_threads,
|
||||
manufacturers,
|
||||
part_colours,
|
||||
part_types,
|
||||
roles,
|
||||
scope_models,
|
||||
static_connections,
|
||||
sub_part_types,
|
||||
unc_threads,
|
||||
users,
|
||||
)
|
||||
|
||||
api_router = APIRouter()
|
||||
api_router.include_router(auth.router, prefix="/auth", tags=["auth"])
|
||||
api_router.include_router(users.router, prefix="/users", tags=["users"])
|
||||
api_router.include_router(roles.router, prefix="/roles", tags=["roles"])
|
||||
api_router.include_router(iso_threads.router, prefix="/iso-threads", tags=["iso-threads"])
|
||||
api_router.include_router(unc_threads.router, prefix="/unc-threads", tags=["unc-threads"])
|
||||
api_router.include_router(manufacturers.router, prefix="/manufacturers", tags=["manufacturers"])
|
||||
api_router.include_router(scope_models.router, prefix="/scope-models", tags=["scope-models"])
|
||||
api_router.include_router(part_colours.router, prefix="/part-colours", tags=["part-colours"])
|
||||
api_router.include_router(
|
||||
iso_threads.router, prefix="/iso-threads", tags=["iso-threads"]
|
||||
)
|
||||
api_router.include_router(
|
||||
unc_threads.router, prefix="/unc-threads", tags=["unc-threads"]
|
||||
)
|
||||
api_router.include_router(
|
||||
manufacturers.router, prefix="/manufacturers", tags=["manufacturers"]
|
||||
)
|
||||
api_router.include_router(
|
||||
scope_models.router, prefix="/scope-models", tags=["scope-models"]
|
||||
)
|
||||
api_router.include_router(
|
||||
part_colours.router, prefix="/part-colours", tags=["part-colours"]
|
||||
)
|
||||
api_router.include_router(part_types.router, prefix="/part-types", tags=["part-types"])
|
||||
api_router.include_router(sub_part_types.router, prefix="/sub-part-types", tags=["sub-part-types"])
|
||||
api_router.include_router(static_connections.router, prefix="/static-connections", tags=["static-connections"])
|
||||
api_router.include_router(clamp_connections.router, prefix="/clamp-connections", tags=["clamp-connections"])
|
||||
api_router.include_router(attachment_point_names.router, prefix="/attachment-point-names", tags=["attachment-point-names"])
|
||||
api_router.include_router(attachment_points.router, prefix="/attachment-points", tags=["attachment-points"])
|
||||
api_router.include_router(imported_parts.router, prefix="/imported-parts", tags=["imported-parts"])
|
||||
api_router.include_router(augmented_parts.router, prefix="/augmented-parts", tags=["augmented-parts"])
|
||||
api_router.include_router(
|
||||
sub_part_types.router, prefix="/sub-part-types", tags=["sub-part-types"]
|
||||
)
|
||||
api_router.include_router(
|
||||
static_connections.router, prefix="/static-connections", tags=["static-connections"]
|
||||
)
|
||||
api_router.include_router(
|
||||
clamp_connections.router, prefix="/clamp-connections", tags=["clamp-connections"]
|
||||
)
|
||||
api_router.include_router(
|
||||
attachment_point_names.router,
|
||||
prefix="/attachment-point-names",
|
||||
tags=["attachment-point-names"],
|
||||
)
|
||||
api_router.include_router(
|
||||
attachment_points.router, prefix="/attachment-points", tags=["attachment-points"]
|
||||
)
|
||||
api_router.include_router(
|
||||
imported_parts.router, prefix="/imported-parts", tags=["imported-parts"]
|
||||
)
|
||||
api_router.include_router(
|
||||
augmented_parts.router, prefix="/augmented-parts", tags=["augmented-parts"]
|
||||
)
|
||||
api_router.include_router(audit_log.router, prefix="/audit-log", tags=["audit-log"])
|
||||
+21
-6
@@ -34,7 +34,10 @@ async def create_scope_model(
|
||||
url=str(payload.url) if payload.url else None,
|
||||
)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="ScopeModel",
|
||||
db,
|
||||
actor=actor,
|
||||
action="create",
|
||||
resource_type="ScopeModel",
|
||||
resource_id=sm.id,
|
||||
description=audit_crud.describe_create("ScopeModel", sm.id, sm.name),
|
||||
)
|
||||
@@ -49,7 +52,9 @@ async def get_scope_model(
|
||||
):
|
||||
sm = await scope_model_crud.get(db, scope_model_id)
|
||||
if sm is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Scope model not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Scope model not found"
|
||||
)
|
||||
return sm
|
||||
|
||||
|
||||
@@ -62,13 +67,18 @@ async def update_scope_model(
|
||||
):
|
||||
sm = await scope_model_crud.get(db, scope_model_id)
|
||||
if sm is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Scope model not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Scope model not found"
|
||||
)
|
||||
data = payload.model_dump(exclude_unset=True)
|
||||
if "url" in data and data["url"] is not None:
|
||||
data["url"] = str(data["url"])
|
||||
sm = await scope_model_crud.update(db, sm, data)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="ScopeModel",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="ScopeModel",
|
||||
resource_id=sm.id,
|
||||
description=audit_crud.describe_update("ScopeModel", sm.id, data),
|
||||
)
|
||||
@@ -83,11 +93,16 @@ async def delete_scope_model(
|
||||
):
|
||||
sm = await scope_model_crud.get(db, scope_model_id)
|
||||
if sm is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Scope model not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Scope model not found"
|
||||
)
|
||||
name = sm.name
|
||||
await scope_model_crud.delete(db, sm)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="ScopeModel",
|
||||
db,
|
||||
actor=actor,
|
||||
action="delete",
|
||||
resource_type="ScopeModel",
|
||||
resource_id=scope_model_id,
|
||||
description=audit_crud.describe_delete("ScopeModel", scope_model_id, name),
|
||||
)
|
||||
@@ -25,17 +25,26 @@ async def list_static_connections(
|
||||
return await static_connection_crud.list_all(db, skip=skip, limit=limit)
|
||||
|
||||
|
||||
@router.post("", response_model=StaticConnectionRead, status_code=status.HTTP_201_CREATED)
|
||||
@router.post(
|
||||
"", response_model=StaticConnectionRead, status_code=status.HTTP_201_CREATED
|
||||
)
|
||||
async def create_static_connection(
|
||||
payload: StaticConnectionCreate,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(require_permission("static_connections:write")),
|
||||
):
|
||||
sc = await static_connection_crud.create(db, od_mm=payload.od_mm, od_in=payload.od_in)
|
||||
sc = await static_connection_crud.create(
|
||||
db, od_mm=payload.od_mm, od_in=payload.od_in
|
||||
)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="StaticConnection",
|
||||
db,
|
||||
actor=actor,
|
||||
action="create",
|
||||
resource_type="StaticConnection",
|
||||
resource_id=sc.id,
|
||||
description=audit_crud.describe_create("StaticConnection", sc.id, f"{sc.od_mm} mm"),
|
||||
description=audit_crud.describe_create(
|
||||
"StaticConnection", sc.id, f"{sc.od_mm} mm"
|
||||
),
|
||||
)
|
||||
return sc
|
||||
|
||||
@@ -65,7 +74,10 @@ async def update_static_connection(
|
||||
changes = payload.model_dump(exclude_unset=True)
|
||||
sc = await static_connection_crud.update(db, sc, changes)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="StaticConnection",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="StaticConnection",
|
||||
resource_id=sc.id,
|
||||
description=audit_crud.describe_update("StaticConnection", sc.id, changes),
|
||||
)
|
||||
@@ -84,7 +96,10 @@ async def delete_static_connection(
|
||||
od_mm = sc.od_mm
|
||||
await static_connection_crud.delete(db, sc)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="StaticConnection",
|
||||
db,
|
||||
actor=actor,
|
||||
action="delete",
|
||||
resource_type="StaticConnection",
|
||||
resource_id=static_connection_id,
|
||||
description=audit_crud.describe_delete(
|
||||
"StaticConnection", static_connection_id, f"{od_mm} mm"
|
||||
|
||||
@@ -6,7 +6,11 @@ from app.crud import audit as audit_crud
|
||||
from app.crud import sub_part_type as sub_part_type_crud
|
||||
from app.deps import require_permission
|
||||
from app.models.user import User
|
||||
from app.schemas.sub_part_type import SubPartTypeCreate, SubPartTypeRead, SubPartTypeUpdate
|
||||
from app.schemas.sub_part_type import (
|
||||
SubPartTypeCreate,
|
||||
SubPartTypeRead,
|
||||
SubPartTypeUpdate,
|
||||
)
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -31,7 +35,10 @@ async def create_sub_part_type(
|
||||
db, name=payload.name, part_type_id=payload.part_type_id
|
||||
)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="SubPartType",
|
||||
db,
|
||||
actor=actor,
|
||||
action="create",
|
||||
resource_type="SubPartType",
|
||||
resource_id=spt.id,
|
||||
description=audit_crud.describe_create("SubPartType", spt.id, spt.name),
|
||||
)
|
||||
@@ -46,7 +53,9 @@ async def get_sub_part_type(
|
||||
):
|
||||
spt = await sub_part_type_crud.get(db, sub_part_type_id)
|
||||
if spt is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Sub part type not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Sub part type not found"
|
||||
)
|
||||
return spt
|
||||
|
||||
|
||||
@@ -59,11 +68,16 @@ async def update_sub_part_type(
|
||||
):
|
||||
spt = await sub_part_type_crud.get(db, sub_part_type_id)
|
||||
if spt is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Sub part type not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Sub part type not found"
|
||||
)
|
||||
changes = payload.model_dump(exclude_unset=True)
|
||||
spt = await sub_part_type_crud.update(db, spt, changes)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="SubPartType",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="SubPartType",
|
||||
resource_id=spt.id,
|
||||
description=audit_crud.describe_update("SubPartType", spt.id, changes),
|
||||
)
|
||||
@@ -78,11 +92,16 @@ async def delete_sub_part_type(
|
||||
):
|
||||
spt = await sub_part_type_crud.get(db, sub_part_type_id)
|
||||
if spt is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Sub part type not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Sub part type not found"
|
||||
)
|
||||
name = spt.name
|
||||
await sub_part_type_crud.delete(db, spt)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="SubPartType",
|
||||
db,
|
||||
actor=actor,
|
||||
action="delete",
|
||||
resource_type="SubPartType",
|
||||
resource_id=sub_part_type_id,
|
||||
description=audit_crud.describe_delete("SubPartType", sub_part_type_id, name),
|
||||
)
|
||||
+26
-7
@@ -35,9 +35,16 @@ async def create_unc_thread(
|
||||
depth_in=payload.depth_in,
|
||||
)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="UncThread",
|
||||
db,
|
||||
actor=actor,
|
||||
action="create",
|
||||
resource_type="UncThread",
|
||||
resource_id=thread.id,
|
||||
description=audit_crud.describe_create("UncThread", thread.id, f"{thread.diameter_fraction}-{thread.tpi} {thread.series.value}"),
|
||||
description=audit_crud.describe_create(
|
||||
"UncThread",
|
||||
thread.id,
|
||||
f"{thread.diameter_fraction}-{thread.tpi} {thread.series.value}",
|
||||
),
|
||||
)
|
||||
return thread
|
||||
|
||||
@@ -50,7 +57,9 @@ async def get_unc_thread(
|
||||
):
|
||||
thread = await unc_thread_crud.get(db, unc_thread_id)
|
||||
if thread is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="UNC thread not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="UNC thread not found"
|
||||
)
|
||||
return thread
|
||||
|
||||
|
||||
@@ -63,11 +72,16 @@ async def update_unc_thread(
|
||||
):
|
||||
thread = await unc_thread_crud.get(db, unc_thread_id)
|
||||
if thread is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="UNC thread not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="UNC thread not found"
|
||||
)
|
||||
changes = payload.model_dump(exclude_unset=True)
|
||||
thread = await unc_thread_crud.update(db, thread, changes)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="UncThread",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="UncThread",
|
||||
resource_id=thread.id,
|
||||
description=audit_crud.describe_update("UncThread", thread.id, changes),
|
||||
)
|
||||
@@ -82,11 +96,16 @@ async def delete_unc_thread(
|
||||
):
|
||||
thread = await unc_thread_crud.get(db, unc_thread_id)
|
||||
if thread is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="UNC thread not found")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="UNC thread not found"
|
||||
)
|
||||
name = f"{thread.diameter_fraction}-{thread.tpi} {thread.series.value}"
|
||||
await unc_thread_crud.delete(db, thread)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="UncThread",
|
||||
db,
|
||||
actor=actor,
|
||||
action="delete",
|
||||
resource_type="UncThread",
|
||||
resource_id=unc_thread_id,
|
||||
description=audit_crud.describe_delete("UncThread", unc_thread_id, name),
|
||||
)
|
||||
+12
-3
@@ -45,7 +45,10 @@ async def create_user(
|
||||
role_ids=payload.role_ids,
|
||||
)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="create", resource_type="User",
|
||||
db,
|
||||
actor=actor,
|
||||
action="create",
|
||||
resource_type="User",
|
||||
resource_id=created.id,
|
||||
description=audit_crud.describe_create("User", created.id, created.email),
|
||||
)
|
||||
@@ -81,7 +84,10 @@ async def update_user(
|
||||
changes = payload.model_dump(exclude_unset=True)
|
||||
target = await user_crud.update(db, target, changes)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="update", resource_type="User",
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="User",
|
||||
resource_id=user_id,
|
||||
description=audit_crud.describe_update("User", user_id, changes),
|
||||
)
|
||||
@@ -102,7 +108,10 @@ async def delete_user(
|
||||
email = target.email
|
||||
await user_crud.delete(db, target)
|
||||
await audit_crud.log(
|
||||
db, actor=actor, action="delete", resource_type="User",
|
||||
db,
|
||||
actor=actor,
|
||||
action="delete",
|
||||
resource_type="User",
|
||||
resource_id=user_id,
|
||||
description=audit_crud.describe_delete("User", user_id, email),
|
||||
)
|
||||
Reference in new issue
Block a user