|
|
@@ -5,7 +5,6 @@ import (
|
|
|
"fmt"
|
|
|
"os"
|
|
|
"path"
|
|
|
- "strings"
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
|
|
|
|
|
@@ -15,20 +14,20 @@ import (
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
|
"github.com/grafana/grafana/pkg/log"
|
|
|
"github.com/grafana/grafana/pkg/metrics"
|
|
|
- "github.com/grafana/grafana/pkg/middleware"
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
|
"github.com/grafana/grafana/pkg/plugins"
|
|
|
"github.com/grafana/grafana/pkg/services/guardian"
|
|
|
+ "github.com/grafana/grafana/pkg/services/quota"
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
|
"github.com/grafana/grafana/pkg/util"
|
|
|
)
|
|
|
|
|
|
-func isDashboardStarredByUser(c *middleware.Context, dashId int64) (bool, error) {
|
|
|
+func isDashboardStarredByUser(c *m.ReqContext, dashID int64) (bool, error) {
|
|
|
if !c.IsSignedIn {
|
|
|
return false, nil
|
|
|
}
|
|
|
|
|
|
- query := m.IsStarredByUserQuery{UserId: c.UserId, DashboardId: dashId}
|
|
|
+ query := m.IsStarredByUserQuery{UserId: c.UserId, DashboardId: dashID}
|
|
|
if err := bus.Dispatch(&query); err != nil {
|
|
|
return false, err
|
|
|
}
|
|
|
@@ -38,19 +37,19 @@ func isDashboardStarredByUser(c *middleware.Context, dashId int64) (bool, error)
|
|
|
|
|
|
func dashboardGuardianResponse(err error) Response {
|
|
|
if err != nil {
|
|
|
- return ApiError(500, "Error while checking dashboard permissions", err)
|
|
|
+ return Error(500, "Error while checking dashboard permissions", err)
|
|
|
}
|
|
|
|
|
|
- return ApiError(403, "Access denied to this dashboard", nil)
|
|
|
+ return Error(403, "Access denied to this dashboard", nil)
|
|
|
}
|
|
|
|
|
|
-func GetDashboard(c *middleware.Context) Response {
|
|
|
+func GetDashboard(c *m.ReqContext) Response {
|
|
|
dash, rsp := getDashboardHelper(c.OrgId, c.Params(":slug"), 0, c.Params(":uid"))
|
|
|
if rsp != nil {
|
|
|
return rsp
|
|
|
}
|
|
|
|
|
|
- guardian := guardian.NewDashboardGuardian(dash.Id, c.OrgId, c.SignedInUser)
|
|
|
+ guardian := guardian.New(dash.Id, c.OrgId, c.SignedInUser)
|
|
|
if canView, err := guardian.CanView(); err != nil || !canView {
|
|
|
return dashboardGuardianResponse(err)
|
|
|
}
|
|
|
@@ -61,7 +60,7 @@ func GetDashboard(c *middleware.Context) Response {
|
|
|
|
|
|
isStarred, err := isDashboardStarredByUser(c, dash.Id)
|
|
|
if err != nil {
|
|
|
- return ApiError(500, "Error while checking if dashboard was starred by user", err)
|
|
|
+ return Error(500, "Error while checking if dashboard was starred by user", err)
|
|
|
}
|
|
|
|
|
|
// Finding creator and last updater of the dashboard
|
|
|
@@ -97,7 +96,7 @@ func GetDashboard(c *middleware.Context) Response {
|
|
|
if dash.FolderId > 0 {
|
|
|
query := m.GetDashboardQuery{Id: dash.FolderId, OrgId: c.OrgId}
|
|
|
if err := bus.Dispatch(&query); err != nil {
|
|
|
- return ApiError(500, "Dashboard folder could not be read", err)
|
|
|
+ return Error(500, "Dashboard folder could not be read", err)
|
|
|
}
|
|
|
meta.FolderTitle = query.Result.Title
|
|
|
meta.FolderUrl = query.Result.GetUrl()
|
|
|
@@ -112,44 +111,43 @@ func GetDashboard(c *middleware.Context) Response {
|
|
|
}
|
|
|
|
|
|
c.TimeRequest(metrics.M_Api_Dashboard_Get)
|
|
|
- return Json(200, dto)
|
|
|
+ return JSON(200, dto)
|
|
|
}
|
|
|
|
|
|
-func getUserLogin(userId int64) string {
|
|
|
- query := m.GetUserByIdQuery{Id: userId}
|
|
|
+func getUserLogin(userID int64) string {
|
|
|
+ query := m.GetUserByIdQuery{Id: userID}
|
|
|
err := bus.Dispatch(&query)
|
|
|
if err != nil {
|
|
|
return "Anonymous"
|
|
|
- } else {
|
|
|
- user := query.Result
|
|
|
- return user.Login
|
|
|
}
|
|
|
+ return query.Result.Login
|
|
|
}
|
|
|
|
|
|
-func getDashboardHelper(orgId int64, slug string, id int64, uid string) (*m.Dashboard, Response) {
|
|
|
+func getDashboardHelper(orgID int64, slug string, id int64, uid string) (*m.Dashboard, Response) {
|
|
|
var query m.GetDashboardQuery
|
|
|
|
|
|
if len(uid) > 0 {
|
|
|
- query = m.GetDashboardQuery{Uid: uid, Id: id, OrgId: orgId}
|
|
|
+ query = m.GetDashboardQuery{Uid: uid, Id: id, OrgId: orgID}
|
|
|
} else {
|
|
|
- query = m.GetDashboardQuery{Slug: slug, Id: id, OrgId: orgId}
|
|
|
+ query = m.GetDashboardQuery{Slug: slug, Id: id, OrgId: orgID}
|
|
|
}
|
|
|
|
|
|
if err := bus.Dispatch(&query); err != nil {
|
|
|
- return nil, ApiError(404, "Dashboard not found", err)
|
|
|
+ return nil, Error(404, "Dashboard not found", err)
|
|
|
}
|
|
|
+
|
|
|
return query.Result, nil
|
|
|
}
|
|
|
|
|
|
-func DeleteDashboard(c *middleware.Context) Response {
|
|
|
+func DeleteDashboard(c *m.ReqContext) Response {
|
|
|
query := m.GetDashboardsBySlugQuery{OrgId: c.OrgId, Slug: c.Params(":slug")}
|
|
|
|
|
|
if err := bus.Dispatch(&query); err != nil {
|
|
|
- return ApiError(500, "Failed to retrieve dashboards by slug", err)
|
|
|
+ return Error(500, "Failed to retrieve dashboards by slug", err)
|
|
|
}
|
|
|
|
|
|
if len(query.Result) > 1 {
|
|
|
- return Json(412, util.DynMap{"status": "multiple-slugs-exists", "message": m.ErrDashboardsWithSameSlugExists.Error()})
|
|
|
+ return JSON(412, util.DynMap{"status": "multiple-slugs-exists", "message": m.ErrDashboardsWithSameSlugExists.Error()})
|
|
|
}
|
|
|
|
|
|
dash, rsp := getDashboardHelper(c.OrgId, c.Params(":slug"), 0, "")
|
|
|
@@ -157,78 +155,57 @@ func DeleteDashboard(c *middleware.Context) Response {
|
|
|
return rsp
|
|
|
}
|
|
|
|
|
|
- guardian := guardian.NewDashboardGuardian(dash.Id, c.OrgId, c.SignedInUser)
|
|
|
+ guardian := guardian.New(dash.Id, c.OrgId, c.SignedInUser)
|
|
|
if canSave, err := guardian.CanSave(); err != nil || !canSave {
|
|
|
return dashboardGuardianResponse(err)
|
|
|
}
|
|
|
|
|
|
cmd := m.DeleteDashboardCommand{OrgId: c.OrgId, Id: dash.Id}
|
|
|
if err := bus.Dispatch(&cmd); err != nil {
|
|
|
- return ApiError(500, "Failed to delete dashboard", err)
|
|
|
+ return Error(500, "Failed to delete dashboard", err)
|
|
|
}
|
|
|
|
|
|
- var resp = map[string]interface{}{"title": dash.Title}
|
|
|
- return Json(200, resp)
|
|
|
+ return JSON(200, util.DynMap{
|
|
|
+ "title": dash.Title,
|
|
|
+ "message": fmt.Sprintf("Dashboard %s deleted", dash.Title),
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
-func DeleteDashboardByUid(c *middleware.Context) Response {
|
|
|
+func DeleteDashboardByUID(c *m.ReqContext) Response {
|
|
|
dash, rsp := getDashboardHelper(c.OrgId, "", 0, c.Params(":uid"))
|
|
|
if rsp != nil {
|
|
|
return rsp
|
|
|
}
|
|
|
|
|
|
- guardian := guardian.NewDashboardGuardian(dash.Id, c.OrgId, c.SignedInUser)
|
|
|
+ guardian := guardian.New(dash.Id, c.OrgId, c.SignedInUser)
|
|
|
if canSave, err := guardian.CanSave(); err != nil || !canSave {
|
|
|
return dashboardGuardianResponse(err)
|
|
|
}
|
|
|
|
|
|
cmd := m.DeleteDashboardCommand{OrgId: c.OrgId, Id: dash.Id}
|
|
|
if err := bus.Dispatch(&cmd); err != nil {
|
|
|
- return ApiError(500, "Failed to delete dashboard", err)
|
|
|
+ return Error(500, "Failed to delete dashboard", err)
|
|
|
}
|
|
|
|
|
|
- var resp = map[string]interface{}{"title": dash.Title}
|
|
|
- return Json(200, resp)
|
|
|
+ return JSON(200, util.DynMap{
|
|
|
+ "title": dash.Title,
|
|
|
+ "message": fmt.Sprintf("Dashboard %s deleted", dash.Title),
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
-func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
|
|
|
+func PostDashboard(c *m.ReqContext, cmd m.SaveDashboardCommand) Response {
|
|
|
cmd.OrgId = c.OrgId
|
|
|
cmd.UserId = c.UserId
|
|
|
|
|
|
dash := cmd.GetDashboardModel()
|
|
|
|
|
|
- dashId := dash.Id
|
|
|
-
|
|
|
- // if new dashboard, use parent folder permissions instead
|
|
|
- if dashId == 0 {
|
|
|
- dashId = cmd.FolderId
|
|
|
- }
|
|
|
-
|
|
|
- guardian := guardian.NewDashboardGuardian(dashId, c.OrgId, c.SignedInUser)
|
|
|
- if canSave, err := guardian.CanSave(); err != nil || !canSave {
|
|
|
- return dashboardGuardianResponse(err)
|
|
|
- }
|
|
|
-
|
|
|
- if dash.IsFolder && dash.FolderId > 0 {
|
|
|
- return ApiError(400, m.ErrDashboardFolderCannotHaveParent.Error(), nil)
|
|
|
- }
|
|
|
-
|
|
|
- // Check if Title is empty
|
|
|
- if dash.Title == "" {
|
|
|
- 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 dash.Id == 0 && dash.Uid == "" {
|
|
|
+ limitReached, err := quota.QuotaReached(c, "dashboard")
|
|
|
if err != nil {
|
|
|
- return ApiError(500, "failed to get quota", err)
|
|
|
+ return Error(500, "failed to get quota", err)
|
|
|
}
|
|
|
if limitReached {
|
|
|
- return ApiError(403, "Quota reached", nil)
|
|
|
+ return Error(403, "Quota reached", nil)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -236,32 +213,39 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
|
|
|
Dashboard: dash,
|
|
|
Message: cmd.Message,
|
|
|
OrgId: c.OrgId,
|
|
|
- UserId: c.UserId,
|
|
|
+ User: c.SignedInUser,
|
|
|
Overwrite: cmd.Overwrite,
|
|
|
}
|
|
|
|
|
|
- dashboard, err := dashboards.GetRepository().SaveDashboard(dashItem)
|
|
|
+ dashboard, err := dashboards.NewService().SaveDashboard(dashItem)
|
|
|
|
|
|
if err == m.ErrDashboardTitleEmpty ||
|
|
|
err == m.ErrDashboardWithSameNameAsFolder ||
|
|
|
err == m.ErrDashboardFolderWithSameNameAsDashboard ||
|
|
|
- err == m.ErrDashboardTypeMismatch {
|
|
|
- return ApiError(400, err.Error(), nil)
|
|
|
+ err == m.ErrDashboardTypeMismatch ||
|
|
|
+ err == m.ErrDashboardInvalidUid ||
|
|
|
+ err == m.ErrDashboardUidToLong ||
|
|
|
+ err == m.ErrDashboardWithSameUIDExists ||
|
|
|
+ err == m.ErrFolderNotFound ||
|
|
|
+ err == m.ErrDashboardFolderCannotHaveParent ||
|
|
|
+ err == m.ErrDashboardFolderNameExists {
|
|
|
+ return Error(400, err.Error(), nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ if err == m.ErrDashboardUpdateAccessDenied {
|
|
|
+ return Error(403, err.Error(), err)
|
|
|
}
|
|
|
|
|
|
if err == m.ErrDashboardContainsInvalidAlertData {
|
|
|
- return ApiError(500, "Invalid alert data. Cannot save dashboard", err)
|
|
|
+ return Error(500, "Invalid alert data. Cannot save dashboard", err)
|
|
|
}
|
|
|
|
|
|
if err != nil {
|
|
|
- if err == m.ErrDashboardWithSameUIDExists {
|
|
|
- return Json(412, util.DynMap{"status": "name-exists", "message": err.Error()})
|
|
|
- }
|
|
|
if err == m.ErrDashboardWithSameNameInFolderExists {
|
|
|
- return Json(412, util.DynMap{"status": "name-exists", "message": err.Error()})
|
|
|
+ return JSON(412, util.DynMap{"status": "name-exists", "message": err.Error()})
|
|
|
}
|
|
|
if err == m.ErrDashboardVersionMismatch {
|
|
|
- return Json(412, util.DynMap{"status": "version-mismatch", "message": err.Error()})
|
|
|
+ return JSON(412, util.DynMap{"status": "version-mismatch", "message": err.Error()})
|
|
|
}
|
|
|
if pluginErr, ok := err.(m.UpdatePluginDashboardError); ok {
|
|
|
message := "The dashboard belongs to plugin " + pluginErr.PluginId + "."
|
|
|
@@ -269,22 +253,20 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
|
|
|
if pluginDef, exist := plugins.Plugins[pluginErr.PluginId]; exist {
|
|
|
message = "The dashboard belongs to plugin " + pluginDef.Name + "."
|
|
|
}
|
|
|
- return Json(412, util.DynMap{"status": "plugin-dashboard", "message": message})
|
|
|
+ return JSON(412, util.DynMap{"status": "plugin-dashboard", "message": message})
|
|
|
}
|
|
|
if err == m.ErrDashboardNotFound {
|
|
|
- return Json(404, util.DynMap{"status": "not-found", "message": err.Error()})
|
|
|
+ return JSON(404, util.DynMap{"status": "not-found", "message": err.Error()})
|
|
|
}
|
|
|
- return ApiError(500, "Failed to save dashboard", err)
|
|
|
+ return Error(500, "Failed to save dashboard", err)
|
|
|
}
|
|
|
|
|
|
if err == m.ErrDashboardFailedToUpdateAlertData {
|
|
|
- return ApiError(500, "Invalid alert data. Cannot save dashboard", err)
|
|
|
+ return Error(500, "Invalid alert data. Cannot save dashboard", err)
|
|
|
}
|
|
|
|
|
|
- dashboard.IsFolder = dash.IsFolder
|
|
|
-
|
|
|
c.TimeRequest(metrics.M_Api_Dashboard_Save)
|
|
|
- return Json(200, util.DynMap{
|
|
|
+ return JSON(200, util.DynMap{
|
|
|
"status": "success",
|
|
|
"slug": dashboard.Slug,
|
|
|
"version": dashboard.Version,
|
|
|
@@ -294,10 +276,10 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-func GetHomeDashboard(c *middleware.Context) Response {
|
|
|
+func GetHomeDashboard(c *m.ReqContext) Response {
|
|
|
prefsQuery := m.GetPreferencesWithDefaultsQuery{OrgId: c.OrgId, UserId: c.UserId}
|
|
|
if err := bus.Dispatch(&prefsQuery); err != nil {
|
|
|
- return ApiError(500, "Failed to get preferences", err)
|
|
|
+ return Error(500, "Failed to get preferences", err)
|
|
|
}
|
|
|
|
|
|
if prefsQuery.Result.HomeDashboardId != 0 {
|
|
|
@@ -306,16 +288,15 @@ func GetHomeDashboard(c *middleware.Context) Response {
|
|
|
if err == nil {
|
|
|
url := m.GetDashboardUrl(slugQuery.Result.Uid, slugQuery.Result.Slug)
|
|
|
dashRedirect := dtos.DashboardRedirect{RedirectUri: url}
|
|
|
- return Json(200, &dashRedirect)
|
|
|
- } else {
|
|
|
- log.Warn("Failed to get slug from database, %s", err.Error())
|
|
|
+ return JSON(200, &dashRedirect)
|
|
|
}
|
|
|
+ log.Warn("Failed to get slug from database, %s", err.Error())
|
|
|
}
|
|
|
|
|
|
filePath := path.Join(setting.StaticRootPath, "dashboards/home.json")
|
|
|
file, err := os.Open(filePath)
|
|
|
if err != nil {
|
|
|
- return ApiError(500, "Failed to load home dashboard", err)
|
|
|
+ return Error(500, "Failed to load home dashboard", err)
|
|
|
}
|
|
|
|
|
|
dash := dtos.DashboardFullWithMeta{}
|
|
|
@@ -325,14 +306,14 @@ func GetHomeDashboard(c *middleware.Context) Response {
|
|
|
|
|
|
jsonParser := json.NewDecoder(file)
|
|
|
if err := jsonParser.Decode(&dash.Dashboard); err != nil {
|
|
|
- return ApiError(500, "Failed to load home dashboard", err)
|
|
|
+ return Error(500, "Failed to load home dashboard", err)
|
|
|
}
|
|
|
|
|
|
if c.HasUserRole(m.ROLE_ADMIN) && !c.HasHelpFlag(m.HelpFlagGettingStartedPanelDismissed) {
|
|
|
addGettingStartedPanelToHomeDashboard(dash.Dashboard)
|
|
|
}
|
|
|
|
|
|
- return Json(200, &dash)
|
|
|
+ return JSON(200, &dash)
|
|
|
}
|
|
|
|
|
|
func addGettingStartedPanelToHomeDashboard(dash *simplejson.Json) {
|
|
|
@@ -354,23 +335,23 @@ func addGettingStartedPanelToHomeDashboard(dash *simplejson.Json) {
|
|
|
}
|
|
|
|
|
|
// GetDashboardVersions returns all dashboard versions as JSON
|
|
|
-func GetDashboardVersions(c *middleware.Context) Response {
|
|
|
- dashId := c.ParamsInt64(":dashboardId")
|
|
|
+func GetDashboardVersions(c *m.ReqContext) Response {
|
|
|
+ dashID := c.ParamsInt64(":dashboardId")
|
|
|
|
|
|
- guardian := guardian.NewDashboardGuardian(dashId, c.OrgId, c.SignedInUser)
|
|
|
+ guardian := guardian.New(dashID, c.OrgId, c.SignedInUser)
|
|
|
if canSave, err := guardian.CanSave(); err != nil || !canSave {
|
|
|
return dashboardGuardianResponse(err)
|
|
|
}
|
|
|
|
|
|
query := m.GetDashboardVersionsQuery{
|
|
|
OrgId: c.OrgId,
|
|
|
- DashboardId: dashId,
|
|
|
+ DashboardId: dashID,
|
|
|
Limit: c.QueryInt("limit"),
|
|
|
Start: c.QueryInt("start"),
|
|
|
}
|
|
|
|
|
|
if err := bus.Dispatch(&query); err != nil {
|
|
|
- return ApiError(404, fmt.Sprintf("No versions found for dashboardId %d", dashId), err)
|
|
|
+ return Error(404, fmt.Sprintf("No versions found for dashboardId %d", dashID), err)
|
|
|
}
|
|
|
|
|
|
for _, version := range query.Result {
|
|
|
@@ -389,26 +370,26 @@ func GetDashboardVersions(c *middleware.Context) Response {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return Json(200, query.Result)
|
|
|
+ return JSON(200, query.Result)
|
|
|
}
|
|
|
|
|
|
// GetDashboardVersion returns the dashboard version with the given ID.
|
|
|
-func GetDashboardVersion(c *middleware.Context) Response {
|
|
|
- dashId := c.ParamsInt64(":dashboardId")
|
|
|
+func GetDashboardVersion(c *m.ReqContext) Response {
|
|
|
+ dashID := c.ParamsInt64(":dashboardId")
|
|
|
|
|
|
- guardian := guardian.NewDashboardGuardian(dashId, c.OrgId, c.SignedInUser)
|
|
|
+ guardian := guardian.New(dashID, c.OrgId, c.SignedInUser)
|
|
|
if canSave, err := guardian.CanSave(); err != nil || !canSave {
|
|
|
return dashboardGuardianResponse(err)
|
|
|
}
|
|
|
|
|
|
query := m.GetDashboardVersionQuery{
|
|
|
OrgId: c.OrgId,
|
|
|
- DashboardId: dashId,
|
|
|
+ DashboardId: dashID,
|
|
|
Version: c.ParamsInt(":id"),
|
|
|
}
|
|
|
|
|
|
if err := bus.Dispatch(&query); err != nil {
|
|
|
- return ApiError(500, fmt.Sprintf("Dashboard version %d not found for dashboardId %d", query.Version, dashId), err)
|
|
|
+ return Error(500, fmt.Sprintf("Dashboard version %d not found for dashboardId %d", query.Version, dashID), err)
|
|
|
}
|
|
|
|
|
|
creator := "Anonymous"
|
|
|
@@ -421,11 +402,23 @@ func GetDashboardVersion(c *middleware.Context) Response {
|
|
|
CreatedBy: creator,
|
|
|
}
|
|
|
|
|
|
- return Json(200, dashVersionMeta)
|
|
|
+ return JSON(200, dashVersionMeta)
|
|
|
}
|
|
|
|
|
|
// POST /api/dashboards/calculate-diff performs diffs on two dashboards
|
|
|
-func CalculateDashboardDiff(c *middleware.Context, apiOptions dtos.CalculateDiffOptions) Response {
|
|
|
+func CalculateDashboardDiff(c *m.ReqContext, apiOptions dtos.CalculateDiffOptions) Response {
|
|
|
+
|
|
|
+ guardianBase := guardian.New(apiOptions.Base.DashboardId, c.OrgId, c.SignedInUser)
|
|
|
+ if canSave, err := guardianBase.CanSave(); err != nil || !canSave {
|
|
|
+ return dashboardGuardianResponse(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if apiOptions.Base.DashboardId != apiOptions.New.DashboardId {
|
|
|
+ guardianNew := guardian.New(apiOptions.New.DashboardId, c.OrgId, c.SignedInUser)
|
|
|
+ if canSave, err := guardianNew.CanSave(); err != nil || !canSave {
|
|
|
+ return dashboardGuardianResponse(err)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
options := dashdiffs.Options{
|
|
|
OrgId: c.OrgId,
|
|
|
@@ -445,33 +438,33 @@ func CalculateDashboardDiff(c *middleware.Context, apiOptions dtos.CalculateDiff
|
|
|
result, err := dashdiffs.CalculateDiff(&options)
|
|
|
if err != nil {
|
|
|
if err == m.ErrDashboardVersionNotFound {
|
|
|
- return ApiError(404, "Dashboard version not found", err)
|
|
|
+ return Error(404, "Dashboard version not found", err)
|
|
|
}
|
|
|
- return ApiError(500, "Unable to compute diff", err)
|
|
|
+ return Error(500, "Unable to compute diff", err)
|
|
|
}
|
|
|
|
|
|
if options.DiffType == dashdiffs.DiffDelta {
|
|
|
return Respond(200, result.Delta).Header("Content-Type", "application/json")
|
|
|
- } else {
|
|
|
- return Respond(200, result.Delta).Header("Content-Type", "text/html")
|
|
|
}
|
|
|
+
|
|
|
+ return Respond(200, result.Delta).Header("Content-Type", "text/html")
|
|
|
}
|
|
|
|
|
|
// RestoreDashboardVersion restores a dashboard to the given version.
|
|
|
-func RestoreDashboardVersion(c *middleware.Context, apiCmd dtos.RestoreDashboardVersionCommand) Response {
|
|
|
+func RestoreDashboardVersion(c *m.ReqContext, apiCmd dtos.RestoreDashboardVersionCommand) Response {
|
|
|
dash, rsp := getDashboardHelper(c.OrgId, "", c.ParamsInt64(":dashboardId"), "")
|
|
|
if rsp != nil {
|
|
|
return rsp
|
|
|
}
|
|
|
|
|
|
- guardian := guardian.NewDashboardGuardian(dash.Id, c.OrgId, c.SignedInUser)
|
|
|
+ guardian := guardian.New(dash.Id, c.OrgId, c.SignedInUser)
|
|
|
if canSave, err := guardian.CanSave(); err != nil || !canSave {
|
|
|
return dashboardGuardianResponse(err)
|
|
|
}
|
|
|
|
|
|
versionQuery := m.GetDashboardVersionQuery{DashboardId: dash.Id, Version: apiCmd.Version, OrgId: c.OrgId}
|
|
|
if err := bus.Dispatch(&versionQuery); err != nil {
|
|
|
- return ApiError(404, "Dashboard version not found", nil)
|
|
|
+ return Error(404, "Dashboard version not found", nil)
|
|
|
}
|
|
|
|
|
|
version := versionQuery.Result
|
|
|
@@ -488,7 +481,7 @@ func RestoreDashboardVersion(c *middleware.Context, apiCmd dtos.RestoreDashboard
|
|
|
return PostDashboard(c, saveCmd)
|
|
|
}
|
|
|
|
|
|
-func GetDashboardTags(c *middleware.Context) {
|
|
|
+func GetDashboardTags(c *m.ReqContext) {
|
|
|
query := m.GetDashboardTagsQuery{OrgId: c.OrgId}
|
|
|
err := bus.Dispatch(&query)
|
|
|
if err != nil {
|