Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update controlled_lists endpoint to accept node aliases #58

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading