mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-05 21:38:24 -04:00
Merge pull request #3037 from alphagov/fix-org-invite
Fix a bug with inviting existing users to an organisation.
This commit is contained in:
@@ -65,7 +65,11 @@ def accept_invite(token):
|
|||||||
invited_user.auth_type == 'email_auth'
|
invited_user.auth_type == 'email_auth'
|
||||||
):
|
):
|
||||||
existing_user.update(auth_type=invited_user.auth_type)
|
existing_user.update(auth_type=invited_user.auth_type)
|
||||||
invited_user.add_to_service(existing_user_id=existing_user.id)
|
existing_user.add_to_service(
|
||||||
|
service_id=invited_user.service,
|
||||||
|
permissions=invited_user.permissions,
|
||||||
|
folder_permissions=invited_user.folder_permissions,
|
||||||
|
)
|
||||||
return redirect(url_for('main.service_dashboard', service_id=service.id))
|
return redirect(url_for('main.service_dashboard', service_id=service.id))
|
||||||
else:
|
else:
|
||||||
return redirect(url_for('main.register_from_invite'))
|
return redirect(url_for('main.register_from_invite'))
|
||||||
@@ -105,7 +109,7 @@ def accept_org_invite(token):
|
|||||||
if existing_user:
|
if existing_user:
|
||||||
invited_org_user.accept_invite()
|
invited_org_user.accept_invite()
|
||||||
if existing_user not in organisation_users:
|
if existing_user not in organisation_users:
|
||||||
invited_org_user.add_to_organisation()
|
existing_user.add_to_organisation(organisation_id=invited_org_user.organisation)
|
||||||
return redirect(url_for('main.organisation_dashboard', org_id=invited_org_user.organisation))
|
return redirect(url_for('main.organisation_dashboard', org_id=invited_org_user.organisation))
|
||||||
else:
|
else:
|
||||||
return redirect(url_for('main.register_from_org_invite'))
|
return redirect(url_for('main.register_from_org_invite'))
|
||||||
|
|||||||
@@ -389,6 +389,20 @@ class User(JSONModel, UserMixin):
|
|||||||
self.current_session_id = user_api_client.get_user(self.id).get('current_session_id')
|
self.current_session_id = user_api_client.get_user(self.id).get('current_session_id')
|
||||||
session['current_session_id'] = self.current_session_id
|
session['current_session_id'] = self.current_session_id
|
||||||
|
|
||||||
|
def add_to_service(self, service_id, permissions, folder_permissions):
|
||||||
|
user_api_client.add_user_to_service(
|
||||||
|
service_id,
|
||||||
|
self.id,
|
||||||
|
permissions,
|
||||||
|
folder_permissions,
|
||||||
|
)
|
||||||
|
|
||||||
|
def add_to_organisation(self, organisation_id):
|
||||||
|
user_api_client.add_user_to_organisation(
|
||||||
|
organisation_id,
|
||||||
|
self.id,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class InvitedUser(JSONModel):
|
class InvitedUser(JSONModel):
|
||||||
|
|
||||||
@@ -430,14 +444,6 @@ class InvitedUser(JSONModel):
|
|||||||
def accept_invite(self):
|
def accept_invite(self):
|
||||||
invite_api_client.accept_invite(self.service, self.id)
|
invite_api_client.accept_invite(self.service, self.id)
|
||||||
|
|
||||||
def add_to_service(self, existing_user_id):
|
|
||||||
user_api_client.add_user_to_service(
|
|
||||||
self.service,
|
|
||||||
existing_user_id,
|
|
||||||
self.permissions,
|
|
||||||
self.folder_permissions,
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def permissions(self):
|
def permissions(self):
|
||||||
return self._permissions
|
return self._permissions
|
||||||
@@ -584,9 +590,6 @@ class InvitedOrgUser(JSONModel):
|
|||||||
def accept_invite(self):
|
def accept_invite(self):
|
||||||
org_invite_api_client.accept_invite(self.organisation, self.id)
|
org_invite_api_client.accept_invite(self.organisation, self.id)
|
||||||
|
|
||||||
def add_to_organisation(self):
|
|
||||||
user_api_client.add_user_to_organisation(self.organisation, self.id)
|
|
||||||
|
|
||||||
|
|
||||||
class AnonymousUser(AnonymousUserMixin):
|
class AnonymousUser(AnonymousUserMixin):
|
||||||
# set the anonymous user so that if a new browser hits us we don't error http://stackoverflow.com/a/19275188
|
# set the anonymous user so that if a new browser hits us we don't error http://stackoverflow.com/a/19275188
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from unittest.mock import ANY
|
from unittest.mock import ANY
|
||||||
from uuid import UUID
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
@@ -84,7 +83,7 @@ def test_invite_org_user_errors_when_same_email_as_inviter(
|
|||||||
assert normalize_spaces(page.select_one('.error-message').text) == 'You can’t send an invitation to yourself'
|
assert normalize_spaces(page.select_one('.error-message').text) == 'You can’t send an invitation to yourself'
|
||||||
|
|
||||||
|
|
||||||
def test_accepted_invite_when_user_already_logged_in(
|
def test_accepted_invite_when_other_user_already_logged_in(
|
||||||
client_request,
|
client_request,
|
||||||
mock_check_org_invite_token
|
mock_check_org_invite_token
|
||||||
):
|
):
|
||||||
@@ -165,6 +164,7 @@ def test_existing_user_invite_already_is_member_of_organisation(
|
|||||||
|
|
||||||
def test_existing_user_invite_not_a_member_of_organisation(
|
def test_existing_user_invite_not_a_member_of_organisation(
|
||||||
client,
|
client,
|
||||||
|
api_user_active,
|
||||||
mock_check_org_invite_token,
|
mock_check_org_invite_token,
|
||||||
mock_get_user_by_email,
|
mock_get_user_by_email,
|
||||||
mock_get_users_for_organisation,
|
mock_get_users_for_organisation,
|
||||||
@@ -186,7 +186,7 @@ def test_existing_user_invite_not_a_member_of_organisation(
|
|||||||
mock_get_users_for_organisation.assert_called_once_with(ORGANISATION_ID)
|
mock_get_users_for_organisation.assert_called_once_with(ORGANISATION_ID)
|
||||||
mock_add_user_to_organisation.assert_called_once_with(
|
mock_add_user_to_organisation.assert_called_once_with(
|
||||||
ORGANISATION_ID,
|
ORGANISATION_ID,
|
||||||
str(UUID(bytes=b'sample_org_invit', version=4))
|
api_user_active['id'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user