diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 2f91772191..ea8ef65f12 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -35,6 +35,8 @@ const i18n = getContext('i18n'); + $: canImportChats = $user?.role === 'admin' || ($user?.permissions?.chat?.import ?? true); + import { getChatList, getAllTags, @@ -372,6 +374,11 @@ }; const importChatHandler = async (items, pinned = false, folderId = null) => { + if (!canImportChats) { + toast.error($i18n.t('Access prohibited')); + return; + } + console.log('importChatHandler', items, pinned, folderId); for (const item of items) { console.log(item); @@ -1401,6 +1408,11 @@ return null; }); if (!chat && item) { + if (!canImportChats) { + toast.error($i18n.t('Access prohibited')); + return; + } + chat = await importChats(localStorage.token, [ { chat: item.chat, @@ -1409,9 +1421,9 @@ folder_id: null, created_at: item?.created_at ?? null, updated_at: item?.updated_at ?? null - } - ]); - } + } + ]); + } if (chat) { console.log(chat); @@ -1467,6 +1479,11 @@ return null; }); if (!chat && item) { + if (!canImportChats) { + toast.error($i18n.t('Access prohibited')); + return; + } + chat = await importChats(localStorage.token, [ { chat: item.chat, diff --git a/src/lib/components/layout/Sidebar/ChatItem.svelte b/src/lib/components/layout/Sidebar/ChatItem.svelte index 498dffbd9f..4b60fa7c81 100644 --- a/src/lib/components/layout/Sidebar/ChatItem.svelte +++ b/src/lib/components/layout/Sidebar/ChatItem.svelte @@ -9,10 +9,6 @@ import { toast } from 'svelte-sonner'; import { goto, invalidate, invalidateAll } from '$app/navigation'; import { onMount, getContext, createEventDispatcher, tick } from 'svelte'; - const i18n = getContext('i18n'); - - const dispatch = createEventDispatcher(); - import { archiveChatById, cloneChatById, @@ -35,7 +31,8 @@ currentChatPage, tags, selectedFolder, - activeChatIds + activeChatIds, + user } from '$lib/stores'; import ChatMenu from './ChatMenu.svelte'; @@ -53,6 +50,10 @@ import { generateTitle } from '$lib/apis'; import { createMessagesList } from '$lib/utils'; + const i18n = getContext('i18n'); + + const dispatch = createEventDispatcher(); + export let className = ''; export let id; @@ -143,6 +144,11 @@ }; const cloneChatHandler = async (id) => { + if (!($user?.role === 'admin' || ($user?.permissions?.chat?.import ?? true))) { + toast.error($i18n.t('Access prohibited')); + return; + } + const res = await cloneChatById( localStorage.token, id, diff --git a/src/lib/components/layout/Sidebar/ChatMenu.svelte b/src/lib/components/layout/Sidebar/ChatMenu.svelte index 1bc932e430..79ea2d0db9 100644 --- a/src/lib/components/layout/Sidebar/ChatMenu.svelte +++ b/src/lib/components/layout/Sidebar/ChatMenu.svelte @@ -387,17 +387,19 @@ {/if} - { - show = false; - cloneChatHandler(); - }} - > - - {$i18n.t('Clone')} - + {#if $user?.role === 'admin' || ($user?.permissions?.chat?.import ?? true)} + { + show = false; + cloneChatHandler(); + }} + > + + {$i18n.t('Clone')} + + {/if} {#if chatId && $folders.length > 0} { + if (!($sessionUser?.role === 'admin' || ($sessionUser?.permissions?.chat?.import ?? true))) { + toast.error($i18n.t('Access prohibited')); + return; + } + if (!chat) return; const res = await cloneSharedChatById(localStorage.token, chat.id).catch((error) => { @@ -197,18 +202,20 @@ - - - - {$i18n.t('Clone Chat')} - + {#if $sessionUser?.role === 'admin' || ($sessionUser?.permissions?.chat?.import ?? true)} + + + + {$i18n.t('Clone Chat')} + + - + {/if} {/if}