Allow invite form to be pre-populated

At the moment users must be invited to join a service. But this means:
- users must know that a service already exists
- they need to know who to ask for an invite

If the user doesn’t know these thing then sometimes they just go ahead
and set up a new service. Which means they have to get all the way to
the point of requesting to go live before we tell them that there’s
already a service with a similar name or purpose.

So we should let users:
1. discover what other services exist in their organisation
2. apply to join a service
3. automatically notify the service managers of their interest
4. be invited by a service manager
5. accept the invite

This commit implements step 4. We can just link them to the invite form
in step 3., but we should make it easy for them to send the invite,
without having to copy and paste email addresses.

So this commit let the invite form be pre-populated with an existing
user’s email address.
This commit is contained in:
Chris Hill-Scott
2020-06-08 10:58:15 +01:00
parent 6d8fdb669c
commit 6edc356c22
3 changed files with 83 additions and 8 deletions

View File

@@ -48,8 +48,9 @@ def manage_users(service_id):
@main.route("/services/<uuid:service_id>/users/invite", methods=['GET', 'POST'])
@main.route("/services/<uuid:service_id>/users/invite/<uuid:user_id>", methods=['GET', 'POST'])
@user_has_permissions('manage_service')
def invite_user(service_id):
def invite_user(service_id, user_id=None):
if current_service.has_permission('broadcast'):
form_class = BroadcastInviteUserForm
@@ -62,6 +63,12 @@ def invite_user(service_id):
folder_permissions=[f['id'] for f in current_service.all_template_folders]
)
if user_id:
user_to_invite = User.from_id(user_id)
form.email_address.data = user_to_invite.email_address
else:
user_to_invite = None
service_has_email_auth = current_service.has_permission('email_auth')
if not service_has_email_auth:
form.login_authentication.data = 'sms_auth'
@@ -85,6 +92,7 @@ def invite_user(service_id):
form=form,
service_has_email_auth=service_has_email_auth,
mobile_number=True,
user_to_invite=user_to_invite,
)

View File

@@ -10,18 +10,24 @@
{% block maincolumn_content %}
{{ page_header(
'Invite a team member',
'Invite {}'.format(user_to_invite.name if user_to_invite else 'a team member') ,
back_link=url_for('main.manage_users', service_id=current_service.id)
) }}
{% call form_wrapper() %}
{{ form.email_address(
param_extensions={
"classes": "govuk-!-width-full"
},
error_message_with_html=True
) }}
{% if user_to_invite %}
<p class="govuk-body">
{{ user_to_invite.email_address }}
</p>
{% else %}
{{ form.email_address(
param_extensions={
"classes": "govuk-!-width-full"
},
error_message_with_html=True
) }}
{% endif %}
{% include 'views/manage-users/permissions.html' %}

View File

@@ -806,6 +806,29 @@ def test_should_show_page_for_inviting_user(
assert not page.find('div', class_='checkboxes-nested')
def test_should_show_page_for_inviting_user_with_email_prefilled(
client_request,
mock_get_template_folders,
fake_uuid,
):
page = client_request.get(
'main.invite_user',
service_id=SERVICE_ONE_ID,
user_id=fake_uuid,
# We have the users name in the H1 but dont want it duplicated
# in the page title
_test_page_title=False,
)
assert normalize_spaces(page.select_one('h1').text) == (
'Invite Test User'
)
assert normalize_spaces(page.select_one('main .govuk-body').text) == (
'test@user.gov.uk'
)
assert not page.select("input#email_address") or page.select("input[type=email]")
def test_should_show_folder_permission_form_if_service_has_folder_permissions_enabled(
client_request,
mocker,
@@ -877,6 +900,44 @@ def test_invite_user(
[])
def test_invite_user_when_email_address_is_prefilled(
client_request,
active_user_with_permissions,
active_caseworking_user,
fake_uuid,
mocker,
sample_invite,
mock_get_template_folders,
):
mocker.patch('app.models.user.user_api_client.get_user', side_effect=[
# First call is to get the current user
active_user_with_permissions,
# Second call gets the user to invite
active_caseworking_user,
])
mocker.patch('app.invite_api_client.create_invite', return_value=sample_invite)
client_request.post(
'main.invite_user',
service_id=SERVICE_ONE_ID,
user_id=fake_uuid,
_data={
# No posted email address
'permissions_field': [
'send_messages',
],
},
)
app.invite_api_client.create_invite.assert_called_once_with(
active_user_with_permissions['id'],
SERVICE_ONE_ID,
active_caseworking_user['email_address'],
{'send_messages'},
'sms_auth',
[],
)
@pytest.mark.parametrize('auth_type', [
('sms_auth'),
('email_auth')