mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugins: Avoid returning 404 for AutoEnabled
apps (#93436)
avoid errors for autoenabled apps
This commit is contained in:
parent
d5f205fdef
commit
362ffff591
@ -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)
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user