fix: restore rag chat permission feedback

This commit is contained in:
wren
2026-05-22 15:36:13 +08:00
parent 9434f2b22b
commit d52b1cfdb9
5 changed files with 258 additions and 4 deletions
@@ -1,3 +1,5 @@
"""RAG 知识库服务实现。"""
from __future__ import annotations
import asyncio
@@ -42,6 +44,8 @@ from fastapi_modules.fastapi_leaudit.services.impl.tenantResolver import TenantR
class RagDatasetServiceImpl(IRagDatasetService):
"""RAG 知识库服务实现。"""
_ACTIVE_INDEXING_STATUSES = {"waiting", "parsing", "cleaning", "splitting", "indexing"}
_DELETABLE_DOCUMENT_STATUSES = {"completed", "error", "paused"}
_APP_LINK_SQL = """
@@ -295,7 +299,32 @@ class RagDatasetServiceImpl(IRagDatasetService):
if target_is_default:
await self._clear_default_flags(session, tenant_code=resolved_tenant_code)
elif existing.get("is_default") and Body.get("is_default") is False:
raise LeauditException(StatusCodeEnum.HTTP_400_BAD_REQUEST, "默认知识库不能直接取消,请先将其他知识库设为默认")
normalized_tenant_code = str(resolved_tenant_code or "").strip()
default_filters = [
"deleted_at IS NULL",
"is_default = TRUE",
"id <> :dataset_id",
]
default_params = {"dataset_id": DatasetId}
if normalized_tenant_code:
default_filters.append("tenant_code = :tenant_code")
default_params["tenant_code"] = normalized_tenant_code
else:
default_filters.append("(tenant_code IS NULL OR BTRIM(tenant_code) = '')")
other_default_count = (
await session.execute(
text(
f"""
SELECT COUNT(1)
FROM rag_dataset
WHERE {" AND ".join(default_filters)}
"""
),
default_params,
)
).scalar_one()
if int(other_default_count or 0) <= 0:
raise LeauditException(StatusCodeEnum.HTTP_400_BAD_REQUEST, "默认知识库不能直接取消,请先将其他知识库设为默认")
await session.execute(
text(
"""