diff --git a/fastapi_modules/fastapi_leaudit/services/impl/homeServiceImpl.py b/fastapi_modules/fastapi_leaudit/services/impl/homeServiceImpl.py index 630c9e0..89d9f01 100644 --- a/fastapi_modules/fastapi_leaudit/services/impl/homeServiceImpl.py +++ b/fastapi_modules/fastapi_leaudit/services/impl/homeServiceImpl.py @@ -30,6 +30,11 @@ class HomeServiceImpl(IHomeService): "/chat-with-llm/chat", "/cross-checking", ) + _DOCUMENT_ENTRY_TARGETS: tuple[str, ...] = ( + "/files/upload", + "/documents", + "/documents/list", + ) def __init__(self) -> None: self.RbacService = RbacServiceImpl() @@ -404,6 +409,9 @@ class HomeServiceImpl(IHomeService): def _isAllowedTargetPath(self, TargetPath: str, AllowedPaths: set[str]) -> bool: """判断首页目标路径是否被当前用户路由树覆盖。""" + if TargetPath in self._DOCUMENT_ENTRY_TARGETS: + return True + if TargetPath in AllowedPaths: return True diff --git a/tests/test_home_entry_visibility.py b/tests/test_home_entry_visibility.py new file mode 100644 index 0000000..a9e3980 --- /dev/null +++ b/tests/test_home_entry_visibility.py @@ -0,0 +1,21 @@ +"""首页入口可见性测试。""" + +from fastapi_modules.fastapi_leaudit.services.impl.homeServiceImpl import HomeServiceImpl + + +def test_document_entry_targets_are_visible_without_file_management_routes(): + """文档类首页入口只受租户配置控制,不因缺少文件管理路由消失。""" + service = HomeServiceImpl() + + assert service._isAllowedTargetPath("/documents", set()) is True + assert service._isAllowedTargetPath("/documents/list", set()) is True + assert service._isAllowedTargetPath("/files/upload", set()) is True + + +def test_non_document_entry_targets_still_require_route_grant(): + """非文档入口仍需要当前用户路由树覆盖。""" + service = HomeServiceImpl() + + assert service._isAllowedTargetPath("/tenants", set()) is False + assert service._isAllowedTargetPath("/cross-checking", set()) is False + assert service._isAllowedTargetPath("/cross-checking", {"/cross-checking"}) is True