diff --git a/app/main/forms.py b/app/main/forms.py index 4d0cb8f80..166323db7 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -104,7 +104,7 @@ class RegisterUserFromInviteForm(Form): mobile_number = mobile_number() password = password() service = HiddenField('service') - email_address = HiddenField('email_address') + email_address = email_address() class InviteUserForm(Form): diff --git a/app/templates/components/textbox.html b/app/templates/components/textbox.html index b50fb9ee4..2fb5ea89e 100644 --- a/app/templates/components/textbox.html +++ b/app/templates/components/textbox.html @@ -6,7 +6,8 @@ help_link=None, help_link_text=None, width='2-3', - suffix=None + suffix=None, + disabled=False ) %}
- {{ field(**{ - 'class': 'form-control form-control-{} textbox-highlight-textbox'.format(width) if highlight_tags else 'form-control form-control-{} {}'.format(width, 'textbox-right-aligned' if suffix else ''), - 'data-module': 'highlight-tags' if highlight_tags else '' - }) }} + {% if disabled %} + {{ field(**{ + 'class': 'form-control form-control-{} textbox-highlight-textbox'.format(width) if highlight_tags else 'form-control form-control-{} {}'.format(width, 'textbox-right-aligned' if suffix else ''), + 'data-module': 'highlight-tags' if highlight_tags else '', + 'disabled': 'disabled' + }) }} + {% else %} + {{ field(**{ + 'class': 'form-control form-control-{} textbox-highlight-textbox'.format(width) if highlight_tags else 'form-control form-control-{} {}'.format(width, 'textbox-right-aligned' if suffix else ''), + 'data-module': 'highlight-tags' if highlight_tags else '' + }) }} + {% endif %} + + {% if suffix %} {{ suffix }} {% endif %} diff --git a/app/templates/views/register-from-invite.html b/app/templates/views/register-from-invite.html index 7e7e81aaa..b08e8d24f 100644 --- a/app/templates/views/register-from-invite.html +++ b/app/templates/views/register-from-invite.html @@ -12,12 +12,12 @@ Create an account – GOV.UK Notify

Create an account

+ {{ textbox(form.email_address, width='3-4', disabled=True ) }} {{ textbox(form.name, width='3-4') }} {{ textbox(form.mobile_number, width='3-4') }} {{ textbox(form.password, hint="Your password must have at least 10 characters", width='3-4') }} {{ page_footer("Continue") }} {{form.service}} - {{form.email_address}}
diff --git a/tests/app/main/views/test_accept_invite.py b/tests/app/main/views/test_accept_invite.py index 3a83f7578..0cc735aeb 100644 --- a/tests/app/main/views/test_accept_invite.py +++ b/tests/app/main/views/test_accept_invite.py @@ -81,6 +81,39 @@ def test_new_user_accept_invite_calls_api_and_redirects_to_registration(app_, assert response.location == expected_redirect_location +def test_new_user_accept_invite_calls_api_and_views_registration_page(app_, + service_one, + mock_check_invite_token, + mock_dont_get_user_by_email, + mock_add_user_to_service, + mock_accept_invite): + + with app_.test_request_context(): + with app_.test_client() as client: + + response = client.get(url_for('main.accept_invite', token='thisisnotarealtoken'), follow_redirects=True) + + mock_check_invite_token.assert_called_with('thisisnotarealtoken') + mock_dont_get_user_by_email.assert_called_with('invited_user@test.gov.uk') + + assert response.status_code == 200 + page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') + assert page.h1.string.strip() == 'Create an account' + + form = page.find('form') + email = form.find('input', id='email_address') + name = form.find('input', id='name') + password = form.find('input', id='password') + service = form.find('input', type='hidden', id='service') + + assert email + assert email.attrs['disabled'] + assert name + assert password + assert service + assert service.attrs['value'] == service_one['id'] + + def test_cancelled_invited_user_accepts_invited_redirect_to_cancelled_invitation(app_, service_one, mocker,