mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-15 05:45:19 +00:00
Optimize chats.py
Fixed null pointer exceptions and permission validation in the delete_chat_by_id function, enhancing error handling and robustness.
This commit is contained in:
parent
6f1486ffd0
commit
365db5770e
1 changed files with 16 additions and 11 deletions
|
|
@ -568,13 +568,15 @@ async def send_chat_message_event_by_id(
|
||||||
async def delete_chat_by_id(request: Request, id: str, user=Depends(get_verified_user)):
|
async def delete_chat_by_id(request: Request, id: str, user=Depends(get_verified_user)):
|
||||||
if user.role == "admin":
|
if user.role == "admin":
|
||||||
chat = Chats.get_chat_by_id(id)
|
chat = Chats.get_chat_by_id(id)
|
||||||
for tag in chat.meta.get("tags", []):
|
if chat:
|
||||||
if Chats.count_chats_by_tag_name_and_user_id(tag, user.id) == 1:
|
for tag in chat.meta.get("tags", []):
|
||||||
Tags.delete_tag_by_name_and_user_id(tag, user.id)
|
if Chats.count_chats_by_tag_name_and_user_id(tag, user.id) == 1:
|
||||||
|
Tags.delete_tag_by_name_and_user_id(tag, user.id)
|
||||||
|
|
||||||
result = Chats.delete_chat_by_id(id)
|
result = Chats.delete_chat_by_id(id)
|
||||||
|
return result
|
||||||
return result
|
else:
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
if not has_permission(
|
if not has_permission(
|
||||||
user.id, "chat.delete", request.app.state.config.USER_PERMISSIONS
|
user.id, "chat.delete", request.app.state.config.USER_PERMISSIONS
|
||||||
|
|
@ -584,12 +586,15 @@ async def delete_chat_by_id(request: Request, id: str, user=Depends(get_verified
|
||||||
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
||||||
)
|
)
|
||||||
|
|
||||||
chat = Chats.get_chat_by_id(id)
|
chat = Chats.get_chat_by_id_and_user_id(id, user.id)
|
||||||
for tag in chat.meta.get("tags", []):
|
if chat:
|
||||||
if Chats.count_chats_by_tag_name_and_user_id(tag, user.id) == 1:
|
for tag in chat.meta.get("tags", []):
|
||||||
Tags.delete_tag_by_name_and_user_id(tag, user.id)
|
if Chats.count_chats_by_tag_name_and_user_id(tag, user.id) == 1:
|
||||||
|
Tags.delete_tag_by_name_and_user_id(tag, user.id)
|
||||||
|
|
||||||
result = Chats.delete_chat_by_id_and_user_id(id, user.id)
|
result = Chats.delete_chat_by_id_and_user_id(id, user.id)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue