Browse Source

refac/enh: chat controls permissions

Timothy Jaeryang Baek 2 months ago
parent
commit
708e0ed05e

+ 10 - 0
backend/open_webui/config.py

@@ -1143,10 +1143,18 @@ USER_PERMISSIONS_CHAT_CONTROLS = (
     os.environ.get("USER_PERMISSIONS_CHAT_CONTROLS", "True").lower() == "true"
 )
 
+USER_PERMISSIONS_CHAT_VALVES = (
+    os.environ.get("USER_PERMISSIONS_CHAT_VALVES", "True").lower() == "true"
+)
+
 USER_PERMISSIONS_CHAT_SYSTEM_PROMPT = (
     os.environ.get("USER_PERMISSIONS_CHAT_SYSTEM_PROMPT", "True").lower() == "true"
 )
 
+USER_PERMISSIONS_CHAT_PARAMS = (
+    os.environ.get("USER_PERMISSIONS_CHAT_PARAMS", "True").lower() == "true"
+)
+
 USER_PERMISSIONS_CHAT_FILE_UPLOAD = (
     os.environ.get("USER_PERMISSIONS_CHAT_FILE_UPLOAD", "True").lower() == "true"
 )
@@ -1232,7 +1240,9 @@ DEFAULT_USER_PERMISSIONS = {
     },
     "chat": {
         "controls": USER_PERMISSIONS_CHAT_CONTROLS,
+        "valves": USER_PERMISSIONS_CHAT_VALVES,
         "system_prompt": USER_PERMISSIONS_CHAT_SYSTEM_PROMPT,
+        "params": USER_PERMISSIONS_CHAT_PARAMS,
         "file_upload": USER_PERMISSIONS_CHAT_FILE_UPLOAD,
         "delete": USER_PERMISSIONS_CHAT_DELETE,
         "edit": USER_PERMISSIONS_CHAT_EDIT,

+ 2 - 0
backend/open_webui/routers/users.py

@@ -134,7 +134,9 @@ class SharingPermissions(BaseModel):
 
 class ChatPermissions(BaseModel):
     controls: bool = True
+    valves: bool = True
     system_prompt: bool = True
+    params: bool = True
     file_upload: bool = True
     delete: bool = True
     edit: bool = True

+ 2 - 0
src/lib/components/admin/Users/Groups.svelte

@@ -66,7 +66,9 @@
 		},
 		chat: {
 			controls: true,
+			valves: true,
 			system_prompt: true,
+			params: true,
 			file_upload: true,
 			delete: true,
 			edit: true,

+ 11 - 1
src/lib/components/admin/Users/Groups/EditGroupModal.svelte

@@ -48,10 +48,20 @@
 		},
 		chat: {
 			controls: true,
+			valves: true,
+			system_prompt: true,
+			params: true,
 			file_upload: true,
 			delete: true,
 			edit: true,
-			temporary: true
+			share: true,
+			export: true,
+			stt: true,
+			tts: true,
+			call: true,
+			multiple_models: true,
+			temporary: true,
+			temporary_enforced: false
 		},
 		features: {
 			direct_tool_servers: false,

+ 19 - 0
src/lib/components/admin/Users/Groups/Permissions.svelte

@@ -21,6 +21,9 @@
 		},
 		chat: {
 			controls: true,
+			valves: true,
+			system_prompt: true,
+			params: true,
 			file_upload: true,
 			delete: true,
 			edit: true,
@@ -263,6 +266,14 @@
 			<Switch bind:state={permissions.chat.controls} />
 		</div>
 
+		<div class="  flex w-full justify-between my-2 pr-2">
+			<div class=" self-center text-xs font-medium">
+				{$i18n.t('Allow Chat Valves')}
+			</div>
+
+			<Switch bind:state={permissions.chat.valves} />
+		</div>
+
 		<div class="  flex w-full justify-between my-2 pr-2">
 			<div class=" self-center text-xs font-medium">
 				{$i18n.t('Allow Chat System Prompt')}
@@ -271,6 +282,14 @@
 			<Switch bind:state={permissions.chat.system_prompt} />
 		</div>
 
+		<div class="  flex w-full justify-between my-2 pr-2">
+			<div class=" self-center text-xs font-medium">
+				{$i18n.t('Allow Chat Params')}
+			</div>
+
+			<Switch bind:state={permissions.chat.params} />
+		</div>
+
 		<div class="  flex w-full justify-between my-2 pr-2">
 			<div class=" self-center text-xs font-medium">
 				{$i18n.t('Allow Chat Delete')}

+ 62 - 58
src/lib/components/chat/Controls/Controls.svelte

@@ -30,70 +30,74 @@
 		</button>
 	</div>
 
-	<div class=" dark:text-gray-200 text-sm font-primary py-0.5 px-0.5">
-		{#if chatFiles.length > 0}
-			<Collapsible title={$i18n.t('Files')} open={true} buttonClassName="w-full">
-				<div class="flex flex-col gap-1 mt-1.5" slot="content">
-					{#each chatFiles as file, fileIdx}
-						<FileItem
-							className="w-full"
-							item={file}
-							edit={true}
-							url={file?.url ? file.url : null}
-							name={file.name}
-							type={file.type}
-							size={file?.size}
-							dismissible={true}
-							on:dismiss={() => {
-								// Remove the file from the chatFiles array
+	{#if $user?.role === 'admin' || ($user?.permissions.chat?.controls ?? true)}
+		<div class=" dark:text-gray-200 text-sm font-primary py-0.5 px-0.5">
+			{#if chatFiles.length > 0}
+				<Collapsible title={$i18n.t('Files')} open={true} buttonClassName="w-full">
+					<div class="flex flex-col gap-1 mt-1.5" slot="content">
+						{#each chatFiles as file, fileIdx}
+							<FileItem
+								className="w-full"
+								item={file}
+								edit={true}
+								url={file?.url ? file.url : null}
+								name={file.name}
+								type={file.type}
+								size={file?.size}
+								dismissible={true}
+								on:dismiss={() => {
+									// Remove the file from the chatFiles array
 
-								chatFiles.splice(fileIdx, 1);
-								chatFiles = chatFiles;
-							}}
-							on:click={() => {
-								console.log(file);
-							}}
-						/>
-					{/each}
-				</div>
-			</Collapsible>
+									chatFiles.splice(fileIdx, 1);
+									chatFiles = chatFiles;
+								}}
+								on:click={() => {
+									console.log(file);
+								}}
+							/>
+						{/each}
+					</div>
+				</Collapsible>
 
-			<hr class="my-2 border-gray-50 dark:border-gray-700/10" />
-		{/if}
+				<hr class="my-2 border-gray-50 dark:border-gray-700/10" />
+			{/if}
 
-		<Collapsible bind:open={showValves} title={$i18n.t('Valves')} buttonClassName="w-full">
-			<div class="text-sm" slot="content">
-				<Valves show={showValves} />
-			</div>
-		</Collapsible>
+			{#if $user?.role === 'admin' || ($user?.permissions.chat?.valves ?? true)}
+				<Collapsible bind:open={showValves} title={$i18n.t('Valves')} buttonClassName="w-full">
+					<div class="text-sm" slot="content">
+						<Valves show={showValves} />
+					</div>
+				</Collapsible>
+			{/if}
 
-		{#if $user?.role === 'admin' || ($user?.permissions.chat?.system_prompt ?? true)}
-			<hr class="my-2 border-gray-50 dark:border-gray-700/10" />
+			{#if $user?.role === 'admin' || ($user?.permissions.chat?.system_prompt ?? true)}
+				<hr class="my-2 border-gray-50 dark:border-gray-700/10" />
 
-			<Collapsible title={$i18n.t('System Prompt')} open={true} buttonClassName="w-full">
-				<div class="" slot="content">
-					<textarea
-						bind:value={params.system}
-						class="w-full text-xs outline-hidden resize-vertical {$settings.highContrastMode
-							? 'border-2 border-gray-300 dark:border-gray-700 rounded-lg bg-gray-50 dark:bg-gray-800 p-2.5'
-							: 'py-1.5 bg-transparent'}"
-						rows="4"
-						placeholder={$i18n.t('Enter system prompt')}
-					/>
-				</div>
-			</Collapsible>
-		{/if}
+				<Collapsible title={$i18n.t('System Prompt')} open={true} buttonClassName="w-full">
+					<div class="" slot="content">
+						<textarea
+							bind:value={params.system}
+							class="w-full text-xs outline-hidden resize-vertical {$settings.highContrastMode
+								? 'border-2 border-gray-300 dark:border-gray-700 rounded-lg bg-gray-50 dark:bg-gray-800 p-2.5'
+								: 'py-1.5 bg-transparent'}"
+							rows="4"
+							placeholder={$i18n.t('Enter system prompt')}
+						/>
+					</div>
+				</Collapsible>
+			{/if}
 
-		{#if $user?.role === 'admin' || ($user?.permissions.chat?.controls ?? true)}
-			<hr class="my-2 border-gray-50 dark:border-gray-700/10" />
+			{#if $user?.role === 'admin' || ($user?.permissions.chat?.params ?? true)}
+				<hr class="my-2 border-gray-50 dark:border-gray-700/10" />
 
-			<Collapsible title={$i18n.t('Advanced Params')} open={true} buttonClassName="w-full">
-				<div class="text-sm mt-1.5" slot="content">
-					<div>
-						<AdvancedParams admin={$user?.role === 'admin'} custom={true} bind:params />
+				<Collapsible title={$i18n.t('Advanced Params')} open={true} buttonClassName="w-full">
+					<div class="text-sm mt-1.5" slot="content">
+						<div>
+							<AdvancedParams admin={$user?.role === 'admin'} custom={true} bind:params />
+						</div>
 					</div>
-				</div>
-			</Collapsible>
-		{/if}
-	</div>
+				</Collapsible>
+			{/if}
+		</div>
+	{/if}
 </div>

+ 15 - 13
src/lib/components/chat/Navbar.svelte

@@ -151,19 +151,21 @@
 						</Menu>
 					{/if}
 
-					<Tooltip content={$i18n.t('Controls')}>
-						<button
-							class=" flex cursor-pointer px-2 py-2 rounded-xl hover:bg-gray-50 dark:hover:bg-gray-850 transition"
-							on:click={async () => {
-								await showControls.set(!$showControls);
-							}}
-							aria-label="Controls"
-						>
-							<div class=" m-auto self-center">
-								<AdjustmentsHorizontal className=" size-5" strokeWidth="0.5" />
-							</div>
-						</button>
-					</Tooltip>
+					{#if $user?.role === 'admin' || ($user?.permissions.chat?.controls ?? true)}
+						<Tooltip content={$i18n.t('Controls')}>
+							<button
+								class=" flex cursor-pointer px-2 py-2 rounded-xl hover:bg-gray-50 dark:hover:bg-gray-850 transition"
+								on:click={async () => {
+									await showControls.set(!$showControls);
+								}}
+								aria-label="Controls"
+							>
+								<div class=" m-auto self-center">
+									<AdjustmentsHorizontal className=" size-5" strokeWidth="0.5" />
+								</div>
+							</button>
+						</Tooltip>
+					{/if}
 
 					{#if $mobile}
 						<Tooltip content={$i18n.t('New Chat')}>