From 25079464b0073c17b599a6c245f674eaa2f9e034 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 7 Apr 2016 15:03:36 +0100 Subject: [PATCH] More helpful error when signed in an accept invite --- app/main/views/invites.py | 9 ++++++++- tests/app/main/views/test_accept_invite.py | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/main/views/invites.py b/app/main/views/invites.py index d4190e09d..19fa49c8a 100644 --- a/app/main/views/invites.py +++ b/app/main/views/invites.py @@ -27,7 +27,14 @@ def accept_invite(token): invited_user = invite_api_client.check_token(token) if not current_user.is_anonymous() and current_user.email_address != invited_user.email_address: - flash("You can't accept an invite for another person.") + flash(""" + You’re signed in as {}. + This invite is for another email address. + Sign out and click the link again to accept this invite. + """.format( + current_user.email_address, + url_for("main.sign_out") + )) abort(403) if invited_user.status == 'cancelled': diff --git a/tests/app/main/views/test_accept_invite.py b/tests/app/main/views/test_accept_invite.py index fb1084cb2..7cfbd8142 100644 --- a/tests/app/main/views/test_accept_invite.py +++ b/tests/app/main/views/test_accept_invite.py @@ -284,7 +284,10 @@ def test_signed_in_existing_user_cannot_use_anothers_invite(app_, assert page.h1.string.strip() == '403' flash_banners = page.find_all('div', class_='banner-dangerous') assert len(flash_banners) == 1 - assert flash_banners[0].text.strip() == "You can't accept an invite for another person." + banner_contents = flash_banners[0].text.strip() + assert "You’re signed in as test@user.gov.uk." in banner_contents + assert "This invite is for another email address." in banner_contents + assert "Sign out and click the link again to accept this invite." in banner_contents assert mock_accept_invite.call_count == 0