Просмотр исходного кода

fix(web): Broaden discover match to catch org slug (#25470)

For logged-out users in an organization that requires SSO, it is
necessary to match the "organization_slug" capturing group in order to
correctly redirect to the organization-specific login page. Broaden the
fallback mapping to react_page_view so that the `discover` path
redirects to login correctly.
Ryan Skonnord 3 лет назад
Родитель
Сommit
d87e92eb71
2 измененных файлов с 20 добавлено и 8 удалено
  1. 3 2
      src/sentry/web/urls.py
  2. 17 6
      tests/sentry/web/frontend/test_react_page.py

+ 3 - 2
src/sentry/web/urls.py

@@ -536,8 +536,9 @@ urlpatterns += [
                     RestoreOrganizationView.as_view(),
                     name="sentry-restore-organization",
                 ),
-                # need to catch settings and force it to react
-                url(r"^(?P<organization_slug>[\w_-]+)/settings/", react_page_view),
+                # need to force these to React and ensure organization_slug is captured
+                # TODO(RyanSkonnord): Generalize to all pages without regressing
+                url(r"^(?P<organization_slug>[\w_-]+)/(settings|discover)/", react_page_view),
             ]
         ),
     ),

+ 17 - 6
tests/sentry/web/frontend/test_react_page.py

@@ -73,12 +73,23 @@ class ReactPageViewTest(TestCase):
         self.assertTemplateUsed(resp, "sentry/bases/react.html")
         assert resp.context["request"]
 
-    def test_org_settings_captures_slug(self):
+    def test_org_subpages_capture_slug(self):
         owner = self.create_user("bar@example.com")
         org = self.create_organization(owner=owner)
-        path = f"/settings/{org.slug}/some-page/"
-
         # User is *not* logged in. Check for redirect to org's auth login.
-        resp = self.client.get(path)
-        assert resp.status_code == 302
-        assert resp.url == f"/auth/login/{org.slug}/"
+
+        # TODO(RyanSkonnord): Generalize URL pattern; add
+        #  f"/organizations/{org.slug}/new_page_that_does_not_exist_yet/"
+        #  to list of test paths without causing other regressions.
+        #  See OrganizationReleasesTest.test_detail_global_header,
+        #  which exposes a buggy interaction with appendTrailingSlash
+        #  in static/app/routes.tsx.
+        for path in [
+            f"/organizations/{org.slug}/settings/",
+            f"/organizations/{org.slug}/discover/",
+            f"/settings/{org.slug}/developer-settings/",
+            f"/settings/{org.slug}/new_page_that_does_not_exist_yet/",
+        ]:
+            resp = self.client.get(path)
+            assert resp.status_code == 302
+            assert resp.url == f"/auth/login/{org.slug}/"