diff --git a/.env.example b/.env.example index 6005bd3..9e05358 100644 --- a/.env.example +++ b/.env.example @@ -109,6 +109,9 @@ DASHBOARD_SESSION_KEY= # https://app-stage.breakpilot.com, production: https://app.breakpilot.com. # Unset hides the link. # PORTAL_URL= +# The docs site the sidebar links to. Default /docs/ (the docs container on +# the dashboard host); production uses https://docs.breakpilot.com/pruefwerk/. +# DOCS_URL= # MCP Server MCP_ENDPOINT_URL=http://localhost:8090 diff --git a/Dockerfile.dashboard b/Dockerfile.dashboard index 6c6567e..d8b9f3a 100644 --- a/Dockerfile.dashboard +++ b/Dockerfile.dashboard @@ -2,17 +2,13 @@ FROM rust:1.94-bookworm AS builder RUN cargo install dioxus-cli --version 0.7.3 --locked -# The docs site, served at /docs/ on the dashboard host. Keep the trailing -# slash: the orca route matches /docs/*, so plain /docs reaches the dashboard. -ARG DOCS_URL=/docs/ # Legal pages linked from the sidebar; the defaults are breakpilot.com's. ARG IMPRINT_URL=https://breakpilot.com/impressum ARG PRIVACY_URL=https://breakpilot.com/datenschutz WORKDIR /app COPY . . -ENV DOCS_URL=${DOCS_URL} \ - IMPRINT_URL=${IMPRINT_URL} \ +ENV IMPRINT_URL=${IMPRINT_URL} \ PRIVACY_URL=${PRIVACY_URL} # compliance-agent (a workspace member) depends on the private firmwerk git # repo, so the workspace resolve needs it even to build the dashboard. diff --git a/compliance-core/src/models/auth.rs b/compliance-core/src/models/auth.rs index a783bc1..08046c0 100644 --- a/compliance-core/src/models/auth.rs +++ b/compliance-core/src/models/auth.rs @@ -15,4 +15,7 @@ pub struct AuthInfo { /// there); empty when no portal is configured. #[serde(default)] pub portal_url: String, + /// The docs site this deployment links to from the sidebar. + #[serde(default)] + pub docs_url: String, } diff --git a/compliance-dashboard/src/components/sidebar.rs b/compliance-dashboard/src/components/sidebar.rs index 4b66b79..88f8c9e 100644 --- a/compliance-dashboard/src/components/sidebar.rs +++ b/compliance-dashboard/src/components/sidebar.rs @@ -10,7 +10,8 @@ use crate::i18n::texts::{common, nav}; use crate::i18n::{use_lang, Text}; use crate::infrastructure::platform::use_source_only; -/// Where the legal pages live. Overridable per build, like `DOCS_URL`. +/// Where the legal pages live. Overridable per build; they are the same on +/// staging and production. const IMPRINT_URL: &str = match option_env!("IMPRINT_URL") { Some(url) => url, None => "https://breakpilot.com/impressum", @@ -89,12 +90,14 @@ pub fn Sidebar() -> Element { }, ]; - // With the trailing slash: the docs route matches /docs/*, and a plain - // /docs lands on the dashboard's "route not found" page. - let docs_url = option_env!("DOCS_URL").unwrap_or("/docs/"); - // Back to the customer's workspace in the platform portal; hidden when - // the dashboard is not configured with one (local development). - let portal_url = use_context::>()().portal_url; + // Both links are set per deployment (`DOCS_URL`, `PORTAL_URL`). The + // portal link is hidden when the dashboard has no portal (local + // development). + let AuthInfo { + docs_url, + portal_url, + .. + } = use_context::>()(); let sidebar_class = if collapsed() { "sidebar collapsed" diff --git a/compliance-dashboard/src/infrastructure/auth_check.rs b/compliance-dashboard/src/infrastructure/auth_check.rs index 8767c28..338b9ee 100644 --- a/compliance-dashboard/src/infrastructure/auth_check.rs +++ b/compliance-dashboard/src/infrastructure/auth_check.rs @@ -21,6 +21,7 @@ pub async fn check_auth() -> Result { authenticated: true, name: "Local User".into(), portal_url: portal_link(state.portal_url.as_deref(), ""), + docs_url: state.docs_url.clone(), ..Default::default() }); } @@ -36,11 +37,15 @@ pub async fn check_auth() -> Result { Some(u) => Ok(AuthInfo { authenticated: true, portal_url: portal_link(state.portal_url.as_deref(), &u.tenant_slug), + docs_url: state.docs_url.clone(), sub: u.sub, email: u.user.email, name: u.user.name, avatar_url: u.user.avatar_url, }), - None => Ok(AuthInfo::default()), + None => Ok(AuthInfo { + docs_url: state.docs_url.clone(), + ..Default::default() + }), } } diff --git a/compliance-dashboard/src/infrastructure/server.rs b/compliance-dashboard/src/infrastructure/server.rs index e0a6f10..5c4975f 100644 --- a/compliance-dashboard/src/infrastructure/server.rs +++ b/compliance-dashboard/src/infrastructure/server.rs @@ -17,6 +17,23 @@ use super::server_state::{ServerState, ServerStateInner}; use super::session_store::{load_session_key, MongoSessionStore}; use super::{auth_callback, auth_login, logout, require_auth, PendingOAuthStore}; +/// The docs site when `DOCS_URL` is unset: served on the dashboard host. +/// Keep the trailing slash: the docs route matches `/docs/*`, and a plain +/// `/docs` lands on the dashboard's "route not found" page. +const DEFAULT_DOCS_URL: &str = "/docs/"; + +/// An optional setting from the environment, trimmed; unset or blank is `None`. +fn env_setting(name: &str) -> Option { + non_blank(std::env::var(name).ok()) +} + +/// `value` trimmed, or `None` when it is missing or blank. +fn non_blank(value: Option) -> Option { + value + .map(|v| v.trim().to_string()) + .filter(|v| !v.is_empty()) +} + pub fn server_start(app: fn() -> Element) -> Result<(), DashboardError> { tokio::runtime::Runtime::new() .map_err(|e| DashboardError::Other(e.to_string()))? @@ -53,15 +70,11 @@ pub fn server_start(app: fn() -> Element) -> Result<(), DashboardError> { // Explicit MCP health URL — needed where an ingress strips the // `/mcp` prefix (staging: `…/mcp/health` → compliance-mcp `/health`). - let mcp_health_url = std::env::var("MCP_HEALTH_URL") - .ok() - .map(|v| v.trim().to_string()) - .filter(|v| !v.is_empty()); - - let portal_url = std::env::var("PORTAL_URL") - .ok() - .map(|v| v.trim().to_string()) - .filter(|v| !v.is_empty()); + let mcp_health_url = env_setting("MCP_HEALTH_URL"); + let portal_url = env_setting("PORTAL_URL"); + // Read at runtime: staging and production share one image but + // not one docs site. + let docs_url = env_setting("DOCS_URL").unwrap_or_else(|| DEFAULT_DOCS_URL.to_string()); // Sessions survive a redeploy: signed with a key from the // environment, stored sealed in Mongo (#260). @@ -82,6 +95,7 @@ pub fn server_start(app: fn() -> Element) -> Result<(), DashboardError> { keycloak, mcp_health_url, portal_url, + docs_url, } .into(); @@ -196,3 +210,18 @@ async fn seed_default_mcp_servers(db: &Database, mcp_endpoint_url: Option<&str>) } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn blank_settings_count_as_unset() { + assert_eq!( + non_blank(Some(" https://docs.breakpilot.com/pruefwerk/ ".into())).as_deref(), + Some("https://docs.breakpilot.com/pruefwerk/") + ); + assert_eq!(non_blank(Some(" ".into())), None); + assert_eq!(non_blank(None), None); + } +} diff --git a/compliance-dashboard/src/infrastructure/server_state.rs b/compliance-dashboard/src/infrastructure/server_state.rs index be96b9e..30ef81c 100644 --- a/compliance-dashboard/src/infrastructure/server_state.rs +++ b/compliance-dashboard/src/infrastructure/server_state.rs @@ -29,6 +29,9 @@ pub struct ServerStateInner { /// differs between staging and production, which share one image, so it /// is read at runtime. `None` hides the link. pub portal_url: Option, + /// The docs site for the sidebar link (`DOCS_URL`, default `/docs/`). + /// Read at runtime for the same reason as `portal_url`. + pub docs_url: String, } impl From for ServerState {