mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 02:42:26 -05:00
Add cancelled-invite html.
If a invited user accepts a cancelled invitation they are directed to a page telling them the invitation is cancelled. Without this they were able to register and were added to the service.
This commit is contained in:
@@ -2,7 +2,8 @@ from flask import (
|
||||
redirect,
|
||||
url_for,
|
||||
session,
|
||||
abort
|
||||
abort,
|
||||
render_template
|
||||
)
|
||||
|
||||
from notifications_python_client.errors import HTTPError
|
||||
@@ -20,6 +21,9 @@ def accept_invite(token):
|
||||
try:
|
||||
|
||||
invited_user = invite_api_client.check_token(token)
|
||||
if invited_user.status == 'cancelled':
|
||||
return render_template('views/cancelled-invitation.html')
|
||||
|
||||
existing_user = user_api_client.get_user_by_email(invited_user.email_address)
|
||||
|
||||
if existing_user:
|
||||
|
||||
14
app/templates/views/cancelled-invitation.html
Normal file
14
app/templates/views/cancelled-invitation.html
Normal file
@@ -0,0 +1,14 @@
|
||||
{% extends "withoutnav_template.html" %}
|
||||
{% block page_title %}Invitation has been cancelled{% endblock %}
|
||||
{% block maincolumn_content %}
|
||||
<div class="grid-row">
|
||||
<div class="column-two-thirds">
|
||||
<h1 class="heading-large">
|
||||
The invitation you were sent has been cancelled.
|
||||
</h1>
|
||||
<p>
|
||||
The person that sent you the invitation decided that it was sent in error and has cancelled the invitation.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -48,12 +48,12 @@ def api_key_json(id_, name, expiry_date=None):
|
||||
}
|
||||
|
||||
|
||||
def invite_json(id, from_user, service_id, email_address, permissions, created_at):
|
||||
def invite_json(id, from_user, service_id, email_address, permissions, created_at, status):
|
||||
return {'id': id,
|
||||
'from_user': from_user,
|
||||
'service': service_id,
|
||||
'email_address': email_address,
|
||||
'status': 'pending',
|
||||
'status': status,
|
||||
'permissions': permissions,
|
||||
'created_at': created_at
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ from flask import url_for
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
import app
|
||||
from tests.conftest import sample_invite as create_sample_invite
|
||||
from tests.conftest import mock_check_invite_token as mock_check_token_invite
|
||||
|
||||
|
||||
def test_existing_user_accept_invite_calls_api_and_redirects_to_dashboard(app_,
|
||||
service_one,
|
||||
@@ -58,7 +62,6 @@ def test_existing_signed_out_user_accept_invite_redirects_to_sign_in(app_,
|
||||
|
||||
def test_new_user_accept_invite_calls_api_and_redirects_to_registration(app_,
|
||||
service_one,
|
||||
sample_invite,
|
||||
mock_check_invite_token,
|
||||
mock_dont_get_user_by_email,
|
||||
mock_add_user_to_service,
|
||||
@@ -78,6 +81,21 @@ def test_new_user_accept_invite_calls_api_and_redirects_to_registration(app_,
|
||||
assert response.location == expected_redirect_location
|
||||
|
||||
|
||||
def test_cancelled_invited_user_accepts_invited_redirect_to_cancelled_invitation(app_,
|
||||
service_one,
|
||||
mocker
|
||||
):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
cancelled_invitation = create_sample_invite(mocker, service_one, status='cancelled')
|
||||
mock_check_token_invite(mocker, cancelled_invitation)
|
||||
response = client.get(url_for('main.accept_invite', token='thisisnotarealtoken'))
|
||||
|
||||
app.invite_api_client.check_token.assert_called_with('thisisnotarealtoken')
|
||||
assert response.status_code == 200
|
||||
assert 'Invitation has been cancelled' in response.get_data(as_text=True)
|
||||
|
||||
|
||||
def test_new_user_accept_invite_completes_new_registration_redirects_to_verify(app_,
|
||||
service_one,
|
||||
sample_invite,
|
||||
|
||||
@@ -585,7 +585,7 @@ def mock_s3_upload(mocker):
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def sample_invite(mocker, service_one):
|
||||
def sample_invite(mocker, service_one, status='pending'):
|
||||
import datetime
|
||||
id = str(uuid.uuid4())
|
||||
from_user = service_one['users'][0]
|
||||
@@ -593,7 +593,7 @@ def sample_invite(mocker, service_one):
|
||||
service_id = service_one['id']
|
||||
permissions = 'send_messages,manage_service,manage_api_keys'
|
||||
created_at = str(datetime.datetime.now())
|
||||
return invite_json(id, from_user, service_id, email_address, permissions, created_at)
|
||||
return invite_json(id, from_user, service_id, email_address, permissions, created_at, status)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
|
||||
Reference in New Issue
Block a user