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 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
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
13 changes: 11 additions & 2 deletions graphql_api/types/query/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,17 @@ async def resolve_owner(
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:
# if the owner tracks plan activated users, check if the user is in the list
target_owner = await get_owner(service, username)
has_plan_activated_users = (
target_owner
and target_owner.plan_activated_users is not None
and len(target_owner.plan_activated_users) > 0
)
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