From 4ebddb4f2377bdd933249877d698cb12974fcf33 Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Thu, 19 Sep 2024 16:19:45 +0300 Subject: [PATCH] [v11.1.x] Plugins: Avoid returning 404 for `AutoEnabled` apps (#93487) Plugins: Avoid returning 404 for `AutoEnabled` apps (#93436) avoid errors for autoenabled apps (cherry picked from commit 362ffff591cd75ba8a0fe2277c50309668c67680) Co-authored-by: Will Browne --- pkg/api/plugin_checks.go | 8 +++++++- pkg/api/plugin_checks_test.go | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/api/plugin_checks.go b/pkg/api/plugin_checks.go index 9a7deb87630..dc1225cbb1f 100644 --- a/pkg/api/plugin_checks.go +++ b/pkg/api/plugin_checks.go @@ -28,7 +28,13 @@ func checkAppEnabled(pluginStore pluginstore.Store, pluginSettings pluginsetting }) if err != nil { if errors.Is(err, pluginsettings.ErrPluginSettingNotFound) { - c.JsonApiErr(http.StatusNotFound, "Plugin not found", nil) + // If the plugin is auto enabled, we don't want to return an error because auto enabling allows us + // to enable plugins that are not explicitly configured. + if p.AutoEnabled { + return + } + + c.JsonApiErr(http.StatusNotFound, "Plugin setting not found", nil) return } c.JsonApiErr(http.StatusInternalServerError, "Failed to get plugin settings", err) diff --git a/pkg/api/plugin_checks_test.go b/pkg/api/plugin_checks_test.go index fffa04453f3..1f92a1cd172 100644 --- a/pkg/api/plugin_checks_test.go +++ b/pkg/api/plugin_checks_test.go @@ -41,6 +41,11 @@ func TestHTTPServer_CheckEnabled(t *testing.T) { pluginID: "grafana-test-app_disabled", expectedCode: 404, }, + { + name: "should not set an error code if the plugin is auto enabled, without a saved plugin setting", + pluginID: "grafana-test-app_autoEnabled", + expectedCode: 0, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -50,6 +55,7 @@ func TestHTTPServer_CheckEnabled(t *testing.T) { {JSONData: plugins.JSONData{ID: "mysql"}}, {JSONData: plugins.JSONData{Type: plugins.TypeApp, ID: "grafana-test-app"}}, {JSONData: plugins.JSONData{Type: plugins.TypeApp, ID: "grafana-test-app_disabled"}}, + {JSONData: plugins.JSONData{Type: plugins.TypeApp, ID: "grafana-test-app_autoEnabled", AutoEnabled: true}}, }, } hs.PluginSettings = &pluginsettings.FakePluginSettings{Plugins: map[string]*pluginsettings.DTO{