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{