Commit 09b3433e by Torkel Ödegaard

change(dashboards): made home dashboard and json file dashboards editable unless…

change(dashboards): made home dashboard and json file dashboards editable unless otherwise specified in json file, closes #2567
parent 323e8437
......@@ -56,7 +56,7 @@ func GetDashboard(c *middleware.Context) {
Type: m.DashTypeDB,
CanStar: c.IsSignedIn,
CanSave: c.OrgRole == m.ROLE_ADMIN || c.OrgRole == m.ROLE_EDITOR,
CanEdit: c.OrgRole == m.ROLE_ADMIN || c.OrgRole == m.ROLE_EDITOR || c.OrgRole == m.ROLE_READ_ONLY_EDITOR,
CanEdit: canEditDashboard(c.OrgRole),
},
}
......@@ -122,6 +122,10 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) {
c.JSON(200, util.DynMap{"status": "success", "slug": cmd.Result.Slug, "version": cmd.Result.Version})
}
func canEditDashboard(role m.RoleType) bool {
return role == m.ROLE_ADMIN || role == m.ROLE_EDITOR || role == m.ROLE_READ_ONLY_EDITOR
}
func GetHomeDashboard(c *middleware.Context) {
filePath := path.Join(setting.StaticRootPath, "dashboards/home.json")
file, err := os.Open(filePath)
......@@ -132,6 +136,7 @@ func GetHomeDashboard(c *middleware.Context) {
dash := dtos.DashboardFullWithMeta{}
dash.Meta.IsHome = true
dash.Meta.CanEdit = canEditDashboard(c.OrgRole)
jsonParser := json.NewDecoder(file)
if err := jsonParser.Decode(&dash.Dashboard); err != nil {
c.JsonApiErr(500, "Failed to load home dashboard", err)
......@@ -152,6 +157,7 @@ func GetDashboardFromJsonFile(c *middleware.Context) {
dash := dtos.DashboardFullWithMeta{Dashboard: dashboard.Data}
dash.Meta.Type = m.DashTypeJson
dash.Meta.CanEdit = canEditDashboard(c.OrgRole)
c.JSON(200, &dash)
}
......
......@@ -9,7 +9,7 @@ function (coreModule) {
if (!$routeParams.slug) {
backendSrv.get('/api/dashboards/home').then(function(result) {
var meta = result.meta;
meta.canSave = meta.canShare = meta.canEdit = meta.canStar = false;
meta.canSave = meta.canShare = meta.canStar = false;
$scope.initDashboard(result, $scope);
});
return;
......
......@@ -3,7 +3,7 @@
"tags": [],
"style": "dark",
"timezone": "browser",
"editable": false,
"editable": true,
"hideControls": true,
"rows": [
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment