diff --git a/compliance-dashboard/src/pages/supply_chain.rs b/compliance-dashboard/src/pages/supply_chain.rs index f65cc27..f70a033 100644 --- a/compliance-dashboard/src/pages/supply_chain.rs +++ b/compliance-dashboard/src/pages/supply_chain.rs @@ -821,7 +821,7 @@ fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element { ProjectDocs { key: "{id}", id: id.to_string(), - portal_url: portal_url.trim_end_matches('/').to_string(), + portal_url: portal_origin(&portal_url).to_string(), can_write, } Link { class: "chain-panel-link", to: Route::MachinePage { id: id.to_string(), tab: String::new() }, {tx::OPEN_PRODUCT.get(lang)} } @@ -832,6 +832,19 @@ fn ChainView(chain: SupplyChainDto, layout: LayoutDto) -> Element { } } +/// The scheme and host of `url`, without a path: what the portal's own paths +/// (`/{slug}/dokumente/…`) go after. `PORTAL_URL` may point at a page of the +/// portal (on stage, the workspace's dashboard), not at its root. +fn portal_origin(url: &str) -> &str { + let Some(scheme_end) = url.find("://") else { + return url.trim_end_matches('/'); + }; + let host_start = scheme_end + 3; + url[host_start..] + .find('/') + .map_or(url, |slash| &url[..host_start + slash]) +} + /// A file size as people read it: "340 KB", "1,2 MB". fn size_text(bytes: u64, lang: Lang) -> String { const KB: f64 = 1024.0; @@ -1136,6 +1149,23 @@ mod tests { assert!(folded_keys(&c).is_empty()); } + #[test] + fn a_documents_path_goes_after_the_portals_origin() { + assert_eq!( + portal_origin("https://app-stage.breakpilot.com/sharna/dashboard"), + "https://app-stage.breakpilot.com" + ); + assert_eq!( + portal_origin("https://app.breakpilot.com/"), + "https://app.breakpilot.com" + ); + assert_eq!( + portal_origin("http://127.0.0.1:9999"), + "http://127.0.0.1:9999" + ); + assert_eq!(portal_origin(""), ""); + } + #[test] fn a_file_size_reads_in_the_language() { assert_eq!(size_text(1_258_291, Lang::De), "1,2 MB");