Skip to content

Commit

Permalink
query: search filter on item
Browse files Browse the repository at this point in the history
* Adds a new search query to resource with masked flag.
* Fixes query filter on resource without masked flag.

Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
Garfield-fr committed Feb 17, 2021
1 parent 7894beb commit 2955915
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 91 deletions.
2 changes: 1 addition & 1 deletion rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,10 @@ <h3>
{% if record.harvested %}
{% include('rero_ils/_document_online.html') %}
{% else %}
<public-holdings-items
documenttype="{{ record | document_main_type }}"
<public-search-holdings
documentpid="{{ record.pid }}"
viewcode="{{ viewcode }}"
></public-holdings-items>
></public-search-holdings>
{% endif %}
</section>
{% endif %}
Expand Down
22 changes: 0 additions & 22 deletions rero_ils/modules/holdings/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -65,27 +64,6 @@ def decorated_view(*args, **kwargs):
return decorated_view


@api_blueprint.route('/pids/<document_pid>', 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/<holding_pid>', methods=['GET'])
@check_authentication
@jsonify_error
Expand Down
25 changes: 21 additions & 4 deletions rero_ils/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
61 changes: 0 additions & 61 deletions tests/api/holdings/test_holdings_rest_api.py

This file was deleted.

0 comments on commit 2955915

Please sign in to comment.