Add inbound sms permission check

This commit is contained in:
Ken Tsang
2017-06-29 15:33:44 +01:00
committed by venusbb
parent b1a7ed46eb
commit 5a82fe0a70
3 changed files with 62 additions and 17 deletions

View File

@@ -9,7 +9,7 @@ from app.celery import tasks
from app.config import QueueNames
from app.dao.services_dao import dao_fetch_services_by_sms_sender
from app.dao.inbound_sms_dao import dao_create_inbound_sms
from app.models import InboundSms
from app.models import InboundSms, INBOUND_SMS_TYPE, SMS_TYPE
from app.errors import register_errors
from app.utils import convert_bst_to_utc
@@ -34,8 +34,8 @@ def receive_mmg_sms():
potential_services = fetch_potential_services(inbound_number, 'mmg')
if not potential_services:
# since this is an issue with our service <-> number mapping, we should still tell MMG that we received
# successfully
# since this is an issue with our service <-> number mapping, or no inbound_sms service permission
# we should still tell MMG that we received it successfully
return 'RECEIVED', 200
statsd_client.incr('inbound.mmg.successful')
@@ -128,6 +128,13 @@ def fetch_potential_services(inbound_number, provider_name):
))
statsd_client.incr('inbound.{}.failed'.format(provider_name))
return False
str_permissions = [p.permission for p in potential_services[0].permissions]
if set([INBOUND_SMS_TYPE, SMS_TYPE]).issubset(set(str_permissions)) is False:
current_app.logger.error(
'Service "{}" does not allow inbound SMS'.format(potential_services[0].id))
return False
return potential_services