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,42 +470,44 @@
</button> </button>
</div> </div>
<div class="px-1.5 flex justify-center text-gray-800 dark:text-gray-200"> {#if $user?.role === 'admin' || $user?.permissions?.workspace?.models || $user?.permissions?.workspace?.knowledge || $user?.permissions?.workspace?.prompts || $user?.permissions?.workspace?.tools}
<a <div class="px-1.5 flex justify-center text-gray-800 dark:text-gray-200">
class="flex-grow flex space-x-3 rounded-lg px-2 py-[7px] hover:bg-gray-100 dark:hover:bg-gray-900 transition" <a
href="/workspace" class="flex-grow flex space-x-3 rounded-lg px-2 py-[7px] hover:bg-gray-100 dark:hover:bg-gray-900 transition"
on:click={() => { href="/workspace"
selectedChatId = null; on:click={() => {
chatId.set(''); selectedChatId = null;
chatId.set('');
if ($mobile) { if ($mobile) {
showSidebar.set(false); showSidebar.set(false);
} }
}} }}
draggable="false" draggable="false"
> >
<div class="self-center"> <div class="self-center">
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
fill="none" fill="none"
viewBox="0 0 24 24" viewBox="0 0 24 24"
stroke-width="2" stroke-width="2"
stroke="currentColor" stroke="currentColor"
class="size-[1.1rem]" class="size-[1.1rem]"
> >
<path <path
stroke-linecap="round" stroke-linecap="round"
stroke-linejoin="round" stroke-linejoin="round"
d="M13.5 16.875h3.375m0 0h3.375m-3.375 0V13.5m0 3.375v3.375M6 10.5h2.25a2.25 2.25 0 0 0 2.25-2.25V6a2.25 2.25 0 0 0-2.25-2.25H6A2.25 2.25 0 0 0 3.75 6v2.25A2.25 2.25 0 0 0 6 10.5Zm0 9.75h2.25A2.25 2.25 0 0 0 10.5 18v-2.25a2.25 2.25 0 0 0-2.25-2.25H6a2.25 2.25 0 0 0-2.25 2.25V18A2.25 2.25 0 0 0 6 20.25Zm9.75-9.75H18a2.25 2.25 0 0 0 2.25-2.25V6A2.25 2.25 0 0 0 18 3.75h-2.25A2.25 2.25 0 0 0 13.5 6v2.25a2.25 2.25 0 0 0 2.25 2.25Z" d="M13.5 16.875h3.375m0 0h3.375m-3.375 0V13.5m0 3.375v3.375M6 10.5h2.25a2.25 2.25 0 0 0 2.25-2.25V6a2.25 2.25 0 0 0-2.25-2.25H6A2.25 2.25 0 0 0 3.75 6v2.25A2.25 2.25 0 0 0 6 10.5Zm0 9.75h2.25A2.25 2.25 0 0 0 10.5 18v-2.25a2.25 2.25 0 0 0-2.25-2.25H6a2.25 2.25 0 0 0-2.25 2.25V18A2.25 2.25 0 0 0 6 20.25Zm9.75-9.75H18a2.25 2.25 0 0 0 2.25-2.25V6A2.25 2.25 0 0 0 18 3.75h-2.25A2.25 2.25 0 0 0 13.5 6v2.25a2.25 2.25 0 0 0 2.25 2.25Z"
/> />
</svg> </svg>
</div> </div>
<div class="flex self-center"> <div class="flex self-center">
<div class=" self-center font-medium text-sm font-primary">{$i18n.t('Workspace')}</div> <div class=" self-center font-medium text-sm font-primary">{$i18n.t('Workspace')}</div>
</div> </div>
</a> </a>
</div> </div>
{/if}
<div class="relative {$temporaryChatEnabled ? 'opacity-20' : ''}"> <div class="relative {$temporaryChatEnabled ? 'opacity-20' : ''}">
{#if $temporaryChatEnabled} {#if $temporaryChatEnabled}

View File

@ -12,6 +12,7 @@
tools tools
} from '$lib/stores'; } from '$lib/stores';
import { page } from '$app/stores'; import { page } from '$app/stores';
import { goto } from '$app/navigation';
import MenuLines from '$lib/components/icons/MenuLines.svelte'; import MenuLines from '$lib/components/icons/MenuLines.svelte';
@ -20,6 +21,24 @@
let loaded = false; let loaded = false;
onMount(async () => { 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; loaded = true;
}); });
</script> </script>
@ -57,39 +76,51 @@
<div <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" 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"
> >
<a {#if $user?.role === 'admin' || $user?.permissions?.workspace?.models}
class="min-w-fit rounded-full p-1.5 {$page.url.pathname.includes('/workspace/models') <a
? '' class="min-w-fit rounded-full p-1.5 {$page.url.pathname.includes(
: 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition" '/workspace/models'
href="/workspace/models">{$i18n.t('Models')}</a )
> ? ''
: 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition"
href="/workspace/models">{$i18n.t('Models')}</a
>
{/if}
<a {#if $user?.role === 'admin' || $user?.permissions?.workspace?.knowledge}
class="min-w-fit rounded-full p-1.5 {$page.url.pathname.includes( <a
'/workspace/knowledge' class="min-w-fit rounded-full p-1.5 {$page.url.pathname.includes(
) '/workspace/knowledge'
? '' )
: 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition" ? ''
href="/workspace/knowledge" : 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition"
> href="/workspace/knowledge"
{$i18n.t('Knowledge')} >
</a> {$i18n.t('Knowledge')}
</a>
{/if}
<a {#if $user?.role === 'admin' || $user?.permissions?.workspace?.prompts}
class="min-w-fit rounded-full p-1.5 {$page.url.pathname.includes('/workspace/prompts') <a
? '' class="min-w-fit rounded-full p-1.5 {$page.url.pathname.includes(
: 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition" '/workspace/prompts'
href="/workspace/prompts">{$i18n.t('Prompts')}</a )
> ? ''
: 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition"
href="/workspace/prompts">{$i18n.t('Prompts')}</a
>
{/if}
<a {#if $user?.role === 'admin' || $user?.permissions?.workspace?.tools}
class="min-w-fit rounded-full p-1.5 {$page.url.pathname.includes('/workspace/tools') <a
? '' class="min-w-fit rounded-full p-1.5 {$page.url.pathname.includes('/workspace/tools')
: 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition" ? ''
href="/workspace/tools" : 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition"
> href="/workspace/tools"
{$i18n.t('Tools')} >
</a> {$i18n.t('Tools')}
</a>
{/if}
</div> </div>
</div> </div>