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 deactivated enterprise user when no plan activated users #1088

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
20 changes: 20 additions & 0 deletions graphql_api/tests/test_owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,26 @@ def test_fetch_owner_on_unauthenticated_enteprise_guest_access_not_activated(sel
assert e.message == UnauthorizedGuestAccess.message
assert e.extensions["code"] == UnauthorizedGuestAccess.code

@override_settings(IS_ENTERPRISE=True, GUEST_ACCESS=False)
def test_fetch_owner_plan_activated_users_is_none(self):
"""
This test is when Enterprise guest access is disabled, and you are
trying to view an org that does not track plan activated users (e.g., historic data)
"""
user = OwnerFactory(username="sample-user")
owner = OwnerFactory(username="sample-owner", plan_activated_users=None)
user.save()
owner.save()
query = """{
owner(username: "%s") {
username
}
}
""" % (owner.username)

data = self.gql_request(query, owner=user)
assert data["owner"]["username"] == "sample-owner"

def test_fetch_current_user_is_okta_authenticated(self):
account = AccountFactory()
owner = OwnerFactory(username="sample-owner", service="github", account=account)
Expand Down
11 changes: 8 additions & 3 deletions graphql_api/types/query/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ async def resolve_owner(
if settings.IS_ENTERPRISE and settings.GUEST_ACCESS is False:
if not user or not user.is_authenticated:
raise UnauthorizedGuestAccess()

target = await get_owner(service, username)
if user.ownerid not in target.plan_activated_users:
target_owner = await get_owner(service, username)
has_plan_activated_users = (
target_owner and target_owner.plan_activated_users is not None
)
if (
has_plan_activated_users
and user.ownerid not in target_owner.plan_activated_users
):
raise UnauthorizedGuestAccess()

return await get_owner(service, username)
Expand Down
Loading