Skip to content

Commit

Permalink
Optional node aliase filter on controlled list endpoint #57
Browse files Browse the repository at this point in the history
  • Loading branch information
johnatawnclementawn committed Jan 15, 2025
1 parent 6a7bc00 commit bb0c1f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 6 additions & 2 deletions arches_references/src/arches_references/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ function getToken() {
return token;
}

export const fetchLists = async () => {
const response = await fetch(arches.urls.controlled_lists);
export const fetchLists = async (
nodeAliases: string[] | undefined = undefined,
) => {
const params = new URLSearchParams();
nodeAliases?.forEach((alias) => params.append("node_alias", alias));
const response = await fetch(`${arches.urls.controlled_lists}?${params}`);
try {
const parsed = await response.json();
if (response.ok) {
Expand Down
14 changes: 10 additions & 4 deletions arches_references/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@ def _prefetch_terms(request):
class ListsView(APIBase):
def get(self, request):
"""Returns either a flat representation (?flat=true) or a tree (default)."""
lists = (
flat = str_to_bool(request.GET.get("flat", "false"))
permitted = get_nodegroups_by_perm(request.user, "read_nodegroup")
NOT_PROVIDED = object()
node_aliases = request.GET.getlist("node_alias", NOT_PROVIDED)
lists_query = (
List.objects.annotate_node_fields(
node_ids="pk",
node_alias="alias",
node_names="name",
nodegroup_ids="nodegroup_id",
graph_ids="graph_id",
Expand All @@ -74,11 +79,12 @@ def get(self, request):
.order_by("name")
.prefetch_related(*_prefetch_terms(request))
)
if node_aliases is not NOT_PROVIDED:
lists_query = lists_query.filter(node_alias__overlap=node_aliases)

flat = str_to_bool(request.GET.get("flat", "false"))
permitted = get_nodegroups_by_perm(request.user, "read_nodegroup")
serialized = [
obj.serialize(flat=flat, permitted_nodegroups=permitted) for obj in lists
obj.serialize(flat=flat, permitted_nodegroups=permitted)
for obj in lists_query
]

return JSONResponse({"controlled_lists": serialized})
Expand Down

0 comments on commit bb0c1f3

Please sign in to comment.