Refactor code to use inbound_numbers if set

This commit is contained in:
Ken Tsang
2017-08-14 19:47:09 +01:00
parent e14fa2d87e
commit 667ee57a35
8 changed files with 103 additions and 7 deletions

View File

@@ -51,7 +51,7 @@ def send_sms_to_provider(notification):
to=validate_and_format_phone_number(notification.to, international=notification.international),
content=str(template),
reference=str(notification.id),
sender=service.sms_sender or current_app.config['FROM_NUMBER']
sender=service.get_inbound_number()
)
except Exception as e:
dao_toggle_sms_provider(provider.name)

View File

@@ -241,6 +241,12 @@ class Service(db.Model, Versioned):
return cls(**fields)
def get_inbound_number(self):
if self.inbound_number and self.inbound_number.active:
return self.inbound_number.number
else:
return self.sms_sender or current_app.config['FROM_NUMBER']
class InboundNumber(db.Model):
__tablename__ = "inbound_numbers"

View File

@@ -107,7 +107,7 @@ def create_inbound_sms_object(service, content, from_number, provider_ref, date_
inbound = InboundSms(
service=service,
notify_number=service.sms_sender,
notify_number=service.get_inbound_number(),
user_number=user_number,
provider_date=provider_date,
provider_reference=provider_ref,

View File

@@ -80,10 +80,9 @@ def post_notification(notification_type):
)
if notification_type == SMS_TYPE:
sms_sender = authenticated_service.sms_sender or current_app.config.get('FROM_NUMBER')
create_resp_partial = functools.partial(
create_post_sms_response_from_notification,
from_number=sms_sender
from_number=authenticated_service.get_inbound_number()
)
elif notification_type == EMAIL_TYPE:
create_resp_partial = functools.partial(