mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-17 04:58:50 -04:00
Merge pull request #3478 from alphagov/custom-base-url-register-email
Allow admin app to specify domain for registration email
This commit is contained in:
@@ -374,6 +374,8 @@ def send_user_confirm_new_email(user_id):
|
||||
|
||||
@user_blueprint.route('/<uuid:user_id>/email-verification', methods=['POST'])
|
||||
def send_new_user_email_verification(user_id):
|
||||
request_json = request.get_json()
|
||||
|
||||
# when registering, we verify all users' email addresses using this function
|
||||
user_to_send_to = get_user_by_id(user_id=user_id)
|
||||
|
||||
@@ -387,7 +389,10 @@ def send_new_user_email_verification(user_id):
|
||||
service=service,
|
||||
personalisation={
|
||||
'name': user_to_send_to.name,
|
||||
'url': _create_verification_url(user_to_send_to)
|
||||
'url': _create_verification_url(
|
||||
user_to_send_to,
|
||||
base_url=request_json.get('admin_base_url'),
|
||||
),
|
||||
},
|
||||
notification_type=template.template_type,
|
||||
api_key_id=None,
|
||||
@@ -556,10 +561,10 @@ def _create_reset_password_url(email, next_redirect, base_url=None):
|
||||
return full_url
|
||||
|
||||
|
||||
def _create_verification_url(user):
|
||||
def _create_verification_url(user, base_url):
|
||||
data = json.dumps({'user_id': str(user.id), 'email': user.email_address})
|
||||
url = '/verify-email/'
|
||||
return url_with_token(data, url, current_app.config)
|
||||
return url_with_token(data, url, current_app.config, base_url=base_url)
|
||||
|
||||
|
||||
def _create_confirmation_url(user, email_address):
|
||||
|
||||
@@ -292,15 +292,29 @@ def test_send_sms_code_returns_204_when_too_many_codes_already_created(client, s
|
||||
assert VerifyCode.query.count() == 5
|
||||
|
||||
|
||||
def test_send_new_user_email_verification(client,
|
||||
sample_user,
|
||||
mocker,
|
||||
email_verification_template):
|
||||
@pytest.mark.parametrize('post_data, expected_url_starts_with', (
|
||||
(
|
||||
{},
|
||||
'http://localhost',
|
||||
),
|
||||
(
|
||||
{'admin_base_url': 'https://example.com'},
|
||||
'https://example.com',
|
||||
),
|
||||
))
|
||||
def test_send_new_user_email_verification(
|
||||
client,
|
||||
sample_user,
|
||||
mocker,
|
||||
email_verification_template,
|
||||
post_data,
|
||||
expected_url_starts_with,
|
||||
):
|
||||
mocked = mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
|
||||
auth_header = create_admin_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.send_new_user_email_verification', user_id=str(sample_user.id)),
|
||||
data=json.dumps({}),
|
||||
data=json.dumps(post_data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
notify_service = email_verification_template.service
|
||||
assert resp.status_code == 204
|
||||
@@ -308,6 +322,8 @@ def test_send_new_user_email_verification(client,
|
||||
assert VerifyCode.query.count() == 0
|
||||
mocked.assert_called_once_with(([str(notification.id)]), queue="notify-internal-tasks")
|
||||
assert notification.reply_to_text == notify_service.get_default_reply_to_email_address()
|
||||
assert notification.personalisation['name'] == 'Test User'
|
||||
assert notification.personalisation['url'].startswith(expected_url_starts_with)
|
||||
|
||||
|
||||
def test_send_email_verification_returns_404_for_bad_input_data(client, notify_db_session, mocker):
|
||||
|
||||
Reference in New Issue
Block a user