enh: access control

This commit is contained in:
Timothy Jaeryang Baek 2024-11-16 21:26:10 -08:00
parent 07e0712b87
commit 057c957f5d
2 changed files with 97 additions and 64 deletions

View File

@ -470,6 +470,7 @@
</button>
</div>
{#if $user?.role === 'admin' || $user?.permissions?.workspace?.models || $user?.permissions?.workspace?.knowledge || $user?.permissions?.workspace?.prompts || $user?.permissions?.workspace?.tools}
<div class="px-1.5 flex justify-center text-gray-800 dark:text-gray-200">
<a
class="flex-grow flex space-x-3 rounded-lg px-2 py-[7px] hover:bg-gray-100 dark:hover:bg-gray-900 transition"
@ -506,6 +507,7 @@
</div>
</a>
</div>
{/if}
<div class="relative {$temporaryChatEnabled ? 'opacity-20' : ''}">
{#if $temporaryChatEnabled}

View File

@ -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;
});
</script>
@ -57,13 +76,18 @@
<div
class="flex gap-1 scrollbar-none overflow-x-auto w-fit text-center text-sm font-medium rounded-full bg-transparent py-1 touch-auto pointer-events-auto"
>
{#if $user?.role === 'admin' || $user?.permissions?.workspace?.models}
<a
class="min-w-fit rounded-full p-1.5 {$page.url.pathname.includes('/workspace/models')
class="min-w-fit rounded-full p-1.5 {$page.url.pathname.includes(
'/workspace/models'
)
? ''
: 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition"
href="/workspace/models">{$i18n.t('Models')}</a
>
{/if}
{#if $user?.role === 'admin' || $user?.permissions?.workspace?.knowledge}
<a
class="min-w-fit rounded-full p-1.5 {$page.url.pathname.includes(
'/workspace/knowledge'
@ -74,14 +98,20 @@
>
{$i18n.t('Knowledge')}
</a>
{/if}
{#if $user?.role === 'admin' || $user?.permissions?.workspace?.prompts}
<a
class="min-w-fit rounded-full p-1.5 {$page.url.pathname.includes('/workspace/prompts')
class="min-w-fit rounded-full p-1.5 {$page.url.pathname.includes(
'/workspace/prompts'
)
? ''
: 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition"
href="/workspace/prompts">{$i18n.t('Prompts')}</a
>
{/if}
{#if $user?.role === 'admin' || $user?.permissions?.workspace?.tools}
<a
class="min-w-fit rounded-full p-1.5 {$page.url.pathname.includes('/workspace/tools')
? ''
@ -90,6 +120,7 @@
>
{$i18n.t('Tools')}
</a>
{/if}
</div>
</div>