Skip to content

Commit

Permalink
Merge branch 'main' into bug/WP-361-job-search
Browse files Browse the repository at this point in the history
  • Loading branch information
chandra-tacc authored Nov 7, 2023
2 parents 47aa370 + e935225 commit 50a190d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ const DataFilesProjectsList = ({ modal }) => {
Header: 'ID',
headerStyle: { textAlign: 'left' },
accessor: 'name',
Cell: (el) => <span>{el.value.split('-').slice(-1)[0]}</span>,
Cell: (el) => (
<span>{el.value ? el.value.split('-').slice(-1)[0] : ''}</span>
),
},
];

Expand Down
11 changes: 9 additions & 2 deletions server/portal/apps/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion server/portal/apps/site_search/api/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_file_search_util(mock_file_search, regular_user):
[{'name': 'testfile',
'path': '/path/to/testfile'}]}
client = regular_user.tapis_oauth.client
res = files_search(client, 'test_query', 'test_system')
res = files_search(client, 'test_query', 'test_system', '/',)

mock_file_search.assert_called_with(client, 'test_system', '/',
query_string='test_query',
Expand Down
8 changes: 4 additions & 4 deletions server/portal/apps/site_search/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def cms_search(query_string, offset=0, limit=10):
return total, results


def files_search(client, query_string, system, filter=None, offset=0, limit=10):
res = search_operation(client, system, '/', offset=offset, limit=limit,
def files_search(client, query_string, system, path, filter=None, offset=0, limit=10):
res = search_operation(client, system, path, offset=offset, limit=limit,
query_string=query_string, filter=filter)
return (res['count'], res['listing'])

Expand Down Expand Up @@ -65,7 +65,7 @@ def get(self, request, *args, **kwargs):
and ('siteSearchPriority' in conf and conf['siteSearchPriority'] is not None))
client = request.user.tapis_oauth.client if (request.user.is_authenticated and request.user.profile.setup_complete) else service_account()
(public_total, public_results) = \
files_search(client, qs, public_conf['system'], filter=filter,
files_search(client, qs, public_conf['system'], public_conf.get("homeDir", "/"), filter=filter,
offset=offset, limit=limit)
response['public'] = {'count': public_total,
'listing': public_results,
Expand All @@ -84,7 +84,7 @@ def get(self, request, *args, **kwargs):
and ('siteSearchPriority' in conf and conf['siteSearchPriority'] is not None))
client = request.user.tapis_oauth.client
(community_total, community_results) = \
files_search(client, qs, community_conf['system'], filter=filter,
files_search(client, qs, community_conf['system'], community_conf.get("homeDir", "/"), filter=filter,
offset=offset,
limit=limit)
response['community'] = {'count': community_total,
Expand Down

0 comments on commit 50a190d

Please sign in to comment.