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
This commit is contained in:
Chris Hill-Scott
2020-07-28 10:19:46 +01:00
parent 6384b9ef4f
commit 4d896aa642
5 changed files with 14 additions and 14 deletions

View File

@@ -78,8 +78,8 @@ def check_template_is_active(template):
message="Template has been deleted") message="Template has been deleted")
def service_can_send_to_recipient(send_to, key_type, service, allow_whitelisted_recipients=True): 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_whitelisted_recipients): if not service_allowed_to_send_to(send_to, service, key_type, allow_guest_list_recipients):
if key_type == KEY_TYPE_TEAM: if key_type == KEY_TYPE_TEAM:
message = 'Cant send to this recipient using a team-only API key' message = 'Cant send to this recipient using a team-only API key'
else: 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: if send_to is None:
raise BadRequestError(message="Recipient can't be empty") 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: if notification_type == SMS_TYPE:
international_phone_info = check_if_service_can_send_to_number(service, send_to) international_phone_info = check_if_service_can_send_to_number(service, send_to)

View File

@@ -119,7 +119,7 @@ from app.service.service_senders_schema import (
add_service_letter_contact_block_request, add_service_letter_contact_block_request,
add_service_sms_sender_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.sender import send_notification_to_service_users
from app.service.send_notification import send_one_off_notification, send_pdf_letter_notification from app.service.send_notification import send_one_off_notification, send_pdf_letter_notification
from app.schemas import ( 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 # doesn't commit so if there are any errors, we preserve old values in db
dao_remove_service_guest_list(service_id) dao_remove_service_guest_list(service_id)
try: 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: except ValueError as e:
current_app.logger.exception(e) current_app.logger.exception(e)
dao_rollback() dao_rollback()

View File

@@ -73,7 +73,7 @@ def send_one_off_notification(service_id, post_data):
key_type=KEY_TYPE_NORMAL, key_type=KEY_TYPE_NORMAL,
service=service, service=service,
notification_type=template.template_type, notification_type=template.template_type,
allow_whitelisted_recipients=False, allow_guest_list_recipients=False,
) )
validate_created_by(service, post_data['created_by']) 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, key_type=KEY_TYPE_NORMAL,
service=service, service=service,
notification_type=LETTER_TYPE, notification_type=LETTER_TYPE,
allow_whitelisted_recipients=False, allow_guest_list_recipients=False,
) )
template = get_precompiled_letter_template(service.id) template = get_precompiled_letter_template(service.id)

View File

@@ -14,7 +14,7 @@ def get_recipients_from_request(request_json, key, type):
return [(type, recipient) for recipient in request_json.get(key)] 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 [ return [
ServiceWhitelist.from_string(service_id, type, recipient) ServiceWhitelist.from_string(service_id, type, recipient)
for type, recipient in ( 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: if key_type == KEY_TYPE_TEST:
return True 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( team_members = itertools.chain.from_iterable(
[user.mobile_number, user.email_address] for user in service.users [user.mobile_number, user.email_address] for user in service.users
) )
whitelist_members = [ guest_list_members = [
member.recipient for member in service.whitelist member.recipient for member in service.whitelist
if allow_whitelisted_recipients if allow_guest_list_recipients
] ]
if ( if (
@@ -55,6 +55,6 @@ def service_allowed_to_send_to(recipient, service, key_type, allow_whitelisted_r
recipient, recipient,
itertools.chain( itertools.chain(
team_members, team_members,
whitelist_members guest_list_members
) )
) )

View File

@@ -272,7 +272,7 @@ def test_service_can_send_to_recipient_fails_when_ignoring_whitelist(
next(iter(recipient.values())), next(iter(recipient.values())),
'team', 'team',
sample_service, sample_service,
allow_whitelisted_recipients=False, allow_guest_list_recipients=False,
) )
assert exec_info.value.status_code == 400 assert exec_info.value.status_code == 400
assert exec_info.value.message == 'Cant send to this recipient using a team-only API key' assert exec_info.value.message == 'Cant send to this recipient using a team-only API key'