From 54c9b11ae805409a079f9900604533b28550a995 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Wed, 15 Jan 2020 12:10:02 +0100 Subject: [PATCH] Fix importing plugin dashboards (#21501) #21350 introduced a bug regarding import of plugin dashboards. This should fix this and add custom validation if not importing plugin dashboard and dashboard property is missing. Ref #21350 Co-Authored-By: Arve Knudsen --- pkg/api/dtos/plugins.go | 2 +- pkg/api/plugins.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/api/dtos/plugins.go b/pkg/api/dtos/plugins.go index 48ed908d797..8b32bea41dc 100644 --- a/pkg/api/dtos/plugins.go +++ b/pkg/api/dtos/plugins.go @@ -56,7 +56,7 @@ type ImportDashboardCommand struct { PluginId string `json:"pluginId"` Path string `json:"path"` Overwrite bool `json:"overwrite"` - Dashboard *simplejson.Json `json:"dashboard" binding:"Required"` + Dashboard *simplejson.Json `json:"dashboard"` Inputs []plugins.ImportDashboardInput `json:"inputs"` FolderId int64 `json:"folderId"` } diff --git a/pkg/api/plugins.go b/pkg/api/plugins.go index d275eb267bc..e473ce0f935 100644 --- a/pkg/api/plugins.go +++ b/pkg/api/plugins.go @@ -179,6 +179,10 @@ func GetPluginMarkdown(c *m.ReqContext) Response { } func ImportDashboard(c *m.ReqContext, apiCmd dtos.ImportDashboardCommand) Response { + if apiCmd.PluginId == "" && apiCmd.Dashboard == nil { + return Error(422, "Dashboard must be set", nil) + } + cmd := plugins.ImportDashboardCommand{ OrgId: c.OrgId, User: c.SignedInUser,