From 00d7299fad6e5838644e66dd2b7a0e1c8553c10a Mon Sep 17 00:00:00 2001 From: Christopher Ostrouchov Date: Wed, 20 Oct 2021 15:12:38 -0400 Subject: [PATCH] Fix 191 to only show non-deleted environments/namespaces (#194) * Make builds, environments, and namespaces conditionally show up * Wrong SQL logic for NULL values in columns * Black formatting --- conda-store-server/conda_store_server/api.py | 16 +++++++++++++--- .../conda_store_server/server/views/api.py | 10 +++++++--- .../conda_store_server/server/views/ui.py | 12 +++++++++--- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/conda-store-server/conda_store_server/api.py b/conda-store-server/conda_store_server/api.py index 08125dec2..1466f7d1f 100644 --- a/conda-store-server/conda_store_server/api.py +++ b/conda-store-server/conda_store_server/api.py @@ -1,13 +1,16 @@ from typing import List -from sqlalchemy import func +from sqlalchemy import func, null from conda_store_server import orm from .conda import conda_platform -def list_namespaces(db): +def list_namespaces(db, show_soft_deleted: bool = False): filters = [] + if not show_soft_deleted: + filters.append(orm.Namespace.deleted_on == null()) + return db.query(orm.Namespace).filter(*filters) @@ -35,6 +38,7 @@ def list_environments( db, namespace: str = None, search: str = None, + show_soft_deleted: bool = False, ): filters = [] if namespace: @@ -43,6 +47,9 @@ def list_environments( if search: filters.append(orm.Environment.name.contains(search, autoescape=True)) + if not show_soft_deleted: + filters.append(orm.Environment.deleted_on == null()) + return db.query(orm.Environment).join(orm.Environment.namespace).filter(*filters) @@ -81,11 +88,14 @@ def post_specification(conda_store, specification, namespace=None): conda_store.register_environment(specification, namespace) -def list_builds(db, status: orm.BuildStatus = None): +def list_builds(db, status: orm.BuildStatus = None, show_soft_deleted: bool = False): filters = [] if status: filters.append(orm.Build.status == status) + if not show_soft_deleted: + filters.append(orm.Build.deleted_on == null()) + return db.query(orm.Build).filter(*filters) diff --git a/conda-store-server/conda_store_server/server/views/api.py b/conda-store-server/conda_store_server/server/views/api.py index 832473fed..8c42018c6 100644 --- a/conda-store-server/conda_store_server/server/views/api.py +++ b/conda-store-server/conda_store_server/server/views/api.py @@ -106,7 +106,9 @@ def api_list_namespaces(): conda_store = get_conda_store() auth = get_auth() - orm_namespaces = auth.filter_namespaces(api.list_namespaces(conda_store.db)) + orm_namespaces = auth.filter_namespaces( + api.list_namespaces(conda_store.db, show_soft_deleted=False) + ) return paginated_api_response( orm_namespaces, schema.Namespace, @@ -176,7 +178,7 @@ def api_list_environments(): search = request.args.get("search") orm_environments = auth.filter_environments( - api.list_environments(conda_store.db, search=search) + api.list_environments(conda_store.db, search=search, show_soft_deleted=False) ) return paginated_api_response( orm_environments, @@ -284,7 +286,9 @@ def api_list_builds(): conda_store = get_conda_store() auth = get_auth() - orm_builds = auth.filter_builds(api.list_builds(conda_store.db)) + orm_builds = auth.filter_builds( + api.list_builds(conda_store.db, show_soft_deleted=True) + ) return paginated_api_response( orm_builds, schema.Build, diff --git a/conda-store-server/conda_store_server/server/views/ui.py b/conda-store-server/conda_store_server/server/views/ui.py index 0a68d0301..301c70ba3 100644 --- a/conda-store-server/conda_store_server/server/views/ui.py +++ b/conda-store-server/conda_store_server/server/views/ui.py @@ -22,7 +22,9 @@ def ui_create_get_environment(): conda_store = get_conda_store() auth = get_auth() - orm_namespaces = auth.filter_namespaces(api.list_namespaces(conda_store.db)) + orm_namespaces = auth.filter_namespaces( + api.list_namespaces(conda_store.db, show_soft_deleted=False) + ) context = { "namespaces": orm_namespaces.all(), @@ -63,7 +65,9 @@ def ui_list_environments(): server = get_server() auth = get_auth() - orm_environments = auth.filter_environments(api.list_environments(conda_store.db)) + orm_environments = auth.filter_environments( + api.list_environments(conda_store.db, show_soft_deleted=False) + ) context = { "environments": orm_environments.all(), @@ -79,7 +83,9 @@ def ui_list_namespaces(): conda_store = get_conda_store() auth = get_auth() - orm_namespaces = auth.filter_namespaces(api.list_namespaces(conda_store.db)) + orm_namespaces = auth.filter_namespaces( + api.list_namespaces(conda_store.db, show_soft_deleted=False) + ) context = { "namespaces": orm_namespaces.all(),