mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Update logic for create/update dashboard, validation and plugin dashboard links (#10809)
* enables overwrite if dashboard allready exist in folder * dashboard: Don't allow creating a folder named General * dashboards: update logic for save/update dashboard No id and uid creates a new dashboard/folder. No id and uid, with an existing title in folder allows overwrite of dashboard. Id without uid, allows update of existing dashboard/folder without overwrite. Uid without id allows update of existing dashboard/folder without overwrite. Id without uid, with an existing title in folder allows overwrite of dashboard/folder and updated will have the uid of overwritten. Uid without id, with an existing title in folder allows overwrite of dashboard/folder and new will have the same uid as provided. Trying to change an existing folder to a dashboard yields error. Trying to change an existing dashboard to a folder yields error. * dashboards: include folder id when confirmed to save with overwrite * dashboards: fixes due to new url structure Return importedUrl property in response to importing dashboards and getting plugin dashboards and use this for redirects/links in the frontend.
This commit is contained in:
committed by
Torkel Ödegaard
parent
fc05fc42c9
commit
0e8377a9f4
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
|
||||
@@ -217,6 +218,10 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
|
||||
return ApiError(400, m.ErrDashboardTitleEmpty.Error(), nil)
|
||||
}
|
||||
|
||||
if dash.IsFolder && strings.ToLower(dash.Title) == strings.ToLower(m.RootFolderName) {
|
||||
return ApiError(400, "A folder already exists with that name", nil)
|
||||
}
|
||||
|
||||
if dash.Id == 0 {
|
||||
limitReached, err := middleware.QuotaReached(c, "dashboard")
|
||||
if err != nil {
|
||||
@@ -237,8 +242,11 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
|
||||
|
||||
dashboard, err := dashboards.GetRepository().SaveDashboard(dashItem)
|
||||
|
||||
if err == m.ErrDashboardTitleEmpty {
|
||||
return ApiError(400, m.ErrDashboardTitleEmpty.Error(), nil)
|
||||
if err == m.ErrDashboardTitleEmpty ||
|
||||
err == m.ErrDashboardWithSameNameAsFolder ||
|
||||
err == m.ErrDashboardFolderWithSameNameAsDashboard ||
|
||||
err == m.ErrDashboardTypeMismatch {
|
||||
return ApiError(400, err.Error(), nil)
|
||||
}
|
||||
|
||||
if err == m.ErrDashboardContainsInvalidAlertData {
|
||||
|
||||
Reference in New Issue
Block a user