From b80ec764354fdf66a23c5cb036a708ecb1c88dc5 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 14 Nov 2024 20:51:49 -0800 Subject: [PATCH] refac --- backend/open_webui/config.py | 26 ++--- backend/open_webui/main.py | 5 - src/lib/components/admin/Users/Groups.svelte | 84 ++++++---------- .../admin/Users/Groups/EditGroupModal.svelte | 43 +++++--- .../admin/Users/Groups/GroupItem.svelte | 43 +++++++- .../admin/Users/Groups/Permissions.svelte | 98 +++++++------------ .../admin/Users/Groups/Users.svelte | 24 +---- 7 files changed, 145 insertions(+), 178 deletions(-) diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index 83efa89fa..4362eae0b 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -739,12 +739,12 @@ DEFAULT_USER_ROLE = PersistentConfig( os.getenv("DEFAULT_USER_ROLE", "pending"), ) -USER_PERMISSIONS_CHAT_DELETION = ( - os.environ.get("USER_PERMISSIONS_CHAT_DELETION", "True").lower() == "true" +USER_PERMISSIONS_CHAT_DELETE = ( + os.environ.get("USER_PERMISSIONS_CHAT_DELETE", "True").lower() == "true" ) -USER_PERMISSIONS_CHAT_EDITING = ( - os.environ.get("USER_PERMISSIONS_CHAT_EDITING", "True").lower() == "true" +USER_PERMISSIONS_CHAT_EDIT = ( + os.environ.get("USER_PERMISSIONS_CHAT_EDIT", "True").lower() == "true" ) USER_PERMISSIONS_CHAT_TEMPORARY = ( @@ -753,11 +753,11 @@ USER_PERMISSIONS_CHAT_TEMPORARY = ( USER_PERMISSIONS = PersistentConfig( "USER_PERMISSIONS", - "ui.user_permissions", + "user.permissions", { "chat": { - "deletion": USER_PERMISSIONS_CHAT_DELETION, - "editing": USER_PERMISSIONS_CHAT_EDITING, + "deletion": USER_PERMISSIONS_CHAT_DELETE, + "editing": USER_PERMISSIONS_CHAT_EDIT, "temporary": USER_PERMISSIONS_CHAT_TEMPORARY, } }, @@ -785,18 +785,6 @@ DEFAULT_ARENA_MODEL = { }, } -ENABLE_MODEL_FILTER = PersistentConfig( - "ENABLE_MODEL_FILTER", - "model_filter.enable", - os.environ.get("ENABLE_MODEL_FILTER", "False").lower() == "true", -) -MODEL_FILTER_LIST = os.environ.get("MODEL_FILTER_LIST", "") -MODEL_FILTER_LIST = PersistentConfig( - "MODEL_FILTER_LIST", - "model_filter.list", - [model.strip() for model in MODEL_FILTER_LIST.split(";")], -) - WEBHOOK_URL = PersistentConfig( "WEBHOOK_URL", "webhook_url", os.environ.get("WEBHOOK_URL", "") ) diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 353a1198f..faef9e81c 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -70,13 +70,11 @@ from open_webui.config import ( DEFAULT_LOCALE, ENABLE_ADMIN_CHAT_ACCESS, ENABLE_ADMIN_EXPORT, - ENABLE_MODEL_FILTER, ENABLE_OLLAMA_API, ENABLE_OPENAI_API, ENABLE_TAGS_GENERATION, ENV, FRONTEND_BUILD_DIR, - MODEL_FILTER_LIST, OAUTH_PROVIDERS, ENABLE_SEARCH_QUERY, SEARCH_QUERY_GENERATION_PROMPT_TEMPLATE, @@ -194,9 +192,6 @@ app.state.config = AppConfig() app.state.config.ENABLE_OPENAI_API = ENABLE_OPENAI_API app.state.config.ENABLE_OLLAMA_API = ENABLE_OLLAMA_API -app.state.config.ENABLE_MODEL_FILTER = ENABLE_MODEL_FILTER -app.state.config.MODEL_FILTER_LIST = MODEL_FILTER_LIST - app.state.config.WEBHOOK_URL = WEBHOOK_URL app.state.config.TASK_MODEL = TASK_MODEL diff --git a/src/lib/components/admin/Users/Groups.svelte b/src/lib/components/admin/Users/Groups.svelte index 7e3977755..ff78169b3 100644 --- a/src/lib/components/admin/Users/Groups.svelte +++ b/src/lib/components/admin/Users/Groups.svelte @@ -48,69 +48,38 @@ let showCreateGroupModal = false; let showDefaultPermissionsModal = false; + const setGroups = async () => { + groups = await getGroups(localStorage.token); + }; + + const addGroupHandler = async (group) => { + const res = await createNewGroup(localStorage.token, group).catch((error) => { + toast.error(error); + return null; + }); + + if (res) { + toast.success($i18n.t('Group created successfully')); + groups = await getGroups(localStorage.token); + } + }; + + const updateDefaultPermissionsHandler = async (permissions) => { + console.log(permissions); + }; + onMount(async () => { if ($user?.role !== 'admin') { await goto('/'); } else { - groups = await getGroups(localStorage.token); - - // [ - // { - // id: '1', - // name: 'Group A', - // description: 'Group A description', - // permissions: { - // model: { - // enable_filter: false, // boolean - // ids: [], // array of strings - // default_id: null // null or string - // }, - // workspace: { - // models: false, // boolean - // knowledge: false, // boolean - // prompts: false // boolean - // }, - // chat: { - // delete: true, // boolean - // edit: true, // boolean - // temporary: true // boolean - // } - // }, - // user_ids: ['1', '2', '3'], // array of strings - // admin_ids: ['1'] // array of strings - // }, - // { - // id: '2', - // name: 'Moderators', - // description: 'Moderators description', - // permissions: { - // model: { - // enable_filter: false, // boolean - // ids: [], // array of strings - // default_id: null // null or string - // }, - // workspace: { - // models: false, // boolean - // knowledge: false, // boolean - // prompts: false // boolean - // }, - // chat: { - // delete: true, // boolean - // edit: true, // boolean - // temporary: true // boolean - // } - // }, - // user_ids: ['1', '5', '6'], // array of strings - // admin_ids: ['1'] // array of strings - // } - // ]; + await setGroups(); } loaded = true; }); {#if loaded} - +
{$i18n.t('Groups')} @@ -196,7 +165,7 @@ {#each filteredGroups as group}
- +
{/each}
@@ -204,7 +173,12 @@
- +
diff --git a/src/lib/components/admin/Users/Groups/GroupItem.svelte b/src/lib/components/admin/Users/Groups/GroupItem.svelte index 6204fa691..1cc6223ec 100644 --- a/src/lib/components/admin/Users/Groups/GroupItem.svelte +++ b/src/lib/components/admin/Users/Groups/GroupItem.svelte @@ -1,7 +1,13 @@ - +
diff --git a/src/lib/components/admin/Users/Groups/Permissions.svelte b/src/lib/components/admin/Users/Groups/Permissions.svelte index 6db005c11..45cf3e993 100644 --- a/src/lib/components/admin/Users/Groups/Permissions.svelte +++ b/src/lib/components/admin/Users/Groups/Permissions.svelte @@ -3,34 +3,25 @@ const i18n = getContext('i18n'); import Switch from '$lib/components/common/Switch.svelte'; - import { models } from '$lib/stores'; - import Minus from '$lib/components/icons/Minus.svelte'; - import Plus from '$lib/components/icons/Plus.svelte'; + import Tooltip from '$lib/components/common/Tooltip.svelte'; - export let permissions = {}; - export let custom = true; - - let defaultModelId = ''; - - let selectedModelId = ''; - - let filterEnabled = false; - let filterMode = 'include'; - let filterModelIds = []; - - let workspaceModelsAccess = false; - let workspaceKnowledgeAccess = false; - let workspacePromptsAccess = false; - let workspaceToolsAccess = false; - let workspaceFunctionsAccess = false; - - let chatDeletion = true; - let chatEdit = true; - let chatTemporary = true; + export let permissions = { + workspace: { + models: false, + knowledge: false, + prompts: false, + tools: false + }, + chat: { + delete: true, + edit: true, + temporary: true + } + };
-
+
{$i18n.t('Workspace Permissions')}
- {#if custom} - {$i18n.t('Admins')}: - {/if} {$i18n.t('Models Access')}
- +
- {#if custom} - {$i18n.t('Admins')}: - {/if} - {$i18n.t('Knowledge Access')}
- +
- {#if custom} - {$i18n.t('Admins')}: - {/if} - {$i18n.t('Prompts Access')}
- +
-

@@ -185,35 +170,26 @@
- {#if custom} - {$i18n.t('Members')}: - {/if} - {$i18n.t('Allow Chat Deletion')} + {$i18n.t('Allow Chat Delete')}
- +
- {#if custom} - {$i18n.t('Members')}: - {/if} - {$i18n.t('Allow Chat Editing')} + {$i18n.t('Allow Chat Edit')}
- +
- {#if custom} - {$i18n.t('Members')}: - {/if} {$i18n.t('Allow Temporary Chat')}
- +
diff --git a/src/lib/components/admin/Users/Groups/Users.svelte b/src/lib/components/admin/Users/Groups/Users.svelte index 68f8831c7..22f9877ab 100644 --- a/src/lib/components/admin/Users/Groups/Users.svelte +++ b/src/lib/components/admin/Users/Groups/Users.svelte @@ -10,7 +10,6 @@ export let users = []; export let userIds = []; - export let adminIds = []; let filteredUsers = []; @@ -30,16 +29,10 @@ ); }) .sort((a, b) => { - const aIsAdmin = adminIds.includes(a.id); - const bIsAdmin = adminIds.includes(b.id); const aUserIndex = userIds.indexOf(a.id); const bUserIndex = userIds.indexOf(b.id); - // Admin users should come first - if (aIsAdmin && !bIsAdmin) return -1; // Place 'a' first if it's admin - if (!aIsAdmin && bIsAdmin) return 1; // Place 'b' first if it's admin - - // Neither are admin, compare based on userIds or fall back to alphabetical order + // Compare based on userIds or fall back to alphabetical order if (aUserIndex !== -1 && bUserIndex === -1) return -1; // 'a' has valid userId -> prioritize if (bUserIndex !== -1 && aUserIndex === -1) return 1; // 'b' has valid userId -> prioritize @@ -114,20 +107,7 @@ {#if userIds.includes(user.id)} - + {/if}