diff --git a/rero_ils/config.py b/rero_ils/config.py
index 1d700eb26b..b0b7ad64db 100644
--- a/rero_ils/config.py
+++ b/rero_ils/config.py
@@ -733,7 +733,7 @@ def _(x):
'"rero_ils.modules.holdings.api:Holding"):pid_value>'),
default_media_type='application/json',
max_result_window=MAX_RESULT_WINDOW,
- search_factory_imp='rero_ils.query:viewcode_patron_search_factory',
+ search_factory_imp='rero_ils.query:viewcode_patron_search_masked_factory',
list_permission_factory_imp=lambda record: record_permission_factory(
action='list', record=record, cls=HoldingPermission),
read_permission_factory_imp=lambda record: record_permission_factory(
diff --git a/rero_ils/modules/documents/templates/rero_ils/detailed_view_documents.html b/rero_ils/modules/documents/templates/rero_ils/detailed_view_documents.html
index 5fbf4c8778..028710cf47 100644
--- a/rero_ils/modules/documents/templates/rero_ils/detailed_view_documents.html
+++ b/rero_ils/modules/documents/templates/rero_ils/detailed_view_documents.html
@@ -169,11 +169,10 @@
{% if record.harvested %}
{% include('rero_ils/_document_online.html') %}
{% else %}
-
+ >
{% endif %}
{% endif %}
diff --git a/rero_ils/modules/holdings/api_views.py b/rero_ils/modules/holdings/api_views.py
index 590522cfe7..db48d72688 100644
--- a/rero_ils/modules/holdings/api_views.py
+++ b/rero_ils/modules/holdings/api_views.py
@@ -30,7 +30,6 @@
from .api import Holding
from ..errors import RegularReceiveNotAllowed
from ..items.api_views import check_authentication
-from ..organisations.api import Organisation
from ...permissions import can_receive_regular_issue
api_blueprint = Blueprint(
@@ -65,27 +64,6 @@ def decorated_view(*args, **kwargs):
return decorated_view
-@api_blueprint.route('/pids/', methods=['GET'])
-def holding_pids(document_pid):
- """HTTP GET all holdings PIDs by document Pid and viewcode."""
- from ..holdings.api import HoldingsSearch
- try:
- view = flask_request.args.get('view')
- 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'):
- organisation = Organisation.get_record_by_viewcode(view)
- query = query.filter('term', organisation__pid=organisation['pid'])
- return jsonify([
- holdings.pid for holdings in query.source('pid').scan()
- ])
- except:
- return jsonify([])
-
-
@api_blueprint.route('/availabilty/', methods=['GET'])
@check_authentication
@jsonify_error
diff --git a/rero_ils/query.py b/rero_ils/query.py
index c31c6a3729..9da8ae60f9 100644
--- a/rero_ils/query.py
+++ b/rero_ils/query.py
@@ -154,10 +154,27 @@ def viewcode_patron_search_factory(self, search, query_parser=None):
if view:
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']).filter(
- 'term', _masked=False
- )
+ search = search.filter('term', organisation__pid=org['pid'])
+ # Admin interface
+ elif current_patron:
+ search = search.filter(
+ 'term', organisation__pid=current_organisation.pid
+ )
+ # exclude draft records
+ search = search.filter('bool', must_not=[Q('term', _draft=True)])
+ return search, urlkwargs
+
+
+def viewcode_patron_search_masked_factory(self, search, query_parser=None):
+ """Search factory with viewcode or current patron."""
+ search, urlkwargs = search_factory(self, search)
+ view = request.args.get('view')
+ # Public interface
+ if view:
+ 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'])\
+ .filter('term', _masked=False)
# Admin interface
elif current_patron:
search = search.filter(
diff --git a/tests/api/holdings/test_holdings_rest_api.py b/tests/api/holdings/test_holdings_rest_api.py
deleted file mode 100644
index 16135507ec..0000000000
--- a/tests/api/holdings/test_holdings_rest_api.py
+++ /dev/null
@@ -1,61 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# RERO ILS
-# Copyright (C) 2021 RERO
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, version 3 of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see .
-
-from flask import url_for
-from utils import get_json
-
-
-def test_holdings_pids(es_clear, client, holding_lib_sion, holding_lib_fully):
- """Test retrieve holdings pids by document pid."""
- url = url_for(
- 'api_holding.holding_pids',
- document_pid=holding_lib_fully.document_pid,
- view='global'
- )
- res = client.get(url)
- assert res.status_code == 200
-
- data = get_json(res)
- assert len(data) == 2
- 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,
- view='org1'
- )
- res = client.get(url)
- assert res.status_code == 200
-
- data = get_json(res)
- assert len(data) == 1
- assert holding_lib_fully.get('pid') in data
-