CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Dashboard (push) Skipped
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Agent (push) Successful in 6m2s
61 lines
1.9 KiB
Rust
61 lines
1.9 KiB
Rust
//! `GET /api/v1/git-source` — the workspace's managed git source (#439),
|
|
//! read-only. The platform configures it (`/api/v1/platform/...`); the
|
|
//! organisation's IT administrator and BreakPilot support may look at it.
|
|
|
|
use axum::http::StatusCode;
|
|
use axum::Json;
|
|
|
|
use compliance_core::models::GitSourceView;
|
|
use compliance_core::tenant_ctx::TenantCtx;
|
|
|
|
use super::dto::{tenant_db, AgentExt};
|
|
use super::ApiResponse;
|
|
|
|
/// Whether the caller may see the git source: administrators (IT_ADMIN,
|
|
/// OWNER) and support.
|
|
fn may_view(tenant: &TenantCtx) -> bool {
|
|
tenant.0.staff.is_some() || tenant.0.is_admin()
|
|
}
|
|
|
|
/// The workspace's managed git source, without secrets.
|
|
///
|
|
/// Plus the webhook URL; `data: null` when the workspace has none. For
|
|
/// administrators (IT_ADMIN, OWNER) and support.
|
|
#[utoipa::path(
|
|
get,
|
|
path = "/api/v1/git-source",
|
|
tag = "Workspace",
|
|
responses(
|
|
(status = 200, description = "The source, or null"),
|
|
(status = 403, description = "Not an administrator or support"),
|
|
(status = 401, description = "No valid bearer token"),
|
|
)
|
|
)]
|
|
pub async fn get_git_source(
|
|
axum::extract::Extension(agent): AgentExt,
|
|
tenant: TenantCtx,
|
|
) -> Result<Json<ApiResponse<Option<serde_json::Value>>>, StatusCode> {
|
|
if !may_view(&tenant) {
|
|
return Err(StatusCode::FORBIDDEN);
|
|
}
|
|
let db = tenant_db(&agent, &tenant).await?;
|
|
let source = crate::git_source::load_source(&db)
|
|
.await
|
|
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
|
let data = source.map(|s| {
|
|
let mut v = serde_json::to_value(GitSourceView::from(&s)).unwrap_or_default();
|
|
if let Some(obj) = v.as_object_mut() {
|
|
obj.insert(
|
|
"webhook_url".into(),
|
|
agent.git_source.webhook_url(&tenant.0.tenant_id).into(),
|
|
);
|
|
}
|
|
v
|
|
});
|
|
Ok(Json(ApiResponse {
|
|
data,
|
|
total: None,
|
|
page: None,
|
|
}))
|
|
}
|