diff --git a/rero_ils/modules/documents/views.py b/rero_ils/modules/documents/views.py index bb6d920ab2..847d101d20 100644 --- a/rero_ils/modules/documents/views.py +++ b/rero_ils/modules/documents/views.py @@ -69,7 +69,8 @@ def doc_item_view_method(pid, record, template=None, **kwargs): # Counting holdings to display the get button from ..holdings.api import HoldingsSearch query = HoldingsSearch()\ - .filter('term', document__pid=pid.pid_value) + .filter('term', document__pid=pid.pid_value).filter( + 'term', _masked=False) if organisation: query = query.filter('term', organisation__pid=organisation.pid) holdings_count = query.count() @@ -593,7 +594,8 @@ def online_holdings(document_pid, viewcode='global'): if viewcode != current_app.config.get('RERO_ILS_SEARCH_GLOBAL_VIEW_CODE'): organisation = Organisation.get_record_by_viewcode(viewcode) query = HoldingsSearch()\ - .filter('term', document__pid=document_pid) + .filter('term', document__pid=document_pid) \ + .filter('term', _masked=False) if organisation: query = query.filter('term', organisation__pid=organisation.pid) results = query.source(['library', 'electronic_location', 'notes']).scan() diff --git a/rero_ils/modules/holdings/api.py b/rero_ils/modules/holdings/api.py index 0e7b30ab38..502c83127b 100644 --- a/rero_ils/modules/holdings/api.py +++ b/rero_ils/modules/holdings/api.py @@ -725,9 +725,13 @@ class HoldingsIndexer(IlsRecordsIndexer): record_cls = Holding def index(self, record): - """Indexing a holding record.""" + """Indexing a holding record. + + Parent document is indexed as well. + """ return_value = super().index(record) - # current_search.flush_and_refresh(HoldingsSearch.Meta.index) + document = Document.get_record_by_pid(record.document_pid) + document.reindex() return return_value def bulk_index(self, record_id_iterator): diff --git a/rero_ils/modules/holdings/api_views.py b/rero_ils/modules/holdings/api_views.py index eadc89bea8..590522cfe7 100644 --- a/rero_ils/modules/holdings/api_views.py +++ b/rero_ils/modules/holdings/api_views.py @@ -71,7 +71,9 @@ def holding_pids(document_pid): from ..holdings.api import HoldingsSearch try: view = flask_request.args.get('view') - query = HoldingsSearch().filter('term', document__pid=document_pid) \ + query = HoldingsSearch().filter( + 'term', _masked=False).filter( + 'term', document__pid=document_pid) \ .sort({'library.pid': {'order': 'asc'}}) \ .params(preserve_order=True) if view != current_app.config.get('RERO_ILS_SEARCH_GLOBAL_VIEW_CODE'): diff --git a/rero_ils/query.py b/rero_ils/query.py index e09340dc7b..c31c6a3729 100644 --- a/rero_ils/query.py +++ b/rero_ils/query.py @@ -155,7 +155,8 @@ def viewcode_patron_search_factory(self, search, query_parser=None): if view != current_app.config.get('RERO_ILS_SEARCH_GLOBAL_VIEW_CODE'): org = Organisation.get_record_by_viewcode(view) search = search.filter( - 'term', organisation__pid=org['pid'] + 'term', organisation__pid=org['pid']).filter( + 'term', _masked=False ) # Admin interface elif current_patron: diff --git a/tests/api/holdings/test_holdings_rest_api.py b/tests/api/holdings/test_holdings_rest_api.py index 83c730e3bd..16135507ec 100644 --- a/tests/api/holdings/test_holdings_rest_api.py +++ b/tests/api/holdings/test_holdings_rest_api.py @@ -34,6 +34,19 @@ def test_holdings_pids(es_clear, client, holding_lib_sion, holding_lib_fully): assert holding_lib_sion.get('pid') in data assert holding_lib_fully.get('pid') in data + holding_lib_sion['_masked'] = True + holding_lib_sion.update(holding_lib_sion, dbcommit=True, reindex=True) + url = url_for( + 'api_holding.holding_pids', + document_pid=holding_lib_sion.document_pid, + view='global' + ) + res = client.get(url) + assert res.status_code == 200 + + data = get_json(res) + assert len(data) == 1 + url = url_for( 'api_holding.holding_pids', document_pid=holding_lib_fully.document_pid, @@ -45,3 +58,4 @@ def test_holdings_pids(es_clear, client, holding_lib_sion, holding_lib_fully): data = get_json(res) assert len(data) == 1 assert holding_lib_fully.get('pid') in data + diff --git a/tests/data/data.json b/tests/data/data.json index 3a700c4e7e..5f47e15485 100644 --- a/tests/data/data.json +++ b/tests/data/data.json @@ -3156,6 +3156,7 @@ "holding1": { "$schema": "https://ils.rero.ch/schemas/holdings/holding-v0.0.1.json", "pid": "holding1", + "_masked": false, "call_number": "h00001", "document": { "$ref": "https://ils.rero.ch/api/documents/doc1" @@ -3170,6 +3171,7 @@ "holding2": { "$schema": "https://ils.rero.ch/schemas/holdings/holding-v0.0.1.json", "pid": "holding2", + "_masked": false, "call_number": "h00002", "document": { "$ref": "https://ils.rero.ch/api/documents/doc1" @@ -3184,6 +3186,7 @@ "holding3": { "$schema": "https://ils.rero.ch/schemas/holdings/holding-v0.0.1.json", "pid": "holding3", + "_masked": false, "call_number": "h00003", "document": { "$ref": "https://ils.rero.ch/api/documents/doc1" @@ -3198,6 +3201,7 @@ "holding4": { "$schema": "https://ils.rero.ch/schemas/holdings/holding-v0.0.1.json", "pid": "holding4", + "_masked": false, "call_number": "h00004", "document": { "$ref": "https://ils.rero.ch/api/documents/doc1" diff --git a/tests/data/holdings.json b/tests/data/holdings.json index 9bd5caf354..dc9cd05398 100644 --- a/tests/data/holdings.json +++ b/tests/data/holdings.json @@ -158,6 +158,7 @@ "holding1": { "$schema": "https://ils.rero.ch/schemas/holdings/holding-v0.0.1.json", "pid": "holding1", + "_masked": false, "call_number": "h00001", "document": { "$ref": "https://ils.rero.ch/api/documents/doc1" @@ -173,6 +174,7 @@ "holding2": { "$schema": "https://ils.rero.ch/schemas/holdings/holding-v0.0.1.json", "pid": "holding2", + "_masked": false, "call_number": "h00002", "document": { "$ref": "https://ils.rero.ch/api/documents/doc1" @@ -188,6 +190,7 @@ "holding3": { "$schema": "https://ils.rero.ch/schemas/holdings/holding-v0.0.1.json", "pid": "holding3", + "_masked": false, "call_number": "h00003", "document": { "$ref": "https://ils.rero.ch/api/documents/doc1" @@ -203,6 +206,7 @@ "holding4": { "$schema": "https://ils.rero.ch/schemas/holdings/holding-v0.0.1.json", "pid": "holding4", + "_masked": false, "call_number": "h00004", "document": { "$ref": "https://ils.rero.ch/api/documents/doc1" @@ -218,6 +222,7 @@ "holding5": { "$schema": "https://ils.rero.ch/schemas/holdings/holding-v0.0.1.json", "pid": "holding5", + "_masked": false, "call_number": "h00005", "document": { "$ref": "https://ils.rero.ch/api/documents/doc4" @@ -291,6 +296,7 @@ "holding6": { "$schema": "https://ils.rero.ch/schemas/holdings/holding-v0.0.1.json", "pid": "holding6", + "_masked": false, "call_number": "h00006", "document": { "$ref": "https://ils.rero.ch/api/documents/doc4"