From 7c0ba551b8d53f16758ec0f7b7d8ca0994df08b1 Mon Sep 17 00:00:00 2001 From: Chandra Y Date: Tue, 7 Nov 2023 13:41:45 -0600 Subject: [PATCH] Bug/WP-354: Workspace search - filter results visible to user (#893) * Workspace search - result filtering * add comments * Add protection in client side processing * Test with system prefix filter on id field * Add back search filtering with tapis listing * Use -1 as limit for listing projects --- .../DataFilesProjectsList/DataFilesProjectsList.jsx | 4 +++- server/portal/apps/projects/views.py | 11 +++++++++-- .../shared_workspace_operations.py | 5 ++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/client/src/components/DataFiles/DataFilesProjectsList/DataFilesProjectsList.jsx b/client/src/components/DataFiles/DataFilesProjectsList/DataFilesProjectsList.jsx index 93c4f3181..f90f80791 100644 --- a/client/src/components/DataFiles/DataFilesProjectsList/DataFilesProjectsList.jsx +++ b/client/src/components/DataFiles/DataFilesProjectsList/DataFilesProjectsList.jsx @@ -85,7 +85,9 @@ const DataFilesProjectsList = ({ modal }) => { Header: 'ID', headerStyle: { textAlign: 'left' }, accessor: 'name', - Cell: (el) => {el.value.split('-').slice(-1)[0]}, + Cell: (el) => ( + {el.value ? el.value.split('-').slice(-1)[0] : ''} + ), }, ]; diff --git a/server/portal/apps/projects/views.py b/server/portal/apps/projects/views.py index ca03a8479..d98e8807b 100644 --- a/server/portal/apps/projects/views.py +++ b/server/portal/apps/projects/views.py @@ -84,10 +84,17 @@ def get(self, request): search = search.query(ngram_query | wildcard_query) search = search.extra(from_=int(offset), size=int(limit)) + search = search.filter('prefix', **{'id': f'{settings.PORTAL_PROJECTS_SYSTEM_PREFIX}'}) res = search.execute() - hits = [hit.to_dict() for hit in res] - listing = hits + hits = list(map(lambda hit: hit.id, res)) + listing = [] + # Filter search results to projects specific to user + if hits: + client = request.user.tapis_oauth.client + listing = list_projects(client) + filtered_list = filter(lambda prj: prj['id'] in hits, listing) + listing = list(filtered_list) else: client = request.user.tapis_oauth.client listing = list_projects(client) diff --git a/server/portal/apps/projects/workspace_operations/shared_workspace_operations.py b/server/portal/apps/projects/workspace_operations/shared_workspace_operations.py index a72cff46e..081a6059a 100644 --- a/server/portal/apps/projects/workspace_operations/shared_workspace_operations.py +++ b/server/portal/apps/projects/workspace_operations/shared_workspace_operations.py @@ -274,9 +274,12 @@ def list_projects(client): fields = "id,host,description,notes,updated,owner,rootDir" query = f"id.like.{settings.PORTAL_PROJECTS_SYSTEM_PREFIX}.*" + # use limit as -1 to allow search to corelate with + # all projects available to the api user listing = client.systems.getSystems(listType='ALL', search=query, - select=fields) + select=fields, + limit=-1) serialized_listing = map(lambda prj: { "id": prj.id,