diff --git a/src/lib/components/admin/Users/Groups.svelte b/src/lib/components/admin/Users/Groups.svelte index 96028b1641..39dea4c4a0 100644 --- a/src/lib/components/admin/Users/Groups.svelte +++ b/src/lib/components/admin/Users/Groups.svelte @@ -23,11 +23,7 @@ import Pencil from '$lib/components/icons/Pencil.svelte'; import GroupItem from './Groups/GroupItem.svelte'; import { createNewGroup, getGroups } from '$lib/apis/groups'; - import { - getUserDefaultPermissions, - getAllUsers, - updateUserDefaultPermissions - } from '$lib/apis/users'; + import { getUserDefaultPermissions, getAllUsers, updateUserDefaultPermissions } from '$lib/apis/users'; const i18n = getContext('i18n'); @@ -50,54 +46,20 @@ }); let search = ''; - let defaultPermissions = { - workspace: { - models: false, - knowledge: false, - prompts: false, - tools: false - }, - sharing: { - public_models: false, - public_knowledge: false, - public_prompts: false, - public_tools: false - }, - chat: { - controls: true, - valves: true, - system_prompt: true, - params: true, - file_upload: true, - delete: true, - delete_message: true, - continue_response: true, - regenerate_response: true, - rate_response: true, - edit: true, - share: true, - export: true, - stt: true, - tts: true, - call: true, - multiple_models: true, - temporary: true, - temporary_enforced: false - }, - features: { - direct_tool_servers: false, - web_search: true, - image_generation: true, - code_interpreter: true, - notes: true - } - }; + let defaultPermissions = {}; let showAddGroupModal = false; let showDefaultPermissionsModal = false; const setGroups = async () => { - groups = await getGroups(localStorage.token); + const allGroups = await getGroups(localStorage.token); + const userGroup = allGroups.find((g) => g.name.toLowerCase() === 'user'); + + if (userGroup) { + defaultPermissions = userGroup.permissions; + } + + groups = allGroups.filter((g) => g.name.toLowerCase() !== 'user'); }; const addGroupHandler = async (group) => { @@ -145,8 +107,6 @@ } await setGroups(); - defaultPermissions = await getUserDefaultPermissions(localStorage.token); - loaded = true; }); @@ -231,7 +191,7 @@ {#each filteredGroups as group}
- +
{/each} diff --git a/src/lib/components/admin/Users/Groups/EditGroupModal.svelte b/src/lib/components/admin/Users/Groups/EditGroupModal.svelte index 151735e3d1..1225a3dcf4 100644 --- a/src/lib/components/admin/Users/Groups/EditGroupModal.svelte +++ b/src/lib/components/admin/Users/Groups/EditGroupModal.svelte @@ -21,6 +21,7 @@ export let users = []; export let group = null; + export let defaultPermissions = {}; export let custom = true; @@ -230,7 +231,7 @@ {#if selectedTab == 'general'} {:else if selectedTab == 'permissions'} - + {:else if selectedTab == 'users'} {/if} diff --git a/src/lib/components/admin/Users/Groups/GroupItem.svelte b/src/lib/components/admin/Users/Groups/GroupItem.svelte index 7a208f84a6..a16ab6560e 100644 --- a/src/lib/components/admin/Users/Groups/GroupItem.svelte +++ b/src/lib/components/admin/Users/Groups/GroupItem.svelte @@ -17,6 +17,7 @@ name: 'Admins', user_ids: [1, 2, 3] }; + export let defaultPermissions = {}; export let setGroups = () => {}; @@ -59,6 +60,7 @@ edit {users} {group} + {defaultPermissions} onSubmit={updateHandler} onDelete={deleteHandler} /> diff --git a/src/lib/components/admin/Users/Groups/Permissions.svelte b/src/lib/components/admin/Users/Groups/Permissions.svelte index b7f7c3093f..dfba887fd4 100644 --- a/src/lib/components/admin/Users/Groups/Permissions.svelte +++ b/src/lib/components/admin/Users/Groups/Permissions.svelte @@ -6,7 +6,7 @@ import Tooltip from '$lib/components/common/Tooltip.svelte'; // Default values for permissions - const defaultPermissions = { + const DEFAULT_PERMISSIONS = { workspace: { models: false, knowledge: false, @@ -51,10 +51,11 @@ }; export let permissions = {}; + export let defaultPermissions = {}; // Reactive statement to ensure all fields are present in `permissions` $: { - permissions = fillMissingProperties(permissions, defaultPermissions); + permissions = fillMissingProperties(permissions, DEFAULT_PERMISSIONS); } function fillMissingProperties(obj: any, defaults: any) { @@ -69,140 +70,65 @@ } onMount(() => { - permissions = fillMissingProperties(permissions, defaultPermissions); + permissions = fillMissingProperties(permissions, DEFAULT_PERMISSIONS); }); -
- - +
{$i18n.t('Workspace Permissions')}
-
-
- {$i18n.t('Models Access')} +
+
+
+ {$i18n.t('Models Access')} +
+
- + {#if defaultPermissions?.workspace?.models && !permissions.workspace.models} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Knowledge Access')} +
+
+
+ {$i18n.t('Knowledge Access')} +
+
- + {#if defaultPermissions?.workspace?.knowledge && !permissions.workspace.knowledge} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Prompts Access')} +
+
+
+ {$i18n.t('Prompts Access')} +
+
- + {#if defaultPermissions?.workspace?.prompts && !permissions.workspace.prompts} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
+
+ {#if defaultPermissions?.workspace?.tools && !permissions.workspace.tools} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
+
{$i18n.t('Sharing Permissions')}
-
-
- {$i18n.t('Models Public Sharing')} +
+
+
+ {$i18n.t('Models Public Sharing')} +
+
- + {#if defaultPermissions?.sharing?.public_models && !permissions.sharing.public_models} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Knowledge Public Sharing')} +
+
+
+ {$i18n.t('Knowledge Public Sharing')} +
+
- + {#if defaultPermissions?.sharing?.public_knowledge && !permissions.sharing.public_knowledge} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Prompts Public Sharing')} +
+
+
+ {$i18n.t('Prompts Public Sharing')} +
+
- + {#if defaultPermissions?.sharing?.public_prompts && !permissions.sharing.public_prompts} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Tools Public Sharing')} +
+
+
+ {$i18n.t('Tools Public Sharing')} +
+
- + {#if defaultPermissions?.sharing?.public_tools && !permissions.sharing.public_tools} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Notes Public Sharing')} +
+
+
+ {$i18n.t('Notes Public Sharing')} +
+
- + {#if defaultPermissions?.sharing?.public_notes && !permissions.sharing.public_notes} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
+
{$i18n.t('Chat Permissions')}
-
-
- {$i18n.t('Allow File Upload')} +
+
+
+ {$i18n.t('Allow File Upload')} +
+
- - + {#if defaultPermissions?.chat?.file_upload && !permissions.chat.file_upload} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Allow Chat Controls')} +
+
+
+ {$i18n.t('Allow Chat Controls')} +
+
- - + {#if defaultPermissions?.chat?.controls && !permissions.chat.controls} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
{#if permissions.chat.controls} -
-
- {$i18n.t('Allow Chat Valves')} +
+
+
+ {$i18n.t('Allow Chat Valves')} +
+
- - + {#if defaultPermissions?.chat?.valves && !permissions.chat.valves} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Allow Chat System Prompt')} +
+
+
+ {$i18n.t('Allow Chat System Prompt')} +
+
- - + {#if defaultPermissions?.chat?.system_prompt && !permissions.chat.system_prompt} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Allow Chat Params')} +
+
+
+ {$i18n.t('Allow Chat Params')} +
+
- - + {#if defaultPermissions?.chat?.params && !permissions.chat.params} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
{/if} -
-
- {$i18n.t('Allow Chat Edit')} +
+
+
+ {$i18n.t('Allow Chat Edit')} +
+
- - + {#if defaultPermissions?.chat?.edit && !permissions.chat.edit} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Allow Chat Delete')} +
+
+
+ {$i18n.t('Allow Chat Delete')} +
+
- - + {#if defaultPermissions?.chat?.delete && !permissions.chat.delete} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Allow Delete Messages')} +
+
+
+ {$i18n.t('Allow Delete Messages')} +
+
- - + {#if defaultPermissions?.chat?.delete_message && !permissions.chat.delete_message} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Allow Continue Response')} +
+
+
+ {$i18n.t('Allow Continue Response')} +
+
- - + {#if defaultPermissions?.chat?.continue_response && !permissions.chat.continue_response} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Allow Regenerate Response')} +
+
+
+ {$i18n.t('Allow Regenerate Response')} +
+
- - + {#if defaultPermissions?.chat?.regenerate_response && !permissions.chat.regenerate_response} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Allow Rate Response')} +
+
+
+ {$i18n.t('Allow Rate Response')} +
+
- - + {#if defaultPermissions?.chat?.rate_response && !permissions.chat.rate_response} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Allow Chat Share')} +
+
+
+ {$i18n.t('Allow Chat Share')} +
+
- - + {#if defaultPermissions?.chat?.share && !permissions.chat.share} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Allow Chat Export')} +
+
+
+ {$i18n.t('Allow Chat Export')} +
+
- - + {#if defaultPermissions?.chat?.export && !permissions.chat.export} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Allow Speech to Text')} +
+
+
+ {$i18n.t('Allow Speech to Text')} +
+
- - -
-
-
- {$i18n.t('Allow Text to Speech')} -
- - + {#if defaultPermissions?.chat?.stt && !permissions.chat.stt} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Allow Call')} +
+
+
+ {$i18n.t('Allow Text to Speech')} +
+
- - + {#if defaultPermissions?.chat?.tts && !permissions.chat.tts} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Allow Multiple Models in Chat')} +
+
+
+ {$i18n.t('Allow Call')} +
+
- - + {#if defaultPermissions?.chat?.call && !permissions.chat.call} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Allow Temporary Chat')} +
+
+
+ {$i18n.t('Allow Multiple Models in Chat')} +
+
+ {#if defaultPermissions?.chat?.multiple_models && !permissions.chat.multiple_models} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if} +
- +
+
+
+ {$i18n.t('Allow Temporary Chat')} +
+ +
+ {#if defaultPermissions?.chat?.temporary && !permissions.chat.temporary} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
{#if permissions.chat.temporary} -
-
- {$i18n.t('Enforce Temporary Chat')} +
+
+
+ {$i18n.t('Enforce Temporary Chat')} +
+
- - + {#if defaultPermissions?.chat?.temporary_enforced && !permissions.chat.temporary_enforced} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
{/if}
-
+
{$i18n.t('Features Permissions')}
-
-
- {$i18n.t('Direct Tool Servers')} +
+
+
+ {$i18n.t('Direct Tool Servers')} +
+
- - + {#if defaultPermissions?.features?.direct_tool_servers && !permissions.features.direct_tool_servers} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Web Search')} +
+
+
+ {$i18n.t('Web Search')} +
+
- - + {#if defaultPermissions?.features?.web_search && !permissions.features.web_search} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Image Generation')} +
+
+
+ {$i18n.t('Image Generation')} +
+
- - + {#if defaultPermissions?.features?.image_generation && !permissions.features.image_generation} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Code Interpreter')} +
+
+
+ {$i18n.t('Code Interpreter')} +
+
- - + {#if defaultPermissions?.features?.code_interpreter && !permissions.features.code_interpreter} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}
-
-
- {$i18n.t('Notes')} +
+
+
+ {$i18n.t('Notes')} +
+
- - + {#if defaultPermissions?.features?.notes && !permissions.features.notes} +
+
+ ⚠️ {$i18n.t('This permission is enabled for the default "user" role and will remain active.')} +
+
+ {/if}