From 1111a3a222f387afa39722606c6bb94ed1c1d946 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 25 Jun 2026 03:26:07 +0100 Subject: [PATCH] refac --- backend/open_webui/routers/pipelines.py | 29 ++++++++++++ backend/open_webui/routers/skills.py | 47 ++++++++++++++++++- src/lib/apis/folders/index.ts | 6 +-- .../admin/Analytics/Dashboard.svelte | 4 +- .../admin/Users/Groups/Permissions.svelte | 1 - .../channel/Messages/Message.svelte | 4 +- 6 files changed, 77 insertions(+), 14 deletions(-) diff --git a/backend/open_webui/routers/pipelines.py b/backend/open_webui/routers/pipelines.py index 7eb578bc4e..3f50d23f86 100644 --- a/backend/open_webui/routers/pipelines.py +++ b/backend/open_webui/routers/pipelines.py @@ -18,6 +18,7 @@ from fastapi import ( from open_webui.config import CACHE_DIR from open_webui.constants import ERROR_MESSAGES from open_webui.env import AIOHTTP_CLIENT_SESSION_SSL +from open_webui.events import EVENTS, publish_event from open_webui.models.config import Config from open_webui.routers.openai import get_all_models_responses from open_webui.utils.auth import get_admin_user @@ -262,6 +263,13 @@ async def upload_pipeline( response.raise_for_status() data = await response.json() + await publish_event( + request, + EVENTS.PIPELINE_UPLOADED, + actor=user, + subject_id=data.get('id') or filename, + data={'url_idx': urlIdx, 'filename': filename}, + ) return {**data} except Exception as e: # Handle connection error here @@ -311,6 +319,13 @@ async def add_pipeline(request: Request, form_data: AddPipelineForm, user=Depend response.raise_for_status() data = await response.json() + await publish_event( + request, + EVENTS.PIPELINE_ADDED, + actor=user, + subject_id=data.get('id') or form_data.url, + data={'url_idx': urlIdx, 'url': form_data.url}, + ) return {**data} except Exception as e: # Handle connection error here @@ -354,6 +369,13 @@ async def delete_pipeline(request: Request, form_data: DeletePipelineForm, user= response.raise_for_status() data = await response.json() + await publish_event( + request, + EVENTS.PIPELINE_DELETED, + actor=user, + subject_id=form_data.id, + data={'url_idx': urlIdx}, + ) return {**data} except Exception as e: # Handle connection error here @@ -389,6 +411,13 @@ async def get_pipelines(request: Request, urlIdx: Optional[int] = None, user=Dep response.raise_for_status() data = await response.json() + await publish_event( + request, + EVENTS.PIPELINE_VALVES_UPDATED, + actor=user, + subject_id=pipeline_id, + data={'url_idx': urlIdx}, + ) return {**data} except Exception as e: # Handle connection error here diff --git a/backend/open_webui/routers/skills.py b/backend/open_webui/routers/skills.py index ae6c210e29..064529abae 100644 --- a/backend/open_webui/routers/skills.py +++ b/backend/open_webui/routers/skills.py @@ -4,6 +4,7 @@ from typing import Optional from fastapi import APIRouter, Depends, HTTPException, Request, status from open_webui.config import BYPASS_ADMIN_ACCESS_CONTROL from open_webui.constants import ERROR_MESSAGES +from open_webui.events import EVENTS, publish_event from open_webui.internal.db import get_async_session from open_webui.models.access_grants import AccessGrants from open_webui.models.config import Config @@ -190,6 +191,13 @@ async def create_new_skill( try: skill = await Skills.insert_new_skill(user.id, form_data, db=db) if skill: + await publish_event( + request, + EVENTS.SKILL_CREATED, + actor=user, + subject_id=skill.id, + data={'name': skill.name}, + ) return skill else: raise HTTPException( @@ -308,6 +316,13 @@ async def update_skill_by_id( skill = await Skills.update_skill_by_id(id, updated, db=db) if skill: + await publish_event( + request, + EVENTS.SKILL_UPDATED, + actor=user, + subject_id=skill.id, + data={'name': skill.name}, + ) return skill else: raise HTTPException( @@ -371,7 +386,15 @@ async def update_skill_access_by_id( await AccessGrants.set_access_grants('skill', id, form_data.access_grants, db=db) - return await Skills.get_skill_by_id(id, db=db) + skill = await Skills.get_skill_by_id(id, db=db) + await publish_event( + request, + EVENTS.SKILL_UPDATED, + actor=user, + subject_id=id, + data={'access_updated': True, 'name': skill.name if skill else None}, + ) + return skill ############################ @@ -380,7 +403,12 @@ async def update_skill_access_by_id( @router.post('/id/{id}/toggle', response_model=Optional[SkillModel]) -async def toggle_skill_by_id(id: str, user=Depends(get_verified_user), db: AsyncSession = Depends(get_async_session)): +async def toggle_skill_by_id( + request: Request, + id: str, + user=Depends(get_verified_user), + db: AsyncSession = Depends(get_async_session), +): skill = await Skills.get_skill_by_id(id, db=db) if skill: if ( @@ -397,6 +425,13 @@ async def toggle_skill_by_id(id: str, user=Depends(get_verified_user), db: Async skill = await Skills.toggle_skill_by_id(id, db=db) if skill: + await publish_event( + request, + EVENTS.SKILL_ENABLED if skill.is_active else EVENTS.SKILL_DISABLED, + actor=user, + subject_id=skill.id, + data={'name': skill.name}, + ) return skill else: raise HTTPException( @@ -451,4 +486,12 @@ async def delete_skill_by_id( ) result = await Skills.delete_skill_by_id(id, db=db) + if result: + await publish_event( + request, + EVENTS.SKILL_DELETED, + actor=user, + subject_id=id, + data={'name': skill.name}, + ) return result diff --git a/src/lib/apis/folders/index.ts b/src/lib/apis/folders/index.ts index cd63d4d2e0..b79e588947 100644 --- a/src/lib/apis/folders/index.ts +++ b/src/lib/apis/folders/index.ts @@ -235,11 +235,7 @@ export const deleteFolderById = async (token: string, id: string, deleteContents return res; }; -export const updateFolderAccessById = async ( - token: string, - id: string, - accessGrants: any[] -) => { +export const updateFolderAccessById = async (token: string, id: string, accessGrants: any[]) => { let error = null; const res = await fetch(`${WEBUI_API_BASE_URL}/folders/${id}/access/update`, { diff --git a/src/lib/components/admin/Analytics/Dashboard.svelte b/src/lib/components/admin/Analytics/Dashboard.svelte index d94dd4ee79..009ccf2744 100644 --- a/src/lib/components/admin/Analytics/Dashboard.svelte +++ b/src/lib/components/admin/Analytics/Dashboard.svelte @@ -59,9 +59,7 @@ case 'custom': { // Parse YYYY-MM-DD inputs; end date is inclusive (covers the full day) const start = customStart ? Math.floor(new Date(customStart).getTime() / 1000) : null; - const end = customEnd - ? Math.floor(new Date(customEnd).getTime() / 1000) + day - 1 - : null; + const end = customEnd ? Math.floor(new Date(customEnd).getTime() / 1000) + day - 1 : null; return { start, end }; } default: diff --git a/src/lib/components/admin/Users/Groups/Permissions.svelte b/src/lib/components/admin/Users/Groups/Permissions.svelte index 2443531e71..5180b1a240 100644 --- a/src/lib/components/admin/Users/Groups/Permissions.svelte +++ b/src/lib/components/admin/Users/Groups/Permissions.svelte @@ -409,7 +409,6 @@ {/if} - {#if permissions.chat.share}
diff --git a/src/lib/components/channel/Messages/Message.svelte b/src/lib/components/channel/Messages/Message.svelte index 13cf310d65..5bcbaece5a 100644 --- a/src/lib/components/channel/Messages/Message.svelte +++ b/src/lib/components/channel/Messages/Message.svelte @@ -320,9 +320,7 @@