feat: add role-based sidebar link visibility control
Deploy Dashboard (Dev) / deploy-dev (push) Successful in 1m37s
Deploy Dashboard (Dev) / deploy-dev (push) Successful in 1m37s
This commit is contained in:
@@ -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)}
|
||||
|
||||
Reference in New Issue
Block a user