mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-22 21:50:42 -05:00
refac
This commit is contained in:
1 parent
1890952996
commit
f1d735d807
2 files changed
+16
-5
No files matched your search
@@ -2717,6 +2717,7 @@ class ChatTable:
|
||||
self,
|
||||
folder_id: str,
|
||||
user_id: str,
|
||||
folder_write_access: bool = False,
|
||||
skip: int = 0,
|
||||
limit: int = 50,
|
||||
search: str = '',
|
||||
@@ -2879,7 +2880,9 @@ class ChatTable:
|
||||
for key, value in (meta.get('folder_status_durations') or {}).items()
|
||||
if key in valid_status_ids and (seconds := _as_seconds(value))
|
||||
}
|
||||
chat['can_edit_tags'] = chat['can_edit_status'] = chat['user_id'] == user_id
|
||||
# Tags are the owner's own records; status is folder workflow, so folder editors may set it.
|
||||
chat['can_edit_tags'] = chat['user_id'] == user_id
|
||||
chat['can_edit_status'] = folder_write_access or chat['user_id'] == user_id
|
||||
# Only explain matches the title doesn't already show.
|
||||
chat['search_snippet'] = (
|
||||
chat_search_snippet(bodies.get(chat['id']) or {}, search)
|
||||
@@ -2928,17 +2931,20 @@ class ChatTable:
|
||||
result = await session.execute(query, {'folder_id': folder_id})
|
||||
return [dict(row) for row in result.mappings()]
|
||||
|
||||
async def update_chat_folder_status_by_id_and_user_id(
|
||||
self, id: str, folder_id: str, user_id: str, status: str | None, db: AsyncSession | None = None
|
||||
async def update_chat_folder_status_by_id(
|
||||
self, id: str, folder_id: str, user_id: str | None, status: str | None, db: AsyncSession | None = None
|
||||
) -> bool:
|
||||
"""Set (or with None, clear) a chat's folder status, banking the time spent in its previous one.
|
||||
|
||||
Time adds up per status, so moving away and coming back doesn't reset it.
|
||||
A user_id limits this to that user's chats; None allows any chat in the folder.
|
||||
"""
|
||||
async with get_async_db_context(db) as session:
|
||||
row = (
|
||||
await session.execute(
|
||||
select(Chat.meta).filter_by(id=id, folder_id=folder_id, user_id=user_id)
|
||||
select(Chat.meta).filter_by(
|
||||
id=id, folder_id=folder_id, **({'user_id': user_id} if user_id else {})
|
||||
)
|
||||
)
|
||||
).one_or_none()
|
||||
if row is None:
|
||||
|
||||
@@ -628,6 +628,7 @@ async def get_shared_folder_chats(
|
||||
chats, total = await Chats.get_folder_chat_page(
|
||||
id,
|
||||
user.id,
|
||||
folder_write_access=has_write,
|
||||
skip=skip,
|
||||
limit=limit,
|
||||
search=search.strip(),
|
||||
@@ -771,7 +772,11 @@ async def update_folder_chat_status(request: Request, id: str, chat_id: str, for
|
||||
folder = await check_folder_read_access(request, id, user, db)
|
||||
if form_data.status is not None and form_data.status not in folder_status_ids(folder.meta):
|
||||
raise HTTPException(status_code=422, detail='Invalid status')
|
||||
if not await Chats.update_chat_folder_status_by_id_and_user_id(chat_id, id, user.id, form_data.status, db=db):
|
||||
# Folder editors may set status on any chat in the folder; others only on their own.
|
||||
has_write = user.role == 'admin' or folder.user_id == user.id or await _has_folder_access(user.id, folder, 'write', db)
|
||||
if not await Chats.update_chat_folder_status_by_id(
|
||||
chat_id, id, None if has_write else user.id, form_data.status, db=db
|
||||
):
|
||||
raise HTTPException(status_code=403, detail=ERROR_MESSAGES.ACCESS_PROHIBITED)
|
||||
await publish_event(request, EVENTS.CHAT_UPDATED, actor=user, subject_id=chat_id,
|
||||
data={'folder_id': id, 'folder_status': form_data.status})
|
||||
|
||||
Reference in new issue
Block a user