Adding archived flag to augmented parts, fixing migrations so that creation from scratch is successful
This commit is contained in:
1 parent
740dfc97c7
commit
413e9e8381
27 files changed
+695
-126
No files matched your search
+74
-6
@@ -1660,6 +1660,7 @@ async def _default_augmented_parts_table_ctx(db: AsyncSession) -> dict:
|
||||
),
|
||||
"sort": "description",
|
||||
"dir": "asc",
|
||||
"include_archived": False,
|
||||
}
|
||||
|
||||
|
||||
@@ -1668,17 +1669,24 @@ async def augmented_parts_page(
|
||||
request: Request,
|
||||
sort: str = "description",
|
||||
dir: str = "asc",
|
||||
include_archived: bool = False,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user: User = Depends(web_require("augmented_parts:read")),
|
||||
):
|
||||
ctx = await _augmented_part_form_ctx(db)
|
||||
total = await augmented_part_crud.count_filtered(db)
|
||||
total = await augmented_part_crud.count_filtered(
|
||||
db, include_archived=include_archived
|
||||
)
|
||||
ctx["augmented_parts"] = await augmented_part_crud.list_filtered(
|
||||
db, sort=sort, direction=dir, limit=_PAGE_SIZE
|
||||
db,
|
||||
sort=sort,
|
||||
direction=dir,
|
||||
include_archived=include_archived,
|
||||
limit=_PAGE_SIZE,
|
||||
)
|
||||
ctx["pagination"] = _paginate(
|
||||
"/admin/augmented-parts/filter",
|
||||
{"sort": sort, "dir": dir},
|
||||
{"sort": sort, "dir": dir, "include_archived": include_archived},
|
||||
1,
|
||||
_PAGE_SIZE,
|
||||
total,
|
||||
@@ -1686,7 +1694,7 @@ async def augmented_parts_page(
|
||||
)
|
||||
ctx["sort_headers"] = _sort_headers(
|
||||
"/admin/augmented-parts/filter",
|
||||
{},
|
||||
{"include_archived": include_archived},
|
||||
_AUGMENTED_PARTS_SORT_COLUMNS,
|
||||
sort,
|
||||
dir,
|
||||
@@ -1694,6 +1702,7 @@ async def augmented_parts_page(
|
||||
)
|
||||
ctx["sort"] = sort
|
||||
ctx["dir"] = dir
|
||||
ctx["include_archived"] = include_archived
|
||||
ctx["user"] = user
|
||||
return templates.TemplateResponse(request, "admin/augmented_parts.html", ctx)
|
||||
|
||||
@@ -1764,7 +1773,7 @@ async def sync_augmented_parts(
|
||||
resource_type="AugmentedPart",
|
||||
resource_id=None,
|
||||
description=(
|
||||
f"Sync: {result.created} created, {result.deleted} deleted, "
|
||||
f"Sync: {result.created} created, {result.archived} archived, "
|
||||
f"{result.skipped} skipped (no type match)"
|
||||
),
|
||||
)
|
||||
@@ -1772,7 +1781,7 @@ async def sync_augmented_parts(
|
||||
job_id,
|
||||
message=(
|
||||
f"Sync complete: {result.created} created, "
|
||||
f"{result.deleted} deleted"
|
||||
f"{result.archived} archived"
|
||||
+ (
|
||||
f", {result.skipped} skipped (type not recognised)"
|
||||
if result.skipped
|
||||
@@ -1846,6 +1855,7 @@ async def filter_augmented_parts(
|
||||
scope_model_id: str = "",
|
||||
part_type_id: str = "",
|
||||
sub_part_type_id: str = "",
|
||||
include_archived: bool = False,
|
||||
sort: str = "description",
|
||||
dir: str = "asc",
|
||||
page: int = 1,
|
||||
@@ -1866,6 +1876,7 @@ async def filter_augmented_parts(
|
||||
scope_model_id=scope_model_id_int,
|
||||
part_type_id=part_type_id_int,
|
||||
sub_part_type_id=sub_part_type_id_int,
|
||||
include_archived=include_archived,
|
||||
)
|
||||
filter_params = {
|
||||
"description": description,
|
||||
@@ -1874,6 +1885,7 @@ async def filter_augmented_parts(
|
||||
"scope_model_id": scope_model_id,
|
||||
"part_type_id": part_type_id,
|
||||
"sub_part_type_id": sub_part_type_id,
|
||||
"include_archived": include_archived,
|
||||
}
|
||||
pagination = _paginate(
|
||||
"/admin/augmented-parts/filter",
|
||||
@@ -1891,6 +1903,7 @@ async def filter_augmented_parts(
|
||||
scope_model_id=scope_model_id_int,
|
||||
part_type_id=part_type_id_int,
|
||||
sub_part_type_id=sub_part_type_id_int,
|
||||
include_archived=include_archived,
|
||||
sort=sort,
|
||||
direction=dir,
|
||||
skip=pagination["skip"],
|
||||
@@ -1913,6 +1926,7 @@ async def filter_augmented_parts(
|
||||
"sort_headers": sort_headers,
|
||||
"sort": sort,
|
||||
"dir": dir,
|
||||
"include_archived": include_archived,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -2210,6 +2224,60 @@ async def delete_augmented_part(
|
||||
return Response(status_code=status.HTTP_200_OK)
|
||||
|
||||
|
||||
async def _set_augmented_part_archived(
|
||||
request: Request,
|
||||
augmented_part_id: int,
|
||||
archived: bool,
|
||||
db: AsyncSession,
|
||||
actor: User,
|
||||
):
|
||||
ap = await augmented_part_crud.get(db, augmented_part_id)
|
||||
if ap is None:
|
||||
raise HTTPException(status_code=404, detail="Augmented part not found")
|
||||
ap = await augmented_part_crud.set_archived(db, ap, archived)
|
||||
await audit_crud.log(
|
||||
db,
|
||||
actor=actor,
|
||||
action="update",
|
||||
resource_type="AugmentedPart",
|
||||
resource_id=augmented_part_id,
|
||||
description=audit_crud.describe_update(
|
||||
"AugmentedPart", augmented_part_id, {"archived": archived}
|
||||
),
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
request, "admin/_augmented_part_row.html", {"ap": ap}
|
||||
)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/augmented-parts/{augmented_part_id}/archive", response_class=HTMLResponse
|
||||
)
|
||||
async def archive_augmented_part(
|
||||
request: Request,
|
||||
augmented_part_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(web_require("augmented_parts:write")),
|
||||
):
|
||||
return await _set_augmented_part_archived(
|
||||
request, augmented_part_id, True, db, actor
|
||||
)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/augmented-parts/{augmented_part_id}/unarchive", response_class=HTMLResponse
|
||||
)
|
||||
async def unarchive_augmented_part(
|
||||
request: Request,
|
||||
augmented_part_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
actor: User = Depends(web_require("augmented_parts:write")),
|
||||
):
|
||||
return await _set_augmented_part_archived(
|
||||
request, augmented_part_id, False, db, actor
|
||||
)
|
||||
|
||||
|
||||
def _can_write_attachment_points(user: User) -> bool:
|
||||
return user.is_superuser or "attachment_points:write" in user.permissions
|
||||
|
||||
|
||||
Reference in new issue
Block a user