Skip to content

Commit

Permalink
holdings: fix several bugs related to version 1.0.0
Browse files Browse the repository at this point in the history
* Hides masked holdings from public interface.
* Indexes parent document after holdings updates.
* Adapts units testing.

Co-Authored-by: Aly Badr <aly.badr@rero.ch>
  • Loading branch information
Aly Badr committed Feb 8, 2021
1 parent 45dd76b commit 1e9f227
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 6 deletions.
6 changes: 4 additions & 2 deletions rero_ils/modules/documents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 6 additions & 2 deletions rero_ils/modules/holdings/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion rero_ils/modules/holdings/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down
3 changes: 2 additions & 1 deletion rero_ils/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions tests/api/holdings/test_holdings_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

4 changes: 4 additions & 0 deletions tests/data/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions tests/data/holdings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 1e9f227

Please sign in to comment.