Files
pruefwerk/compliance-dashboard/src/components/app_shell.rs
T
sharang 0e7a138cd4
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 4s
CI / Deploy Docs (push) Skipped
CI / Deploy Agent (push) Successful in 7m28s
CI / Deploy Dashboard (push) Successful in 5m12s
CI / Deploy MCP (push) Successful in 3m30s
feat(access): blocked workspace members are refused (portal#74) (#471)
2026-10-05 22:21:20 +00:00

106 lines
4.0 KiB
Rust

use dioxus::prelude::*;
use crate::app::Route;
use crate::components::help_chat::HelpChat;
use crate::components::no_access::{NoAccess, ReadOnlyBanner};
use crate::components::notification_bell::NotificationBell;
use crate::components::sidebar::Sidebar;
use crate::components::support::{SupportBanner, SupportPicker};
use crate::components::toast::{ToastContainer, Toasts};
use crate::infrastructure::auth_check::check_auth;
use crate::infrastructure::platform::fetch_platform_info;
/// How often an open page checks that the sign-in is still valid.
#[cfg(feature = "web")]
const SIGN_IN_CHECK_MS: u32 = 60_000;
#[component]
pub fn AppShell() -> Element {
use_context_provider(Toasts::new);
crate::i18n::provide_lang();
// Agent contract handshake (features such as `source_only`), provided
// app-wide so pages can hide runtime-only surfaces. Read on the server
// before the first render, so a page never shows a feature first and
// then takes it away; an unreachable agent reads as the full set.
let platform = use_server_future(fetch_platform_info)?;
let auth = use_server_future(check_auth)?;
let platform_now = platform().and_then(Result::ok).unwrap_or_default();
use_context_provider(|| Signal::new(platform_now));
// A sign-in can run out while a page stays open: check now and then, and
// send the browser to the login rather than letting every page fail.
use_future(move || async move {
#[cfg(feature = "web")]
loop {
gloo_timers::future::TimeoutFuture::new(SIGN_IN_CHECK_MS).await;
if let Ok(info) = check_auth().await {
if !info.authenticated {
crate::infrastructure::auth_check::go_to_login();
break;
}
}
}
});
match auth() {
// BreakPilot support chooses a tenant first: every page asks the agent
// for one, and without it would only be refused.
Some(Ok(info)) if info.authenticated && info.staff && info.support_tenant.is_none() => {
rsx! {
SupportPicker {}
ToastContainer {}
}
}
// A member the workspace blocked (portal#74): the agent refuses
// everything, so the app shows only that.
Some(Ok(info)) if info.authenticated && info.member_blocked => {
rsx! {
NoAccess { portal_url: info.portal_url.clone(), blocked: true }
}
}
// A role without access to Prüfwerk (FINANCE, or none): no navigation
// and no page, so nothing is fetched or shown.
Some(Ok(info)) if info.authenticated && !info.access.can_read() => {
rsx! {
NoAccess { portal_url: info.portal_url.clone() }
}
}
Some(Ok(info)) if info.authenticated => {
use_context_provider(|| Signal::new(info.clone()));
let read_only = !info.access.can_write();
rsx! {
div { class: "app-shell",
Sidebar {}
main { class: "main-content",
if let Some(tenant) = info.support_tenant.clone() {
SupportBanner { tenant }
}
if read_only {
ReadOnlyBanner {}
}
Outlet::<Route> {}
}
NotificationBell {}
ToastContainer {}
HelpChat {}
}
}
}
Some(Ok(_)) | Some(Err(_)) => {
// Not authenticated — redirect to Keycloak login
rsx! {
document::Script {
"window.location.href = '/auth';"
}
}
}
None => {
rsx! {
div { class: "flex items-center justify-center h-screen bg-gray-950",
p { class: "text-gray-400", "Loading..." }
}
}
}
}
}