Skip to content

Commit 4632f20

Browse files
committed
refac
1 parent 9d3e063 commit 4632f20

4 files changed

Lines changed: 59 additions & 0 deletions

File tree

backend/open_webui/routers/models.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ async def create_new_model(
196196
)
197197

198198
else:
199+
form_data.access_grants = filter_allowed_access_grants(
200+
request.app.state.config.USER_PERMISSIONS,
201+
user.id,
202+
user.role,
203+
form_data.access_grants,
204+
'sharing.public_models',
205+
)
206+
199207
model = Models.insert_new_model(form_data, user.id, db=db)
200208
if model:
201209
return model
@@ -460,6 +468,7 @@ async def toggle_model_by_id(id: str, user=Depends(get_verified_user), db: Sessi
460468

461469
@router.post('/model/update', response_model=Optional[ModelModel])
462470
async def update_model_by_id(
471+
request: Request,
463472
form_data: ModelForm,
464473
user=Depends(get_verified_user),
465474
db: Session = Depends(get_session),
@@ -487,6 +496,14 @@ async def update_model_by_id(
487496
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
488497
)
489498

499+
form_data.access_grants = filter_allowed_access_grants(
500+
request.app.state.config.USER_PERMISSIONS,
501+
user.id,
502+
user.role,
503+
form_data.access_grants,
504+
'sharing.public_models',
505+
)
506+
490507
model = Models.update_model_by_id(form_data.id, ModelForm(**form_data.model_dump()), db=db)
491508
return model
492509

backend/open_webui/routers/notes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ async def create_new_note(
175175
detail=ERROR_MESSAGES.UNAUTHORIZED,
176176
)
177177

178+
form_data.access_grants = filter_allowed_access_grants(
179+
request.app.state.config.USER_PERMISSIONS,
180+
user.id,
181+
user.role,
182+
form_data.access_grants,
183+
'sharing.public_notes',
184+
db=db,
185+
)
186+
178187
try:
179188
note = Notes.insert_new_note(user.id, form_data, db=db)
180189
return note

backend/open_webui/routers/prompts.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ async def create_new_prompt(
168168
detail=ERROR_MESSAGES.UNAUTHORIZED,
169169
)
170170

171+
form_data.access_grants = filter_allowed_access_grants(
172+
request.app.state.config.USER_PERMISSIONS,
173+
user.id,
174+
user.role,
175+
form_data.access_grants,
176+
'sharing.public_prompts',
177+
)
178+
171179
prompt = Prompts.get_prompt_by_command(form_data.command, db=db)
172180
if prompt is None:
173181
prompt = Prompts.insert_new_prompt(user.id, form_data, db=db)
@@ -275,6 +283,7 @@ async def get_prompt_by_id(prompt_id: str, user=Depends(get_verified_user), db:
275283

276284
@router.post('/id/{prompt_id}/update', response_model=Optional[PromptModel])
277285
async def update_prompt_by_id(
286+
request: Request,
278287
prompt_id: str,
279288
form_data: PromptForm,
280289
user=Depends(get_verified_user),
@@ -314,6 +323,14 @@ async def update_prompt_by_id(
314323
detail=f"Command '/{form_data.command}' is already in use by another prompt",
315324
)
316325

326+
form_data.access_grants = filter_allowed_access_grants(
327+
request.app.state.config.USER_PERMISSIONS,
328+
user.id,
329+
user.role,
330+
form_data.access_grants,
331+
'sharing.public_prompts',
332+
)
333+
317334
# Use the ID from the found prompt
318335
updated_prompt = Prompts.update_prompt_by_id(prompt.id, form_data, user.id, db=db)
319336
if updated_prompt:

backend/open_webui/routers/tools.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,14 @@ async def create_new_tools(
354354
tools = Tools.get_tool_by_id(form_data.id, db=db)
355355
if tools is None:
356356
try:
357+
form_data.access_grants = filter_allowed_access_grants(
358+
request.app.state.config.USER_PERMISSIONS,
359+
user.id,
360+
user.role,
361+
form_data.access_grants,
362+
'sharing.public_tools',
363+
)
364+
357365
form_data.content = replace_imports(form_data.content)
358366
tool_module, frontmatter = load_tool_module_by_id(form_data.id, content=form_data.content)
359367
form_data.meta.manifest = frontmatter
@@ -481,6 +489,14 @@ async def update_tools_by_id(
481489

482490
specs = get_tool_specs(TOOLS[id])
483491

492+
form_data.access_grants = filter_allowed_access_grants(
493+
request.app.state.config.USER_PERMISSIONS,
494+
user.id,
495+
user.role,
496+
form_data.access_grants,
497+
'sharing.public_tools',
498+
)
499+
484500
updated = {
485501
**form_data.model_dump(exclude={'id'}),
486502
'specs': specs,

0 commit comments

Comments
 (0)