Skip to content

Commit

Permalink
fix site search for pub/community data
Browse files Browse the repository at this point in the history
  • Loading branch information
rstijerina committed Oct 3, 2023
1 parent 78bb6e0 commit aa9ebbb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
7 changes: 4 additions & 3 deletions server/portal/apps/site_search/api/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,16 @@ def test_cms_search_util(mock_dsl_search):
'highlight': {'body': ['highlight 1']}}])


def test_file_search_util(mock_file_search):
def test_file_search_util(mock_file_search, regular_user):
from portal.apps.site_search.api.views import files_search
mock_file_search.return_value = {'count': 1,
'listing':
[{'name': 'testfile',
'path': '/path/to/testfile'}]}
res = files_search('test_query', 'test_system')
client = regular_user.tapis_oauth.client
res = files_search(client, 'test_query', 'test_system')

mock_file_search.assert_called_with(None, 'test_system', '/',
mock_file_search.assert_called_with(client, 'test_system', '/',
query_string='test_query',
filter=None,
offset=0,
Expand Down
11 changes: 7 additions & 4 deletions server/portal/apps/site_search/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from portal.libs.agave.operations import search as search_operation
from portal.views.base import BaseApiView
from django.conf import settings
from portal.libs.agave.utils import service_account
import logging
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -35,8 +36,8 @@ def cms_search(query_string, offset=0, limit=10):
return total, results


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

Expand All @@ -62,8 +63,9 @@ def get(self, request, *args, **kwargs):
in settings.PORTAL_DATAFILES_STORAGE_SYSTEMS
if conf['scheme'] == 'public'
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(qs, public_conf['system'], filter=filter,
files_search(client, qs, public_conf['system'], filter=filter,
offset=offset, limit=limit)
response['public'] = {'count': public_total,
'listing': public_results,
Expand All @@ -80,8 +82,9 @@ def get(self, request, *args, **kwargs):
in settings.PORTAL_DATAFILES_STORAGE_SYSTEMS
if conf['scheme'] == 'community'
and ('siteSearchPriority' in conf and conf['siteSearchPriority'] is not None))
client = request.user.tapis_oauth.client
(community_total, community_results) = \
files_search(qs, community_conf['system'], filter=filter,
files_search(client, qs, community_conf['system'], filter=filter,
offset=offset,
limit=limit)
response['community'] = {'count': community_total,
Expand Down
5 changes: 3 additions & 2 deletions server/portal/libs/agave/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def listing(client, system, path, offset=0, limit=100, *args, **kwargs):
Params
------
client: agavepy.agave.Agave
client: tapipy.tapis.Tapis
Tapis client to use for the listing.
system: str
Tapis system ID.
Expand Down Expand Up @@ -92,7 +92,8 @@ def search(client, system, path='', offset=0, limit=100, query_string='', filter
Params
------
client: NoneType
client: tapipy.tapis.Tapis
Tapis client to use for the listing.
system: str
Tapis system ID to filter on.
path: NoneType
Expand Down

0 comments on commit aa9ebbb

Please sign in to comment.