Skip to content

Commit

Permalink
Fix 191 to only show non-deleted environments/namespaces (#194)
Browse files Browse the repository at this point in the history
* Make builds, environments, and namespaces conditionally show up

* Wrong SQL logic for NULL values in columns

* Black formatting
  • Loading branch information
costrouc authored Oct 20, 2021
1 parent 0f25a65 commit 00d7299
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
16 changes: 13 additions & 3 deletions conda-store-server/conda_store_server/api.py
Original file line number Diff line number Diff line change
@@ -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)


Expand Down Expand Up @@ -35,6 +38,7 @@ def list_environments(
db,
namespace: str = None,
search: str = None,
show_soft_deleted: bool = False,
):
filters = []
if namespace:
Expand All @@ -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)


Expand Down Expand Up @@ -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)


Expand Down
10 changes: 7 additions & 3 deletions conda-store-server/conda_store_server/server/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 9 additions & 3 deletions conda-store-server/conda_store_server/server/views/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand 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(),
Expand Down

0 comments on commit 00d7299

Please sign in to comment.