Skip to content

Commit

Permalink
Skip OwnerNotActivated error on unconfigured repos (#516)
Browse files Browse the repository at this point in the history
* Skip error on unconfigured repos

* update test

* fix test

* Update to product code

* Update var names

* Update tests

* Update
  • Loading branch information
rohitvinnakota-codecov committed May 2, 2024
1 parent 5208a04 commit e79b910
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
31 changes: 31 additions & 0 deletions graphql_api/tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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",
Expand Down
11 changes: 7 additions & 4 deletions graphql_api/types/owner/owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit e79b910

Please sign in to comment.