Dashboard: When saving a dashboard and another user has made changes inbetween, the user is promted with a warning if he really wants to overwrite the other's changes, Closes #718

This commit is contained in:
Torkel Ödegaard
2015-03-02 22:24:01 +01:00
parent 56c83cefe9
commit 04d25dc58a
14 changed files with 324 additions and 22 deletions
+19 -2
View File
@@ -28,13 +28,30 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error {
return err
}
if hasExisting && dash.Id != existing.Id {
return m.ErrDashboardWithSameNameExists
if hasExisting {
// another dashboard with same name
if dash.Id != existing.Id {
if cmd.Overwrite {
dash.Id = existing.Id
} else {
return m.ErrDashboardWithSameNameExists
}
}
// check for is someone else has written in between
if dash.Version != existing.Version {
if cmd.Overwrite {
dash.Version = existing.Version
} else {
return m.ErrDashboardVersionMismatch
}
}
}
if dash.Id == 0 {
_, err = sess.Insert(dash)
} else {
dash.Version += 1
dash.Data["version"] = dash.Version
_, err = sess.Id(dash.Id).Update(dash)
}