diff --git a/graphql_api/tests/test_repository.py b/graphql_api/tests/test_repository.py index a2224b714a..cc1c033345 100644 --- a/graphql_api/tests/test_repository.py +++ b/graphql_api/tests/test_repository.py @@ -405,6 +405,8 @@ def test_repository_auto_activate(self, try_auto_activate): author=self.owner, active=True, private=True, + coverage_enabled=True, + bundle_analysis_enabled=True, ) self.gql_request( @@ -425,6 +427,8 @@ def test_repository_not_activated(self, try_auto_activate, is_activated): author=self.owner, active=True, private=True, + coverage_enabled=True, + bundle_analysis_enabled=True, ) is_activated.return_value = False @@ -446,6 +450,8 @@ def test_repository_not_activated_self_hosted(self, try_auto_activate): author=self.owner, active=True, private=True, + coverage_enabled=True, + bundle_analysis_enabled=True, ) data = self.gql_request( @@ -458,6 +464,31 @@ def test_repository_not_activated_self_hosted(self, try_auto_activate): "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( + self, try_auto_activate, is_activated + ): + repo = RepositoryFactory( + author=self.owner, + active=False, + activated=False, + private=True, + name="test-one", + coverage_enabled=True, + bundle_analysis_enabled=False, + ) + + is_activated.return_value = False + + data = self.gql_request( + query_repository % "name", + owner=self.owner, + variables={"name": repo.name}, + ) + + assert data["me"]["owner"]["repository"]["name"] == "test-one" + def test_repository_not_found(self): data = self.gql_request( query_repository % "name", diff --git a/graphql_api/types/owner/owner.py b/graphql_api/types/owner/owner.py index 7164c8e6c8..49b1fce829 100644 --- a/graphql_api/types/owner/owner.py +++ b/graphql_api/types/owner/owner.py @@ -114,16 +114,19 @@ async def resolve_repository(owner, info, name): return NotFoundError() current_owner = info.context["request"].current_owner - if repository.private: + has_products_enabled = ( + repository.bundle_analysis_enabled and repository.coverage_enabled + ) + + if repository.private and has_products_enabled: await sync_to_async(activation.try_auto_activate)(owner, current_owner) - is_activated = await sync_to_async(activation.is_activated)( + is_owner_activated = await sync_to_async(activation.is_activated)( owner, current_owner ) - if not is_activated: + if not is_owner_activated: return OwnerNotActivatedError() info.context["profiling_summary"] = ProfilingSummary(repository) - return repository