Ensure updates on a research mode service or test key don't touch the history table

- note this is an unexpectedly big change.
- When we create a service we pass the service id to the persist method. This means that we don't have the service available to check if in research mode.
- All calling methods (expecting the one where we use the notify service) have the service available. So rather than reload it I changed the method signature to pass the service, not the ID to persist.
- Touches a few places.

Note this means that the update or create methods will fall over on a null service. But this seems correct.

Goes back to the story which we need to play to make the service available as the API user so that the need to load and pass around services is minimised.
This commit is contained in:
Martyn Inglis
2016-12-19 16:45:18 +00:00
parent 35aa888658
commit 0f37824b0c
9 changed files with 110 additions and 41 deletions

View File

@@ -18,7 +18,7 @@ from app.dao.users_dao import (
from app.dao.permissions_dao import permission_dao
from app.dao.services_dao import dao_fetch_service_by_id
from app.dao.templates_dao import dao_get_template_by_id
from app.models import SMS_TYPE, KEY_TYPE_NORMAL
from app.models import SMS_TYPE, KEY_TYPE_NORMAL, Service
from app.notifications.process_notifications import (
persist_notification,
send_notification_to_queue
@@ -147,13 +147,13 @@ def send_user_sms_code(user_id):
mobile = user_to_send_to.mobile_number if verify_code.get('to', None) is None else verify_code.get('to')
sms_code_template_id = current_app.config['SMS_CODE_TEMPLATE_ID']
sms_code_template = dao_get_template_by_id(sms_code_template_id)
notify_service_id = current_app.config['NOTIFY_SERVICE_ID']
service = Service.query.get(current_app.config['NOTIFY_SERVICE_ID'])
saved_notification = persist_notification(
template_id=sms_code_template_id,
template_version=sms_code_template.version,
recipient=mobile,
service_id=notify_service_id,
service=service,
personalisation={'verify_code': secret_code},
notification_type=SMS_TYPE,
api_key_id=None,