Skip to main content

krabka_admin_ui/views/
layout.rs

1use super::Route;
2use crate::permissions::Capabilities;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub struct SidebarLink {
6    pub route: Route,
7    pub path: &'static str,
8    pub label: &'static str,
9}
10
11impl SidebarLink {
12    const fn new(route: Route) -> Self {
13        Self {
14            route,
15            path: route.path(),
16            label: route.label(),
17        }
18    }
19}
20
21const SIDEBAR_LINKS: &[SidebarLink] = &[
22    SidebarLink::new(Route::Overview),
23    SidebarLink::new(Route::Topics),
24    SidebarLink::new(Route::Groups),
25    SidebarLink::new(Route::Acls),
26    SidebarLink::new(Route::Users),
27    SidebarLink::new(Route::Quotas),
28    SidebarLink::new(Route::LogDirs),
29];
30
31#[must_use]
32pub const fn sidebar_links() -> &'static [SidebarLink] {
33    SIDEBAR_LINKS
34}
35
36/// The sidebar links the operator's ACLs permit, in the order above.
37#[must_use]
38pub fn sidebar_links_for(capabilities: Capabilities) -> Vec<SidebarLink> {
39    SIDEBAR_LINKS
40        .iter()
41        .copied()
42        .filter(|link| link.route.is_permitted(capabilities))
43        .collect()
44}