diff --git a/bento_beacon/utils/beacon_response.py b/bento_beacon/utils/beacon_response.py index 7b96781d..8c4dedbf 100644 --- a/bento_beacon/utils/beacon_response.py +++ b/bento_beacon/utils/beacon_response.py @@ -1,6 +1,6 @@ from flask import current_app, g, request from .katsu_utils import search_summary_statistics, overview_statistics -from .censorship import get_censorship_threshold, censored_count +from .censorship import get_censorship_threshold, censored_count, MESSAGE_FOR_CENSORED_QUERY_WITH_NO_RESULTS from .exceptions import InvalidQuery, APIException from ..constants import GRANULARITY_BOOLEAN, GRANULARITY_COUNT, GRANULARITY_RECORD @@ -10,6 +10,7 @@ def init_response_data(): g.response_data = {} g.response_info = {} + def add_info_to_response(info): add_message({"description": info, "level": "info"}) @@ -20,6 +21,11 @@ def add_message(message_obj): g.response_info["messages"] = messages +def add_no_results_censorship_message_to_response(): + add_info_to_response(MESSAGE_FOR_CENSORED_QUERY_WITH_NO_RESULTS) + add_info_to_response(f"censorship threshold: {current_app.config['COUNT_THRESHOLD']}") + + def add_stats_to_response(ids): if ids is not None and len(ids) <= get_censorship_threshold(): return @@ -107,6 +113,8 @@ def build_query_response(ids=None, numTotalResults=None, full_record_handler=Non granularity = response_granularity() count = len(ids) if numTotalResults is None else numTotalResults returned_count = censored_count(count) + if returned_count == 0 and get_censorship_threshold() > 0: + add_no_results_censorship_message_to_response() if granularity == GRANULARITY_BOOLEAN: return beacon_boolean_response(returned_count) if granularity == GRANULARITY_COUNT: diff --git a/bento_beacon/utils/censorship.py b/bento_beacon/utils/censorship.py index 49a8005d..a4186288 100644 --- a/bento_beacon/utils/censorship.py +++ b/bento_beacon/utils/censorship.py @@ -2,6 +2,9 @@ from .exceptions import APIException, InvalidQuery +MESSAGE_FOR_CENSORED_QUERY_WITH_NO_RESULTS = "No results. Either none were found, or the query produced results numbering at or below the threshold for censorship." + + def get_censorship_threshold(): if g.permission_query_data: return 0