refactor(api): avoid DSL export for catalog membership

This commit is contained in:
hjlarry 2026-08-14 21:27:28 +08:00
parent e04b991d33
commit 4917eca691
3 changed files with 21 additions and 6 deletions

View File

@ -79,8 +79,20 @@ class DatabaseRecommendedAppCatalogRepository(RecommendedAppCatalogQuery):
@override
def contains(self, app_id: str) -> bool:
# Preserve the legacy database membership check, including DSL export.
return self.get_detail(app_id) is not None
with self._session_factory() as session:
return (
session.scalar(
select(RecommendedApp.app_id)
.join(App, App.id == RecommendedApp.app_id)
.where(
RecommendedApp.app_id == app_id,
RecommendedApp.is_listed.is_(True),
App.is_public.is_(True),
)
.limit(1)
)
is not None
)
@staticmethod
def _list_rows(

View File

@ -83,7 +83,7 @@ def test_list_maps_postgres_models_with_owned_session(
assert no_site_app.id not in {item.app_id for item in page.recommended_apps}
def test_detail_and_membership_export_with_owned_session(
def test_membership_does_not_export_dsl_with_owned_session(
db_session_with_containers: Session,
) -> None:
app = _add_catalog_app(db_session_with_containers, with_site=False)
@ -110,4 +110,4 @@ def test_detail_and_membership_export_with_owned_session(
export_data="exported_yaml",
)
assert is_in_catalog is True
assert mock_export_dsl.call_count == 2
mock_export_dsl.assert_called_once()

View File

@ -152,7 +152,7 @@ def test_list_learn_dify_filters_flag_and_hides_page_categories(
assert page.categories == ()
def test_detail_and_membership_preserve_dsl_export(
def test_membership_does_not_export_dsl(
sqlite_session_factory: sessionmaker[Session],
) -> None:
with sqlite_session_factory() as session:
@ -175,7 +175,7 @@ def test_detail_and_membership_preserve_dsl_export(
export_data="exported yaml",
)
assert is_in_catalog is True
assert export_dsl.call_count == 2
export_dsl.assert_called_once()
def test_detail_rejects_unlisted_or_private_apps(sqlite_session_factory: sessionmaker[Session]) -> None:
@ -189,6 +189,9 @@ def test_detail_rejects_unlisted_or_private_apps(sqlite_session_factory: session
assert repository.get_detail(private_app.id) is None
assert repository.get_detail(unlisted_app.id) is None
assert repository.get_detail(missing_app_id) is None
assert repository.contains(private_app.id) is False
assert repository.contains(unlisted_app.id) is False
assert repository.contains(missing_app_id) is False
def test_detail_does_not_require_site(sqlite_session_factory: sessionmaker[Session]) -> None: