From 147bd0717df886be8c7a6a424efabe93a6db41e6 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 15 Nov 2024 03:02:08 -0800 Subject: [PATCH] refac --- backend/open_webui/apps/webui/routers/models.py | 2 +- src/lib/components/workspace/Models.svelte | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/backend/open_webui/apps/webui/routers/models.py b/backend/open_webui/apps/webui/routers/models.py index 906defb76..86b8515fd 100644 --- a/backend/open_webui/apps/webui/routers/models.py +++ b/backend/open_webui/apps/webui/routers/models.py @@ -116,7 +116,7 @@ async def delete_model_by_id(id: str, user=Depends(get_verified_user)): detail=ERROR_MESSAGES.NOT_FOUND, ) - if model.user_id != user.id: + if model.user_id != user.id and user.role != "admin": raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail=ERROR_MESSAGES.UNAUTHORIZED, diff --git a/src/lib/components/workspace/Models.svelte b/src/lib/components/workspace/Models.svelte index c44587895..d7adc5628 100644 --- a/src/lib/components/workspace/Models.svelte +++ b/src/lib/components/workspace/Models.svelte @@ -28,6 +28,7 @@ import GarbageBin from '../icons/GarbageBin.svelte'; import Search from '../icons/Search.svelte'; import Plus from '../icons/Plus.svelte'; + import { get } from 'svelte/store'; let shiftKey = false; @@ -51,13 +52,17 @@ let searchValue = ''; const deleteModelHandler = async (model) => { - const res = await deleteModelById(localStorage.token, model.id); + const res = await deleteModelById(localStorage.token, model.id).catch((e) => { + toast.error(e); + return null; + }); + if (res) { toast.success($i18n.t(`Deleted {{name}}`, { name: model.id })); } await _models.set(await getModels(localStorage.token)); - models = $_models; + models = await getWorkspaceModels(localStorage.token); }; const cloneModelHandler = async (model) => { @@ -123,7 +128,7 @@ } await _models.set(await getModels(localStorage.token)); - models = $_models; + models = await getWorkspaceModels(localStorage.token); }; const downloadModels = async (models) => { @@ -431,7 +436,7 @@ } await _models.set(await getModels(localStorage.token)); - models = $_models; + models = await getWorkspaceModels(localStorage.token); }; reader.readAsText(importFiles[0]);