mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 01:50:44 +08:00
fix(chat): allow administrator to delete channel-only sessions
Align administrator session deletion with the administrator chat view so sessions surfaced through channel_session_v2 can be removed without a ui_session_owner row. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
4f36f4a36f
commit
e3828418d4
5 changed files with 93 additions and 4 deletions
|
|
@ -60,6 +60,7 @@ class AssistantStoreProtocol(Protocol):
|
|||
def delete_memory_item(self, *, memory_id: 'str') -> 'int': ...
|
||||
def delete_message(self, *, session_id: 'str', message_id: 'int') -> 'bool': ...
|
||||
def delete_session(self, session_id: 'str') -> 'None': ...
|
||||
def delete_session_for_administrator_chat_view(self, *, session_id: 'str', username: 'str', tenant_id: 'str') -> 'bool': ...
|
||||
def delete_session_for_user(self, *, session_id: 'str', tenant_id: 'str', user_id: 'str') -> 'bool': ...
|
||||
def delete_session_in_tenant(self, *, session_id: 'str', tenant_id: 'str') -> 'bool': ...
|
||||
def delete_setting(self, key: 'str') -> 'None': ...
|
||||
|
|
|
|||
|
|
@ -614,6 +614,31 @@ class ChatSessionsSaRepository:
|
|||
conn.execute(delete(chat_session).where(chat_session.c.id == sid))
|
||||
return True
|
||||
|
||||
def try_delete_chat_session_for_administrator_chat_view(
|
||||
self, *, session_id: str, username: str, tenant_id: str
|
||||
) -> bool:
|
||||
sid = str(session_id or "").strip()
|
||||
if not sid:
|
||||
return False
|
||||
ids = self._administrator_chat_session_ids_subquery(
|
||||
username=username,
|
||||
tenant_id=tenant_id,
|
||||
)
|
||||
with self._engine.begin() as conn:
|
||||
chk = conn.execute(
|
||||
select(1)
|
||||
.select_from(chat_session)
|
||||
.where(
|
||||
chat_session.c.id == sid,
|
||||
chat_session.c.id.in_(select(ids.c.sid)),
|
||||
)
|
||||
.limit(1)
|
||||
).first()
|
||||
if not chk:
|
||||
return False
|
||||
conn.execute(delete(chat_session).where(chat_session.c.id == sid))
|
||||
return True
|
||||
|
||||
def try_delete_chat_session_for_tenant(self, *, session_id: str, tenant_id: str) -> bool:
|
||||
sid, tid = str(session_id or "").strip(), str(tenant_id)
|
||||
if not sid:
|
||||
|
|
|
|||
|
|
@ -1666,6 +1666,15 @@ class SqliteStore(ScheduledJobStoreMixin):
|
|||
session_id=session_id, username=username, tenant_id=tenant_id
|
||||
)
|
||||
|
||||
def delete_session_for_administrator_chat_view(
|
||||
self, *, session_id: str, username: str, tenant_id: str
|
||||
) -> bool:
|
||||
return self._chat_sessions_repo().try_delete_chat_session_for_administrator_chat_view(
|
||||
session_id=session_id,
|
||||
username=username,
|
||||
tenant_id=tenant_id,
|
||||
)
|
||||
|
||||
def get_session_for_administrator_username(
|
||||
self, *, session_id: str, username: str
|
||||
) -> Optional[ChatSession]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue