From 8e32995c8d38e964dfca4cc1fdcd6a9fdfe010e7 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Thu, 4 Jul 2019 15:12:08 +0100 Subject: [PATCH] only send emails if a user signed the MOU the agreement_signed field can also be edited by a platform admin - if that happened we might not have details for who signed it, and even if we did they shouldn't find out about, and we don't need an email since we were the ones who clicked the button. the `agreement_signed_by` field is only set when a user confirms that they are signing the MOU on the admin page - not if a platform admin modifies the page from the platform admin page --- app/dao/organisation_dao.py | 4 ++-- app/organisation/rest.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/dao/organisation_dao.py b/app/dao/organisation_dao.py index a667661c2..3f17823c0 100644 --- a/app/dao/organisation_dao.py +++ b/app/dao/organisation_dao.py @@ -64,7 +64,7 @@ def dao_update_organisation(organisation_id, **kwargs): domains = kwargs.pop('domains', None) - organisation = Organisation.query.filter_by(id=organisation_id).update( + num_updated = Organisation.query.filter_by(id=organisation_id).update( kwargs ) @@ -79,7 +79,7 @@ def dao_update_organisation(organisation_id, **kwargs): db.session.commit() - return organisation + return num_updated @transactional diff --git a/app/organisation/rest.py b/app/organisation/rest.py index fd63698cc..1d3da458b 100644 --- a/app/organisation/rest.py +++ b/app/organisation/rest.py @@ -96,7 +96,9 @@ def update_organisation(organisation_id): result = dao_update_organisation(organisation_id, **data) if data.get('agreement_signed') is True: - send_notifications_on_mou_signed(organisation_id) + # if a platform admin has manually adjusted the organisation, don't tell people + if data.get('agreement_signed_by_id'): + send_notifications_on_mou_signed(organisation_id) if result: return '', 204 @@ -159,6 +161,7 @@ def check_request_args(request): def send_notifications_on_mou_signed(organisation_id): + organisation = dao_get_organisation_by_id(organisation_id) notify_service = dao_fetch_service_by_id(current_app.config['NOTIFY_SERVICE_ID']) def _send_notification(template_id, recipient, personalisation): @@ -178,7 +181,6 @@ def send_notifications_on_mou_signed(organisation_id): send_notification_to_queue(saved_notification, research_mode=False, queue=QueueNames.NOTIFY) - organisation = dao_get_organisation_by_id(organisation_id) personalisation = { 'mou_link': '{}/agreement/{}.pdf'.format( current_app.config['ADMIN_BASE_URL'],