Require permission side bar

This commit is contained in:
Ittipat Lusuk 2026-03-27 14:26:44 +07:00
parent f4b8df2c27
commit 08f7626dcb
2 changed files with 31 additions and 9 deletions

View file

@ -3,6 +3,7 @@
import { onDestroy, type ComponentProps } from 'svelte'; import { onDestroy, type ComponentProps } from 'svelte';
import { asset } from '$app/paths'; import { asset } from '$app/paths';
import AppAccountSelect from './app-account-select.svelte'; import AppAccountSelect from './app-account-select.svelte';
import { needPermission } from '$lib/core/handlers/permissionHandler';
import { import {
Code, Code,
LayoutDashboard, LayoutDashboard,
@ -34,7 +35,8 @@
{ {
title: 'Dashboard', title: 'Dashboard',
url: '/dashboard', url: '/dashboard',
icon: LayoutDashboard icon: LayoutDashboard,
requirePerm: ''
} }
] ]
}, },
@ -44,17 +46,20 @@
{ {
title: 'Overview', title: 'Overview',
url: '/recipe/overview', url: '/recipe/overview',
icon: LucideEye icon: LucideEye,
requirePerm: ''
}, },
{ {
title: 'Topping', title: 'Topping',
url: '/recipe/topping', url: '/recipe/topping',
icon: CherryIcon icon: CherryIcon,
requirePerm: ''
}, },
{ {
title: 'Material', title: 'Material',
url: '/recipe/material', url: '/recipe/material',
icon: DiamondIcon icon: DiamondIcon,
requirePerm: ''
} }
] ]
}, },
@ -64,12 +69,14 @@
{ {
title: 'Brew', title: 'Brew',
url: '/tools/brew', url: '/tools/brew',
icon: CupSodaIcon icon: CupSodaIcon,
requirePerm: ''
}, },
{ {
title: 'Debug', title: 'Debug',
url: '/tools/debug', url: '/tools/debug',
icon: BugIcon icon: BugIcon,
requirePerm: ''
} }
] ]
}, },
@ -79,8 +86,8 @@
{ {
title: 'Overview', title: 'Overview',
url: '/departments', url: '/departments',
icon: FileSpreadsheet icon: FileSpreadsheet,
requirePerm: 'document.write.*'
} }
] ]
} }
@ -126,6 +133,19 @@
unsubSidebar(); unsubSidebar();
}); });
let authorizedNavMain = $derived(
data.navMain.map(nav => {
const filteredItems = nav.items.filter(item => {
if (!item.requirePerm) return true;
return needPermission(item.requirePerm);
});
return { ...nav, items: filteredItems };
}).filter(nav => nav.items.length > 0)
);
let { let {
ref = sideBar, ref = sideBar,
collapsible = 'icon', collapsible = 'icon',
@ -142,7 +162,7 @@
</div> </div>
</Sidebar.Header> </Sidebar.Header>
<Sidebar.Content> <Sidebar.Content>
{#each data.navMain as nav} {#each authorizedNavMain as nav}
<Sidebar.Group> <Sidebar.Group>
<Sidebar.GroupLabel>{nav.title}</Sidebar.GroupLabel> <Sidebar.GroupLabel>{nav.title}</Sidebar.GroupLabel>
<Sidebar.GroupContent> <Sidebar.GroupContent>

View file

@ -81,7 +81,9 @@
> >
<img src={RecipeModuleBtn} alt="Recipes" loading="lazy" /> <img src={RecipeModuleBtn} alt="Recipes" loading="lazy" />
</button> </button>
{/if}
{#if perms.filter((x) => x.startsWith('document.write')).length > 0}
<button <button
class="button" class="button"
id="sheet_mod_btn" id="sheet_mod_btn"