Skip to content

Commit 01b3ff9

Browse files
authored
fix(hybrid-cloud): Update customer domain middleware to support nameless routes (#38034)
1 parent 2b9dd40 commit 01b3ff9

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/sentry/middleware/customer_domain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _resolve_redirect_url(request, activeorg):
6060
kwargs = {**result.kwargs}
6161
if org_slug_path_mismatch:
6262
kwargs["organization_slug"] = activeorg
63-
path = reverse(result.url_name, kwargs=kwargs)
63+
path = reverse(result.url_name or result.func, kwargs=kwargs)
6464
qs = _query_string(request)
6565
redirect_url = f"{redirect_url}{path}{qs}"
6666
return redirect_url

src/sentry/web/urls.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,11 @@
444444
react_page_view,
445445
name="sentry-organization-auth-settings",
446446
),
447-
url(r"^(?P<organization_slug>[\w_-]+)/[\w_-]+/$", react_page_view),
447+
url(
448+
r"^(?P<organization_slug>[\w_-]+)/(?P<sub_page>[\w_-]+)/$",
449+
react_page_view,
450+
name="sentry-organization-sub-page-settings",
451+
),
448452
url(r"^", react_page_view),
449453
]
450454
),
@@ -552,7 +556,11 @@
552556
name="sentry-organization-disabled-member",
553557
),
554558
# need to force these to React and ensure organization_slug is captured
555-
url(r"^(?P<organization_slug>[\w_-]+)/[\w_-]+/", react_page_view),
559+
url(
560+
r"^(?P<organization_slug>[\w_-]+)/(?P<sub_page>[\w_-]+)/",
561+
react_page_view,
562+
name="sentry-organization-sub-page",
563+
),
556564
]
557565
),
558566
),

tests/sentry/middleware/test_customer_domain.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ def post(self, request, organization_slug):
146146
OrganizationTestEndpoint.as_view(),
147147
name="org-events-endpoint",
148148
),
149+
url(
150+
r"^api/0/(?P<organization_slug>[^\/]+)/nameless/$",
151+
OrganizationTestEndpoint.as_view(),
152+
),
149153
]
150154

151155

@@ -387,3 +391,22 @@ def test_without_middleware(self):
387391
}
388392
assert "activeorg" in self.client.session
389393
assert self.client.session["activeorg"] == "test"
394+
395+
def test_with_middleware_and_nameless_view(self):
396+
self.create_organization(name="albertos-apples")
397+
398+
with override_settings(MIDDLEWARE=tuple(self.middleware)):
399+
response = self.client.get(
400+
"/api/0/some-org/nameless/",
401+
HTTP_HOST="albertos-apples.testserver",
402+
follow=True,
403+
)
404+
assert response.status_code == 200
405+
assert response.redirect_chain == [("/api/0/albertos-apples/nameless/", 302)]
406+
assert response.data == {
407+
"organization_slug": "albertos-apples",
408+
"subdomain": "albertos-apples",
409+
"activeorg": "albertos-apples",
410+
}
411+
assert "activeorg" in self.client.session
412+
assert self.client.session["activeorg"] == "albertos-apples"

0 commit comments

Comments
 (0)