Przeglądaj źródła

feat(apps): more work on plugin dashboard sync

Torkel Ödegaard 9 lat temu
rodzic
commit
68a8d9bc91

+ 8 - 14
pkg/api/dashboard.go

@@ -130,20 +130,6 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
 		}
 		}
 	}
 	}
 
 
-	if !cmd.Overwrite {
-		if autoUpdate, exists := dash.Data.CheckGet("autoUpdate"); exists {
-			message := "Dashboard marked as auto updated."
-
-			if pluginId, err := autoUpdate.Get("pluginId").String(); err == nil {
-				if pluginDef, ok := plugins.Plugins[pluginId]; ok {
-					message = "Dashboard updated automatically when plugin " + pluginDef.Name + " is updated."
-				}
-			}
-
-			return Json(412, util.DynMap{"status": "auto-update-dashboard", "message": message})
-		}
-	}
-
 	err := bus.Dispatch(&cmd)
 	err := bus.Dispatch(&cmd)
 	if err != nil {
 	if err != nil {
 		if err == m.ErrDashboardWithSameNameExists {
 		if err == m.ErrDashboardWithSameNameExists {
@@ -152,6 +138,14 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
 		if err == m.ErrDashboardVersionMismatch {
 		if err == m.ErrDashboardVersionMismatch {
 			return Json(412, util.DynMap{"status": "version-mismatch", "message": err.Error()})
 			return Json(412, util.DynMap{"status": "version-mismatch", "message": err.Error()})
 		}
 		}
+		if pluginErr, ok := err.(m.UpdatePluginDashboardError); ok {
+			message := "Dashboard is belongs to plugin " + pluginErr.PluginId + "."
+			// look up plugin name
+			if pluginDef, exist := plugins.Plugins[pluginErr.PluginId]; exist {
+				message = "Dashboard is belongs to plugin " + pluginDef.Name + "."
+			}
+			return Json(412, util.DynMap{"status": "plugin-dashboard", "message": message})
+		}
 		if err == m.ErrDashboardNotFound {
 		if err == m.ErrDashboardNotFound {
 			return Json(404, util.DynMap{"status": "not-found", "message": err.Error()})
 			return Json(404, util.DynMap{"status": "not-found", "message": err.Error()})
 		}
 		}

+ 8 - 0
pkg/models/dashboards.go

@@ -17,6 +17,14 @@ var (
 	ErrDashboardVersionMismatch    = errors.New("The dashboard has been changed by someone else")
 	ErrDashboardVersionMismatch    = errors.New("The dashboard has been changed by someone else")
 )
 )
 
 
+type UpdatePluginDashboardError struct {
+	PluginId string
+}
+
+func (d UpdatePluginDashboardError) Error() string {
+	return "Dashboard belong to plugin"
+}
+
 var (
 var (
 	DashTypeJson     = "file"
 	DashTypeJson     = "file"
 	DashTypeDB       = "db"
 	DashTypeDB       = "db"

+ 5 - 0
pkg/services/sqlstore/dashboard.go

@@ -46,6 +46,11 @@ func SaveDashboard(cmd *m.SaveDashboardCommand) error {
 					return m.ErrDashboardVersionMismatch
 					return m.ErrDashboardVersionMismatch
 				}
 				}
 			}
 			}
+
+			// do not allow plugin dashboard updates without overwrite flag
+			if existing.PluginId != "" && cmd.Overwrite == false {
+				return m.UpdatePluginDashboardError{PluginId: existing.PluginId}
+			}
 		}
 		}
 
 
 		sameTitleExists, err := sess.Where("org_id=? AND slug=?", dash.OrgId, dash.Slug).Get(&sameTitle)
 		sameTitleExists, err := sess.Where("org_id=? AND slug=?", dash.OrgId, dash.Slug).Get(&sameTitle)

+ 3 - 3
public/app/features/dashboard/dashnav/dashnav.ts

@@ -135,13 +135,13 @@ export class DashNavCtrl {
         });
         });
       }
       }
 
 
-      if (err.data && err.data.status === "auto-update-dashboard") {
+      if (err.data && err.data.status === "plugin-dashboard") {
         err.isHandled = true;
         err.isHandled = true;
 
 
         $scope.appEvent('confirm-modal', {
         $scope.appEvent('confirm-modal', {
-          title: 'Auto Update Dashboard',
+          title: 'Plugin Dashboard',
           text: err.data.message,
           text: err.data.message,
-          text2: 'Use Save As... to create copy or ignore this warning.',
+          text2: 'Your changes will be overwritten next time you update the plugin. Use Save As to create custom version.',
           yesText: "Save & Overwrite",
           yesText: "Save & Overwrite",
           icon: "fa-warning",
           icon: "fa-warning",
           onConfirm: function() {
           onConfirm: function() {

+ 1 - 1
public/sass/components/_modals.scss

@@ -105,7 +105,7 @@
   }
   }
 
 
   .confirm-modal-text2 {
   .confirm-modal-text2 {
-    font-size: $font-size-h5;
+    font-size: $font-size-root;
     padding-top: $spacer;
     padding-top: $spacer;
   }
   }