feat: add role-based sidebar link visibility control
Deploy Dashboard (Dev) / deploy-dev (push) Successful in 1m37s

This commit is contained in:
Gan, Jimmy
2026-03-01 18:17:45 +08:00
parent 20aa6f12a3
commit 7ab2ad41c4
7 changed files with 74 additions and 17 deletions
@@ -1,5 +1,5 @@
<script>
let { page = $bindable("dashboard"), dark = false, toggleTheme = () => {}, logout = () => {}, sidebarOpen = $bindable(false), allowedPages = "*", userRole = "admin", sidebarOrder = null, onOrderChange = () => {} } = $props();
let { page = $bindable("dashboard"), dark = false, toggleTheme = () => {}, logout = () => {}, sidebarOpen = $bindable(false), allowedPages = "*", allowedSidebarLinks = "*", userRole = "admin", sidebarOrder = null, onOrderChange = () => {} } = $props();
function canAccess(id) {
if (!id) return true;
@@ -7,6 +7,13 @@
return Array.isArray(allowedPages) && allowedPages.includes(id);
}
function canSeeSidebarLink(item) {
if (allowedSidebarLinks === "*") return true;
// Check by label or id
const key = item.label || item.id;
return Array.isArray(allowedSidebarLinks) && allowedSidebarLinks.includes(key);
}
const defaultLinks = [
{ id: "dashboard", label: "Overview", icon: "grid" },
{ id: "docker", label: "Docker", icon: "box" },
@@ -283,7 +290,7 @@
</div>
{/if}
{#each items as item, i}
{#if canAccess(item.id)}
{#if canAccess(item.id) && canSeeSidebarLink(item)}
{#if item.external || item.remoteHref || item.port}
<a
href={extHref(item)}