mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 15:15:38 -05:00
Merge pull request #925 from alphagov/feat-use-intl-provider-send-sms
Feat use intl provider send sms
This commit is contained in:
@@ -60,6 +60,7 @@ def dao_toggle_sms_provider(identifier):
|
||||
@transactional
|
||||
def dao_switch_sms_provider_to_provider_with_identifier(identifier):
|
||||
new_provider = get_provider_details_by_identifier(identifier)
|
||||
|
||||
if provider_is_inactive(new_provider):
|
||||
return
|
||||
|
||||
@@ -69,7 +70,7 @@ def dao_switch_sms_provider_to_provider_with_identifier(identifier):
|
||||
providers_to_update = []
|
||||
|
||||
if conflicting_provider:
|
||||
providers_to_update = switch_providers(conflicting_provider, new_provider)
|
||||
switch_providers(conflicting_provider, new_provider)
|
||||
else:
|
||||
current_provider = get_current_provider('sms')
|
||||
if not provider_is_primary(current_provider, new_provider, identifier):
|
||||
@@ -79,10 +80,14 @@ def dao_switch_sms_provider_to_provider_with_identifier(identifier):
|
||||
dao_update_provider_details(provider)
|
||||
|
||||
|
||||
def get_provider_details_by_notification_type(notification_type):
|
||||
return ProviderDetails.query.filter_by(
|
||||
notification_type=notification_type
|
||||
).order_by(asc(ProviderDetails.priority)).all()
|
||||
def get_provider_details_by_notification_type(notification_type, supports_international=False):
|
||||
|
||||
filters = [ProviderDetails.notification_type == notification_type]
|
||||
|
||||
if supports_international:
|
||||
filters.append(ProviderDetails.supports_international == supports_international)
|
||||
|
||||
return ProviderDetails.query.filter(*filters).order_by(asc(ProviderDetails.priority)).all()
|
||||
|
||||
|
||||
@transactional
|
||||
|
||||
@@ -25,7 +25,7 @@ def send_sms_to_provider(notification):
|
||||
return
|
||||
|
||||
if notification.status == 'created':
|
||||
provider = provider_to_use(SMS_TYPE, notification.id)
|
||||
provider = provider_to_use(SMS_TYPE, notification.id, notification.international)
|
||||
current_app.logger.info(
|
||||
"Starting sending SMS {} to provider at {}".format(notification.id, datetime.utcnow())
|
||||
)
|
||||
@@ -120,9 +120,9 @@ def update_notification(notification, provider):
|
||||
dao_update_notification(notification)
|
||||
|
||||
|
||||
def provider_to_use(notification_type, notification_id):
|
||||
def provider_to_use(notification_type, notification_id, international=False):
|
||||
active_providers_in_order = [
|
||||
provider for provider in get_provider_details_by_notification_type(notification_type) if provider.active
|
||||
p for p in get_provider_details_by_notification_type(notification_type, international) if p.active
|
||||
]
|
||||
|
||||
if not active_providers_in_order:
|
||||
@@ -147,11 +147,8 @@ def get_logo_url(base_url, branding_path, logo_file):
|
||||
base_url = parse.urlparse(base_url)
|
||||
netloc = base_url.netloc
|
||||
|
||||
if (
|
||||
base_url.netloc.startswith('localhost') or
|
||||
# covers both preview and staging
|
||||
'notify.works' in base_url.netloc
|
||||
):
|
||||
# covers both preview and staging
|
||||
if base_url.netloc.startswith('localhost') or 'notify.works' in base_url.netloc:
|
||||
path = '/static' + branding_path + logo_file
|
||||
else:
|
||||
if base_url.netloc.startswith('www'):
|
||||
|
||||
Reference in New Issue
Block a user