mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-01 14:41:25 -04:00
Short circuit if team member is already invited
It would be confusing if people got invited twice, so let’s tell people if someone’s has a pending invite.
This commit is contained in:
@@ -65,7 +65,10 @@ def invite_user(service_id, user_id=None):
|
||||
|
||||
if user_id:
|
||||
user_to_invite = User.from_id(user_id)
|
||||
if user_to_invite.belongs_to_service(current_service.id):
|
||||
if (
|
||||
user_to_invite.belongs_to_service(current_service.id)
|
||||
or current_service.invite_pending_for(user_to_invite.email_address)
|
||||
):
|
||||
return render_template(
|
||||
'views/user-already-invited.html',
|
||||
user_to_invite=user_to_invite,
|
||||
|
||||
@@ -160,6 +160,12 @@ class Service(JSONModel):
|
||||
def invited_users(self):
|
||||
return InvitedUsers(self.id)
|
||||
|
||||
def invite_pending_for(self, email_address):
|
||||
return email_address.lower() in (
|
||||
invited_user.email_address.lower()
|
||||
for invited_user in self.invited_users
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def active_users(self):
|
||||
return Users(self.id)
|
||||
|
||||
@@ -817,6 +817,7 @@ def test_should_show_page_for_inviting_user_with_email_prefilled(
|
||||
active_user_with_permissions,
|
||||
active_user_with_permission_to_other_service,
|
||||
mock_get_organisation_by_domain,
|
||||
mock_get_invites_for_service,
|
||||
):
|
||||
service_one['organisation'] = ORGANISATION_ID
|
||||
mocker.patch('app.models.user.user_api_client.get_user', side_effect=[
|
||||
@@ -881,6 +882,38 @@ def test_should_show_page_if_prefilled_user_is_already_a_team_member(
|
||||
assert not page.select("form")
|
||||
|
||||
|
||||
def test_should_show_page_if_prefilled_user_is_already_invited(
|
||||
mocker,
|
||||
client_request,
|
||||
mock_get_template_folders,
|
||||
fake_uuid,
|
||||
active_user_with_permissions,
|
||||
active_user_with_permission_to_other_service,
|
||||
mock_get_invites_for_service,
|
||||
):
|
||||
active_user_with_permission_to_other_service['email_address'] = (
|
||||
'user_1@testnotify.gov.uk'
|
||||
)
|
||||
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_user_with_permission_to_other_service,
|
||||
])
|
||||
page = client_request.get(
|
||||
'main.invite_user',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
user_id=fake_uuid,
|
||||
# We have the user’s name in the H1 but don’t want it duplicated
|
||||
# in the page title
|
||||
_test_page_title=False,
|
||||
)
|
||||
|
||||
assert normalize_spaces(page.select_one('title').text).startswith(
|
||||
'This person is already a team member'
|
||||
)
|
||||
|
||||
|
||||
def test_should_403_if_trying_to_prefill_email_address_for_user_with_no_organisation(
|
||||
mocker,
|
||||
client_request,
|
||||
@@ -889,6 +922,7 @@ def test_should_403_if_trying_to_prefill_email_address_for_user_with_no_organisa
|
||||
fake_uuid,
|
||||
active_user_with_permissions,
|
||||
active_user_with_permission_to_other_service,
|
||||
mock_get_invites_for_service,
|
||||
mock_get_no_organisation_by_domain,
|
||||
):
|
||||
service_one['organisation'] = ORGANISATION_ID
|
||||
@@ -914,6 +948,7 @@ def test_should_403_if_trying_to_prefill_email_address_for_user_from_other_organ
|
||||
fake_uuid,
|
||||
active_user_with_permissions,
|
||||
active_user_with_permission_to_other_service,
|
||||
mock_get_invites_for_service,
|
||||
mock_get_organisation_by_domain,
|
||||
):
|
||||
service_one['organisation'] = ORGANISATION_TWO_ID
|
||||
@@ -1011,6 +1046,7 @@ def test_invite_user_when_email_address_is_prefilled(
|
||||
mocker,
|
||||
sample_invite,
|
||||
mock_get_template_folders,
|
||||
mock_get_invites_for_service,
|
||||
mock_get_organisation_by_domain,
|
||||
):
|
||||
service_one['organisation'] = ORGANISATION_ID
|
||||
|
||||
Reference in New Issue
Block a user