This commit is contained in:
Timothy Jaeryang Baek committed 2026-06-25 03:31:45 +01:00
1 parent 35f8bf97e3
commit b5c43968db
32 files changed
+2251 -120

No files matched your search

+64 -4
View File
@@ -20,6 +20,7 @@ from fastapi import (
from fastapi.responses import RedirectResponse, StreamingResponse
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.env import ENABLE_PROFILE_IMAGE_URL_FORWARDING, PROFILE_IMAGE_ALLOWED_MIME_TYPES
from open_webui.internal.db import get_async_session
from open_webui.models.access_grants import AccessGrants
@@ -268,6 +269,13 @@ async def create_new_model(
model = await Models.insert_new_model(form_data, user.id, db=db)
if model:
await publish_event(
request,
EVENTS.MODEL_CREATED,
actor=user,
subject_id=model.id,
data={'name': model.name},
)
return model
else:
raise HTTPException(
@@ -360,10 +368,12 @@ async def import_models(
else:
writable_model_ids = set(existing_model_ids)
imported_ids = []
for model_data in data:
model_id = model_data.get('id')
if model_id and is_valid_model_id(model_id):
imported_ids.append(model_id)
# Defense-in-depth: skip models referencing inaccessible files
try:
await _verify_knowledge_file_access(
@@ -424,6 +434,13 @@ async def import_models(
'sharing.public_models',
)
await Models.insert_new_model(user_id=user.id, form_data=new_model, db=db)
await publish_event(
request,
EVENTS.MODEL_IMPORTED,
actor=user,
subject_type='model',
data={'count': len(imported_ids), 'model_ids': imported_ids},
)
return True
else:
raise HTTPException(status_code=400, detail='Invalid JSON format')
@@ -448,7 +465,15 @@ async def sync_models(
user=Depends(get_admin_user),
db: AsyncSession = Depends(get_async_session),
):
return await Models.sync_models(user.id, form_data.models, db=db)
models = await Models.sync_models(user.id, form_data.models, db=db)
await publish_event(
request,
EVENTS.MODEL_SYNCED,
actor=user,
subject_type='model',
data={'count': len(models), 'model_ids': [model.id for model in models]},
)
return models
###########################
@@ -596,7 +621,9 @@ async def get_model_profile_image(
@router.post('/model/toggle', response_model=ModelResponse | None)
async def toggle_model_by_id(id: str, user=Depends(get_verified_user), db: AsyncSession = Depends(get_async_session)):
async def toggle_model_by_id(
request: Request, id: str, user=Depends(get_verified_user), db: AsyncSession = Depends(get_async_session)
):
model = await Models.get_model_by_id(id, db=db)
if model:
if (
@@ -613,6 +640,13 @@ async def toggle_model_by_id(id: str, user=Depends(get_verified_user), db: Async
model = await Models.toggle_model_by_id(id, db=db)
if model:
await publish_event(
request,
EVENTS.MODEL_ENABLED if model.is_active else EVENTS.MODEL_DISABLED,
actor=user,
subject_id=model.id, subject_type='model',
data={'name': model.name},
)
return model
else:
raise HTTPException(
@@ -682,6 +716,14 @@ async def update_model_by_id(
)
model = await Models.update_model_by_id(form_data.id, ModelForm(**form_data.model_dump()), db=db)
if model:
await publish_event(
request,
EVENTS.MODEL_UPDATED,
actor=user,
subject_id=model.id,
data={'name': model.name},
)
return model
@@ -757,7 +799,14 @@ async def update_model_access_by_id(
await Models.update_model_updated_at_by_id(form_data.id, db=db)
return await Models.get_model_by_id(form_data.id, db=db)
model = await Models.get_model_by_id(form_data.id, db=db)
await publish_event(
request,
EVENTS.MODEL_ACCESS_UPDATED,
actor=user,
subject_id=form_data.id,
)
return model
############################
@@ -767,6 +816,7 @@ async def update_model_access_by_id(
@router.post('/model/delete', response_model=bool)
async def delete_model_by_id(
request: Request,
form_data: ModelIdForm,
user=Depends(get_verified_user),
db: AsyncSession = Depends(get_async_session),
@@ -795,10 +845,20 @@ async def delete_model_by_id(
)
result = await Models.delete_model_by_id(form_data.id, db=db)
if result:
await publish_event(
request,
EVENTS.MODEL_DELETED,
actor=user,
subject_id=form_data.id,
data={'name': model.name},
)
return result
@router.delete('/delete/all', response_model=bool)
async def delete_all_models(user=Depends(get_admin_user), db: AsyncSession = Depends(get_async_session)):
async def delete_all_models(request: Request, user=Depends(get_admin_user), db: AsyncSession = Depends(get_async_session)):
result = await Models.delete_all_models(db=db)
if result:
await publish_event(request, EVENTS.MODEL_DELETED, actor=user, subject_type='model')
return result