Skip to content

Commit 1111a3a

Browse files
committed
refac
1 parent f812072 commit 1111a3a

6 files changed

Lines changed: 77 additions & 14 deletions

File tree

backend/open_webui/routers/pipelines.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from open_webui.config import CACHE_DIR
1919
from open_webui.constants import ERROR_MESSAGES
2020
from open_webui.env import AIOHTTP_CLIENT_SESSION_SSL
21+
from open_webui.events import EVENTS, publish_event
2122
from open_webui.models.config import Config
2223
from open_webui.routers.openai import get_all_models_responses
2324
from open_webui.utils.auth import get_admin_user
@@ -262,6 +263,13 @@ async def upload_pipeline(
262263
response.raise_for_status()
263264
data = await response.json()
264265

266+
await publish_event(
267+
request,
268+
EVENTS.PIPELINE_UPLOADED,
269+
actor=user,
270+
subject_id=data.get('id') or filename,
271+
data={'url_idx': urlIdx, 'filename': filename},
272+
)
265273
return {**data}
266274
except Exception as e:
267275
# Handle connection error here
@@ -311,6 +319,13 @@ async def add_pipeline(request: Request, form_data: AddPipelineForm, user=Depend
311319
response.raise_for_status()
312320
data = await response.json()
313321

322+
await publish_event(
323+
request,
324+
EVENTS.PIPELINE_ADDED,
325+
actor=user,
326+
subject_id=data.get('id') or form_data.url,
327+
data={'url_idx': urlIdx, 'url': form_data.url},
328+
)
314329
return {**data}
315330
except Exception as e:
316331
# Handle connection error here
@@ -354,6 +369,13 @@ async def delete_pipeline(request: Request, form_data: DeletePipelineForm, user=
354369
response.raise_for_status()
355370
data = await response.json()
356371

372+
await publish_event(
373+
request,
374+
EVENTS.PIPELINE_DELETED,
375+
actor=user,
376+
subject_id=form_data.id,
377+
data={'url_idx': urlIdx},
378+
)
357379
return {**data}
358380
except Exception as e:
359381
# Handle connection error here
@@ -389,6 +411,13 @@ async def get_pipelines(request: Request, urlIdx: Optional[int] = None, user=Dep
389411
response.raise_for_status()
390412
data = await response.json()
391413

414+
await publish_event(
415+
request,
416+
EVENTS.PIPELINE_VALVES_UPDATED,
417+
actor=user,
418+
subject_id=pipeline_id,
419+
data={'url_idx': urlIdx},
420+
)
392421
return {**data}
393422
except Exception as e:
394423
# Handle connection error here

backend/open_webui/routers/skills.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from fastapi import APIRouter, Depends, HTTPException, Request, status
55
from open_webui.config import BYPASS_ADMIN_ACCESS_CONTROL
66
from open_webui.constants import ERROR_MESSAGES
7+
from open_webui.events import EVENTS, publish_event
78
from open_webui.internal.db import get_async_session
89
from open_webui.models.access_grants import AccessGrants
910
from open_webui.models.config import Config
@@ -190,6 +191,13 @@ async def create_new_skill(
190191
try:
191192
skill = await Skills.insert_new_skill(user.id, form_data, db=db)
192193
if skill:
194+
await publish_event(
195+
request,
196+
EVENTS.SKILL_CREATED,
197+
actor=user,
198+
subject_id=skill.id,
199+
data={'name': skill.name},
200+
)
193201
return skill
194202
else:
195203
raise HTTPException(
@@ -308,6 +316,13 @@ async def update_skill_by_id(
308316
skill = await Skills.update_skill_by_id(id, updated, db=db)
309317

310318
if skill:
319+
await publish_event(
320+
request,
321+
EVENTS.SKILL_UPDATED,
322+
actor=user,
323+
subject_id=skill.id,
324+
data={'name': skill.name},
325+
)
311326
return skill
312327
else:
313328
raise HTTPException(
@@ -371,7 +386,15 @@ async def update_skill_access_by_id(
371386

372387
await AccessGrants.set_access_grants('skill', id, form_data.access_grants, db=db)
373388

374-
return await Skills.get_skill_by_id(id, db=db)
389+
skill = await Skills.get_skill_by_id(id, db=db)
390+
await publish_event(
391+
request,
392+
EVENTS.SKILL_UPDATED,
393+
actor=user,
394+
subject_id=id,
395+
data={'access_updated': True, 'name': skill.name if skill else None},
396+
)
397+
return skill
375398

376399

377400
############################
@@ -380,7 +403,12 @@ async def update_skill_access_by_id(
380403

381404

382405
@router.post('/id/{id}/toggle', response_model=Optional[SkillModel])
383-
async def toggle_skill_by_id(id: str, user=Depends(get_verified_user), db: AsyncSession = Depends(get_async_session)):
406+
async def toggle_skill_by_id(
407+
request: Request,
408+
id: str,
409+
user=Depends(get_verified_user),
410+
db: AsyncSession = Depends(get_async_session),
411+
):
384412
skill = await Skills.get_skill_by_id(id, db=db)
385413
if skill:
386414
if (
@@ -397,6 +425,13 @@ async def toggle_skill_by_id(id: str, user=Depends(get_verified_user), db: Async
397425
skill = await Skills.toggle_skill_by_id(id, db=db)
398426

399427
if skill:
428+
await publish_event(
429+
request,
430+
EVENTS.SKILL_ENABLED if skill.is_active else EVENTS.SKILL_DISABLED,
431+
actor=user,
432+
subject_id=skill.id,
433+
data={'name': skill.name},
434+
)
400435
return skill
401436
else:
402437
raise HTTPException(
@@ -451,4 +486,12 @@ async def delete_skill_by_id(
451486
)
452487

453488
result = await Skills.delete_skill_by_id(id, db=db)
489+
if result:
490+
await publish_event(
491+
request,
492+
EVENTS.SKILL_DELETED,
493+
actor=user,
494+
subject_id=id,
495+
data={'name': skill.name},
496+
)
454497
return result

src/lib/apis/folders/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,7 @@ export const deleteFolderById = async (token: string, id: string, deleteContents
235235
return res;
236236
};
237237

238-
export const updateFolderAccessById = async (
239-
token: string,
240-
id: string,
241-
accessGrants: any[]
242-
) => {
238+
export const updateFolderAccessById = async (token: string, id: string, accessGrants: any[]) => {
243239
let error = null;
244240

245241
const res = await fetch(`${WEBUI_API_BASE_URL}/folders/${id}/access/update`, {

src/lib/components/admin/Analytics/Dashboard.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@
5959
case 'custom': {
6060
// Parse YYYY-MM-DD inputs; end date is inclusive (covers the full day)
6161
const start = customStart ? Math.floor(new Date(customStart).getTime() / 1000) : null;
62-
const end = customEnd
63-
? Math.floor(new Date(customEnd).getTime() / 1000) + day - 1
64-
: null;
62+
const end = customEnd ? Math.floor(new Date(customEnd).getTime() / 1000) + day - 1 : null;
6563
return { start, end };
6664
}
6765
default:

src/lib/components/admin/Users/Groups/Permissions.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@
409409
{/if}
410410
</div>
411411

412-
413412
{#if permissions.chat.share}
414413
<div class="flex flex-col w-full">
415414
<div class="flex w-full justify-between my-1">

src/lib/components/channel/Messages/Message.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,7 @@
320320
<button
321321
class="ml-12 flex items-center space-x-2 relative z-0"
322322
on:click={() => {
323-
const messageElement = document.getElementById(
324-
`message-${replyToMessageId}`
325-
);
323+
const messageElement = document.getElementById(`message-${replyToMessageId}`);
326324
if (messageElement) {
327325
messageElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
328326
messageElement.classList.add('highlight');

0 commit comments

Comments
 (0)