mirror of
https://github.com/open-webui/open-webui.git
synced 2026-12-05 11:07:55 -05:00
refac
This commit is contained in:
1 parent
5cc0ed71d6
commit
5f95008abd
33 files changed
+359
-363
No files matched your search
@@ -20,7 +20,8 @@
|
||||
searchKnowledgeBases,
|
||||
testExternalKnowledgeSource,
|
||||
updateExternalKnowledgeConnection,
|
||||
updateExternalKnowledgeSource
|
||||
updateExternalKnowledgeSource,
|
||||
updateKnowledgeAccessGrants
|
||||
} from '$lib/apis/knowledge';
|
||||
import SettingsSelect from '$lib/components/common/SettingsSelect.svelte';
|
||||
|
||||
@@ -173,7 +174,7 @@
|
||||
tableName: sourceConfig.table_name ?? defaults.tableName,
|
||||
collectionField: sourceConfig.collection_field ?? defaults.collectionField
|
||||
};
|
||||
accessGrants = item.access_grants ?? [];
|
||||
accessGrants = structuredClone(item.access_grants ?? []);
|
||||
showSourceModal = true;
|
||||
};
|
||||
|
||||
@@ -352,7 +353,6 @@
|
||||
description: sourceForm.description,
|
||||
connection: connectionPayload(),
|
||||
source: sourcePayload(),
|
||||
access_grants: accessGrants,
|
||||
test_query: sourceForm.testQuery,
|
||||
test_count: 5
|
||||
}).catch((error) => {
|
||||
@@ -773,6 +773,22 @@
|
||||
share={true}
|
||||
sharePublic={true}
|
||||
shareUsers={true}
|
||||
onChange={async () => {
|
||||
if (editingItem) {
|
||||
try {
|
||||
await updateKnowledgeAccessGrants(
|
||||
localStorage.token,
|
||||
editingItem.id,
|
||||
accessGrants
|
||||
);
|
||||
editingItem.access_grants = structuredClone(accessGrants);
|
||||
toast.success($i18n.t('Saved'));
|
||||
} catch (error) {
|
||||
accessGrants = structuredClone(editingItem.access_grants ?? []);
|
||||
toast.error(`${error}`);
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
<div class="flex justify-between items-center pt-3 text-sm font-normal">
|
||||
|
||||
@@ -58,11 +58,10 @@
|
||||
edit={true}
|
||||
{onUpdate}
|
||||
onSubmit={async (payload: any) => {
|
||||
const { name, is_private, access_grants, group_ids, user_ids } = payload ?? {};
|
||||
const { name, is_private, group_ids, user_ids } = payload ?? {};
|
||||
const res = await updateChannelById(localStorage.token, channel.id, {
|
||||
name,
|
||||
is_private,
|
||||
access_grants,
|
||||
group_ids,
|
||||
user_ids
|
||||
}).catch((error) => {
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
<script lang="ts">
|
||||
import { getContext, createEventDispatcher, onMount } from 'svelte';
|
||||
const i18n = getContext('i18n');
|
||||
const i18n = getContext<any>('i18n');
|
||||
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { page } from '$app/stores';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
import { createNewChannel, deleteChannelById } from '$lib/apis/channels';
|
||||
import {
|
||||
createNewChannel,
|
||||
deleteChannelById,
|
||||
updateChannelAccessGrants
|
||||
} from '$lib/apis/channels';
|
||||
import { user } from '$lib/stores';
|
||||
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
@@ -31,7 +35,7 @@
|
||||
let name = '';
|
||||
|
||||
let isPrivate = null;
|
||||
let accessGrants = [];
|
||||
let accessGrants: any[] = [];
|
||||
|
||||
let groupIds = [];
|
||||
let userIds = [];
|
||||
@@ -66,7 +70,7 @@
|
||||
type: type,
|
||||
name: name.replace(/\s/g, '-'),
|
||||
is_private: type === 'group' ? (isPrivate ?? true) : null,
|
||||
access_grants: type === '' ? accessGrants : [],
|
||||
...(!edit ? { access_grants: type === '' ? accessGrants : [] } : {}),
|
||||
group_ids: groupIds,
|
||||
user_ids: userIds
|
||||
});
|
||||
@@ -90,7 +94,7 @@
|
||||
} else {
|
||||
isPrivate = null;
|
||||
}
|
||||
accessGrants = channel?.access_grants ?? [];
|
||||
accessGrants = structuredClone(channel?.access_grants ?? []);
|
||||
userIds = channel?.user_ids ?? [];
|
||||
}
|
||||
};
|
||||
@@ -237,7 +241,27 @@
|
||||
{#if type !== 'dm'}
|
||||
<div class="-mx-2 mb-1 mt-2.5 px-2">
|
||||
{#if type === ''}
|
||||
<AccessControl bind:accessGrants accessRoles={['read', 'write']} />
|
||||
<AccessControl
|
||||
bind:accessGrants
|
||||
accessRoles={['read', 'write']}
|
||||
onChange={async () => {
|
||||
if (edit && channel?.id) {
|
||||
try {
|
||||
await updateChannelAccessGrants(
|
||||
localStorage.token,
|
||||
channel.id,
|
||||
accessGrants
|
||||
);
|
||||
channel.access_grants = structuredClone(accessGrants);
|
||||
toast.success($i18n.t('Saved'));
|
||||
onUpdate();
|
||||
} catch (error) {
|
||||
accessGrants = structuredClone(channel.access_grants ?? []);
|
||||
toast.error(`${error}`);
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{:else if type === 'group'}
|
||||
<Visibility
|
||||
state={isPrivate ? 'private' : 'public'}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import { getLanguages } from '$lib/i18n';
|
||||
import {
|
||||
getBaseModelTags,
|
||||
updateModelAccessGrants,
|
||||
getModelTags,
|
||||
type ModelHistoryEntry,
|
||||
type ModelSnapshot
|
||||
@@ -230,7 +231,7 @@
|
||||
let builtinTools = {};
|
||||
|
||||
let actionIds = [];
|
||||
let accessGrants = [];
|
||||
let accessGrants: any[] = [];
|
||||
let terminalId = '';
|
||||
$: hasTerminal =
|
||||
$config?.features?.enable_terminal_servers || $config?.features?.enable_direct_integrations;
|
||||
@@ -397,7 +398,8 @@
|
||||
|
||||
modelInfo.params = { ...modelInfo.params, ...params };
|
||||
|
||||
modelInfo.access_grants = accessGrants;
|
||||
if (edit) delete modelInfo.access_grants;
|
||||
else modelInfo.access_grants = accessGrants;
|
||||
modelInfo.meta.capabilities = capabilities;
|
||||
|
||||
if (enableDescription) {
|
||||
@@ -838,6 +840,18 @@
|
||||
shareUsers={($user?.permissions?.access_grants?.allow_users ?? true) || $user?.role === 'admin'}
|
||||
allowGroups={($user?.permissions?.access_grants?.allow_groups ?? true) ||
|
||||
$user?.role === 'admin'}
|
||||
onChange={async () => {
|
||||
if (edit && model?.id) {
|
||||
try {
|
||||
await updateModelAccessGrants(localStorage.token, model.id, model.name, accessGrants);
|
||||
model.access_grants = structuredClone(accessGrants);
|
||||
toast.success($i18n.t('Saved'));
|
||||
} catch (error) {
|
||||
accessGrants = structuredClone(model.access_grants ?? []);
|
||||
toast.error(`${error}`);
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
<div class="flex h-full min-h-0 w-full flex-col">
|
||||
|
||||
@@ -239,7 +239,7 @@
|
||||
command,
|
||||
content,
|
||||
tags: tags.map((tag) => tag.name),
|
||||
access_grants: accessGrants,
|
||||
...(!edit ? { access_grants: accessGrants } : {}),
|
||||
commit_message: commitMessage || undefined,
|
||||
is_production: production
|
||||
});
|
||||
|
||||
@@ -252,7 +252,7 @@ class Tools:
|
||||
name,
|
||||
meta: { ...meta, i18n: pruneEmptyLocaleEntries(meta.i18n) },
|
||||
content,
|
||||
access_grants: accessGrants
|
||||
...(!edit ? { access_grants: accessGrants } : {})
|
||||
});
|
||||
if (saved) {
|
||||
if (saved.version_id && saved.content !== undefined) await applyProduction(saved);
|
||||
|
||||
Reference in new issue
Block a user