mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-17 18:52:30 -05:00
Make sure we check if a service can send to number harmoniously
We were checking this separately in two places in the code. Now we will have this logic in one place, in validators. Also pull in utils version that recognises crown depenency numbers as international.
This commit is contained in:
@@ -15,7 +15,7 @@ from app.errors import (
|
||||
InvalidRequest
|
||||
)
|
||||
from app.models import (
|
||||
EMAIL_TYPE, INTERNATIONAL_SMS_TYPE, SMS_TYPE,
|
||||
EMAIL_TYPE, SMS_TYPE,
|
||||
KEY_TYPE_TEAM, PRIORITY,
|
||||
LETTER_TYPE)
|
||||
from app.notifications.process_notifications import (
|
||||
@@ -24,9 +24,10 @@ from app.notifications.process_notifications import (
|
||||
simulated_recipient
|
||||
)
|
||||
from app.notifications.validators import (
|
||||
check_if_service_can_send_to_number,
|
||||
check_rate_limiting,
|
||||
service_has_permission,
|
||||
validate_template
|
||||
validate_template,
|
||||
)
|
||||
from app.schemas import (
|
||||
email_notification_schema,
|
||||
@@ -38,7 +39,6 @@ from app.service.utils import service_allowed_to_send_to
|
||||
from app.utils import pagination_links, get_public_notify_type_text
|
||||
|
||||
from notifications_utils import SMS_CHAR_COUNT_LIMIT
|
||||
from notifications_utils.recipients import get_international_phone_info
|
||||
|
||||
notifications = Blueprint('notifications', __name__)
|
||||
|
||||
@@ -115,7 +115,7 @@ def send_notification(notification_type):
|
||||
)
|
||||
|
||||
if notification_type == SMS_TYPE:
|
||||
_service_can_send_internationally(authenticated_service, notification_form['to'])
|
||||
check_if_service_can_send_to_number(authenticated_service, notification_form['to'])
|
||||
# Do not persist or send notification to the queue if it is a simulated recipient
|
||||
simulated = simulated_recipient(notification_form['to'], notification_type)
|
||||
notification_model = persist_notification(template_id=template.id,
|
||||
@@ -160,17 +160,6 @@ def get_notification_return_data(notification_id, notification, template):
|
||||
return output
|
||||
|
||||
|
||||
def _service_can_send_internationally(service, number):
|
||||
international_phone_info = get_international_phone_info(number)
|
||||
|
||||
if (international_phone_info.international and international_phone_info.country_prefix != '44') and \
|
||||
INTERNATIONAL_SMS_TYPE not in [p.permission for p in service.permissions]:
|
||||
raise InvalidRequest(
|
||||
{'to': ["Cannot send to international mobile numbers"]},
|
||||
status_code=400
|
||||
)
|
||||
|
||||
|
||||
def _service_allowed_to_send_to(notification, service):
|
||||
if not service_allowed_to_send_to(notification['to'], service, api_user.key_type):
|
||||
if api_user.key_type == KEY_TYPE_TEAM:
|
||||
|
||||
Reference in New Issue
Block a user