feat: add Fleet operations view
This commit is contained in:
1 parent
c6d01df31c
commit
786a1ab910
12 files changed
+1062
-148
No files matched your search
@@ -5,7 +5,7 @@ from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
||||
|
||||
from app.identity import require_permission
|
||||
from app.identity import require_permission, user_has_permission
|
||||
from app.inventory.dependencies import get_inventory_service
|
||||
from app.inventory.exceptions import (
|
||||
DuplicateAssetID,
|
||||
@@ -16,6 +16,7 @@ from app.inventory.models import (
|
||||
InventoryAssetIDHistoryResponse,
|
||||
InventoryCreateRequest,
|
||||
InventoryListMeta,
|
||||
InventoryLocationOptions,
|
||||
InventoryMetadataUpdateRequest,
|
||||
InventoryMinerDetailResponse,
|
||||
InventoryMinerListResponse,
|
||||
@@ -102,21 +103,35 @@ def list_inventory_miners(
|
||||
service: InventoryServiceDependency,
|
||||
current_user: InventoryReadUser,
|
||||
) -> InventoryMinerListResponse:
|
||||
del current_user
|
||||
include_location_details = user_has_permission(current_user, "locations.view")
|
||||
if (filters.site_id or filters.room_id) and not include_location_details:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Location viewing permission is required for location filters",
|
||||
)
|
||||
try:
|
||||
miners = service.search_miners(filters)
|
||||
miners = service.search_miners(
|
||||
filters,
|
||||
include_location_details=include_location_details,
|
||||
)
|
||||
except InventoryValidationError as exc:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=str(exc),
|
||||
) from exc
|
||||
|
||||
location_options = InventoryLocationOptions()
|
||||
if include_location_details:
|
||||
location_options = InventoryLocationOptions.model_validate(
|
||||
service.list_location_filter_options()
|
||||
)
|
||||
return InventoryMinerListResponse(
|
||||
data=miners,
|
||||
meta=InventoryListMeta(
|
||||
limit=filters.limit,
|
||||
offset=filters.offset,
|
||||
returned=len(miners),
|
||||
location_options=location_options,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user