feat: multiple models chat user permissions

This commit is contained in:
Timothy Jaeryang Baek 2025-04-12 17:37:30 -07:00
parent 881d81d87f
commit 79dff685ea
5 changed files with 69 additions and 50 deletions

View File

@ -1062,6 +1062,10 @@ USER_PERMISSIONS_CHAT_EDIT = (
os.environ.get("USER_PERMISSIONS_CHAT_EDIT", "True").lower() == "true" os.environ.get("USER_PERMISSIONS_CHAT_EDIT", "True").lower() == "true"
) )
USER_PERMISSIONS_CHAT_MULTIPLE_MODELS = (
os.environ.get("USER_PERMISSIONS_CHAT_MULTIPLE_MODELS", "True").lower() == "true"
)
USER_PERMISSIONS_CHAT_TEMPORARY = ( USER_PERMISSIONS_CHAT_TEMPORARY = (
os.environ.get("USER_PERMISSIONS_CHAT_TEMPORARY", "True").lower() == "true" os.environ.get("USER_PERMISSIONS_CHAT_TEMPORARY", "True").lower() == "true"
) )
@ -1071,6 +1075,7 @@ USER_PERMISSIONS_CHAT_TEMPORARY_ENFORCED = (
== "true" == "true"
) )
USER_PERMISSIONS_FEATURES_DIRECT_TOOL_SERVERS = ( USER_PERMISSIONS_FEATURES_DIRECT_TOOL_SERVERS = (
os.environ.get("USER_PERMISSIONS_FEATURES_DIRECT_TOOL_SERVERS", "False").lower() os.environ.get("USER_PERMISSIONS_FEATURES_DIRECT_TOOL_SERVERS", "False").lower()
== "true" == "true"
@ -1109,6 +1114,7 @@ DEFAULT_USER_PERMISSIONS = {
"file_upload": USER_PERMISSIONS_CHAT_FILE_UPLOAD, "file_upload": USER_PERMISSIONS_CHAT_FILE_UPLOAD,
"delete": USER_PERMISSIONS_CHAT_DELETE, "delete": USER_PERMISSIONS_CHAT_DELETE,
"edit": USER_PERMISSIONS_CHAT_EDIT, "edit": USER_PERMISSIONS_CHAT_EDIT,
"multiple_models": USER_PERMISSIONS_CHAT_MULTIPLE_MODELS,
"temporary": USER_PERMISSIONS_CHAT_TEMPORARY, "temporary": USER_PERMISSIONS_CHAT_TEMPORARY,
"temporary_enforced": USER_PERMISSIONS_CHAT_TEMPORARY_ENFORCED, "temporary_enforced": USER_PERMISSIONS_CHAT_TEMPORARY_ENFORCED,
}, },

View File

@ -88,6 +88,7 @@ class ChatPermissions(BaseModel):
file_upload: bool = True file_upload: bool = True
delete: bool = True delete: bool = True
edit: bool = True edit: bool = True
multiple_models: bool = True
temporary: bool = True temporary: bool = True
temporary_enforced: bool = False temporary_enforced: bool = False

View File

@ -63,6 +63,7 @@
file_upload: true, file_upload: true,
delete: true, delete: true,
edit: true, edit: true,
multiple_models: true,
temporary: true, temporary: true,
temporary_enforced: false temporary_enforced: false
}, },

View File

@ -24,6 +24,7 @@
delete: true, delete: true,
edit: true, edit: true,
file_upload: true, file_upload: true,
multiple_models: true,
temporary: true, temporary: true,
temporary_enforced: false temporary_enforced: false
}, },
@ -272,6 +273,14 @@
<Switch bind:state={permissions.chat.edit} /> <Switch bind:state={permissions.chat.edit} />
</div> </div>
<div class=" flex w-full justify-between my-2 pr-2">
<div class=" self-center text-xs font-medium">
{$i18n.t('Allow Multiple Models in Chat')}
</div>
<Switch bind:state={permissions.chat.multiple_models} />
</div>
<div class=" flex w-full justify-between my-2 pr-2"> <div class=" flex w-full justify-between my-2 pr-2">
<div class=" self-center text-xs font-medium"> <div class=" self-center text-xs font-medium">
{$i18n.t('Allow Temporary Chat')} {$i18n.t('Allow Temporary Chat')}

View File

@ -54,58 +54,60 @@
</div> </div>
</div> </div>
{#if selectedModelIdx === 0} {#if $user?.role === 'admin' || ($user?.permissions?.chat?.multiple_models ?? true)}
<div {#if selectedModelIdx === 0}
class=" self-center mx-1 disabled:text-gray-600 disabled:hover:text-gray-600 -translate-y-[0.5px]" <div
> class=" self-center mx-1 disabled:text-gray-600 disabled:hover:text-gray-600 -translate-y-[0.5px]"
<Tooltip content={$i18n.t('Add Model')}> >
<button <Tooltip content={$i18n.t('Add Model')}>
class=" " <button
{disabled} class=" "
on:click={() => { {disabled}
selectedModels = [...selectedModels, '']; on:click={() => {
}} selectedModels = [...selectedModels, ''];
aria-label="Add Model" }}
> aria-label="Add Model"
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2"
stroke="currentColor"
class="size-3.5"
> >
<path stroke-linecap="round" stroke-linejoin="round" d="M12 6v12m6-6H6" /> <svg
</svg> xmlns="http://www.w3.org/2000/svg"
</button> fill="none"
</Tooltip> viewBox="0 0 24 24"
</div> stroke-width="2"
{:else} stroke="currentColor"
<div class="size-3.5"
class=" self-center mx-1 disabled:text-gray-600 disabled:hover:text-gray-600 -translate-y-[0.5px]" >
> <path stroke-linecap="round" stroke-linejoin="round" d="M12 6v12m6-6H6" />
<Tooltip content={$i18n.t('Remove Model')}> </svg>
<button </button>
{disabled} </Tooltip>
on:click={() => { </div>
selectedModels.splice(selectedModelIdx, 1); {:else}
selectedModels = selectedModels; <div
}} class=" self-center mx-1 disabled:text-gray-600 disabled:hover:text-gray-600 -translate-y-[0.5px]"
aria-label="Remove Model" >
> <Tooltip content={$i18n.t('Remove Model')}>
<svg <button
xmlns="http://www.w3.org/2000/svg" {disabled}
fill="none" on:click={() => {
viewBox="0 0 24 24" selectedModels.splice(selectedModelIdx, 1);
stroke-width="2" selectedModels = selectedModels;
stroke="currentColor" }}
class="size-3" aria-label="Remove Model"
> >
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 12h-15" /> <svg
</svg> xmlns="http://www.w3.org/2000/svg"
</button> fill="none"
</Tooltip> viewBox="0 0 24 24"
</div> stroke-width="2"
stroke="currentColor"
class="size-3"
>
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 12h-15" />
</svg>
</button>
</Tooltip>
</div>
{/if}
{/if} {/if}
</div> </div>
{/each} {/each}