Skip to content

Commit

Permalink
Added namespace query parameter to /api/v1/environment/?namespace=... (
Browse files Browse the repository at this point in the history
…#324)

Closes #323
  • Loading branch information
costrouc authored Jun 21, 2022
1 parent 3e4c84a commit 1ce38dc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
14 changes: 12 additions & 2 deletions conda-store-server/conda_store_server/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List
import re

from sqlalchemy import func, null
from sqlalchemy import func, null, or_

from conda_store_server import orm, schema
from conda_store_server.conda import conda_platform
Expand Down Expand Up @@ -46,15 +46,25 @@ def delete_namespace(db, name: str = None, id: int = None):
def list_environments(
db,
namespace: str = None,
name: str = None,
search: str = None,
show_soft_deleted: bool = False,
):
filters = []

if namespace:
filters.append(orm.Namespace.name == namespace)

if name:
filters.append(orm.Environment.name == name)

if search:
filters.append(orm.Environment.name.contains(search, autoescape=True))
filters.append(
or_(
orm.Namespace.name.contains(search, autoescape=True),
orm.Environment.name.contains(search, autoescape=True),
)
)

if not show_soft_deleted:
filters.append(orm.Environment.deleted_on == null())
Expand Down
10 changes: 9 additions & 1 deletion conda-store-server/conda_store_server/server/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,22 @@ def api_delete_namespace(
)
def api_list_environments(
search: Optional[str] = None,
namespace: Optional[str] = None,
name: Optional[str] = None,
conda_store=Depends(dependencies.get_conda_store),
auth=Depends(dependencies.get_auth),
entity=Depends(dependencies.get_entity),
paginated_args=Depends(get_paginated_args),
):
orm_environments = auth.filter_environments(
entity,
api.list_environments(conda_store.db, search=search, show_soft_deleted=False),
api.list_environments(
conda_store.db,
search=search,
namespace=namespace,
name=name,
show_soft_deleted=False,
),
)
return paginated_api_response(
orm_environments,
Expand Down
6 changes: 5 additions & 1 deletion conda-store-server/conda_store_server/server/views/ui.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from fastapi import APIRouter, Request, Depends
from fastapi.responses import RedirectResponse, PlainTextResponse
import yaml
Expand Down Expand Up @@ -44,14 +46,16 @@ def sort_namespace(n):
@router_ui.get("/")
def ui_list_environments(
request: Request,
search: Optional[str] = None,
templates=Depends(dependencies.get_templates),
conda_store=Depends(dependencies.get_conda_store),
auth=Depends(dependencies.get_auth),
server=Depends(dependencies.get_server),
entity=Depends(dependencies.get_entity),
):
orm_environments = auth.filter_environments(
entity, api.list_environments(conda_store.db, show_soft_deleted=False)
entity,
api.list_environments(conda_store.db, search=search, show_soft_deleted=False),
)

context = {
Expand Down

0 comments on commit 1ce38dc

Please sign in to comment.