From 057c957f5da44726724271360ff3b6d59d544882 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 16 Nov 2024 21:26:10 -0800 Subject: [PATCH] enh: access control --- src/lib/components/layout/Sidebar.svelte | 70 ++++++++--------- src/routes/(app)/workspace/+layout.svelte | 91 +++++++++++++++-------- 2 files changed, 97 insertions(+), 64 deletions(-) diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 6b739f0e7..392a9e732 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -470,42 +470,44 @@ -
- { - selectedChatId = null; - chatId.set(''); + {#if $user?.role === 'admin' || $user?.permissions?.workspace?.models || $user?.permissions?.workspace?.knowledge || $user?.permissions?.workspace?.prompts || $user?.permissions?.workspace?.tools} + +
+
{$i18n.t('Workspace')}
+
+ +
+ {/if}
{#if $temporaryChatEnabled} diff --git a/src/routes/(app)/workspace/+layout.svelte b/src/routes/(app)/workspace/+layout.svelte index decce4fdd..856247252 100644 --- a/src/routes/(app)/workspace/+layout.svelte +++ b/src/routes/(app)/workspace/+layout.svelte @@ -12,6 +12,7 @@ tools } from '$lib/stores'; import { page } from '$app/stores'; + import { goto } from '$app/navigation'; import MenuLines from '$lib/components/icons/MenuLines.svelte'; @@ -20,6 +21,24 @@ let loaded = false; onMount(async () => { + if ($user?.role !== 'admin') { + if ($page.url.pathname.includes('/models') && !$user?.permissions?.workspace?.models) { + goto('/'); + } else if ( + $page.url.pathname.includes('/knowledge') && + !$user?.permissions?.workspace?.knowledge + ) { + goto('/'); + } else if ( + $page.url.pathname.includes('/prompts') && + !$user?.permissions?.workspace?.prompts + ) { + goto('/'); + } else if ($page.url.pathname.includes('/tools') && !$user?.permissions?.workspace?.tools) { + goto('/'); + } + } + loaded = true; }); @@ -57,39 +76,51 @@
- {$i18n.t('Models')} + {#if $user?.role === 'admin' || $user?.permissions?.workspace?.models} + {$i18n.t('Models')} + {/if} - - {$i18n.t('Knowledge')} - + {#if $user?.role === 'admin' || $user?.permissions?.workspace?.knowledge} + + {$i18n.t('Knowledge')} + + {/if} - {$i18n.t('Prompts')} + {#if $user?.role === 'admin' || $user?.permissions?.workspace?.prompts} + {$i18n.t('Prompts')} + {/if} - - {$i18n.t('Tools')} - + {#if $user?.role === 'admin' || $user?.permissions?.workspace?.tools} + + {$i18n.t('Tools')} + + {/if}