mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-11 20:05:19 +00:00
refac: folder delete logic
This commit is contained in:
parent
91a9f32904
commit
b8086c5edf
2 changed files with 18 additions and 8 deletions
|
|
@ -943,6 +943,16 @@ class ChatTable:
|
||||||
|
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
def count_chats_by_folder_id_and_user_id(self, folder_id: str, user_id: str) -> int:
|
||||||
|
with get_db() as db:
|
||||||
|
query = db.query(Chat).filter_by(user_id=user_id)
|
||||||
|
|
||||||
|
query = query.filter_by(folder_id=folder_id)
|
||||||
|
count = query.count()
|
||||||
|
|
||||||
|
log.info(f"Count of chats for folder '{folder_id}': {count}")
|
||||||
|
return count
|
||||||
|
|
||||||
def delete_tag_by_id_and_user_id_and_tag_name(
|
def delete_tag_by_id_and_user_id_and_tag_name(
|
||||||
self, id: str, user_id: str, tag_name: str
|
self, id: str, user_id: str, tag_name: str
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
|
|
||||||
|
|
@ -262,15 +262,15 @@ async def update_folder_is_expanded_by_id(
|
||||||
async def delete_folder_by_id(
|
async def delete_folder_by_id(
|
||||||
request: Request, id: str, user=Depends(get_verified_user)
|
request: Request, id: str, user=Depends(get_verified_user)
|
||||||
):
|
):
|
||||||
chat_delete_permission = has_permission(
|
if Chats.count_chats_by_folder_id_and_user_id(id, user.id):
|
||||||
user.id, "chat.delete", request.app.state.config.USER_PERMISSIONS
|
chat_delete_permission = has_permission(
|
||||||
)
|
user.id, "chat.delete", request.app.state.config.USER_PERMISSIONS
|
||||||
|
|
||||||
if user.role != "admin" and not chat_delete_permission:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_403_FORBIDDEN,
|
|
||||||
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
|
||||||
)
|
)
|
||||||
|
if user.role != "admin" and not chat_delete_permission:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_403_FORBIDDEN,
|
||||||
|
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
||||||
|
)
|
||||||
|
|
||||||
folder = Folders.get_folder_by_id_and_user_id(id, user.id)
|
folder = Folders.get_folder_by_id_and_user_id(id, user.id)
|
||||||
if folder:
|
if folder:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue