mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Send confirmation emails to users when team manager edits their
email address or mobile number.
This commit is contained in:
@@ -145,6 +145,8 @@ class Config(object):
|
||||
CHANGE_EMAIL_CONFIRMATION_TEMPLATE_ID = 'eb4d9930-87ab-4aef-9bce-786762687884'
|
||||
SERVICE_NOW_LIVE_TEMPLATE_ID = '618185c6-3636-49cd-b7d2-6f6f5eb3bdde'
|
||||
ORGANISATION_INVITATION_EMAIL_TEMPLATE_ID = '203566f0-d835-47c5-aa06-932439c86573'
|
||||
TEAM_MEMBER_EDIT_EMAIL_TEMPLATE_ID = 'c73f1d71-4049-46d5-a647-d013bdeca3f0'
|
||||
TEAM_MEMBER_EDIT_MOBILE_TEMPLATE_ID = '8a31520f-4751-4789-8ea1-fe54496725eb'
|
||||
|
||||
BROKER_URL = 'sqs://'
|
||||
BROKER_TRANSPORT_OPTIONS = {
|
||||
|
||||
@@ -84,10 +84,45 @@ def create_user():
|
||||
def update_user_attribute(user_id):
|
||||
user_to_update = get_user_by_id(user_id=user_id)
|
||||
req_json = request.get_json()
|
||||
if 'updated_by' in req_json:
|
||||
updated_by = get_user_by_id(user_id=req_json.pop('updated_by'))
|
||||
else:
|
||||
updated_by = None
|
||||
|
||||
update_dct, errors = user_update_schema_load_json.load(req_json)
|
||||
if errors:
|
||||
raise InvalidRequest(errors, status_code=400)
|
||||
save_user_attribute(user_to_update, update_dict=update_dct)
|
||||
if updated_by:
|
||||
if 'email_address' in update_dct:
|
||||
template = dao_get_template_by_id(current_app.config['TEAM_MEMBER_EDIT_EMAIL_TEMPLATE_ID'])
|
||||
recipient = user_to_update.email_address
|
||||
reply_to = template.service.get_default_reply_to_email_address()
|
||||
elif 'mobile_number' in update_dct:
|
||||
template = dao_get_template_by_id(current_app.config['TEAM_MEMBER_EDIT_MOBILE_TEMPLATE_ID'])
|
||||
recipient = user_to_update.mobile_number
|
||||
reply_to = template.service.get_default_sms_sender()
|
||||
else:
|
||||
return jsonify(data=user_to_update.serialize()), 200
|
||||
service = Service.query.get(current_app.config['NOTIFY_SERVICE_ID'])
|
||||
|
||||
saved_notification = persist_notification(
|
||||
template_id=template.id,
|
||||
template_version=template.version,
|
||||
recipient=recipient,
|
||||
service=service,
|
||||
personalisation={
|
||||
'name': user_to_update.name,
|
||||
'servicemanagername': updated_by.name,
|
||||
'email address': user_to_update.email_address
|
||||
},
|
||||
notification_type=template.template_type,
|
||||
api_key_id=None,
|
||||
key_type=KEY_TYPE_NORMAL,
|
||||
reply_to_text=reply_to
|
||||
)
|
||||
|
||||
send_notification_to_queue(saved_notification, False, queue=QueueNames.NOTIFY)
|
||||
return jsonify(data=user_to_update.serialize()), 200
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user