diff --git a/src/sentry/middleware/customer_domain.py b/src/sentry/middleware/customer_domain.py index 8a81a14c2e753a..bc0de539a98136 100644 --- a/src/sentry/middleware/customer_domain.py +++ b/src/sentry/middleware/customer_domain.py @@ -74,8 +74,7 @@ def _resolve_redirect_url(request, activeorg): path = reverse(result.url_name or result.func, kwargs=kwargs) qs = _query_string(request) - redirect_url = f"{redirect_url}{path}{qs}" - return redirect_url + return f"{redirect_url}{path}{qs}" class CustomerDomainMiddleware: diff --git a/src/sentry/templates/sentry/layout.html b/src/sentry/templates/sentry/layout.html index 17a2783c12755e..ea15abda02dfa6 100644 --- a/src/sentry/templates/sentry/layout.html +++ b/src/sentry/templates/sentry/layout.html @@ -3,7 +3,6 @@ {% load sentry_assets %} {% load sentry_features %} {% load sentry_helpers %} -{% load sentry_react %} {% load sentry_status %} {% get_sentry_version %} @@ -41,7 +40,7 @@ {% block initial_data %} {% script %} {% endscript %} {% endblock %} diff --git a/src/sentry/web/frontend/base.py b/src/sentry/web/frontend/base.py index 7eb53b1c374ac9..d8474a83ca9d8d 100644 --- a/src/sentry/web/frontend/base.py +++ b/src/sentry/web/frontend/base.py @@ -467,8 +467,7 @@ def get_not_2fa_compliant_url(self, request: HttpRequest, *args: Any, **kwargs: return reverse("sentry-account-settings-security") def get_context_data(self, request: HttpRequest, **kwargs: Any) -> dict[str, Any]: - context = csrf(request) - return context + return csrf(request) def respond( self, template: str, context: dict[str, Any] | None = None, status: int = 200 diff --git a/src/sentry/web/frontend/js_sdk_loader.py b/src/sentry/web/frontend/js_sdk_loader.py index acc1ae6f66c25b..ad99e0ebc2333c 100644 --- a/src/sentry/web/frontend/js_sdk_loader.py +++ b/src/sentry/web/frontend/js_sdk_loader.py @@ -1,7 +1,7 @@ from __future__ import annotations import time -from typing import NotRequired, TypedDict +from typing import Any, NotRequired, TypedDict from django.conf import settings from django.http import HttpRequest, HttpResponse @@ -55,6 +55,10 @@ class JavaScriptSdkLoader(BaseView): def determine_active_organization(self, request: HttpRequest, organization_slug=None) -> None: pass + # Same as above + def get_context_data(self, request: HttpRequest, **kwargs) -> dict[str, Any]: + return {} + def _get_loader_config( self, key: ProjectKey | None, sdk_version: Version | None ) -> LoaderInternalConfig: diff --git a/src/sentry/web/frontend/react_page.py b/src/sentry/web/frontend/react_page.py index ed03c94d81b96e..81e5c4d26b8051 100644 --- a/src/sentry/web/frontend/react_page.py +++ b/src/sentry/web/frontend/react_page.py @@ -22,6 +22,7 @@ ) from sentry.users.services.user.model import RpcUser from sentry.utils.http import is_using_customer_domain, query_string +from sentry.web.client_config import get_client_config from sentry.web.frontend.base import BaseView, ControlSiloOrganizationView from sentry.web.helpers import render_to_response @@ -86,6 +87,7 @@ def dns_prefetch(self) -> list[str]: return domains def handle_react(self, request: Request, **kwargs) -> HttpResponse: + org_context = getattr(self, "active_organization", None) context = { "CSRF_COOKIE_NAME": settings.CSRF_COOKIE_NAME, "meta_tags": [ @@ -97,7 +99,8 @@ def handle_react(self, request: Request, **kwargs) -> HttpResponse: # Rendering the layout requires serializing the active organization. # Since we already have it here from the OrganizationMixin, we can # save some work and render it faster. - "org_context": getattr(self, "active_organization", None), + "org_context": org_context, + "react_config": get_client_config(request, org_context), } # Force a new CSRF token to be generated and set in user's diff --git a/tests/sentry/web/frontend/test_js_sdk_loader.py b/tests/sentry/web/frontend/test_js_sdk_loader.py index accd733ff63c46..b90a0df0f86529 100644 --- a/tests/sentry/web/frontend/test_js_sdk_loader.py +++ b/tests/sentry/web/frontend/test_js_sdk_loader.py @@ -339,7 +339,7 @@ def test_headers(self, mock_load_version_from_file): assert "sdk-loader" in resp["Surrogate-Key"] assert "Content-Encoding" not in resp assert "Set-Cookie" not in resp - assert "Vary" not in resp + assert "Vary" not in resp, f"Found Vary header: {resp['Vary']}" def test_absolute_url(self): assert ( diff --git a/tests/sentry/web/frontend/test_react_page.py b/tests/sentry/web/frontend/test_react_page.py index bd294f459075e1..d9f25f12b561e9 100644 --- a/tests/sentry/web/frontend/test_react_page.py +++ b/tests/sentry/web/frontend/test_react_page.py @@ -296,11 +296,14 @@ def _run_customer_domain_elevated_privileges(self, is_superuser: bool, is_staff: assert response.redirect_chain == [ (f"http://{other_org.slug}.testserver/issues/", 302) ] - assert self.client.session["activeorg"] == other_org.slug else: assert response.redirect_chain == [ (f"http://{other_org.slug}.testserver/auth/login/{other_org.slug}/", 302) ] + + if is_superuser or is_staff: + assert self.client.session["activeorg"] == other_org.slug + else: assert "activeorg" not in self.client.session # Accessing org without customer domain as superuser and/or staff. diff --git a/tests/sentry/web/test_api.py b/tests/sentry/web/test_api.py index 9f284ead205e9d..f1285d02730fdb 100644 --- a/tests/sentry/web/test_api.py +++ b/tests/sentry/web/test_api.py @@ -301,11 +301,13 @@ def _run_test_with_privileges(self, is_superuser: bool, is_staff: bool): assert response.redirect_chain == [ (f"http://{other_org.slug}.testserver/issues/", 302) ] - assert self.client.session["activeorg"] == other_org.slug else: assert response.redirect_chain == [ (f"http://{other_org.slug}.testserver/auth/login/{other_org.slug}/", 302) ] + if is_superuser or is_staff: + assert self.client.session["activeorg"] == other_org.slug + else: assert "activeorg" not in self.client.session # lastOrganization is set