mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-22 08:58:57 -04:00
Merge branch 'master' of https://github.com/alphagov/notifications-api into Inbound-sms-ip
This commit is contained in:
34
app/dao/service_sms_sender_dao.py
Normal file
34
app/dao/service_sms_sender_dao.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from app import db
|
||||
from app.dao.dao_utils import transactional
|
||||
from app.models import ServiceSmsSender
|
||||
|
||||
|
||||
@transactional
|
||||
def insert_or_update_service_sms_sender(service, sms_sender, inbound_number_id=None):
|
||||
result = db.session.query(
|
||||
ServiceSmsSender
|
||||
).filter(
|
||||
ServiceSmsSender.service_id == service.id
|
||||
).update(
|
||||
{'sms_sender': sms_sender,
|
||||
'inbound_number_id': inbound_number_id
|
||||
}
|
||||
)
|
||||
if result == 0:
|
||||
new_sms_sender = ServiceSmsSender(sms_sender=sms_sender,
|
||||
service=service,
|
||||
is_default=True,
|
||||
inbound_number_id=inbound_number_id
|
||||
)
|
||||
db.session.add(new_sms_sender)
|
||||
|
||||
|
||||
def insert_service_sms_sender(service, sms_sender):
|
||||
"""
|
||||
This method is called from create_service which is wrapped in a transaction.
|
||||
"""
|
||||
new_sms_sender = ServiceSmsSender(sms_sender=sms_sender,
|
||||
service=service,
|
||||
is_default=True
|
||||
)
|
||||
db.session.add(new_sms_sender)
|
||||
@@ -11,6 +11,7 @@ from app.dao.dao_utils import (
|
||||
version_class
|
||||
)
|
||||
from app.dao.notifications_dao import get_financial_year
|
||||
from app.dao.service_sms_sender_dao import insert_service_sms_sender
|
||||
from app.models import (
|
||||
NotificationStatistics,
|
||||
ProviderStatistics,
|
||||
@@ -33,8 +34,8 @@ from app.models import (
|
||||
TEMPLATE_TYPES,
|
||||
JobStatistics,
|
||||
SMS_TYPE,
|
||||
EMAIL_TYPE
|
||||
)
|
||||
EMAIL_TYPE,
|
||||
ServiceSmsSender)
|
||||
from app.service.statistics import format_monthly_template_notification_stats
|
||||
from app.statsd_decorators import statsd
|
||||
from app.utils import get_london_month_from_utc_column, get_london_midnight_in_utc
|
||||
@@ -163,6 +164,7 @@ def dao_create_service(service, user, service_id=None, service_permissions=[SMS_
|
||||
service_permission = ServicePermission(service_id=service.id, permission=permission)
|
||||
service.permissions.append(service_permission)
|
||||
|
||||
insert_service_sms_sender(service, service.sms_sender)
|
||||
db.session.add(service)
|
||||
|
||||
|
||||
@@ -212,6 +214,7 @@ def delete_service_and_all_associated_db_objects(service):
|
||||
subq = db.session.query(Template.id).filter_by(service=service).subquery()
|
||||
_delete_commit(TemplateRedacted.query.filter(TemplateRedacted.template_id.in_(subq)))
|
||||
|
||||
_delete_commit(ServiceSmsSender.query.filter_by(service=service))
|
||||
_delete_commit(NotificationStatistics.query.filter_by(service=service))
|
||||
_delete_commit(ProviderStatistics.query.filter_by(service=service))
|
||||
_delete_commit(InvitedUser.query.filter_by(service=service))
|
||||
|
||||
@@ -7,6 +7,8 @@ from app.dao.inbound_numbers_dao import (
|
||||
dao_set_inbound_number_to_service,
|
||||
dao_set_inbound_number_active_flag
|
||||
)
|
||||
from app.dao.service_sms_sender_dao import insert_or_update_service_sms_sender
|
||||
from app.dao.services_dao import dao_fetch_service_by_id
|
||||
from app.errors import InvalidRequest, register_errors
|
||||
|
||||
inbound_number_blueprint = Blueprint('inbound_number', __name__, url_prefix='/inbound-number')
|
||||
@@ -42,6 +44,8 @@ def post_allocate_inbound_number(service_id):
|
||||
|
||||
if len(available_numbers) > 0:
|
||||
dao_set_inbound_number_to_service(service_id, available_numbers[0])
|
||||
service = dao_fetch_service_by_id(service_id)
|
||||
insert_or_update_service_sms_sender(service, available_numbers[0].number, available_numbers[0].id)
|
||||
return jsonify(), 204
|
||||
else:
|
||||
raise InvalidRequest('No available inbound numbers', status_code=400)
|
||||
|
||||
@@ -202,6 +202,8 @@ class ServiceSchema(BaseSchema):
|
||||
'template_statistics',
|
||||
'service_provider_stats',
|
||||
'service_notification_stats',
|
||||
'service_sms_senders',
|
||||
'monthly_billing',
|
||||
'reply_to_email_addresses',
|
||||
)
|
||||
strict = True
|
||||
@@ -253,7 +255,10 @@ class DetailedServiceSchema(BaseSchema):
|
||||
'template_statistics',
|
||||
'service_provider_stats',
|
||||
'service_notification_stats',
|
||||
'organisation'
|
||||
'organisation',
|
||||
'service_sms_senders',
|
||||
'monthly_billing',
|
||||
'reply_to_email_addresses'
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ from app.dao.service_inbound_api_dao import (
|
||||
reset_service_inbound_api,
|
||||
get_service_inbound_api
|
||||
)
|
||||
from app.dao.service_sms_sender_dao import insert_or_update_service_sms_sender
|
||||
from app.dao.services_dao import (
|
||||
dao_fetch_service_by_id,
|
||||
dao_fetch_all_services,
|
||||
@@ -143,6 +144,8 @@ def update_service(service_id):
|
||||
current_data = dict(service_schema.dump(fetched_service).data.items())
|
||||
current_data.update(request.get_json())
|
||||
update_dict = service_schema.load(current_data).data
|
||||
if 'sms_sender' in req_json:
|
||||
insert_or_update_service_sms_sender(fetched_service, req_json['sms_sender'])
|
||||
dao_update_service(update_dict)
|
||||
|
||||
if service_going_live:
|
||||
|
||||
@@ -22,7 +22,7 @@ def show_status():
|
||||
return jsonify(status="ok"), 200
|
||||
else:
|
||||
return jsonify(
|
||||
status="ok",
|
||||
status="ok", # This should be considered part of the public API
|
||||
travis_commit=version.__travis_commit__,
|
||||
travis_build_number=version.__travis_job_number__,
|
||||
build_time=version.__time__,
|
||||
|
||||
Reference in New Issue
Block a user