From 6130004b0cb6ceff263aaa71b6a1f9ebd89d5e69 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 6 Jun 2019 17:24:48 +0100 Subject: [PATCH] Fix inviting existing users MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The API needs the id of the user, not the id of the invite. The problem with the tests is that the update mock returned a different user ID than the user it was being passed. So the tests didn’t catch this. --- app/main/views/invites.py | 2 +- app/models/user.py | 4 ++-- tests/conftest.py | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/main/views/invites.py b/app/main/views/invites.py index 4bf563c42..8c3eb427e 100644 --- a/app/main/views/invites.py +++ b/app/main/views/invites.py @@ -65,7 +65,7 @@ def accept_invite(token): invited_user.auth_type == 'email_auth' ): existing_user.update(auth_type=invited_user.auth_type) - invited_user.add_to_service() + invited_user.add_to_service(existing_user_id=existing_user.id) return redirect(url_for('main.service_dashboard', service_id=service.id)) else: return redirect(url_for('main.register_from_invite')) diff --git a/app/models/user.py b/app/models/user.py index d649c6ab2..6af8e5aef 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -348,10 +348,10 @@ class InvitedUser(JSONModel): def accept_invite(self): invite_api_client.accept_invite(self.service, self.id) - def add_to_service(self): + def add_to_service(self, existing_user_id): user_api_client.add_user_to_service( self.service, - self.id, + existing_user_id, self.permissions, self.folder_permissions, ) diff --git a/tests/conftest.py b/tests/conftest.py index 4944606ef..71b49b41f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1652,6 +1652,7 @@ def mock_verify_password(mocker): @pytest.fixture(scope='function') def mock_update_user_password(mocker, api_user_active): def _update(user_id, password): + api_user_active['id'] = user_id return api_user_active return mocker.patch('app.user_api_client.update_password', side_effect=_update) @@ -1660,6 +1661,7 @@ def mock_update_user_password(mocker, api_user_active): @pytest.fixture(scope='function') def mock_update_user_attribute(mocker, api_user_active): def _update(user_id, **kwargs): + api_user_active['id'] = user_id return api_user_active return mocker.patch('app.user_api_client.update_user_attribute', side_effect=_update) @@ -1668,6 +1670,7 @@ def mock_update_user_attribute(mocker, api_user_active): @pytest.fixture def mock_activate_user(mocker, api_user_active): def _activate(user_id): + api_user_active['id'] = user_id return {'data': api_user_active} return mocker.patch('app.user_api_client.activate_user', side_effect=_activate)