mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 04:02:30 +08:00
change(dashboards): made home dashboard and json file dashboards editable unless otherwise specified in json file, closes #2567
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user