fix: harden WeKnora knowledge permissions and details

This commit is contained in:
吉鑫升 committed 2026-08-12 15:45:28 +08:00
1 parent e0c09f6704
commit b4d076a2d4
20 files changed
+1713 -298

No files matched your search

@@ -24,6 +24,15 @@ class LlmWikiStore(ABC):
@abstractmethod
async def update_mapping(self, mapping_id: str, *, name: str | None = None, description: str | None = None) -> dict[str, Any] | None: ...
@abstractmethod
async def adopt_conversation_deposit_mapping(
self,
mapping_id: str,
*,
name: str,
description: str,
) -> dict[str, Any] | None: ...
@abstractmethod
async def delete_mapping(self, mapping_id: str) -> bool: ...
@@ -76,6 +76,31 @@ class MemoryLlmWikiStore(LlmWikiStore):
row["updated_at"] = _now()
return dict(row)
async def adopt_conversation_deposit_mapping(
self,
mapping_id: str,
*,
name: str,
description: str,
) -> dict[str, Any] | None:
row = self._rows.get(mapping_id)
if row is None:
return None
now = _now()
row.update(
{
"owner_user_id": "system",
"name": name,
"description": description,
"publication_status": "published",
"published_by": "system",
"reviewed_by": None,
"published_at": row.get("published_at") or now,
"updated_at": now,
}
)
return dict(row)
async def delete_mapping(self, mapping_id: str) -> bool:
return self._rows.pop(mapping_id, None) is not None
@@ -118,7 +143,11 @@ class MemoryLlmWikiStore(LlmWikiStore):
async def get_conversation_deposit_mapping(self) -> dict[str, Any] | None:
for row in self._rows.values():
if row.get("name") == "对话沉淀" and row.get("publication_status") == "published":
if (
row.get("owner_user_id") == "system"
and row.get("name") == "对话沉淀"
and row.get("publication_status") == "published"
):
return dict(row)
return None
@@ -95,6 +95,29 @@ class LlmWikiRepository(LlmWikiStore):
await session.commit()
return _to_dict(row)
async def adopt_conversation_deposit_mapping(
self,
mapping_id: str,
*,
name: str,
description: str,
) -> dict[str, Any] | None:
async with self._sf() as session:
row = await session.get(LlmWikiKnowledgeBaseRow, mapping_id)
if row is None:
return None
now = _now()
row.owner_user_id = "system"
row.name = name
row.description = description
row.publication_status = "published"
row.published_by = "system"
row.reviewed_by = None
row.published_at = row.published_at or now
row.updated_at = now
await session.commit()
return _to_dict(row)
async def delete_mapping(self, mapping_id: str) -> bool:
async with self._sf() as session:
row = await session.get(LlmWikiKnowledgeBaseRow, mapping_id)
@@ -155,6 +178,7 @@ class LlmWikiRepository(LlmWikiStore):
stmt = (
select(LlmWikiKnowledgeBaseRow)
.where(
LlmWikiKnowledgeBaseRow.owner_user_id == "system",
LlmWikiKnowledgeBaseRow.name == "对话沉淀",
LlmWikiKnowledgeBaseRow.publication_status == "published",
)