From 3d7aee19d2827b4c49c72e1a0eb5693bdab6a320 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Tue, 9 Sep 2025 08:24:33 -0700 Subject: [PATCH] fix org invite tests --- app/main/views/register.py | 2 ++ app/models/user.py | 6 +++--- tests/app/main/test_permissions.py | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/main/views/register.py b/app/main/views/register.py index 7a1a07c17..2c97fe1b7 100644 --- a/app/main/views/register.py +++ b/app/main/views/register.py @@ -276,7 +276,9 @@ def set_up_your_profile(): current_app.logger.info(f"#invites redirecting to {url}") return redirect(url) else: + usr = User.from_id(user["id"]) org_id = invite_data["organization"] + usr.add_to_organization(org_id) url = url_for(".organization_dashboard", org_id=org_id) current_app.logger.info(f"#invites redirecting to {url}") return redirect(url) diff --git a/app/models/user.py b/app/models/user.py index 0ab0347de..7aee7c864 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -259,7 +259,7 @@ class User(JSONModel, UserMixin): # TODO this is sketch! Fix this! # This is temporary to restore org invite functionality only - self.add_to_organization(org_id) + # self.add_to_organization(org_id) value = self.belongs_to_organization(org_id) current_app.logger.debug( f"has_permissions returns org: {org_id} returning {value}" @@ -326,8 +326,8 @@ class User(JSONModel, UserMixin): # TODO this is sketch! Fix this! # This is temporary to restore org invite functionality only - if str(organization_id) not in self.organization_ids: - self.add_to_organization(organization_id) + # if str(organization_id) not in self.organization_ids: + # self.add_to_organization(organization_id) return str(organization_id) in self.organization_ids @property diff --git a/tests/app/main/test_permissions.py b/tests/app/main/test_permissions.py index ff57211bb..bf1187ea9 100644 --- a/tests/app/main/test_permissions.py +++ b/tests/app/main/test_permissions.py @@ -19,15 +19,15 @@ from tests.conftest import ( ("user_services", "user_organizations", "expected_status", "organization_checked"), [ ([SERVICE_ONE_ID], [], 200, False), - ([SERVICE_ONE_ID, SERVICE_TWO_ID], [], 201, False), - ([], [ORGANISATION_ID], 202, True), - ([SERVICE_ONE_ID], [ORGANISATION_ID], 203, False), - # ([], [], 403, True), - # ([SERVICE_TWO_ID], [], 403, True), - ([SERVICE_TWO_ID], [ORGANISATION_ID], 204, True), - ([SERVICE_ONE_ID, SERVICE_TWO_ID], [ORGANISATION_ID], 205, False), - # ([], [ORGANISATION_TWO_ID], 403, True), - ([], [ORGANISATION_ID, ORGANISATION_TWO_ID], 206, True), + ([SERVICE_ONE_ID, SERVICE_TWO_ID], [], 200, False), + ([], [ORGANISATION_ID], 200, True), + ([SERVICE_ONE_ID], [ORGANISATION_ID], 200, False), + ([], [], 403, True), + ([SERVICE_TWO_ID], [], 403, True), + ([SERVICE_TWO_ID], [ORGANISATION_ID], 200, True), + ([SERVICE_ONE_ID, SERVICE_TWO_ID], [ORGANISATION_ID], 200, False), + ([], [ORGANISATION_TWO_ID], 403, True), + ([], [ORGANISATION_ID, ORGANISATION_TWO_ID], 200, True), ], ) def test_services_pages_that_org_users_are_allowed_to_see( @@ -81,8 +81,8 @@ def test_services_pages_that_org_users_are_allowed_to_see( endpoint, service_id=SERVICE_ONE_ID, _expected_status=expected_status, - nonce="nonce", - state="state", + nonce="dummy-nonce", + state="dummy-state", ) assert mock_get_service.called is organization_checked