mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-28 16:11:43 -05:00
refac
This commit is contained in:
1 parent
5cc0ed71d6
commit
5f95008abd
33 files changed
+359
-363
No files matched your search
@@ -131,7 +131,7 @@ export const createCalendar = async (token: string, form: CalendarForm): Promise
|
||||
export const updateCalendar = async (
|
||||
token: string,
|
||||
calendarId: string,
|
||||
form: Partial<CalendarForm>
|
||||
form: Partial<Omit<CalendarForm, 'access_grants'>>
|
||||
): Promise<CalendarModel> => {
|
||||
let error = null;
|
||||
|
||||
@@ -142,7 +142,7 @@ export const updateCalendar = async (
|
||||
'Content-Type': 'application/json',
|
||||
authorization: `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify(form)
|
||||
body: JSON.stringify({ ...form, access_grants: undefined })
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
@@ -456,3 +456,36 @@ export const searchCalendarEvents = async (
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
export const updateCalendarAccessGrants = async (
|
||||
token: string,
|
||||
id: string,
|
||||
accessGrants: any[]
|
||||
) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/calendars/${id}/access/update`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
authorization: `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({ access_grants: accessGrants })
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err.detail;
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
@@ -333,7 +333,7 @@ export const removeMembersById = async (
|
||||
export const updateChannelById = async (
|
||||
token: string = '',
|
||||
channel_id: string,
|
||||
channel: ChannelForm
|
||||
channel: Omit<ChannelForm, 'access_grants'>
|
||||
) => {
|
||||
let error = null;
|
||||
|
||||
@@ -344,7 +344,7 @@ export const updateChannelById = async (
|
||||
'Content-Type': 'application/json',
|
||||
authorization: `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({ ...channel })
|
||||
body: JSON.stringify({ ...channel, access_grants: undefined })
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
@@ -1043,3 +1043,32 @@ export const removeAppFromChannel = async (
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
export const updateChannelAccessGrants = async (token: string, id: string, accessGrants: any[]) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/channels/${id}/access/update`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
authorization: `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({ access_grants: accessGrants })
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
error = err.detail;
|
||||
console.error(err);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
@@ -288,7 +288,7 @@ export const updateExternalKnowledgeSource = async (token: string, id: string, p
|
||||
'Content-Type': 'application/json',
|
||||
authorization: `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
body: JSON.stringify({ ...payload, access_grants: undefined })
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
@@ -608,7 +608,6 @@ type KnowledgeUpdateForm = {
|
||||
name?: string;
|
||||
description?: string;
|
||||
data?: object;
|
||||
access_grants?: object[];
|
||||
};
|
||||
|
||||
export const updateKnowledgeById = async (token: string, id: string, form: KnowledgeUpdateForm) => {
|
||||
@@ -624,8 +623,7 @@ export const updateKnowledgeById = async (token: string, id: string, form: Knowl
|
||||
body: JSON.stringify({
|
||||
name: form?.name ? form.name : undefined,
|
||||
description: form?.description ? form.description : undefined,
|
||||
data: form?.data ? form.data : undefined,
|
||||
access_grants: form.access_grants
|
||||
data: form?.data ? form.data : undefined
|
||||
})
|
||||
})
|
||||
.then(async (res) => {
|
||||
|
||||
@@ -326,15 +326,13 @@ export const toggleModelById = async (token: string, id: string) => {
|
||||
export const updateModelById = async (token: string, id: string, model: object) => {
|
||||
let error = null;
|
||||
|
||||
const { base_model_id, name, meta, params, access_grants, is_active, commit_message } =
|
||||
model as any;
|
||||
const { base_model_id, name, meta, params, is_active, commit_message } = model as any;
|
||||
const payload = {
|
||||
id,
|
||||
base_model_id,
|
||||
name,
|
||||
meta,
|
||||
params,
|
||||
access_grants,
|
||||
is_active,
|
||||
commit_message
|
||||
};
|
||||
|
||||
@@ -315,7 +315,11 @@ export const createNoteChatById = async (token: string, id: string) => {
|
||||
return res;
|
||||
};
|
||||
|
||||
export const updateNoteById = async (token: string, id: string, note: NoteItem) => {
|
||||
export const updateNoteById = async (
|
||||
token: string,
|
||||
id: string,
|
||||
note: Omit<NoteItem, 'access_grants'>
|
||||
) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/notes/${id}/update`, {
|
||||
@@ -326,7 +330,8 @@ export const updateNoteById = async (token: string, id: string, note: NoteItem)
|
||||
authorization: `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
...note
|
||||
...note,
|
||||
access_grants: undefined
|
||||
})
|
||||
})
|
||||
.then(async (res) => {
|
||||
|
||||
@@ -262,7 +262,10 @@ export const getPromptById = async (token: string, promptId: string) => {
|
||||
return res;
|
||||
};
|
||||
|
||||
export const updatePromptById = async (token: string, prompt: PromptItem) => {
|
||||
export const updatePromptById = async (
|
||||
token: string,
|
||||
prompt: Omit<PromptItem, 'access_grants'>
|
||||
) => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_API_BASE_URL}/prompts/id/${prompt.id}/update`, {
|
||||
@@ -272,7 +275,7 @@ export const updatePromptById = async (token: string, prompt: PromptItem) => {
|
||||
'Content-Type': 'application/json',
|
||||
authorization: `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify(prompt)
|
||||
body: JSON.stringify({ ...prompt, access_grants: undefined })
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
|
||||
@@ -217,7 +217,8 @@ export const updateSkillById = async (token: string, id: string, skill: object)
|
||||
authorization: `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
...skill
|
||||
...skill,
|
||||
access_grants: undefined
|
||||
})
|
||||
})
|
||||
.then(async (res) => {
|
||||
|
||||
@@ -214,7 +214,8 @@ export const updateToolById = async (token: string, id: string, tool: object) =>
|
||||
authorization: `Bearer ${token}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
...tool
|
||||
...tool,
|
||||
access_grants: undefined
|
||||
})
|
||||
})
|
||||
.then(async (res) => {
|
||||
|
||||
@@ -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