Expose the current execution stop to authorized web sessions
This commit is contained in:
@@ -33,7 +33,34 @@ pub fn routes(r: Router<crate::State>) -> Router<crate::State> {
|
|||||||
"/api/v1/tenants/{tenant}/operation-plans/{plan}/revocation",
|
"/api/v1/tenants/{tenant}/operation-plans/{plan}/revocation",
|
||||||
post(revoke_plan),
|
post(revoke_plan),
|
||||||
)
|
)
|
||||||
.route("/api/v1/tenants/{tenant}/execution-stop", post(stop))
|
.route(
|
||||||
|
"/api/v1/tenants/{tenant}/execution-stop",
|
||||||
|
post(stop).get(stop_status),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
async fn stop_status(
|
||||||
|
State(s): State<crate::State>,
|
||||||
|
h: HeaderMap,
|
||||||
|
Path(tenant): Path<Uuid>,
|
||||||
|
) -> Result<Json<Value>, Error> {
|
||||||
|
let principal = crate::jobs::principal(&s, &h, false).await?;
|
||||||
|
crate::jobs::scope(&principal, tenant, false)?;
|
||||||
|
if principal.session_hash.is_none() {
|
||||||
|
return Err(Error(StatusCode::FORBIDDEN, "INTERACTIVE_AUTH_REQUIRED"));
|
||||||
|
}
|
||||||
|
let mut tx = rmm_persistence::tenant_tx(&s.pool, tenant).await?;
|
||||||
|
if !principal.permits_scope("operations:read")
|
||||||
|
|| !crate::permissions::allowed(&mut tx, &principal.name, "operations:read").await?
|
||||||
|
{
|
||||||
|
crate::permissions::require_principal(&mut tx, &principal, "tenant:stop").await?;
|
||||||
|
}
|
||||||
|
let stopped: bool = sqlx::query_scalar("SELECT changes_stopped FROM tenants WHERE tenant_id=$1")
|
||||||
|
.bind(tenant)
|
||||||
|
.fetch_optional(&mut *tx)
|
||||||
|
.await?
|
||||||
|
.ok_or(Error(StatusCode::NOT_FOUND, "NOT_FOUND"))?;
|
||||||
|
tx.commit().await?;
|
||||||
|
Ok(Json(json!({"tenant_id":tenant,"changes_stopped":stopped})))
|
||||||
}
|
}
|
||||||
async fn context<'a>(
|
async fn context<'a>(
|
||||||
s: &'a crate::State,
|
s: &'a crate::State,
|
||||||
|
|||||||
Reference in New Issue
Block a user