Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix auto activation in the repo level #996

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions graphql_api/tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,50 +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,
)

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,
)

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(
Expand Down
11 changes: 4 additions & 7 deletions graphql_api/types/owner/owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -163,16 +163,13 @@ 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:
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()

info.context["profiling_summary"] = ProfilingSummary(repository)
return repository
Expand Down
2 changes: 1 addition & 1 deletion services/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading