From 90f4451b7094553f780683db85619ac1d18611d4 Mon Sep 17 00:00:00 2001 From: RulaKhaled Date: Thu, 21 Nov 2024 16:13:00 +0100 Subject: [PATCH 1/3] fix: Auto activate when any of the products are enabled --- graphql_api/types/owner/owner.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/graphql_api/types/owner/owner.py b/graphql_api/types/owner/owner.py index 40fa259771..095f962fcc 100644 --- a/graphql_api/types/owner/owner.py +++ b/graphql_api/types/owner/owner.py @@ -163,7 +163,9 @@ async def resolve_repository( current_owner = info.context["request"].current_owner has_products_enabled = ( - repository.bundle_analysis_enabled and repository.coverage_enabled + repository.bundle_analysis_enabled + or repository.coverage_enabled + or repository.test_analytics_enabled ) if repository.private and has_products_enabled: From 70da0bf8cc40365692de56755907fd5acc490082 Mon Sep 17 00:00:00 2001 From: RulaKhaled Date: Thu, 21 Nov 2024 16:54:20 +0100 Subject: [PATCH 2/3] fix tests --- graphql_api/tests/test_repository.py | 2 ++ graphql_api/types/owner/owner.py | 24 ++++++++++++++---------- services/activation.py | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/graphql_api/tests/test_repository.py b/graphql_api/tests/test_repository.py index 5d1aac5659..585dcd33c6 100644 --- a/graphql_api/tests/test_repository.py +++ b/graphql_api/tests/test_repository.py @@ -438,6 +438,7 @@ def test_repository_not_activated(self, try_auto_activate, is_activated): private=True, coverage_enabled=True, bundle_analysis_enabled=True, + test_analytics_enabled=True, ) is_activated.return_value = False @@ -461,6 +462,7 @@ def test_repository_not_activated_self_hosted(self, try_auto_activate): private=True, coverage_enabled=True, bundle_analysis_enabled=True, + test_analytics_enabled=True, ) data = self.gql_request( diff --git a/graphql_api/types/owner/owner.py b/graphql_api/types/owner/owner.py index 095f962fcc..63215d4d91 100644 --- a/graphql_api/types/owner/owner.py +++ b/graphql_api/types/owner/owner.py @@ -162,19 +162,23 @@ async def resolve_repository( return NotFoundError() current_owner = info.context["request"].current_owner - has_products_enabled = ( - repository.bundle_analysis_enabled - or repository.coverage_enabled - or repository.test_analytics_enabled - ) + product_flags = [ + repository.bundle_analysis_enabled, + repository.coverage_enabled, + repository.test_analytics_enabled, + ] + has_products_enabled = any(product_flags) + all_products_enabled = all(product_flags) if repository.private and has_products_enabled: await sync_to_async(activation.try_auto_activate)(owner, current_owner) - is_owner_activated = await sync_to_async(activation.is_activated)( - owner, current_owner - ) - if not is_owner_activated: - return OwnerNotActivatedError() + + is_owner_activated = await sync_to_async(activation.is_activated)( + owner, current_owner + ) + + if all_products_enabled and not is_owner_activated: + return OwnerNotActivatedError() info.context["profiling_summary"] = ProfilingSummary(repository) return repository diff --git a/services/activation.py b/services/activation.py index 033403ba88..b69326d7f1 100644 --- a/services/activation.py +++ b/services/activation.py @@ -71,7 +71,7 @@ def _get_activator(org: Owner, owner: Owner) -> BaseActivator: def try_auto_activate(org: Owner, owner: Owner) -> bool: """ - Returns true iff the user was able to be activated, false otherwise. + Returns true if the user was able to be activated, false otherwise. """ activator = _get_activator(org, owner) From d7732cca35773a4af649fe774c6846512cc6c1b6 Mon Sep 17 00:00:00 2001 From: RulaKhaled Date: Thu, 21 Nov 2024 17:24:34 +0100 Subject: [PATCH 3/3] Remove OwnerNotActivatedError --- graphql_api/tests/test_repository.py | 46 ---------------------------- graphql_api/types/owner/owner.py | 21 ++++--------- 2 files changed, 6 insertions(+), 61 deletions(-) diff --git a/graphql_api/tests/test_repository.py b/graphql_api/tests/test_repository.py index 585dcd33c6..c3cbbed093 100644 --- a/graphql_api/tests/test_repository.py +++ b/graphql_api/tests/test_repository.py @@ -429,52 +429,6 @@ def test_repository_auto_activate(self, try_auto_activate): self.owner, ) - @patch("services.activation.is_activated") - @patch("services.activation.try_auto_activate") - def test_repository_not_activated(self, try_auto_activate, is_activated): - repo = RepositoryFactory( - author=self.owner, - active=True, - private=True, - coverage_enabled=True, - bundle_analysis_enabled=True, - test_analytics_enabled=True, - ) - - is_activated.return_value = False - - data = self.gql_request( - query_repository % "name", - owner=self.owner, - variables={"name": repo.name}, - ) - assert data["me"]["owner"]["repository"] == { - "__typename": "OwnerNotActivatedError", - "message": "You must be activated in the org", - } - - @override_settings(IS_ENTERPRISE=True) - @patch("services.activation.try_auto_activate") - def test_repository_not_activated_self_hosted(self, try_auto_activate): - repo = RepositoryFactory( - author=self.owner, - active=True, - private=True, - coverage_enabled=True, - bundle_analysis_enabled=True, - test_analytics_enabled=True, - ) - - data = self.gql_request( - query_repository % "name", - owner=self.owner, - variables={"name": repo.name}, - ) - assert data["me"]["owner"]["repository"] == { - "__typename": "OwnerNotActivatedError", - "message": "You must be activated in the org", - } - @patch("services.activation.is_activated") @patch("services.activation.try_auto_activate") def test_resolve_inactive_user_on_unconfigured_repo( diff --git a/graphql_api/types/owner/owner.py b/graphql_api/types/owner/owner.py index 63215d4d91..7cca4f9ac1 100644 --- a/graphql_api/types/owner/owner.py +++ b/graphql_api/types/owner/owner.py @@ -37,7 +37,7 @@ require_shared_account_or_part_of_org, ) from graphql_api.types.enums import OrderingDirection, RepositoryOrdering -from graphql_api.types.errors.errors import NotFoundError, OwnerNotActivatedError +from graphql_api.types.errors.errors import NotFoundError from graphql_api.types.repository.repository import TOKEN_UNAVAILABLE from plan.constants import FREE_PLAN_REPRESENTATIONS, PlanData, PlanName from plan.service import PlanService @@ -162,24 +162,15 @@ async def resolve_repository( return NotFoundError() current_owner = info.context["request"].current_owner - product_flags = [ - repository.bundle_analysis_enabled, - repository.coverage_enabled, - repository.test_analytics_enabled, - ] - has_products_enabled = any(product_flags) - all_products_enabled = all(product_flags) + has_products_enabled = ( + repository.bundle_analysis_enabled + or repository.coverage_enabled + or repository.test_analytics_enabled + ) if repository.private and has_products_enabled: await sync_to_async(activation.try_auto_activate)(owner, current_owner) - is_owner_activated = await sync_to_async(activation.is_activated)( - owner, current_owner - ) - - if all_products_enabled and not is_owner_activated: - return OwnerNotActivatedError() - info.context["profiling_summary"] = ProfilingSummary(repository) return repository