瀏覽代碼

WIP: remove dashboard children on delete

Daniel Lee 8 年之前
父節點
當前提交
84ff62d773
共有 2 個文件被更改,包括 17 次插入0 次删除
  1. 1 0
      pkg/services/sqlstore/dashboard.go
  2. 16 0
      pkg/services/sqlstore/dashboard_test.go

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

@@ -371,6 +371,7 @@ func DeleteDashboard(cmd *m.DeleteDashboardCommand) error {
 			"DELETE FROM dashboard WHERE id = ?",
 			"DELETE FROM playlist_item WHERE type = 'dashboard_by_id' AND value = ?",
 			"DELETE FROM dashboard_version WHERE dashboard_id = ?",
+			"DELETE FROM dashboard WHERE parent_id = ?",
 		}
 
 		for _, sql := range deletes {

+ 16 - 0
pkg/services/sqlstore/dashboard_test.go

@@ -247,6 +247,22 @@ func TestDashboardDataAccess(t *testing.T) {
 				So(query.Result.ParentId, ShouldEqual, 0)
 			})
 
+			Convey("Should be able to delete a dashboard folder and its children", func() {
+				deleteCmd := &m.DeleteDashboardCommand{Slug: savedFolder.Slug}
+				err := DeleteDashboard(deleteCmd)
+				So(err, ShouldBeNil)
+
+				query := search.FindPersistedDashboardsQuery{
+					OrgId:    1,
+					ParentId: savedFolder.Id,
+				}
+
+				err = SearchDashboards(&query)
+				So(err, ShouldBeNil)
+
+				So(len(query.Result), ShouldEqual, 0)
+			})
+
 			Convey("Should be able to get dashboard tags", func() {
 				query := m.GetDashboardTagsQuery{OrgId: 1}