Browse Source

fix(dashboards) Fix users with discover-basic not getting dashboards (#19779)

Update the feature flags for dashboards to allow either flavour of
discover. The new performance plans will not include discover1 but
will include discover2.

Update the discover1 endpoint to accept the discover2 feature
flag as that is what dashboards is built against.

Co-authored-by: Tony <Zylphrex@users.noreply.github.com>
Co-authored-by: Tony <Zylphrex@users.noreply.github.com>
Mark Story 4 years ago
parent
commit
ef2ec40c42

+ 6 - 1
src/sentry/discover/endpoints/discover_query.py

@@ -24,6 +24,11 @@ class DiscoverQueryPermission(OrganizationPermission):
 class DiscoverQueryEndpoint(OrganizationEndpoint):
     permission_classes = (DiscoverQueryPermission,)
 
+    def has_feature(self, request, organization):
+        return features.has(
+            "organizations:discover", organization, actor=request.user
+        ) or features.has("organizations:discover-basic", organization, actor=request.user)
+
     def handle_results(self, snuba_results, requested_query, projects):
         if "project.name" in requested_query["selected_columns"]:
             project_name_index = requested_query["selected_columns"].index("project.name")
@@ -99,7 +104,7 @@ class DiscoverQueryEndpoint(OrganizationEndpoint):
             )
 
     def post(self, request, organization):
-        if not features.has("organizations:discover", organization, actor=request.user):
+        if not self.has_feature(request, organization):
             return Response(status=404)
 
         try:

+ 5 - 1
src/sentry/static/sentry/app/components/sidebar/index.tsx

@@ -467,7 +467,11 @@ class Sidebar extends React.Component<Props, State> {
                 </SidebarSection>
 
                 <SidebarSection>
-                  <Feature features={['discover']} organization={organization}>
+                  <Feature
+                    features={['discover', 'discover-basic']}
+                    organization={organization}
+                    requireAll={false}
+                  >
                     <SidebarItem
                       {...sidebarItemProps}
                       index

+ 2 - 2
src/sentry/static/sentry/app/views/dashboards/exploreWidget.jsx

@@ -128,8 +128,8 @@ class ExploreWidget extends React.Component {
         target={!flags.discover2 ? '_blank' : ''}
         title={
           flags.discover2
-            ? t('Explore data in the new Discover')
-            : t('You do not have access to the new Discover. Click to learn more.')
+            ? t('Explore data in Discover')
+            : t('You do not have access to Discover. Click to learn more.')
         }
       >
         <IconTelescope size="xs" />

+ 5 - 1
src/sentry/static/sentry/app/views/dashboards/index.jsx

@@ -18,7 +18,11 @@ class Dashboards extends React.Component {
     const {organization, children} = this.props;
 
     return (
-      <Feature features={['discover']} renderDisabled>
+      <Feature
+        features={['discover', 'discover-basic']}
+        renderDisabled
+        requireAll={false}
+      >
         <GlobalSelectionHeader showEnvironmentSelector={false}>
           <PageContent>
             <LightWeightNoProjectMessage organization={organization}>

+ 30 - 12
tests/snuba/api/endpoints/test_discover_query.py

@@ -74,6 +74,24 @@ class DiscoverQueryTest(APITestCase, SnubaTestCase):
         assert response.data["data"][0]["environment"] == "production"
         assert response.data["data"][0]["platform.name"] == "python"
 
+    def test_with_discover_basic(self):
+        # Dashboards requires access to the discover1 endpoints for now.
+        # But newer saas plans don't include discover1, only discover2 (discover-basic).
+        with self.feature("organizations:discover-basic"):
+            url = reverse("sentry-api-0-discover-query", args=[self.org.slug])
+            response = self.client.post(
+                url,
+                {
+                    "projects": [self.project.id],
+                    "fields": ["environment", "platform.name"],
+                    "start": iso_format(datetime.now() - timedelta(seconds=10)),
+                    "end": iso_format(datetime.now()),
+                    "orderby": "-timestamp",
+                    "range": None,
+                },
+            )
+        assert response.status_code == 200, response.content
+
     def test_relative_dates(self):
         with self.feature("organizations:discover"):
             url = reverse("sentry-api-0-discover-query", args=[self.org.slug])
@@ -465,18 +483,18 @@ class DiscoverQueryTest(APITestCase, SnubaTestCase):
 
     def test_no_feature_access(self):
         url = reverse("sentry-api-0-discover-query", args=[self.org.slug])
-        response = self.client.post(
-            url,
-            {
-                "projects": [self.project.id],
-                "fields": ["message", "platform"],
-                "range": "14d",
-                "orderby": "-timestamp",
-                "start": None,
-                "end": None,
-            },
-        )
-
+        with self.feature({"organizations:discover": False, "organizations:discover-basic": False}):
+            response = self.client.post(
+                url,
+                {
+                    "projects": [self.project.id],
+                    "fields": ["message", "platform"],
+                    "range": "14d",
+                    "orderby": "-timestamp",
+                    "start": None,
+                    "end": None,
+                },
+            )
         assert response.status_code == 404, response.content
 
     def test_invalid_project(self):