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(setup-wizard): Always create a new user API token #69388

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 6 additions & 9 deletions src/sentry/web/frontend/setup_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,12 @@ def get_token(mappings: list[OrganizationMapping], user: RpcUser):
return token

# Otherwise, generate a user token
tokens = ApiToken.objects.filter(user_id=user.id)
token = next((token for token in tokens if "project:releases" in token.get_scopes()), None)
if token is None:
token = ApiToken.objects.create(
user_id=user.id,
scope_list=["project:releases"],
token_type=AuthTokenType.USER,
expires_at=None,
)
token = ApiToken.objects.create(
user_id=user.id,
scope_list=["project:releases"],
token_type=AuthTokenType.USER,
expires_at=None,
)
return serialize(token)


Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/web/frontend/test_setup_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_return_user_auth_token_if_multiple_orgs(self):
assert resp.status_code == 200
self.assertTemplateUsed(resp, "sentry/setup-wizard.html")
cached = default_cache.get(key)

assert cached.get("apiKeys") is not None
assert cached.get("apiKeys") == serialize(user_api_token)

def test_return_org_auth_token_if_one_org(self):
Expand Down
Loading