From 4d896aa642089155571d1c42d53964994e9cf84a Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 28 Jul 2020 10:19:46 +0100 Subject: [PATCH] Rename function in service utils To reflect the new name of the feature. squash! Rename function in service utils Rename function, variable and argument names in service utils --- app/notifications/validators.py | 8 ++++---- app/service/rest.py | 4 ++-- app/service/send_notification.py | 4 ++-- app/service/utils.py | 10 +++++----- tests/app/notifications/test_validators.py | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/notifications/validators.py b/app/notifications/validators.py index 93992c580..d26068b92 100644 --- a/app/notifications/validators.py +++ b/app/notifications/validators.py @@ -78,8 +78,8 @@ def check_template_is_active(template): message="Template has been deleted") -def service_can_send_to_recipient(send_to, key_type, service, allow_whitelisted_recipients=True): - if not service_allowed_to_send_to(send_to, service, key_type, allow_whitelisted_recipients): +def service_can_send_to_recipient(send_to, key_type, service, allow_guest_list_recipients=True): + if not service_allowed_to_send_to(send_to, service, key_type, allow_guest_list_recipients): if key_type == KEY_TYPE_TEAM: message = 'Can’t send to this recipient using a team-only API key' else: @@ -109,11 +109,11 @@ def check_if_service_can_send_files_by_email(service_contact_link, service_id): ) -def validate_and_format_recipient(send_to, key_type, service, notification_type, allow_whitelisted_recipients=True): +def validate_and_format_recipient(send_to, key_type, service, notification_type, allow_guest_list_recipients=True): if send_to is None: raise BadRequestError(message="Recipient can't be empty") - service_can_send_to_recipient(send_to, key_type, service, allow_whitelisted_recipients) + service_can_send_to_recipient(send_to, key_type, service, allow_guest_list_recipients) if notification_type == SMS_TYPE: international_phone_info = check_if_service_can_send_to_number(service, send_to) diff --git a/app/service/rest.py b/app/service/rest.py index 3db7f858f..1f794eb0b 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -119,7 +119,7 @@ from app.service.service_senders_schema import ( add_service_letter_contact_block_request, add_service_sms_sender_request ) -from app.service.utils import get_whitelist_objects +from app.service.utils import get_guest_list_objects from app.service.sender import send_notification_to_service_users from app.service.send_notification import send_one_off_notification, send_pdf_letter_notification from app.schemas import ( @@ -584,7 +584,7 @@ def update_guest_list(service_id): # doesn't commit so if there are any errors, we preserve old values in db dao_remove_service_guest_list(service_id) try: - guest_list_objects = get_whitelist_objects(service_id, request.get_json()) + guest_list_objects = get_guest_list_objects(service_id, request.get_json()) except ValueError as e: current_app.logger.exception(e) dao_rollback() diff --git a/app/service/send_notification.py b/app/service/send_notification.py index 10ed42ab7..2987a5362 100644 --- a/app/service/send_notification.py +++ b/app/service/send_notification.py @@ -73,7 +73,7 @@ def send_one_off_notification(service_id, post_data): key_type=KEY_TYPE_NORMAL, service=service, notification_type=template.template_type, - allow_whitelisted_recipients=False, + allow_guest_list_recipients=False, ) validate_created_by(service, post_data['created_by']) @@ -147,7 +147,7 @@ def send_pdf_letter_notification(service_id, post_data): key_type=KEY_TYPE_NORMAL, service=service, notification_type=LETTER_TYPE, - allow_whitelisted_recipients=False, + allow_guest_list_recipients=False, ) template = get_precompiled_letter_template(service.id) diff --git a/app/service/utils.py b/app/service/utils.py index c6e0e0476..3ab1ed97c 100644 --- a/app/service/utils.py +++ b/app/service/utils.py @@ -14,7 +14,7 @@ def get_recipients_from_request(request_json, key, type): return [(type, recipient) for recipient in request_json.get(key)] -def get_whitelist_objects(service_id, request_json): +def get_guest_list_objects(service_id, request_json): return [ ServiceWhitelist.from_string(service_id, type, recipient) for type, recipient in ( @@ -28,7 +28,7 @@ def get_whitelist_objects(service_id, request_json): ] -def service_allowed_to_send_to(recipient, service, key_type, allow_whitelisted_recipients=True): +def service_allowed_to_send_to(recipient, service, key_type, allow_guest_list_recipients=True): if key_type == KEY_TYPE_TEST: return True @@ -42,9 +42,9 @@ def service_allowed_to_send_to(recipient, service, key_type, allow_whitelisted_r team_members = itertools.chain.from_iterable( [user.mobile_number, user.email_address] for user in service.users ) - whitelist_members = [ + guest_list_members = [ member.recipient for member in service.whitelist - if allow_whitelisted_recipients + if allow_guest_list_recipients ] if ( @@ -55,6 +55,6 @@ def service_allowed_to_send_to(recipient, service, key_type, allow_whitelisted_r recipient, itertools.chain( team_members, - whitelist_members + guest_list_members ) ) diff --git a/tests/app/notifications/test_validators.py b/tests/app/notifications/test_validators.py index 4e6748917..f69060bf1 100644 --- a/tests/app/notifications/test_validators.py +++ b/tests/app/notifications/test_validators.py @@ -272,7 +272,7 @@ def test_service_can_send_to_recipient_fails_when_ignoring_whitelist( next(iter(recipient.values())), 'team', sample_service, - allow_whitelisted_recipients=False, + allow_guest_list_recipients=False, ) assert exec_info.value.status_code == 400 assert exec_info.value.message == 'Can’t send to this recipient using a team-only API key'