Add approval template revision administration
This commit is contained in:
@@ -173,6 +173,80 @@ def api_publish_template(
|
||||
raise _error(exc) from exc
|
||||
|
||||
|
||||
@router.get("/templates/{template_id}", response_model=dict[str, Any])
|
||||
def api_get_template(
|
||||
template_id: str,
|
||||
revision: int | None = Query(default=None, ge=1),
|
||||
session: Session = Depends(get_session),
|
||||
principal: ApiPrincipal = Depends(get_api_principal),
|
||||
) -> dict[str, Any]:
|
||||
from govoplan_approvals.backend.manifest import READ_SCOPE
|
||||
|
||||
_require(principal, READ_SCOPE)
|
||||
item = SqlApprovalRequests().get_template(
|
||||
session,
|
||||
principal,
|
||||
template_id=template_id,
|
||||
revision=revision,
|
||||
)
|
||||
if item is None:
|
||||
raise HTTPException(status_code=404, detail="Approval template not found")
|
||||
return dict(item)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/templates/{template_id}/history",
|
||||
response_model=list[dict[str, Any]],
|
||||
)
|
||||
def api_get_template_history(
|
||||
template_id: str,
|
||||
session: Session = Depends(get_session),
|
||||
principal: ApiPrincipal = Depends(get_api_principal),
|
||||
) -> list[dict[str, Any]]:
|
||||
from govoplan_approvals.backend.manifest import READ_SCOPE
|
||||
|
||||
_require(principal, READ_SCOPE)
|
||||
try:
|
||||
return [
|
||||
dict(item)
|
||||
for item in SqlApprovalRequests().template_history(
|
||||
session,
|
||||
principal,
|
||||
template_id=template_id,
|
||||
)
|
||||
]
|
||||
except (ApprovalStoreError, LookupError) as exc:
|
||||
raise _error(exc) from exc
|
||||
|
||||
|
||||
@router.get(
|
||||
"/templates/{template_id}/compare",
|
||||
response_model=dict[str, Any],
|
||||
)
|
||||
def api_compare_template_revisions(
|
||||
template_id: str,
|
||||
from_revision: int = Query(ge=1),
|
||||
to_revision: int = Query(ge=1),
|
||||
session: Session = Depends(get_session),
|
||||
principal: ApiPrincipal = Depends(get_api_principal),
|
||||
) -> dict[str, Any]:
|
||||
from govoplan_approvals.backend.manifest import READ_SCOPE
|
||||
|
||||
_require(principal, READ_SCOPE)
|
||||
try:
|
||||
return dict(
|
||||
SqlApprovalRequests().compare_template_revisions(
|
||||
session,
|
||||
principal,
|
||||
template_id=template_id,
|
||||
from_revision=from_revision,
|
||||
to_revision=to_revision,
|
||||
)
|
||||
)
|
||||
except (ApprovalStoreError, LookupError) as exc:
|
||||
raise _error(exc) from exc
|
||||
|
||||
|
||||
@router.get("/{request_id}", response_model=dict[str, Any])
|
||||
def api_get_request(
|
||||
request_id: str,
|
||||
|
||||
Reference in New Issue
Block a user