| 
									
										
										
										
											2014-12-29 20:36:08 +08:00
										 |  |  | package api | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2021-06-15 22:08:27 +08:00
										 |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2015-02-03 22:04:35 +08:00
										 |  |  | 	"encoding/json" | 
					
						
							| 
									
										
										
										
											2020-07-21 17:12:01 +08:00
										 |  |  | 	"errors" | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | 	"fmt" | 
					
						
							| 
									
										
										
										
											2021-11-29 17:18:01 +08:00
										 |  |  | 	"net/http" | 
					
						
							| 
									
										
										
										
											2015-02-03 22:04:35 +08:00
										 |  |  | 	"os" | 
					
						
							| 
									
										
										
										
											2019-04-30 19:32:18 +08:00
										 |  |  | 	"path/filepath" | 
					
						
							| 
									
										
										
										
											2021-11-17 17:57:37 +08:00
										 |  |  | 	"strconv" | 
					
						
							| 
									
										
										
										
											2022-05-17 00:59:02 +08:00
										 |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2015-02-03 22:04:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-28 17:28:33 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/api/apierrors" | 
					
						
							| 
									
										
										
										
											2015-02-05 17:37:13 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/api/dtos" | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/api/response" | 
					
						
							| 
									
										
										
										
											2017-06-06 06:14:40 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/components/dashdiffs" | 
					
						
							| 
									
										
										
										
											2016-12-08 17:25:05 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/components/simplejson" | 
					
						
							| 
									
										
										
										
											2022-05-22 08:44:12 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/coremodel/dashboard" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/cuectx" | 
					
						
							| 
									
										
										
										
											2019-02-24 06:35:26 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/infra/metrics" | 
					
						
							| 
									
										
										
										
											2021-10-11 20:30:59 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/models" | 
					
						
							| 
									
										
										
										
											2022-04-04 22:57:43 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/accesscontrol" | 
					
						
							| 
									
										
										
										
											2021-10-11 20:30:59 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/alerting" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/services/dashboards" | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 	dashver "github.com/grafana/grafana/pkg/services/dashboardversion" | 
					
						
							| 
									
										
										
										
											2022-05-22 08:44:12 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/featuremgmt" | 
					
						
							| 
									
										
										
										
											2017-06-12 21:48:55 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/guardian" | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/org" | 
					
						
							| 
									
										
										
										
											2022-04-21 21:03:17 +08:00
										 |  |  | 	pref "github.com/grafana/grafana/pkg/services/preference" | 
					
						
							| 
									
										
										
										
											2022-05-19 20:32:10 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/star" | 
					
						
							| 
									
										
										
										
											2022-08-02 22:58:05 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/services/user" | 
					
						
							| 
									
										
										
										
											2015-02-05 17:37:13 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/util" | 
					
						
							| 
									
										
										
										
											2021-10-11 20:30:59 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/web" | 
					
						
							| 
									
										
										
										
											2014-12-29 20:36:08 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-22 16:50:00 +08:00
										 |  |  | const ( | 
					
						
							|  |  |  | 	anonString = "Anonymous" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-07 19:43:43 +08:00
										 |  |  | func (hs *HTTPServer) isDashboardStarredByUser(c *models.ReqContext, dashID int64) (bool, error) { | 
					
						
							| 
									
										
										
										
											2015-02-02 18:32:32 +08:00
										 |  |  | 	if !c.IsSignedIn { | 
					
						
							|  |  |  | 		return false, nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	query := star.IsStarredByUserQuery{UserID: c.UserID, DashboardID: dashID} | 
					
						
							| 
									
										
										
										
											2022-05-19 20:32:10 +08:00
										 |  |  | 	return hs.starService.IsStarredByUser(c.Req.Context(), &query) | 
					
						
							| 
									
										
										
										
											2015-02-02 18:32:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | func dashboardGuardianResponse(err error) response.Response { | 
					
						
							| 
									
										
										
										
											2017-06-20 01:47:44 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(500, "Error while checking dashboard permissions", err) | 
					
						
							| 
									
										
										
										
											2017-06-20 01:47:44 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 	return response.Error(403, "Access denied to this dashboard", nil) | 
					
						
							| 
									
										
										
										
											2017-06-20 01:47:44 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-27 21:54:37 +08:00
										 |  |  | // swagger:route POST /dashboards/trim dashboards trimDashboard
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Trim defaults from dashboard.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: trimDashboardResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2021-11-29 17:18:01 +08:00
										 |  |  | func (hs *HTTPServer) TrimDashboard(c *models.ReqContext) response.Response { | 
					
						
							|  |  |  | 	cmd := models.TrimDashboardCommand{} | 
					
						
							|  |  |  | 	if err := web.Bind(c.Req, &cmd); err != nil { | 
					
						
							|  |  |  | 		return response.Error(http.StatusBadRequest, "bad request data", err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-04-28 19:38:33 +08:00
										 |  |  | 	dash := cmd.Dashboard | 
					
						
							|  |  |  | 	meta := cmd.Meta | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-07 08:52:44 +08:00
										 |  |  | 	// TODO temporarily just return the input as a no-op while we convert to thema calls
 | 
					
						
							| 
									
										
										
										
											2021-04-28 19:38:33 +08:00
										 |  |  | 	dto := dtos.TrimDashboardFullWithMeta{ | 
					
						
							| 
									
										
										
										
											2022-06-07 08:52:44 +08:00
										 |  |  | 		Dashboard: dash, | 
					
						
							| 
									
										
										
										
											2021-04-28 19:38:33 +08:00
										 |  |  | 		Meta:      meta, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	c.TimeRequest(metrics.MApiDashboardGet) | 
					
						
							| 
									
										
										
										
											2022-04-15 20:01:58 +08:00
										 |  |  | 	return response.JSON(http.StatusOK, dto) | 
					
						
							| 
									
										
										
										
											2021-04-28 19:38:33 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-27 21:54:37 +08:00
										 |  |  | // swagger:route GET /dashboards/uid/{uid} dashboards getDashboardByUID
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Get dashboard by uid.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Will return the dashboard given the dashboard unique identifier (uid).
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: dashboardResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 404: notFoundError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | func (hs *HTTPServer) GetDashboard(c *models.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2021-10-11 20:30:59 +08:00
										 |  |  | 	uid := web.Params(c.Req)[":uid"] | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	dash, rsp := hs.getDashboardHelper(c.Req.Context(), c.OrgID, 0, uid) | 
					
						
							| 
									
										
										
										
											2017-06-18 06:24:38 +08:00
										 |  |  | 	if rsp != nil { | 
					
						
							|  |  |  | 		return rsp | 
					
						
							| 
									
										
										
										
											2014-12-29 20:36:08 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-07-20 07:44:41 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	var ( | 
					
						
							|  |  |  | 		hasPublicDashboard bool | 
					
						
							|  |  |  | 		err                error | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | 	if hs.Features.IsEnabled(featuremgmt.FlagPublicDashboards) { | 
					
						
							|  |  |  | 		hasPublicDashboard, err = hs.PublicDashboardsApi.PublicDashboardService.PublicDashboardEnabled(c.Req.Context(), dash.Uid) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return response.Error(500, "Error while retrieving public dashboards", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 21:41:17 +08:00
										 |  |  | 	// When dash contains only keys id, uid that means dashboard data is not valid and json decode failed.
 | 
					
						
							|  |  |  | 	if dash.Data != nil { | 
					
						
							|  |  |  | 		isEmptyData := true | 
					
						
							|  |  |  | 		for k := range dash.Data.MustMap() { | 
					
						
							|  |  |  | 			if k != "id" && k != "uid" { | 
					
						
							|  |  |  | 				isEmptyData = false | 
					
						
							|  |  |  | 				break | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if isEmptyData { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 			return response.Error(500, "Error while loading dashboard, dashboard data is invalid", nil) | 
					
						
							| 
									
										
										
										
											2021-01-04 21:41:17 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	guardian := guardian.New(c.Req.Context(), dash.Id, c.OrgID, c.SignedInUser) | 
					
						
							| 
									
										
										
										
											2017-06-20 01:47:44 +08:00
										 |  |  | 	if canView, err := guardian.CanView(); err != nil || !canView { | 
					
						
							|  |  |  | 		return dashboardGuardianResponse(err) | 
					
						
							| 
									
										
										
										
											2017-06-12 21:48:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-06-18 06:24:38 +08:00
										 |  |  | 	canEdit, _ := guardian.CanEdit() | 
					
						
							|  |  |  | 	canSave, _ := guardian.CanSave() | 
					
						
							| 
									
										
										
										
											2017-06-23 06:34:19 +08:00
										 |  |  | 	canAdmin, _ := guardian.CanAdmin() | 
					
						
							| 
									
										
										
										
											2022-03-03 22:05:47 +08:00
										 |  |  | 	canDelete, _ := guardian.CanDelete() | 
					
						
							| 
									
										
										
										
											2017-06-18 06:24:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-07 19:43:43 +08:00
										 |  |  | 	isStarred, err := hs.isDashboardStarredByUser(c, dash.Id) | 
					
						
							| 
									
										
										
										
											2017-06-12 21:48:55 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(500, "Error while checking if dashboard was starred by user", err) | 
					
						
							| 
									
										
										
										
											2017-06-12 21:48:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-01-29 01:53:19 +08:00
										 |  |  | 	// Finding creator and last updater of the dashboard
 | 
					
						
							| 
									
										
										
										
											2018-09-22 16:50:00 +08:00
										 |  |  | 	updater, creator := anonString, anonString | 
					
						
							| 
									
										
										
										
											2016-01-28 13:55:54 +08:00
										 |  |  | 	if dash.UpdatedBy > 0 { | 
					
						
							| 
									
										
										
										
											2022-02-07 19:43:43 +08:00
										 |  |  | 		updater = hs.getUserLogin(c.Req.Context(), dash.UpdatedBy) | 
					
						
							| 
									
										
										
										
											2016-01-28 14:00:24 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if dash.CreatedBy > 0 { | 
					
						
							| 
									
										
										
										
											2022-02-07 19:43:43 +08:00
										 |  |  | 		creator = hs.getUserLogin(c.Req.Context(), dash.CreatedBy) | 
					
						
							| 
									
										
										
										
											2016-01-28 14:00:24 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-12-18 19:38:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-04 22:57:43 +08:00
										 |  |  | 	annotationPermissions := &dtos.AnnotationPermission{} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if !hs.AccessControl.IsDisabled() { | 
					
						
							|  |  |  | 		hs.getAnnotationPermissionsByScope(c, &annotationPermissions.Dashboard, accesscontrol.ScopeAnnotationsTypeDashboard) | 
					
						
							|  |  |  | 		hs.getAnnotationPermissionsByScope(c, &annotationPermissions.Organization, accesscontrol.ScopeAnnotationsTypeOrganization) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-17 04:57:37 +08:00
										 |  |  | 	meta := dtos.DashboardMeta{ | 
					
						
							| 
									
										
										
										
											2022-04-04 22:57:43 +08:00
										 |  |  | 		IsStarred:              isStarred, | 
					
						
							|  |  |  | 		Slug:                   dash.Slug, | 
					
						
							|  |  |  | 		Type:                   models.DashTypeDB, | 
					
						
							|  |  |  | 		CanStar:                c.IsSignedIn, | 
					
						
							|  |  |  | 		CanSave:                canSave, | 
					
						
							|  |  |  | 		CanEdit:                canEdit, | 
					
						
							|  |  |  | 		CanAdmin:               canAdmin, | 
					
						
							|  |  |  | 		CanDelete:              canDelete, | 
					
						
							|  |  |  | 		Created:                dash.Created, | 
					
						
							|  |  |  | 		Updated:                dash.Updated, | 
					
						
							|  |  |  | 		UpdatedBy:              updater, | 
					
						
							|  |  |  | 		CreatedBy:              creator, | 
					
						
							|  |  |  | 		Version:                dash.Version, | 
					
						
							| 
									
										
										
										
											2022-07-18 21:14:58 +08:00
										 |  |  | 		HasACL:                 dash.HasACL, | 
					
						
							| 
									
										
										
										
											2022-04-04 22:57:43 +08:00
										 |  |  | 		IsFolder:               dash.IsFolder, | 
					
						
							|  |  |  | 		FolderId:               dash.FolderId, | 
					
						
							|  |  |  | 		Url:                    dash.GetUrl(), | 
					
						
							|  |  |  | 		FolderTitle:            "General", | 
					
						
							|  |  |  | 		AnnotationsPermissions: annotationPermissions, | 
					
						
							| 
									
										
										
										
											2022-07-20 07:44:41 +08:00
										 |  |  | 		PublicDashboardEnabled: hasPublicDashboard, | 
					
						
							| 
									
										
										
										
											2017-06-17 04:57:37 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// lookup folder title
 | 
					
						
							| 
									
										
										
										
											2017-06-24 04:00:26 +08:00
										 |  |  | 	if dash.FolderId > 0 { | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 		query := models.GetDashboardQuery{Id: dash.FolderId, OrgId: c.OrgID} | 
					
						
							| 
									
										
										
										
											2022-07-07 02:42:39 +08:00
										 |  |  | 		if err := hs.DashboardService.GetDashboard(c.Req.Context(), &query); err != nil { | 
					
						
							| 
									
										
										
										
											2022-06-30 21:31:54 +08:00
										 |  |  | 			if errors.Is(err, dashboards.ErrFolderNotFound) { | 
					
						
							| 
									
										
										
										
											2021-05-26 22:20:13 +08:00
										 |  |  | 				return response.Error(404, "Folder not found", err) | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 			return response.Error(500, "Dashboard folder could not be read", err) | 
					
						
							| 
									
										
										
										
											2017-06-17 04:57:37 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-05-26 22:20:13 +08:00
										 |  |  | 		meta.FolderUid = query.Result.Uid | 
					
						
							| 
									
										
										
										
											2017-06-17 04:57:37 +08:00
										 |  |  | 		meta.FolderTitle = query.Result.Title | 
					
						
							| 
									
										
										
										
											2018-02-05 18:09:05 +08:00
										 |  |  | 		meta.FolderUrl = query.Result.GetUrl() | 
					
						
							| 
									
										
										
										
											2017-06-17 04:57:37 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-16 21:15:44 +08:00
										 |  |  | 	provisioningData, err := hs.dashboardProvisioningService.GetProvisionedDashboardDataByDashboardID(dash.Id) | 
					
						
							| 
									
										
										
										
											2018-04-10 15:31:35 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(500, "Error while checking if dashboard is provisioned", err) | 
					
						
							| 
									
										
										
										
											2018-04-10 15:31:35 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 19:32:18 +08:00
										 |  |  | 	if provisioningData != nil { | 
					
						
							| 
									
										
										
										
											2020-04-15 14:12:52 +08:00
										 |  |  | 		allowUIUpdate := hs.ProvisioningService.GetAllowUIUpdatesFromConfig(provisioningData.Name) | 
					
						
							|  |  |  | 		if !allowUIUpdate { | 
					
						
							| 
									
										
										
										
											2019-10-31 21:27:31 +08:00
										 |  |  | 			meta.Provisioned = true | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 19:32:18 +08:00
										 |  |  | 		meta.ProvisionedExternalId, err = filepath.Rel( | 
					
						
							|  |  |  | 			hs.ProvisioningService.GetDashboardProvisionerResolvedPath(provisioningData.Name), | 
					
						
							|  |  |  | 			provisioningData.ExternalId, | 
					
						
							|  |  |  | 		) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			// Not sure when this could happen so not sure how to better handle this. Right now ProvisionedExternalId
 | 
					
						
							|  |  |  | 			// is for better UX, showing in Save/Delete dialogs and so it won't break anything if it is empty.
 | 
					
						
							|  |  |  | 			hs.log.Warn("Failed to create ProvisionedExternalId", "err", err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-02-28 01:51:04 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-06 21:40:10 +08:00
										 |  |  | 	// make sure db version is in sync with json model version
 | 
					
						
							|  |  |  | 	dash.Data.Set("version", dash.Version) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-12 14:48:17 +08:00
										 |  |  | 	// load library panels JSON for this dashboard
 | 
					
						
							| 
									
										
										
										
											2021-09-27 15:04:36 +08:00
										 |  |  | 	err = hs.LibraryPanelService.LoadLibraryPanelsForDashboard(c.Req.Context(), dash) | 
					
						
							| 
									
										
										
										
											2021-05-12 14:48:17 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return response.Error(500, "Error while loading library panels", err) | 
					
						
							| 
									
										
										
										
											2021-01-20 16:28:10 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-05-12 14:48:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-04 14:36:44 +08:00
										 |  |  | 	dto := dtos.DashboardFullWithMeta{ | 
					
						
							|  |  |  | 		Dashboard: dash.Data, | 
					
						
							| 
									
										
										
										
											2017-06-17 04:57:37 +08:00
										 |  |  | 		Meta:      meta, | 
					
						
							| 
									
										
										
										
											2015-01-29 19:10:34 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-12-29 20:36:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-16 22:58:46 +08:00
										 |  |  | 	c.TimeRequest(metrics.MApiDashboardGet) | 
					
						
							| 
									
										
										
										
											2022-04-15 20:01:58 +08:00
										 |  |  | 	return response.JSON(http.StatusOK, dto) | 
					
						
							| 
									
										
										
										
											2017-06-12 21:48:55 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-04 22:57:43 +08:00
										 |  |  | func (hs *HTTPServer) getAnnotationPermissionsByScope(c *models.ReqContext, actions *dtos.AnnotationActions, scope string) { | 
					
						
							|  |  |  | 	var err error | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-05 19:20:10 +08:00
										 |  |  | 	evaluate := accesscontrol.EvalPermission(accesscontrol.ActionAnnotationsCreate, scope) | 
					
						
							|  |  |  | 	actions.CanAdd, err = hs.AccessControl.Evaluate(c.Req.Context(), c.SignedInUser, evaluate) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		hs.log.Warn("Failed to evaluate permission", "err", err, "action", accesscontrol.ActionAnnotationsCreate, "scope", scope) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	evaluate = accesscontrol.EvalPermission(accesscontrol.ActionAnnotationsDelete, scope) | 
					
						
							| 
									
										
										
										
											2022-04-04 22:57:43 +08:00
										 |  |  | 	actions.CanDelete, err = hs.AccessControl.Evaluate(c.Req.Context(), c.SignedInUser, evaluate) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		hs.log.Warn("Failed to evaluate permission", "err", err, "action", accesscontrol.ActionAnnotationsDelete, "scope", scope) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	evaluate = accesscontrol.EvalPermission(accesscontrol.ActionAnnotationsWrite, scope) | 
					
						
							|  |  |  | 	actions.CanEdit, err = hs.AccessControl.Evaluate(c.Req.Context(), c.SignedInUser, evaluate) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		hs.log.Warn("Failed to evaluate permission", "err", err, "action", accesscontrol.ActionAnnotationsWrite, "scope", scope) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-07 19:43:43 +08:00
										 |  |  | func (hs *HTTPServer) getUserLogin(ctx context.Context, userID int64) string { | 
					
						
							| 
									
										
										
										
											2022-08-02 22:58:05 +08:00
										 |  |  | 	query := user.GetUserByIDQuery{ID: userID} | 
					
						
							|  |  |  | 	user, err := hs.userService.GetByID(ctx, &query) | 
					
						
							| 
									
										
										
										
											2016-01-28 14:00:24 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2018-09-22 16:50:00 +08:00
										 |  |  | 		return anonString | 
					
						
							| 
									
										
										
										
											2016-01-28 14:00:24 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-08-02 22:58:05 +08:00
										 |  |  | 	return user.Login | 
					
						
							| 
									
										
										
										
											2016-01-28 13:55:54 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-07 19:43:43 +08:00
										 |  |  | func (hs *HTTPServer) getDashboardHelper(ctx context.Context, orgID int64, id int64, uid string) (*models.Dashboard, response.Response) { | 
					
						
							| 
									
										
										
										
											2020-03-04 19:57:20 +08:00
										 |  |  | 	var query models.GetDashboardQuery | 
					
						
							| 
									
										
										
										
											2018-01-30 04:23:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if len(uid) > 0 { | 
					
						
							| 
									
										
										
										
											2020-03-04 19:57:20 +08:00
										 |  |  | 		query = models.GetDashboardQuery{Uid: uid, Id: id, OrgId: orgID} | 
					
						
							| 
									
										
										
										
											2018-01-30 04:23:07 +08:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2021-06-03 21:20:13 +08:00
										 |  |  | 		query = models.GetDashboardQuery{Id: id, OrgId: orgID} | 
					
						
							| 
									
										
										
										
											2018-01-30 04:23:07 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 02:42:39 +08:00
										 |  |  | 	if err := hs.DashboardService.GetDashboard(ctx, &query); err != nil { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return nil, response.Error(404, "Dashboard not found", err) | 
					
						
							| 
									
										
										
										
											2017-06-18 06:24:38 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-01-29 20:51:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-18 06:24:38 +08:00
										 |  |  | 	return query.Result, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-27 21:54:37 +08:00
										 |  |  | // DeleteDashboardByUID swagger:route DELETE /dashboards/uid/{uid} dashboards deleteDashboardByUID
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Delete dashboard by uid.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Will delete the dashboard given the specified unique identifier (uid).
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: deleteDashboardResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 404: notFoundError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2021-01-20 16:28:10 +08:00
										 |  |  | func (hs *HTTPServer) DeleteDashboardByUID(c *models.ReqContext) response.Response { | 
					
						
							|  |  |  | 	return hs.deleteDashboard(c) | 
					
						
							| 
									
										
										
										
											2019-04-10 19:29:10 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-20 16:28:10 +08:00
										 |  |  | func (hs *HTTPServer) deleteDashboard(c *models.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	dash, rsp := hs.getDashboardHelper(c.Req.Context(), c.OrgID, 0, web.Params(c.Req)[":uid"]) | 
					
						
							| 
									
										
										
										
											2017-06-18 06:24:38 +08:00
										 |  |  | 	if rsp != nil { | 
					
						
							|  |  |  | 		return rsp | 
					
						
							| 
									
										
										
										
											2017-06-13 05:05:32 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	guardian := guardian.New(c.Req.Context(), dash.Id, c.OrgID, c.SignedInUser) | 
					
						
							| 
									
										
										
										
											2022-03-03 22:05:47 +08:00
										 |  |  | 	if canDelete, err := guardian.CanDelete(); err != nil || !canDelete { | 
					
						
							| 
									
										
										
										
											2017-06-20 01:47:44 +08:00
										 |  |  | 		return dashboardGuardianResponse(err) | 
					
						
							| 
									
										
										
										
											2014-12-29 20:36:08 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-12 14:48:17 +08:00
										 |  |  | 	// disconnect all library elements for this dashboard
 | 
					
						
							| 
									
										
										
										
											2021-09-27 15:04:36 +08:00
										 |  |  | 	err := hs.LibraryElementService.DisconnectElementsFromDashboard(c.Req.Context(), dash.Id) | 
					
						
							| 
									
										
										
										
											2021-05-12 14:48:17 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 		hs.log.Error("Failed to disconnect library elements", "dashboard", dash.Id, "user", c.SignedInUser.UserID, "error", err) | 
					
						
							| 
									
										
										
										
											2021-01-20 16:28:10 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-02-16 21:15:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	err = hs.DashboardService.DeleteDashboard(c.Req.Context(), dash.Id, c.OrgID) | 
					
						
							| 
									
										
										
										
											2020-07-21 17:12:01 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2022-06-30 21:31:54 +08:00
										 |  |  | 		var dashboardErr dashboards.DashboardErr | 
					
						
							| 
									
										
										
										
											2020-07-21 17:12:01 +08:00
										 |  |  | 		if ok := errors.As(err, &dashboardErr); ok { | 
					
						
							| 
									
										
										
										
											2022-06-30 21:31:54 +08:00
										 |  |  | 			if errors.Is(err, dashboards.ErrDashboardCannotDeleteProvisionedDashboard) { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 				return response.Error(dashboardErr.StatusCode, dashboardErr.Error(), err) | 
					
						
							| 
									
										
										
										
											2020-07-21 17:12:01 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(500, "Failed to delete dashboard", err) | 
					
						
							| 
									
										
										
										
											2014-12-29 20:36:08 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-04-27 16:29:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-04 23:44:55 +08:00
										 |  |  | 	if hs.Live != nil { | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 		err := hs.Live.GrafanaScope.Dashboards.DashboardDeleted(c.OrgID, c.ToUserDisplayDTO(), dash.Uid) | 
					
						
							| 
									
										
										
										
											2021-04-24 03:55:31 +08:00
										 |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			hs.log.Error("Failed to broadcast delete info", "dashboard", dash.Uid, "error", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-04-15 20:01:58 +08:00
										 |  |  | 	return response.JSON(http.StatusOK, util.DynMap{ | 
					
						
							| 
									
										
										
										
											2018-02-21 23:38:09 +08:00
										 |  |  | 		"title":   dash.Title, | 
					
						
							|  |  |  | 		"message": fmt.Sprintf("Dashboard %s deleted", dash.Title), | 
					
						
							| 
									
										
										
										
											2020-07-31 14:22:09 +08:00
										 |  |  | 		"id":      dash.Id, | 
					
						
							| 
									
										
										
										
											2018-02-21 23:38:09 +08:00
										 |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2014-12-29 20:36:08 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-27 21:54:37 +08:00
										 |  |  | // swagger:route POST /dashboards/db dashboards postDashboard
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Create / Update dashboard
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Creates a new dashboard or updates an existing dashboard.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: postDashboardResponse
 | 
					
						
							|  |  |  | // 400: badRequestError
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 404: notFoundError
 | 
					
						
							|  |  |  | // 412: preconditionFailedError
 | 
					
						
							|  |  |  | // 422: unprocessableEntityError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2021-11-29 17:18:01 +08:00
										 |  |  | func (hs *HTTPServer) PostDashboard(c *models.ReqContext) response.Response { | 
					
						
							|  |  |  | 	cmd := models.SaveDashboardCommand{} | 
					
						
							|  |  |  | 	if err := web.Bind(c.Req, &cmd); err != nil { | 
					
						
							|  |  |  | 		return response.Error(http.StatusBadRequest, "bad request data", err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-05-22 08:44:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if hs.Features.IsEnabled(featuremgmt.FlagValidateDashboardsOnSave) { | 
					
						
							| 
									
										
										
										
											2022-08-04 04:04:54 +08:00
										 |  |  | 		cm := hs.Coremodels.Dashboard() | 
					
						
							| 
									
										
										
										
											2022-06-15 21:47:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-22 08:44:12 +08:00
										 |  |  | 		// Ideally, coremodel validation calls would be integrated into the web
 | 
					
						
							|  |  |  | 		// framework. But this does the job for now.
 | 
					
						
							| 
									
										
										
										
											2022-06-15 21:47:04 +08:00
										 |  |  | 		schv, err := cmd.Dashboard.Get("schemaVersion").Int() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Only try to validate if the schemaVersion is at least the handoff version
 | 
					
						
							|  |  |  | 		// (the minimum schemaVersion against which the dashboard schema is known to
 | 
					
						
							|  |  |  | 		// work), or if schemaVersion is absent (which will happen once the Thema
 | 
					
						
							|  |  |  | 		// schema becomes canonical).
 | 
					
						
							|  |  |  | 		if err != nil || schv >= dashboard.HandoffSchemaVersion { | 
					
						
							|  |  |  | 			// Can't fail, web.Bind() already ensured it's valid JSON
 | 
					
						
							|  |  |  | 			b, _ := cmd.Dashboard.Bytes() | 
					
						
							|  |  |  | 			v, _ := cuectx.JSONtoCUE("dashboard.json", b) | 
					
						
							|  |  |  | 			if _, err := cm.CurrentSchema().Validate(v); err != nil { | 
					
						
							|  |  |  | 				return response.Error(http.StatusBadRequest, "invalid dashboard json", err) | 
					
						
							| 
									
										
										
										
											2022-05-22 08:44:12 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-29 17:18:01 +08:00
										 |  |  | 	return hs.postDashboard(c, cmd) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (hs *HTTPServer) postDashboard(c *models.ReqContext, cmd models.SaveDashboardCommand) response.Response { | 
					
						
							| 
									
										
										
										
											2021-09-14 22:08:04 +08:00
										 |  |  | 	ctx := c.Req.Context() | 
					
						
							| 
									
										
										
										
											2021-04-28 19:38:33 +08:00
										 |  |  | 	var err error | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	cmd.OrgId = c.OrgID | 
					
						
							|  |  |  | 	cmd.UserId = c.UserID | 
					
						
							| 
									
										
										
										
											2021-05-26 22:20:13 +08:00
										 |  |  | 	if cmd.FolderUid != "" { | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 		folder, err := hs.folderService.GetFolderByUID(ctx, c.SignedInUser, c.OrgID, cmd.FolderUid) | 
					
						
							| 
									
										
										
										
											2021-05-26 22:20:13 +08:00
										 |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2022-06-30 21:31:54 +08:00
										 |  |  | 			if errors.Is(err, dashboards.ErrFolderNotFound) { | 
					
						
							| 
									
										
										
										
											2021-05-26 22:20:13 +08:00
										 |  |  | 				return response.Error(400, "Folder not found", err) | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return response.Error(500, "Error while checking folder ID", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		cmd.FolderId = folder.Id | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-20 22:38:25 +08:00
										 |  |  | 	dash := cmd.GetDashboardModel() | 
					
						
							| 
									
										
										
										
											2021-05-26 22:20:13 +08:00
										 |  |  | 	newDashboard := dash.Id == 0 | 
					
						
							| 
									
										
										
										
											2019-03-05 23:44:41 +08:00
										 |  |  | 	if newDashboard { | 
					
						
							| 
									
										
										
										
											2019-02-12 04:12:01 +08:00
										 |  |  | 		limitReached, err := hs.QuotaService.QuotaReached(c, "dashboard") | 
					
						
							| 
									
										
										
										
											2015-07-20 22:38:25 +08:00
										 |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 			return response.Error(500, "failed to get quota", err) | 
					
						
							| 
									
										
										
										
											2015-07-20 22:38:25 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if limitReached { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 			return response.Error(403, "Quota reached", nil) | 
					
						
							| 
									
										
										
										
											2015-07-20 22:38:25 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-17 23:31:52 +08:00
										 |  |  | 	var provisioningData *models.DashboardProvisioning | 
					
						
							|  |  |  | 	if dash.Id != 0 { | 
					
						
							| 
									
										
										
										
											2022-02-16 21:15:44 +08:00
										 |  |  | 		data, err := hs.dashboardProvisioningService.GetProvisionedDashboardDataByDashboardID(dash.Id) | 
					
						
							| 
									
										
										
										
											2021-12-17 23:31:52 +08:00
										 |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2022-01-12 00:39:53 +08:00
										 |  |  | 			return response.Error(500, "Error while checking if dashboard is provisioned using ID", err) | 
					
						
							| 
									
										
										
										
											2021-12-17 23:31:52 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		provisioningData = data | 
					
						
							|  |  |  | 	} else if dash.Uid != "" { | 
					
						
							| 
									
										
										
										
											2022-02-16 21:15:44 +08:00
										 |  |  | 		data, err := hs.dashboardProvisioningService.GetProvisionedDashboardDataByDashboardUID(dash.OrgId, dash.Uid) | 
					
						
							| 
									
										
										
										
											2022-06-30 21:31:54 +08:00
										 |  |  | 		if err != nil && !errors.Is(err, dashboards.ErrProvisionedDashboardNotFound) && !errors.Is(err, dashboards.ErrDashboardNotFound) { | 
					
						
							| 
									
										
										
										
											2022-02-16 21:15:44 +08:00
										 |  |  | 			return response.Error(500, "Error while checking if dashboard is provisioned", err) | 
					
						
							| 
									
										
										
										
											2021-12-17 23:31:52 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		provisioningData = data | 
					
						
							| 
									
										
										
										
											2019-10-31 21:27:31 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 14:57:03 +08:00
										 |  |  | 	allowUiUpdate := true | 
					
						
							|  |  |  | 	if provisioningData != nil { | 
					
						
							| 
									
										
										
										
											2020-04-15 14:12:52 +08:00
										 |  |  | 		allowUiUpdate = hs.ProvisioningService.GetAllowUIUpdatesFromConfig(provisioningData.Name) | 
					
						
							| 
									
										
										
										
											2019-11-01 14:57:03 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-10-31 21:27:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-12 14:48:17 +08:00
										 |  |  | 	// clean up all unnecessary library panels JSON properties so we store a minimum JSON
 | 
					
						
							|  |  |  | 	err = hs.LibraryPanelService.CleanLibraryPanelsForDashboard(dash) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return response.Error(500, "Error while cleaning library panels", err) | 
					
						
							| 
									
										
										
										
											2021-01-20 16:28:10 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-23 19:28:56 +08:00
										 |  |  | 	dashItem := &dashboards.SaveDashboardDTO{ | 
					
						
							| 
									
										
										
										
											2017-12-01 20:50:47 +08:00
										 |  |  | 		Dashboard: dash, | 
					
						
							|  |  |  | 		Message:   cmd.Message, | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 		OrgId:     c.OrgID, | 
					
						
							| 
									
										
										
										
											2018-02-19 18:12:56 +08:00
										 |  |  | 		User:      c.SignedInUser, | 
					
						
							| 
									
										
										
										
											2017-12-12 20:18:00 +08:00
										 |  |  | 		Overwrite: cmd.Overwrite, | 
					
						
							| 
									
										
										
										
											2016-11-24 18:22:13 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-07 02:42:39 +08:00
										 |  |  | 	dashboard, err := hs.DashboardService.SaveDashboard(alerting.WithUAEnabled(ctx, hs.Cfg.UnifiedAlerting.IsEnabled()), dashItem, allowUiUpdate) | 
					
						
							| 
									
										
										
										
											2021-04-24 03:55:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-04 23:44:55 +08:00
										 |  |  | 	if hs.Live != nil { | 
					
						
							|  |  |  | 		// Tell everyone listening that the dashboard changed
 | 
					
						
							| 
									
										
										
										
											2021-04-24 03:55:31 +08:00
										 |  |  | 		if dashboard == nil { | 
					
						
							|  |  |  | 			dashboard = dash // the original request
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-15 16:33:01 +08:00
										 |  |  | 		// This will broadcast all save requests only if a `gitops` observer exists.
 | 
					
						
							| 
									
										
										
										
											2021-04-24 03:55:31 +08:00
										 |  |  | 		// gitops is useful when trying to save dashboards in an environment where the user can not save
 | 
					
						
							|  |  |  | 		channel := hs.Live.GrafanaScope.Dashboards | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 		liveerr := channel.DashboardSaved(c.SignedInUser.OrgID, c.SignedInUser.ToUserDisplayDTO(), cmd.Message, dashboard, err) | 
					
						
							| 
									
										
										
										
											2021-04-24 03:55:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// When an error exists, but the value broadcast to a gitops listener return 202
 | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 		if liveerr == nil && err != nil && channel.HasGitOpsObserver(c.SignedInUser.OrgID) { | 
					
						
							| 
									
										
										
										
											2021-04-24 03:55:31 +08:00
										 |  |  | 			return response.JSON(202, util.DynMap{ | 
					
						
							|  |  |  | 				"status":  "pending", | 
					
						
							|  |  |  | 				"message": "changes were broadcast to the gitops listener", | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if liveerr != nil { | 
					
						
							|  |  |  | 			hs.log.Warn("unable to broadcast save event", "uid", dashboard.Uid, "error", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-05-04 23:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-20 18:42:47 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2022-01-28 17:28:33 +08:00
										 |  |  | 		return apierrors.ToDashboardErrorResponse(ctx, hs.pluginStore, err) | 
					
						
							| 
									
										
										
										
											2019-12-20 18:42:47 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-12 14:48:17 +08:00
										 |  |  | 	// connect library panels for this dashboard after the dashboard is stored and has an ID
 | 
					
						
							| 
									
										
										
										
											2021-11-17 19:04:22 +08:00
										 |  |  | 	err = hs.LibraryPanelService.ConnectLibraryPanelsForDashboard(ctx, c.SignedInUser, dashboard) | 
					
						
							| 
									
										
										
										
											2021-05-12 14:48:17 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return response.Error(500, "Error while connecting library panels", err) | 
					
						
							| 
									
										
										
										
											2021-01-20 16:28:10 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-20 18:42:47 +08:00
										 |  |  | 	c.TimeRequest(metrics.MApiDashboardSave) | 
					
						
							| 
									
										
										
										
											2022-04-15 20:01:58 +08:00
										 |  |  | 	return response.JSON(http.StatusOK, util.DynMap{ | 
					
						
							| 
									
										
										
										
											2019-12-20 18:42:47 +08:00
										 |  |  | 		"status":  "success", | 
					
						
							|  |  |  | 		"slug":    dashboard.Slug, | 
					
						
							|  |  |  | 		"version": dashboard.Version, | 
					
						
							|  |  |  | 		"id":      dashboard.Id, | 
					
						
							|  |  |  | 		"uid":     dashboard.Uid, | 
					
						
							|  |  |  | 		"url":     dashboard.GetUrl(), | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-12-01 20:50:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-27 21:54:37 +08:00
										 |  |  | // swagger:route GET /dashboards/home dashboards getHomeDashboard
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Get home dashboard.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: getHomeDashboardResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | func (hs *HTTPServer) GetHomeDashboard(c *models.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	prefsQuery := pref.GetPreferenceWithDefaultsQuery{OrgID: c.OrgID, UserID: c.SignedInUser.UserID, Teams: c.Teams} | 
					
						
							| 
									
										
										
										
											2021-04-13 21:27:51 +08:00
										 |  |  | 	homePage := hs.Cfg.HomePage | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-21 21:03:17 +08:00
										 |  |  | 	preference, err := hs.preferenceService.GetWithDefaults(c.Req.Context(), &prefsQuery) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(500, "Failed to get preferences", err) | 
					
						
							| 
									
										
										
										
											2016-03-17 17:29:34 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-21 21:03:17 +08:00
										 |  |  | 	if preference.HomeDashboardID == 0 && len(homePage) > 0 { | 
					
						
							| 
									
										
										
										
											2021-04-13 21:27:51 +08:00
										 |  |  | 		homePageRedirect := dtos.DashboardRedirect{RedirectUri: homePage} | 
					
						
							| 
									
										
										
										
											2022-04-15 20:01:58 +08:00
										 |  |  | 		return response.JSON(http.StatusOK, &homePageRedirect) | 
					
						
							| 
									
										
										
										
											2021-04-13 21:27:51 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-21 21:03:17 +08:00
										 |  |  | 	if preference.HomeDashboardID != 0 { | 
					
						
							|  |  |  | 		slugQuery := models.GetDashboardRefByIdQuery{Id: preference.HomeDashboardID} | 
					
						
							| 
									
										
										
										
											2022-07-07 02:42:39 +08:00
										 |  |  | 		err := hs.DashboardService.GetDashboardUIDById(c.Req.Context(), &slugQuery) | 
					
						
							| 
									
										
										
										
											2016-05-24 13:39:58 +08:00
										 |  |  | 		if err == nil { | 
					
						
							| 
									
										
										
										
											2020-03-04 19:57:20 +08:00
										 |  |  | 			url := models.GetDashboardUrl(slugQuery.Result.Uid, slugQuery.Result.Slug) | 
					
						
							| 
									
										
										
										
											2018-02-05 17:24:48 +08:00
										 |  |  | 			dashRedirect := dtos.DashboardRedirect{RedirectUri: url} | 
					
						
							| 
									
										
										
										
											2022-04-15 20:01:58 +08:00
										 |  |  | 			return response.JSON(http.StatusOK, &dashRedirect) | 
					
						
							| 
									
										
										
										
											2016-03-17 17:29:34 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-12-03 17:11:14 +08:00
										 |  |  | 		hs.log.Warn("Failed to get slug from database", "err", err) | 
					
						
							| 
									
										
										
										
											2016-03-17 17:29:34 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-23 00:00:39 +08:00
										 |  |  | 	filePath := hs.Cfg.DefaultHomeDashboardPath | 
					
						
							|  |  |  | 	if filePath == "" { | 
					
						
							| 
									
										
										
										
											2020-10-19 23:35:31 +08:00
										 |  |  | 		filePath = filepath.Join(hs.Cfg.StaticRootPath, "dashboards/home.json") | 
					
						
							| 
									
										
										
										
											2020-06-23 00:00:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-04 05:13:06 +08:00
										 |  |  | 	// It's safe to ignore gosec warning G304 since the variable part of the file path comes from a configuration
 | 
					
						
							|  |  |  | 	// variable
 | 
					
						
							|  |  |  | 	// nolint:gosec
 | 
					
						
							| 
									
										
										
										
											2015-02-03 22:04:35 +08:00
										 |  |  | 	file, err := os.Open(filePath) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(500, "Failed to load home dashboard", err) | 
					
						
							| 
									
										
										
										
											2015-02-03 22:04:35 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-12-03 17:11:14 +08:00
										 |  |  | 	defer func() { | 
					
						
							|  |  |  | 		if err := file.Close(); err != nil { | 
					
						
							|  |  |  | 			hs.log.Warn("Failed to close dashboard file", "path", filePath, "err", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}() | 
					
						
							| 
									
										
										
										
											2015-02-03 22:04:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-04 14:36:44 +08:00
										 |  |  | 	dash := dtos.DashboardFullWithMeta{} | 
					
						
							| 
									
										
										
										
											2015-02-03 22:04:35 +08:00
										 |  |  | 	dash.Meta.IsHome = true | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 	dash.Meta.CanEdit = c.SignedInUser.HasRole(org.RoleEditor) | 
					
						
							| 
									
										
										
										
											2018-02-02 17:33:31 +08:00
										 |  |  | 	dash.Meta.FolderTitle = "General" | 
					
						
							| 
									
										
										
										
											2022-04-12 15:30:34 +08:00
										 |  |  | 	dash.Dashboard = simplejson.New() | 
					
						
							| 
									
										
										
										
											2017-06-17 09:25:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-03 22:04:35 +08:00
										 |  |  | 	jsonParser := json.NewDecoder(file) | 
					
						
							| 
									
										
										
										
											2022-04-12 15:30:34 +08:00
										 |  |  | 	if err := jsonParser.Decode(dash.Dashboard); err != nil { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(500, "Failed to load home dashboard", err) | 
					
						
							| 
									
										
										
										
											2015-02-03 22:04:35 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-02 23:12:22 +08:00
										 |  |  | 	hs.addGettingStartedPanelToHomeDashboard(c, dash.Dashboard) | 
					
						
							| 
									
										
										
										
											2016-12-08 17:25:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-15 20:01:58 +08:00
										 |  |  | 	return response.JSON(http.StatusOK, &dash) | 
					
						
							| 
									
										
										
										
											2015-02-03 22:04:35 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-05-12 20:11:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-02 23:12:22 +08:00
										 |  |  | func (hs *HTTPServer) addGettingStartedPanelToHomeDashboard(c *models.ReqContext, dash *simplejson.Json) { | 
					
						
							|  |  |  | 	// We only add this getting started panel for Admins who have not dismissed it,
 | 
					
						
							|  |  |  | 	// and if a custom default home dashboard hasn't been configured
 | 
					
						
							| 
									
										
										
										
											2022-08-10 17:56:48 +08:00
										 |  |  | 	if !c.HasUserRole(org.RoleAdmin) || | 
					
						
							|  |  |  | 		c.HasHelpFlag(user.HelpFlagGettingStartedPanelDismissed) || | 
					
						
							| 
									
										
										
										
											2020-11-02 23:12:22 +08:00
										 |  |  | 		hs.Cfg.DefaultHomeDashboardPath != "" { | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-25 20:47:57 +08:00
										 |  |  | 	panels := dash.Get("panels").MustArray() | 
					
						
							| 
									
										
										
										
											2016-12-08 17:25:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	newpanel := simplejson.NewFromAny(map[string]interface{}{ | 
					
						
							| 
									
										
										
										
											2017-10-11 01:48:06 +08:00
										 |  |  | 		"type": "gettingstarted", | 
					
						
							|  |  |  | 		"id":   123123, | 
					
						
							|  |  |  | 		"gridPos": map[string]interface{}{ | 
					
						
							|  |  |  | 			"x": 0, | 
					
						
							| 
									
										
										
										
											2019-01-28 22:01:42 +08:00
										 |  |  | 			"y": 3, | 
					
						
							| 
									
										
										
										
											2017-10-25 01:22:56 +08:00
										 |  |  | 			"w": 24, | 
					
						
							| 
									
										
										
										
											2020-05-13 14:00:40 +08:00
										 |  |  | 			"h": 9, | 
					
						
							| 
									
										
										
										
											2017-10-11 01:48:06 +08:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-12-08 17:25:05 +08:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	panels = append(panels, newpanel) | 
					
						
							| 
									
										
										
										
											2017-08-25 20:47:57 +08:00
										 |  |  | 	dash.Set("panels", panels) | 
					
						
							| 
									
										
										
										
											2016-12-08 17:25:05 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-27 21:54:37 +08:00
										 |  |  | // swagger:route GET /dashboards/id/{DashboardID}/versions dashboard_versions getDashboardVersionsByID
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Gets all existing versions for the dashboard.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Please refer to [updated API](#/dashboard_versions/getDashboardVersionsByUID) instead
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Deprecated: true
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: dashboardVersionsResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 404: notFoundError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:route GET /dashboards/uid/{uid}/versions dashboard_versions getDashboardVersionsByUID
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Gets all existing versions for the dashboard using UID.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: dashboardVersionsResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 404: notFoundError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2022-02-07 19:43:43 +08:00
										 |  |  | func (hs *HTTPServer) GetDashboardVersions(c *models.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2022-05-18 00:57:27 +08:00
										 |  |  | 	var dashID int64 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var err error | 
					
						
							|  |  |  | 	dashUID := web.Params(c.Req)[":uid"] | 
					
						
							| 
									
										
										
										
											2017-06-14 06:28:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-18 00:57:27 +08:00
										 |  |  | 	if dashUID == "" { | 
					
						
							|  |  |  | 		dashID, err = strconv.ParseInt(web.Params(c.Req)[":dashboardId"], 10, 64) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return response.Error(http.StatusBadRequest, "dashboardId is invalid", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		q := models.GetDashboardQuery{ | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 			OrgId: c.SignedInUser.OrgID, | 
					
						
							| 
									
										
										
										
											2022-05-18 00:57:27 +08:00
										 |  |  | 			Uid:   dashUID, | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2022-07-07 02:42:39 +08:00
										 |  |  | 		if err := hs.DashboardService.GetDashboard(c.Req.Context(), &q); err != nil { | 
					
						
							| 
									
										
										
										
											2022-05-18 00:57:27 +08:00
										 |  |  | 			return response.Error(http.StatusBadRequest, "failed to get dashboard by UID", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		dashID = q.Result.Id | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	guardian := guardian.New(c.Req.Context(), dashID, c.OrgID, c.SignedInUser) | 
					
						
							| 
									
										
										
										
											2017-06-20 01:47:44 +08:00
										 |  |  | 	if canSave, err := guardian.CanSave(); err != nil || !canSave { | 
					
						
							|  |  |  | 		return dashboardGuardianResponse(err) | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-02 21:59:05 +08:00
										 |  |  | 	query := dashver.ListDashboardVersionsQuery{ | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 		OrgID:        c.OrgID, | 
					
						
							| 
									
										
										
										
											2022-06-02 21:59:05 +08:00
										 |  |  | 		DashboardID:  dashID, | 
					
						
							| 
									
										
										
										
											2022-05-18 00:57:27 +08:00
										 |  |  | 		DashboardUID: dashUID, | 
					
						
							|  |  |  | 		Limit:        c.QueryInt("limit"), | 
					
						
							|  |  |  | 		Start:        c.QueryInt("start"), | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-02 21:59:05 +08:00
										 |  |  | 	res, err := hs.dashboardVersionService.List(c.Req.Context(), &query) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(404, fmt.Sprintf("No versions found for dashboardId %d", dashID), err) | 
					
						
							| 
									
										
										
										
											2017-06-02 05:57:09 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-02 21:59:05 +08:00
										 |  |  | 	for _, version := range res { | 
					
						
							| 
									
										
										
										
											2017-06-06 04:59:04 +08:00
										 |  |  | 		if version.RestoredFrom == version.Version { | 
					
						
							| 
									
										
										
										
											2017-06-07 05:04:14 +08:00
										 |  |  | 			version.Message = "Initial save (created by migration)" | 
					
						
							| 
									
										
										
										
											2017-06-06 04:59:04 +08:00
										 |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if version.RestoredFrom > 0 { | 
					
						
							|  |  |  | 			version.Message = fmt.Sprintf("Restored from version %d", version.RestoredFrom) | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if version.ParentVersion == 0 { | 
					
						
							|  |  |  | 			version.Message = "Initial save" | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-02 21:59:05 +08:00
										 |  |  | 	return response.JSON(http.StatusOK, res) | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-27 21:54:37 +08:00
										 |  |  | // swagger:route GET /dashboards/id/{DashboardID}/versions/{DashboardVersionID} dashboard_versions getDashboardVersionByID
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Get a specific dashboard version.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Please refer to [updated API](#/dashboard_versions/getDashboardVersionByUID) instead
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Deprecated: true
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: dashboardVersionResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 404: notFoundError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:route GET /dashboards/uid/{uid}/versions/{DashboardVersionID} dashboard_versions getDashboardVersionByUID
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Get a specific dashboard version using UID.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: dashboardVersionResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 404: notFoundError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2022-02-07 19:43:43 +08:00
										 |  |  | func (hs *HTTPServer) GetDashboardVersion(c *models.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2022-05-17 18:59:02 +08:00
										 |  |  | 	var dashID int64 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var err error | 
					
						
							|  |  |  | 	dashUID := web.Params(c.Req)[":uid"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if dashUID == "" { | 
					
						
							|  |  |  | 		dashID, err = strconv.ParseInt(web.Params(c.Req)[":dashboardId"], 10, 64) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return response.Error(http.StatusBadRequest, "dashboardId is invalid", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		q := models.GetDashboardQuery{ | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 			OrgId: c.SignedInUser.OrgID, | 
					
						
							| 
									
										
										
										
											2022-05-17 18:59:02 +08:00
										 |  |  | 			Uid:   dashUID, | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2022-07-07 02:42:39 +08:00
										 |  |  | 		if err := hs.DashboardService.GetDashboard(c.Req.Context(), &q); err != nil { | 
					
						
							| 
									
										
										
										
											2022-05-17 18:59:02 +08:00
										 |  |  | 			return response.Error(http.StatusBadRequest, "failed to get dashboard by UID", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		dashID = q.Result.Id | 
					
						
							| 
									
										
										
										
											2022-01-15 00:55:57 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-06-14 06:28:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	guardian := guardian.New(c.Req.Context(), dashID, c.OrgID, c.SignedInUser) | 
					
						
							| 
									
										
										
										
											2017-06-20 01:47:44 +08:00
										 |  |  | 	if canSave, err := guardian.CanSave(); err != nil || !canSave { | 
					
						
							|  |  |  | 		return dashboardGuardianResponse(err) | 
					
						
							| 
									
										
										
										
											2017-06-14 06:28:34 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-13 22:56:14 +08:00
										 |  |  | 	version, _ := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 32) | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 	query := dashver.GetDashboardVersionQuery{ | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 		OrgID:       c.OrgID, | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 		DashboardID: dashID, | 
					
						
							| 
									
										
										
										
											2021-11-17 17:57:37 +08:00
										 |  |  | 		Version:     int(version), | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-06-05 22:34:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 	res, err := hs.dashboardVersionService.Get(c.Req.Context(), &query) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(500, fmt.Sprintf("Dashboard version %d not found for dashboardId %d", query.Version, dashID), err) | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-22 16:50:00 +08:00
										 |  |  | 	creator := anonString | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 	if res.CreatedBy > 0 { | 
					
						
							|  |  |  | 		creator = hs.getUserLogin(c.Req.Context(), res.CreatedBy) | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-08 18:22:55 +08:00
										 |  |  | 	dashVersionMeta := &dashver.DashboardVersionMeta{ | 
					
						
							|  |  |  | 		ID:            res.ID, | 
					
						
							|  |  |  | 		DashboardID:   res.DashboardID, | 
					
						
							| 
									
										
										
										
											2022-05-17 18:59:02 +08:00
										 |  |  | 		DashboardUID:  dashUID, | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 		Data:          res.Data, | 
					
						
							|  |  |  | 		ParentVersion: res.ParentVersion, | 
					
						
							|  |  |  | 		RestoredFrom:  res.RestoredFrom, | 
					
						
							|  |  |  | 		Version:       res.Version, | 
					
						
							|  |  |  | 		Created:       res.Created, | 
					
						
							|  |  |  | 		Message:       res.Message, | 
					
						
							| 
									
										
										
										
											2019-04-15 15:18:28 +08:00
										 |  |  | 		CreatedBy:     creator, | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-15 20:01:58 +08:00
										 |  |  | 	return response.JSON(http.StatusOK, dashVersionMeta) | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-27 21:54:37 +08:00
										 |  |  | // swagger:route POST /dashboards/calculate-diff dashboards calculateDashboardDiff
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Perform diff on two dashboards.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Produces:
 | 
					
						
							|  |  |  | // - application/json
 | 
					
						
							|  |  |  | // - text/html
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: calculateDashboardDiffResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2022-02-10 16:58:52 +08:00
										 |  |  | func (hs *HTTPServer) CalculateDashboardDiff(c *models.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2021-11-29 17:18:01 +08:00
										 |  |  | 	apiOptions := dtos.CalculateDiffOptions{} | 
					
						
							|  |  |  | 	if err := web.Bind(c.Req, &apiOptions); err != nil { | 
					
						
							|  |  |  | 		return response.Error(http.StatusBadRequest, "bad request data", err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	guardianBase := guardian.New(c.Req.Context(), apiOptions.Base.DashboardId, c.OrgID, c.SignedInUser) | 
					
						
							| 
									
										
										
										
											2018-02-28 00:53:30 +08:00
										 |  |  | 	if canSave, err := guardianBase.CanSave(); err != nil || !canSave { | 
					
						
							|  |  |  | 		return dashboardGuardianResponse(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if apiOptions.Base.DashboardId != apiOptions.New.DashboardId { | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 		guardianNew := guardian.New(c.Req.Context(), apiOptions.New.DashboardId, c.OrgID, c.SignedInUser) | 
					
						
							| 
									
										
										
										
											2018-02-28 00:53:30 +08:00
										 |  |  | 		if canSave, err := guardianNew.CanSave(); err != nil || !canSave { | 
					
						
							|  |  |  | 			return dashboardGuardianResponse(err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-07 17:50:09 +08:00
										 |  |  | 	options := dashdiffs.Options{ | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 		OrgId:    c.OrgID, | 
					
						
							| 
									
										
										
										
											2017-06-07 17:50:09 +08:00
										 |  |  | 		DiffType: dashdiffs.ParseDiffType(apiOptions.DiffType), | 
					
						
							|  |  |  | 		Base: dashdiffs.DiffTarget{ | 
					
						
							|  |  |  | 			DashboardId:      apiOptions.Base.DashboardId, | 
					
						
							|  |  |  | 			Version:          apiOptions.Base.Version, | 
					
						
							|  |  |  | 			UnsavedDashboard: apiOptions.Base.UnsavedDashboard, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		New: dashdiffs.DiffTarget{ | 
					
						
							|  |  |  | 			DashboardId:      apiOptions.New.DashboardId, | 
					
						
							|  |  |  | 			Version:          apiOptions.New.Version, | 
					
						
							|  |  |  | 			UnsavedDashboard: apiOptions.New.UnsavedDashboard, | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 	baseVersionQuery := dashver.GetDashboardVersionQuery{ | 
					
						
							|  |  |  | 		DashboardID: options.Base.DashboardId, | 
					
						
							| 
									
										
										
										
											2022-02-10 16:58:52 +08:00
										 |  |  | 		Version:     options.Base.Version, | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 		OrgID:       options.OrgId, | 
					
						
							| 
									
										
										
										
											2022-02-10 16:58:52 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 	baseVersionRes, err := hs.dashboardVersionService.Get(c.Req.Context(), &baseVersionQuery) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2022-06-08 18:22:55 +08:00
										 |  |  | 		if errors.Is(err, dashver.ErrDashboardVersionNotFound) { | 
					
						
							| 
									
										
										
										
											2022-02-10 16:58:52 +08:00
										 |  |  | 			return response.Error(404, "Dashboard version not found", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return response.Error(500, "Unable to compute diff", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 	newVersionQuery := dashver.GetDashboardVersionQuery{ | 
					
						
							|  |  |  | 		DashboardID: options.New.DashboardId, | 
					
						
							| 
									
										
										
										
											2022-02-10 16:58:52 +08:00
										 |  |  | 		Version:     options.New.Version, | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 		OrgID:       options.OrgId, | 
					
						
							| 
									
										
										
										
											2022-02-10 16:58:52 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 	newVersionRes, err := hs.dashboardVersionService.Get(c.Req.Context(), &newVersionQuery) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2022-06-08 18:22:55 +08:00
										 |  |  | 		if errors.Is(err, dashver.ErrDashboardVersionNotFound) { | 
					
						
							| 
									
										
										
										
											2022-02-10 16:58:52 +08:00
										 |  |  | 			return response.Error(404, "Dashboard version not found", err) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return response.Error(500, "Unable to compute diff", err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 	baseData := baseVersionRes.Data | 
					
						
							|  |  |  | 	newData := newVersionRes.Data | 
					
						
							| 
									
										
										
										
											2022-02-10 16:58:52 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	result, err := dashdiffs.CalculateDiff(c.Req.Context(), &options, baseData, newData) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2022-06-08 18:22:55 +08:00
										 |  |  | 		if errors.Is(err, dashver.ErrDashboardVersionNotFound) { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 			return response.Error(404, "Dashboard version not found", err) | 
					
						
							| 
									
										
										
										
											2017-06-07 20:21:40 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(500, "Unable to compute diff", err) | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-06-06 05:29:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-07 17:50:09 +08:00
										 |  |  | 	if options.DiffType == dashdiffs.DiffDelta { | 
					
						
							| 
									
										
										
										
											2022-04-15 20:01:58 +08:00
										 |  |  | 		return response.Respond(http.StatusOK, result.Delta).SetHeader("Content-Type", "application/json") | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-02-28 00:53:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-15 20:01:58 +08:00
										 |  |  | 	return response.Respond(http.StatusOK, result.Delta).SetHeader("Content-Type", "text/html") | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-27 21:54:37 +08:00
										 |  |  | // swagger:route POST /dashboards/id/{DashboardID}/restore dashboard_versions restoreDashboardVersionByID
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Restore a dashboard to a given dashboard version.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Please refer to [updated API](#/dashboard_versions/restoreDashboardVersionByUID) instead
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Deprecated: true
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: postDashboardResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 404: notFoundError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:route POST /dashboards/uid/{uid}/restore dashboard_versions restoreDashboardVersionByUID
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Restore a dashboard to a given dashboard version using UID.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: postDashboardResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 403: forbiddenError
 | 
					
						
							|  |  |  | // 404: notFoundError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2021-11-29 17:18:01 +08:00
										 |  |  | func (hs *HTTPServer) RestoreDashboardVersion(c *models.ReqContext) response.Response { | 
					
						
							| 
									
										
										
										
											2022-05-18 00:57:27 +08:00
										 |  |  | 	var dashID int64 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var err error | 
					
						
							|  |  |  | 	dashUID := web.Params(c.Req)[":uid"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-29 17:18:01 +08:00
										 |  |  | 	apiCmd := dtos.RestoreDashboardVersionCommand{} | 
					
						
							|  |  |  | 	if err := web.Bind(c.Req, &apiCmd); err != nil { | 
					
						
							|  |  |  | 		return response.Error(http.StatusBadRequest, "bad request data", err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-05-18 00:57:27 +08:00
										 |  |  | 	if dashUID == "" { | 
					
						
							|  |  |  | 		dashID, err = strconv.ParseInt(web.Params(c.Req)[":dashboardId"], 10, 64) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return response.Error(http.StatusBadRequest, "dashboardId is invalid", err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2022-01-15 00:55:57 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	dash, rsp := hs.getDashboardHelper(c.Req.Context(), c.OrgID, dashID, dashUID) | 
					
						
							| 
									
										
										
										
											2017-06-18 06:24:38 +08:00
										 |  |  | 	if rsp != nil { | 
					
						
							|  |  |  | 		return rsp | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-18 00:57:27 +08:00
										 |  |  | 	if dash != nil && dash.Id != 0 { | 
					
						
							|  |  |  | 		dashID = dash.Id | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	guardian := guardian.New(c.Req.Context(), dashID, c.OrgID, c.SignedInUser) | 
					
						
							| 
									
										
										
										
											2017-06-20 01:47:44 +08:00
										 |  |  | 	if canSave, err := guardian.CanSave(); err != nil || !canSave { | 
					
						
							|  |  |  | 		return dashboardGuardianResponse(err) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	versionQuery := dashver.GetDashboardVersionQuery{DashboardID: dashID, Version: apiCmd.Version, OrgID: c.OrgID} | 
					
						
							| 
									
										
										
										
											2022-05-25 16:41:51 +08:00
										 |  |  | 	version, err := hs.dashboardVersionService.Get(c.Req.Context(), &versionQuery) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2021-01-15 21:43:20 +08:00
										 |  |  | 		return response.Error(404, "Dashboard version not found", nil) | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 19:57:20 +08:00
										 |  |  | 	saveCmd := models.SaveDashboardCommand{} | 
					
						
							| 
									
										
										
										
											2017-06-06 04:59:04 +08:00
										 |  |  | 	saveCmd.RestoredFrom = version.Version | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	saveCmd.OrgId = c.OrgID | 
					
						
							|  |  |  | 	saveCmd.UserId = c.UserID | 
					
						
							| 
									
										
										
										
											2017-06-05 23:45:27 +08:00
										 |  |  | 	saveCmd.Dashboard = version.Data | 
					
						
							| 
									
										
										
										
											2017-06-18 06:24:38 +08:00
										 |  |  | 	saveCmd.Dashboard.Set("version", dash.Version) | 
					
						
							| 
									
										
										
										
											2018-02-01 01:16:45 +08:00
										 |  |  | 	saveCmd.Dashboard.Set("uid", dash.Uid) | 
					
						
							| 
									
										
										
										
											2017-06-06 04:59:04 +08:00
										 |  |  | 	saveCmd.Message = fmt.Sprintf("Restored from version %d", version.Version) | 
					
						
							| 
									
										
										
										
											2019-03-06 21:38:40 +08:00
										 |  |  | 	saveCmd.FolderId = dash.FolderId | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-29 17:18:01 +08:00
										 |  |  | 	return hs.postDashboard(c, saveCmd) | 
					
						
							| 
									
										
											  
											
												History and Version Control for Dashboard Updates
A simple version control system for dashboards. Closes #1504.
Goals
1. To create a new dashboard version every time a dashboard is saved.
2. To allow users to view all versions of a given dashboard.
3. To allow users to rollback to a previous version of a dashboard.
4. To allow users to compare two versions of a dashboard.
Usage
Navigate to a dashboard, and click the settings cog. From there, click
the "Changelog" button to be brought to the Changelog view. In this
view, a table containing each version of a dashboard can be seen. Each
entry in the table represents a dashboard version. A selectable
checkbox, the version number, date created, name of the user who created
that version, and commit message is shown in the table, along with a
button that allows a user to restore to a previous version of that
dashboard. If a user wants to restore to a previous version of their
dashboard, they can do so by clicking the previously mentioned button.
If a user wants to compare two different versions of a dashboard, they
can do so by clicking the checkbox of two different dashboard versions,
then clicking the "Compare versions" button located below the dashboard.
From there, the user is brought to a view showing a summary of the
dashboard differences. Each summarized change contains a link that can
be clicked to take the user a JSON diff highlighting the changes line by
line.
Overview of Changes
Backend Changes
- A `dashboard_version` table was created to store each dashboard
  version, along with a dashboard version model and structs to represent
  the queries and commands necessary for the dashboard version API
  methods.
- API endpoints were created to support working with dashboard
  versions.
- Methods were added to create, update, read, and destroy dashboard
  versions in the database.
  - Logic was added to compute the diff between two versions, and
  display it to the user.
  - The dashboard migration logic was updated to save a "Version
  1" of each existing dashboard in the database.
Frontend Changes
- New views
- Methods to pull JSON and HTML from endpoints
New API Endpoints
Each endpoint requires the authorization header to be sent in
the format,
```
Authorization: Bearer <jwt>
```
where `<jwt>` is a JSON web token obtained from the Grafana
admin panel.
`GET "/api/dashboards/db/:dashboardId/versions?orderBy=<string>&limit=<int>&start=<int>"`
Get all dashboard versions for the given dashboard ID. Accepts
three URL parameters:
- `orderBy` String to order the results by. Possible values
  are `version`, `created`, `created_by`, `message`. Default
  is `versions`. Ordering is always in descending order.
- `limit` Maximum number of results to return
- `start` Position in results to start from
`GET "/api/dashboards/db/:dashboardId/versions/:id"`
Get an individual dashboard version by ID, for the given
dashboard ID.
`POST "/api/dashboards/db/:dashboardId/restore"`
Restore to the given dashboard version. Post body is of
content-type `application/json`, and must contain.
```json
{
  "dashboardId": <int>,
  "version": <int>
}
```
`GET "/api/dashboards/db/:dashboardId/compare/:versionA...:versionB"`
Compare two dashboard versions by ID for the given
dashboard ID, returning a JSON delta formatted
representation of the diff. The URL format follows
what GitHub does. For example, visiting
[/api/dashboards/db/18/compare/22...33](http://ec2-54-80-139-44.compute-1.amazonaws.com:3000/api/dashboards/db/18/compare/22...33)
will return the diff between versions 22 and 33 for
the dashboard ID 18.
Dependencies Added
- The Go package [gojsondiff](https://github.com/yudai/gojsondiff)
  was added and vendored.
											
										 
											2017-05-25 07:14:39 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-27 21:54:37 +08:00
										 |  |  | // swagger:route GET /dashboards/tags dashboards getDashboardTags
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Get all dashboards tags of an organisation.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Responses:
 | 
					
						
							|  |  |  | // 200: getDashboardsTagsResponse
 | 
					
						
							|  |  |  | // 401: unauthorisedError
 | 
					
						
							|  |  |  | // 500: internalServerError
 | 
					
						
							| 
									
										
										
										
											2022-02-07 19:43:43 +08:00
										 |  |  | func (hs *HTTPServer) GetDashboardTags(c *models.ReqContext) { | 
					
						
							| 
									
										
										
										
											2022-08-11 19:28:55 +08:00
										 |  |  | 	query := models.GetDashboardTagsQuery{OrgId: c.OrgID} | 
					
						
							| 
									
										
										
										
											2022-07-07 02:42:39 +08:00
										 |  |  | 	err := hs.DashboardService.GetDashboardTags(c.Req.Context(), &query) | 
					
						
							| 
									
										
										
										
											2015-05-13 16:45:53 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		c.JsonApiErr(500, "Failed to get tags from database", err) | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-15 20:01:58 +08:00
										 |  |  | 	c.JSON(http.StatusOK, query.Result) | 
					
						
							| 
									
										
										
										
											2015-05-13 16:45:53 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-05-17 00:59:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // GetDashboardUIDs converts internal ids to UIDs
 | 
					
						
							|  |  |  | func (hs *HTTPServer) GetDashboardUIDs(c *models.ReqContext) { | 
					
						
							|  |  |  | 	ids := strings.Split(web.Params(c.Req)[":ids"], ",") | 
					
						
							|  |  |  | 	uids := make([]string, 0, len(ids)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	q := &models.GetDashboardRefByIdQuery{} | 
					
						
							|  |  |  | 	for _, idstr := range ids { | 
					
						
							|  |  |  | 		id, err := strconv.ParseInt(idstr, 10, 64) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		q.Id = id | 
					
						
							| 
									
										
										
										
											2022-07-07 02:42:39 +08:00
										 |  |  | 		err = hs.DashboardService.GetDashboardUIDById(c.Req.Context(), q) | 
					
						
							| 
									
										
										
										
											2022-05-17 00:59:02 +08:00
										 |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		uids = append(uids, q.Result.Uid) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	c.JSON(http.StatusOK, uids) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-07-27 21:54:37 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | // swagger:parameters renderReportPDF
 | 
					
						
							|  |  |  | type RenderReportPDFParams struct { | 
					
						
							|  |  |  | 	// in:path
 | 
					
						
							|  |  |  | 	DashboardID int64 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:parameters restoreDashboardVersionByID
 | 
					
						
							|  |  |  | type RestoreDashboardVersionByIDParams struct { | 
					
						
							|  |  |  | 	// in:body
 | 
					
						
							|  |  |  | 	// required:true
 | 
					
						
							|  |  |  | 	Body dtos.RestoreDashboardVersionCommand | 
					
						
							|  |  |  | 	// in:path
 | 
					
						
							|  |  |  | 	DashboardID int64 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:parameters getDashboardVersionsByID
 | 
					
						
							|  |  |  | type GetDashboardVersionsByIDParams struct { | 
					
						
							|  |  |  | 	// in:path
 | 
					
						
							|  |  |  | 	DashboardID int64 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:parameters getDashboardVersionsByUID
 | 
					
						
							|  |  |  | type GetDashboardVersionsByUIDParams struct { | 
					
						
							|  |  |  | 	// in:path
 | 
					
						
							|  |  |  | 	// required:true
 | 
					
						
							|  |  |  | 	UID string `json:"uid"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:parameters restoreDashboardVersionByUID
 | 
					
						
							|  |  |  | type RestoreDashboardVersionByUIDParams struct { | 
					
						
							|  |  |  | 	// in:body
 | 
					
						
							|  |  |  | 	// required:true
 | 
					
						
							|  |  |  | 	Body dtos.RestoreDashboardVersionCommand | 
					
						
							|  |  |  | 	// in:path
 | 
					
						
							|  |  |  | 	// required:true
 | 
					
						
							|  |  |  | 	UID string `json:"uid"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:parameters getDashboardVersionByID
 | 
					
						
							|  |  |  | type GetDashboardVersionByIDParams struct { | 
					
						
							|  |  |  | 	// in:path
 | 
					
						
							|  |  |  | 	DashboardID int64 | 
					
						
							|  |  |  | 	// in:path
 | 
					
						
							|  |  |  | 	DashboardVersionID int64 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:parameters getDashboardVersionByUID
 | 
					
						
							|  |  |  | type GetDashboardVersionByUIDParams struct { | 
					
						
							|  |  |  | 	// in:path
 | 
					
						
							|  |  |  | 	DashboardVersionID int64 | 
					
						
							|  |  |  | 	// in:path
 | 
					
						
							|  |  |  | 	// required:true
 | 
					
						
							|  |  |  | 	UID string `json:"uid"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:parameters getDashboardVersions getDashboardVersionsByUID
 | 
					
						
							|  |  |  | type GetDashboardVersionsParams struct { | 
					
						
							|  |  |  | 	// Maximum number of results to return
 | 
					
						
							|  |  |  | 	// in:query
 | 
					
						
							|  |  |  | 	// required:false
 | 
					
						
							|  |  |  | 	// default:0
 | 
					
						
							|  |  |  | 	Limit int `json:"limit"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Version to start from when returning queries
 | 
					
						
							|  |  |  | 	// in:query
 | 
					
						
							|  |  |  | 	// required:false
 | 
					
						
							|  |  |  | 	// default:0
 | 
					
						
							|  |  |  | 	Start int `json:"start"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:parameters getDashboardByUID
 | 
					
						
							|  |  |  | type GetDashboardByUIDParams struct { | 
					
						
							|  |  |  | 	// in:path
 | 
					
						
							|  |  |  | 	// required:true
 | 
					
						
							|  |  |  | 	UID string `json:"uid"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:parameters deleteDashboardByUID
 | 
					
						
							|  |  |  | type DeleteDashboardByUIDParams struct { | 
					
						
							|  |  |  | 	// in:path
 | 
					
						
							|  |  |  | 	// required:true
 | 
					
						
							|  |  |  | 	UID string `json:"uid"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:parameters postDashboard
 | 
					
						
							|  |  |  | type PostDashboardParams struct { | 
					
						
							|  |  |  | 	// in:body
 | 
					
						
							|  |  |  | 	// required:true
 | 
					
						
							|  |  |  | 	Body models.SaveDashboardCommand | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:parameters calculateDashboardDiff
 | 
					
						
							|  |  |  | type CalcDashboardDiffParams struct { | 
					
						
							|  |  |  | 	// in:body
 | 
					
						
							|  |  |  | 	// required:true
 | 
					
						
							|  |  |  | 	Body struct { | 
					
						
							|  |  |  | 		Base dtos.CalculateDiffTarget `json:"base" binding:"Required"` | 
					
						
							|  |  |  | 		New  dtos.CalculateDiffTarget `json:"new" binding:"Required"` | 
					
						
							|  |  |  | 		// The type of diff to return
 | 
					
						
							|  |  |  | 		// Description:
 | 
					
						
							|  |  |  | 		// * `basic`
 | 
					
						
							|  |  |  | 		// * `json`
 | 
					
						
							|  |  |  | 		// Enum: basic,json
 | 
					
						
							|  |  |  | 		DiffType string `json:"diffType" binding:"Required"` | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:parameters trimDashboard
 | 
					
						
							|  |  |  | type TrimDashboardParams struct { | 
					
						
							|  |  |  | 	// in:body
 | 
					
						
							|  |  |  | 	// required:true
 | 
					
						
							|  |  |  | 	Body models.TrimDashboardCommand | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:response dashboardResponse
 | 
					
						
							|  |  |  | type DashboardResponse struct { | 
					
						
							|  |  |  | 	// The response message
 | 
					
						
							|  |  |  | 	// in: body
 | 
					
						
							|  |  |  | 	Body dtos.DashboardFullWithMeta `json:"body"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:response deleteDashboardResponse
 | 
					
						
							|  |  |  | type DeleteDashboardResponse struct { | 
					
						
							|  |  |  | 	// The response message
 | 
					
						
							|  |  |  | 	// in: body
 | 
					
						
							|  |  |  | 	Body struct { | 
					
						
							|  |  |  | 		// ID Identifier of the deleted dashboard.
 | 
					
						
							|  |  |  | 		// required: true
 | 
					
						
							|  |  |  | 		// example: 65
 | 
					
						
							|  |  |  | 		ID int64 `json:"id"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Title Title of the deleted dashboard.
 | 
					
						
							|  |  |  | 		// required: true
 | 
					
						
							|  |  |  | 		// example: My Dashboard
 | 
					
						
							|  |  |  | 		Title string `json:"title"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Message Message of the deleted dashboard.
 | 
					
						
							|  |  |  | 		// required: true
 | 
					
						
							|  |  |  | 		// example: Dashboard My Dashboard deleted
 | 
					
						
							|  |  |  | 		Message string `json:"message"` | 
					
						
							|  |  |  | 	} `json:"body"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:response postDashboardResponse
 | 
					
						
							|  |  |  | type PostDashboardResponse struct { | 
					
						
							|  |  |  | 	// in: body
 | 
					
						
							|  |  |  | 	Body struct { | 
					
						
							|  |  |  | 		// Status status of the response.
 | 
					
						
							|  |  |  | 		// required: true
 | 
					
						
							|  |  |  | 		// example: success
 | 
					
						
							|  |  |  | 		Status string `json:"status"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Slug The slug of the dashboard.
 | 
					
						
							|  |  |  | 		// required: true
 | 
					
						
							|  |  |  | 		// example: my-dashboard
 | 
					
						
							|  |  |  | 		Slug string `json:"title"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Version The version of the dashboard.
 | 
					
						
							|  |  |  | 		// required: true
 | 
					
						
							|  |  |  | 		// example: 2
 | 
					
						
							|  |  |  | 		Verion int64 `json:"version"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// ID The unique identifier (id) of the created/updated dashboard.
 | 
					
						
							|  |  |  | 		// required: true
 | 
					
						
							|  |  |  | 		// example: 1
 | 
					
						
							|  |  |  | 		ID string `json:"id"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// UID The unique identifier (uid) of the created/updated dashboard.
 | 
					
						
							|  |  |  | 		// required: true
 | 
					
						
							|  |  |  | 		// example: nHz3SXiiz
 | 
					
						
							|  |  |  | 		UID string `json:"uid"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// URL The relative URL for accessing the created/updated dashboard.
 | 
					
						
							|  |  |  | 		// required: true
 | 
					
						
							|  |  |  | 		// example: /d/nHz3SXiiz/my-dashboard
 | 
					
						
							|  |  |  | 		URL string `json:"url"` | 
					
						
							|  |  |  | 	} `json:"body"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:response calculateDashboardDiffResponse
 | 
					
						
							|  |  |  | type CalculateDashboardDiffResponse struct { | 
					
						
							|  |  |  | 	// in: body
 | 
					
						
							|  |  |  | 	Body []byte `json:"body"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:response trimDashboardResponse
 | 
					
						
							|  |  |  | type TrimDashboardResponse struct { | 
					
						
							|  |  |  | 	// in: body
 | 
					
						
							|  |  |  | 	Body dtos.TrimDashboardFullWithMeta `json:"body"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:response getHomeDashboardResponse
 | 
					
						
							|  |  |  | type GetHomeDashboardResponse struct { | 
					
						
							|  |  |  | 	// in: body
 | 
					
						
							|  |  |  | 	Body GetHomeDashboardResponseBody `json:"body"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:response getDashboardsTagsResponse
 | 
					
						
							|  |  |  | type DashboardsTagsResponse struct { | 
					
						
							|  |  |  | 	// in: body
 | 
					
						
							|  |  |  | 	Body []*models.DashboardTagCloudItem `json:"body"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Get home dashboard response.
 | 
					
						
							|  |  |  | // swagger:model GetHomeDashboardResponse
 | 
					
						
							|  |  |  | type GetHomeDashboardResponseBody struct { | 
					
						
							|  |  |  | 	// swagger:allOf
 | 
					
						
							|  |  |  | 	// required: false
 | 
					
						
							|  |  |  | 	dtos.DashboardFullWithMeta | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// swagger:allOf
 | 
					
						
							|  |  |  | 	// required: false
 | 
					
						
							|  |  |  | 	dtos.DashboardRedirect | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:response dashboardVersionsResponse
 | 
					
						
							|  |  |  | type DashboardVersionsResponse struct { | 
					
						
							|  |  |  | 	// in: body
 | 
					
						
							|  |  |  | 	Body []*dashver.DashboardVersionDTO `json:"body"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // swagger:response dashboardVersionResponse
 | 
					
						
							|  |  |  | type DashboardVersionResponse struct { | 
					
						
							|  |  |  | 	// in: body
 | 
					
						
							|  |  |  | 	Body *dashver.DashboardVersionMeta `json:"body"` | 
					
						
							|  |  |  | } |