open-webui/src/lib/components/admin/Users/Groups/Permissions.svelte

312 lines
8.6 KiB
Svelte
Raw Normal View History

2024-11-14 13:21:50 +08:00
<script lang="ts">
2025-01-16 15:01:43 +08:00
import { getContext, onMount } from 'svelte';
2024-11-14 13:21:50 +08:00
const i18n = getContext('i18n');
import Switch from '$lib/components/common/Switch.svelte';
2024-11-15 12:51:49 +08:00
import Tooltip from '$lib/components/common/Tooltip.svelte';
2025-01-16 15:01:43 +08:00
// Default values for permissions
const defaultPermissions = {
2024-11-15 12:51:49 +08:00
workspace: {
models: false,
knowledge: false,
prompts: false,
tools: false
},
2025-04-01 08:15:51 +08:00
sharing: {
public_models: false,
public_knowledge: false,
public_prompts: false,
public_tools: false
},
2024-11-15 12:51:49 +08:00
chat: {
2025-01-16 15:01:43 +08:00
controls: true,
2024-11-15 12:51:49 +08:00
delete: true,
edit: true,
2024-11-16 18:31:04 +08:00
temporary: true,
file_upload: true
2025-01-16 15:01:43 +08:00
},
features: {
web_search: true,
2025-02-04 13:56:35 +08:00
image_generation: true,
code_interpreter: true
2024-11-15 12:51:49 +08:00
}
};
2025-01-16 15:01:43 +08:00
export let permissions = {};
// Reactive statement to ensure all fields are present in `permissions`
$: {
permissions = fillMissingProperties(permissions, defaultPermissions);
}
function fillMissingProperties(obj: any, defaults: any) {
return {
...defaults,
...obj,
workspace: { ...defaults.workspace, ...obj.workspace },
2025-04-01 08:15:51 +08:00
sharing: { ...defaults.sharing, ...obj.sharing },
2025-01-16 15:01:43 +08:00
chat: { ...defaults.chat, ...obj.chat },
features: { ...defaults.features, ...obj.features }
};
}
onMount(() => {
permissions = fillMissingProperties(permissions, defaultPermissions);
});
2024-11-14 13:21:50 +08:00
</script>
<div>
2024-11-15 12:51:49 +08:00
<!-- <div>
2024-11-14 13:21:50 +08:00
<div class=" mb-2 text-sm font-medium">{$i18n.t('Model Permissions')}</div>
<div class="mb-2">
<div class="flex justify-between items-center text-xs pr-2">
<div class=" text-xs font-medium">{$i18n.t('Model Filtering')}</div>
2024-11-15 18:05:43 +08:00
<Switch bind:state={permissions.model.filter} />
2024-11-14 13:21:50 +08:00
</div>
</div>
2024-11-15 18:05:43 +08:00
{#if permissions.model.filter}
2024-11-14 13:21:50 +08:00
<div class="mb-2">
<div class=" space-y-1.5">
<div class="flex flex-col w-full">
<div class="mb-1 flex justify-between">
<div class="text-xs text-gray-500">{$i18n.t('Model IDs')}</div>
</div>
2024-11-15 18:05:43 +08:00
{#if model_ids.length > 0}
2024-11-14 13:21:50 +08:00
<div class="flex flex-col">
2024-11-15 18:05:43 +08:00
{#each model_ids as modelId, modelIdx}
2024-11-14 13:21:50 +08:00
<div class=" flex gap-2 w-full justify-between items-center">
<div class=" text-sm flex-1 rounded-lg">
{modelId}
</div>
2025-02-16 11:27:25 +08:00
<div class="shrink-0">
2024-11-14 13:21:50 +08:00
<button
type="button"
on:click={() => {
2024-11-15 18:05:43 +08:00
model_ids = model_ids.filter((_, idx) => idx !== modelIdx);
2024-11-14 13:21:50 +08:00
}}
>
<Minus strokeWidth="2" className="size-3.5" />
</button>
</div>
</div>
{/each}
</div>
{:else}
<div class="text-gray-500 text-xs text-center py-2 px-10">
{$i18n.t('No model IDs')}
</div>
{/if}
</div>
</div>
<hr class=" border-gray-100 dark:border-gray-700/10 mt-2.5 mb-1 w-full" />
<div class="flex items-center">
<select
class="w-full py-1 text-sm rounded-lg bg-transparent {selectedModelId
? ''
2025-02-16 11:27:25 +08:00
: 'text-gray-500'} placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-hidden"
2024-11-14 13:21:50 +08:00
bind:value={selectedModelId}
>
<option value="">{$i18n.t('Select a model')}</option>
{#each $models.filter((m) => m?.owned_by !== 'arena') as model}
<option value={model.id} class="bg-gray-50 dark:bg-gray-700">{model.name}</option>
{/each}
</select>
<div>
<button
type="button"
on:click={() => {
2024-11-15 18:05:43 +08:00
if (selectedModelId && !permissions.model.model_ids.includes(selectedModelId)) {
permissions.model.model_ids = [...permissions.model.model_ids, selectedModelId];
2024-11-14 13:21:50 +08:00
selectedModelId = '';
}
}}
>
<Plus className="size-3.5" strokeWidth="2" />
</button>
</div>
</div>
</div>
{/if}
<div class=" space-y-1 mb-3">
<div class="">
<div class="flex justify-between items-center text-xs">
<div class=" text-xs font-medium">{$i18n.t('Default Model')}</div>
</div>
</div>
<div class="flex-1 mr-2">
<select
2025-02-16 11:27:25 +08:00
class="w-full bg-transparent outline-hidden py-0.5 text-sm"
2024-11-15 18:05:43 +08:00
bind:value={permissions.model.default_id}
2024-11-14 13:21:50 +08:00
placeholder="Select a model"
>
<option value="" disabled selected>{$i18n.t('Select a model')}</option>
2024-11-15 18:05:43 +08:00
{#each permissions.model.filter ? $models.filter( (model) => filterModelIds.includes(model.id) ) : $models.filter((model) => model.id) as model}
2024-11-14 13:21:50 +08:00
<option value={model.id} class="bg-gray-100 dark:bg-gray-700">{model.name}</option>
{/each}
</select>
</div>
</div>
</div>
2025-02-16 11:50:40 +08:00
<hr class=" border-gray-100 dark:border-gray-850 my-2" /> -->
2024-11-14 13:21:50 +08:00
<div>
<div class=" mb-2 text-sm font-medium">{$i18n.t('Workspace Permissions')}</div>
<div class=" flex w-full justify-between my-2 pr-2">
2024-11-14 18:20:34 +08:00
<div class=" self-center text-xs font-medium">
{$i18n.t('Models Access')}
</div>
2024-11-15 12:51:49 +08:00
<Switch bind:state={permissions.workspace.models} />
2024-11-14 13:21:50 +08:00
</div>
<div class=" flex w-full justify-between my-2 pr-2">
2024-11-14 18:20:34 +08:00
<div class=" self-center text-xs font-medium">
{$i18n.t('Knowledge Access')}
</div>
2024-11-15 12:51:49 +08:00
<Switch bind:state={permissions.workspace.knowledge} />
2024-11-14 13:21:50 +08:00
</div>
<div class=" flex w-full justify-between my-2 pr-2">
2024-11-14 18:20:34 +08:00
<div class=" self-center text-xs font-medium">
{$i18n.t('Prompts Access')}
</div>
2024-11-15 12:51:49 +08:00
<Switch bind:state={permissions.workspace.prompts} />
2024-11-14 13:21:50 +08:00
</div>
2024-11-15 12:51:49 +08:00
<div class=" ">
<Tooltip
className=" flex w-full justify-between my-2 pr-2"
content={$i18n.t(
'Warning: Enabling this will allow users to upload arbitrary code on the server.'
)}
placement="top-start"
>
<div class=" self-center text-xs font-medium">
{$i18n.t('Tools Access')}
</div>
<Switch bind:state={permissions.workspace.tools} />
</Tooltip>
2024-11-14 13:21:50 +08:00
</div>
</div>
2025-02-16 11:50:40 +08:00
<hr class=" border-gray-100 dark:border-gray-850 my-2" />
2025-04-01 08:15:51 +08:00
<div>
<div class=" mb-2 text-sm font-medium">{$i18n.t('Sharing Permissions')}</div>
<div class=" flex w-full justify-between my-2 pr-2">
<div class=" self-center text-xs font-medium">
{$i18n.t('Models Public Sharing')}
</div>
<Switch bind:state={permissions.sharing.public_models} />
</div>
<div class=" flex w-full justify-between my-2 pr-2">
<div class=" self-center text-xs font-medium">
{$i18n.t('Knowledge Public Sharing')}
</div>
<Switch bind:state={permissions.sharing.public_knowledge} />
</div>
<div class=" flex w-full justify-between my-2 pr-2">
<div class=" self-center text-xs font-medium">
{$i18n.t('Prompts Public Sharing')}
</div>
<Switch bind:state={permissions.sharing.public_prompts} />
</div>
<div class=" flex w-full justify-between my-2 pr-2">
<div class=" self-center text-xs font-medium">
{$i18n.t('Tools Public Sharing')}
</div>
<Switch bind:state={permissions.sharing.public_tools} />
</div>
</div>
<hr class=" border-gray-100 dark:border-gray-850 my-2" />
2024-11-14 13:21:50 +08:00
<div>
<div class=" mb-2 text-sm font-medium">{$i18n.t('Chat Permissions')}</div>
2025-01-16 15:01:43 +08:00
<div class=" flex w-full justify-between my-2 pr-2">
<div class=" self-center text-xs font-medium">
{$i18n.t('Allow Chat Controls')}
</div>
<Switch bind:state={permissions.chat.controls} />
</div>
2024-11-16 18:31:04 +08:00
<div class=" flex w-full justify-between my-2 pr-2">
<div class=" self-center text-xs font-medium">
{$i18n.t('Allow File Upload')}
</div>
<Switch bind:state={permissions.chat.file_upload} />
</div>
2024-11-14 13:21:50 +08:00
<div class=" flex w-full justify-between my-2 pr-2">
2024-11-14 18:20:34 +08:00
<div class=" self-center text-xs font-medium">
2024-11-15 12:51:49 +08:00
{$i18n.t('Allow Chat Delete')}
2024-11-14 18:20:34 +08:00
</div>
2024-11-14 13:21:50 +08:00
2024-11-15 12:51:49 +08:00
<Switch bind:state={permissions.chat.delete} />
2024-11-14 13:21:50 +08:00
</div>
<div class=" flex w-full justify-between my-2 pr-2">
2024-11-14 18:20:34 +08:00
<div class=" self-center text-xs font-medium">
2024-11-15 12:51:49 +08:00
{$i18n.t('Allow Chat Edit')}
2024-11-14 18:20:34 +08:00
</div>
2024-11-14 13:21:50 +08:00
2024-11-15 12:51:49 +08:00
<Switch bind:state={permissions.chat.edit} />
2024-11-14 13:21:50 +08:00
</div>
<div class=" flex w-full justify-between my-2 pr-2">
2024-11-14 18:20:34 +08:00
<div class=" self-center text-xs font-medium">
{$i18n.t('Allow Temporary Chat')}
</div>
2024-11-14 13:21:50 +08:00
2024-11-15 12:51:49 +08:00
<Switch bind:state={permissions.chat.temporary} />
2024-11-14 13:21:50 +08:00
</div>
</div>
2025-01-16 15:01:43 +08:00
2025-02-16 11:50:40 +08:00
<hr class=" border-gray-100 dark:border-gray-850 my-2" />
2025-01-16 15:01:43 +08:00
<div>
<div class=" mb-2 text-sm font-medium">{$i18n.t('Features Permissions')}</div>
<div class=" flex w-full justify-between my-2 pr-2">
<div class=" self-center text-xs font-medium">
{$i18n.t('Web Search')}
</div>
<Switch bind:state={permissions.features.web_search} />
</div>
<div class=" flex w-full justify-between my-2 pr-2">
<div class=" self-center text-xs font-medium">
{$i18n.t('Image Generation')}
</div>
<Switch bind:state={permissions.features.image_generation} />
</div>
2025-02-04 13:56:35 +08:00
<div class=" flex w-full justify-between my-2 pr-2">
<div class=" self-center text-xs font-medium">
{$i18n.t('Code Interpreter')}
</div>
<Switch bind:state={permissions.features.code_interpreter} />
</div>
2025-01-16 15:01:43 +08:00
</div>
2024-11-14 13:21:50 +08:00
</div>