-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
ref(cells): Implement org member invite redirect from old path to new #112513
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
Merged
+97
−1
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f77e5e9
ref(cells): Implement org member invite redirect from old path to new
lynnagara cea1e5a
validate token first
lynnagara 7be8700
member_id type fix
lynnagara bcfbba6
match type signature of parent class
lynnagara ac4de07
Merge branch 'master' into add-org-invite-redirect
lynnagara 9fc820a
update test
lynnagara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/sentry/web/frontend/accept_organization_invite_redirect.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from django.http import HttpRequest, HttpResponse, HttpResponseRedirect | ||
| from django.urls import reverse | ||
|
|
||
| from sentry.api.endpoints.accept_organization_invite import get_invite_state | ||
| from sentry.api.invite_helper import ApiInviteHelper | ||
| from sentry.demo_mode.utils import is_demo_user | ||
| from sentry.utils.http import query_string | ||
| from sentry.web.frontend.react_page import GenericReactPageView | ||
|
|
||
|
|
||
| # TODO(cells): Temporary redirect to support previous invitations. Remove after May 8th | ||
| class AcceptOrganizationInviteRedirectView(GenericReactPageView): | ||
| auth_required = False | ||
|
|
||
| def handle(self, request: HttpRequest, **kwargs) -> HttpResponse: | ||
| member_id: str = kwargs["member_id"] | ||
| token: str = kwargs["token"] | ||
| if request.user.is_authenticated and not is_demo_user(request.user): | ||
| user_id: int | None = request.user.id | ||
| else: | ||
| user_id = None | ||
|
|
||
| invite_context = get_invite_state( | ||
| member_id=int(member_id), | ||
| organization_id_or_slug=None, | ||
| user_id=user_id, | ||
| request=request, | ||
| ) | ||
| if invite_context is None: | ||
| return self.handle_react(request, **kwargs) | ||
|
|
||
| helper = ApiInviteHelper(request=request, token=token, invite_context=invite_context) | ||
| if not helper.valid_token: | ||
| return self.handle_react(request, **kwargs) | ||
|
|
||
| redirect_url = reverse( | ||
| "sentry-organization-accept-invite", | ||
| kwargs={ | ||
| "organization_slug": invite_context.organization.slug, | ||
| "member_id": member_id, | ||
| "token": token, | ||
| }, | ||
| ) | ||
|
sentry-warden[bot] marked this conversation as resolved.
|
||
| return HttpResponseRedirect(f"{redirect_url}{query_string(request)}") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
tests/sentry/web/frontend/test_accept_organization_invite_redirect.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| from django.urls import reverse | ||
|
|
||
| from sentry.testutils.cases import TestCase | ||
| from sentry.testutils.silo import control_silo_test | ||
|
|
||
|
|
||
| @control_silo_test | ||
| class AcceptOrganizationInviteRedirectViewTest(TestCase): | ||
| def test_redirects_legacy_invite_to_org_scoped_route(self) -> None: | ||
| organization = self.create_organization() | ||
| member = self.create_member( | ||
| organization=organization, email="newuser@example.com", token="abc" | ||
| ) | ||
|
|
||
| response = self.client.get( | ||
| reverse("sentry-accept-invite", args=[member.id, member.token]) + "?referrer=email" | ||
| ) | ||
|
|
||
| assert response.status_code == 302 | ||
| assert response["Location"] == ( | ||
| reverse( | ||
| "sentry-organization-accept-invite", | ||
| kwargs={ | ||
| "organization_slug": organization.slug, | ||
| "member_id": member.id, | ||
| "token": member.token, | ||
| }, | ||
| ) | ||
| + "?referrer=email" | ||
| ) | ||
|
|
||
| def test_invalid_token_does_not_leak_org_slug(self) -> None: | ||
| organization = self.create_organization() | ||
| member = self.create_member(organization=organization, email="newuser@example.com") | ||
|
|
||
| response = self.client.get( | ||
| reverse("sentry-accept-invite", args=[member.id, "invalidtoken"]) | ||
| ) | ||
|
|
||
| assert response.status_code == 200 | ||
| self.assertTemplateUsed(response, "sentry/base-react.html") | ||
|
|
||
| def test_unresolved_legacy_invite_falls_back_to_react_page(self) -> None: | ||
| response = self.client.get(reverse("sentry-accept-invite", args=[123456, "invalidtoken"])) | ||
|
|
||
| assert response.status_code == 200 | ||
| self.assertTemplateUsed(response, "sentry/base-react.html") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.