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

public ui: fix missing library facet on org view #2217

Merged
merged 1 commit into from
Jul 21, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion rero_ils/modules/documents/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def post_process_serialize_search(self, results, pid_fetcher):
if lib_buckets:
org_term['library']['buckets'] = lib_buckets

# TODO: Move this logic in the front end (needs backend adaptation)
# TODO: this should be done in the facet factory as we compute
# unused aggs values
if (viewcode is not None) and (viewcode != global_view_code):
org = Organisation.get_record_by_viewcode(viewcode)
org_buckets = results.get('aggregations', {}).get(
Expand Down
10 changes: 10 additions & 0 deletions rero_ils/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from flask import current_app, request
from invenio_i18n.ext import current_i18n
from invenio_records_rest.errors import InvalidQueryRESTError
from werkzeug.datastructures import ImmutableMultiDict

from .facets import i18n_facets_factory
from .modules.organisations.api import Organisation
Expand Down Expand Up @@ -133,6 +134,15 @@ def inner(values):
def documents_search_factory(self, search, query_parser=None):
"""Search factory with view code parameter."""
view = request.args.get('view')
# force to have organisation aggs if library is set
facets = request.args.get('facets', [])
if facets:
facets = facets.split(',')
if 'library' in facets and 'organisation' not in facets:
args = request.args.to_dict()
facets.append('organisation')
args['facets'] = ','.join(facets)
request.args = ImmutableMultiDict(args)
search, urlkwargs = search_factory(self, search)
# public interface
if view:
Expand Down
38 changes: 38 additions & 0 deletions tests/api/documents/test_documents_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,50 @@ def test_documents_facets(
res = client.get(list_url, headers=rero_json_header)
data = get_json(res)
aggs = data['aggregations']

# check all facets are present
for facet in [
'document_type', 'author', 'language', 'subject', 'status'
]:
assert aggs[facet]

list_url = url_for(
'invenio_records_rest.doc_list', view='global', facets='')
res = client.get(list_url, headers=rero_json_header)
data = get_json(res)
aggs = data['aggregations']
assert not aggs

list_url = url_for(
'invenio_records_rest.doc_list', view='global', facets='document_type')
res = client.get(list_url, headers=rero_json_header)
data = get_json(res)
aggs = data['aggregations']
assert list(aggs.keys()) == ['document_type']

list_url = url_for(
'invenio_records_rest.doc_list', view='global', facets='document_type')
res = client.get(list_url, headers=rero_json_header)
data = get_json(res)
aggs = data['aggregations']
assert list(aggs.keys()) == ['document_type']

list_url = url_for(
'invenio_records_rest.doc_list', view='org1', facets='document_type')
res = client.get(list_url, headers=rero_json_header)
data = get_json(res)
aggs = data['aggregations']
assert list(aggs.keys()) == ['document_type']

# test the patch that the library facet is computed by the serializer
list_url = url_for(
'invenio_records_rest.doc_list', view='org1',
facets='document_type,library,author')
res = client.get(list_url, headers=rero_json_header)
data = get_json(res)
aggs = data['aggregations']
assert set(aggs.keys()) == set(['document_type', 'library', 'author'])

# FILTERS
# contribution
list_url = url_for('invenio_records_rest.doc_list', view='global',
Expand Down