Skip to content
Snippets Groups Projects
Commit 8b16e3ea authored by Allen Gilliland's avatar Allen Gilliland
Browse files

fix issue where deleting a DashboardCard wasn't properly cascading to DashboardCardSeries as well.

parent 5cf426f6
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,7 @@
[card :refer [Card]]
[common :as common]
[dashboard :refer [Dashboard]]
[dashboard-card :refer [DashboardCard create-dashboard-card update-dashboard-card]])))
[dashboard-card :refer [DashboardCard create-dashboard-card update-dashboard-card delete-dashboard-card]])))
(defendpoint GET "/"
"Get `Dashboards`. With filter option `f` (default `all`), restrict results as follows:
......@@ -107,11 +107,10 @@
"Remove a `DashboardCard` from a `Dashboard`."
[id dashcardId]
{dashcardId [Required String->Integer]}
(write-check Dashboard id)
;; TODO - it would be nicer to do this if `del` returned the object that was deleted instead of an api response
(let [dashcard (db/sel :one DashboardCard :id dashcardId)
result (db/del DashboardCard :id dashcardId :dashboard_id id)]
(events/publish-event :dashboard-remove-cards {:id id :actor_id *current-user-id* :dashcards [dashcard]})
result))
(let-404 [dashboard (Dashboard id)]
(write-check Dashboard id)
(when-let [dashboard-card (DashboardCard dashcardId)]
(check-500 (delete-dashboard-card dashboard-card *current-user-id*))
{:success true})))
(define-routes)
......@@ -35,6 +35,13 @@
;;; ## ---------------------------------------- HYDRATION ----------------------------------------
(defn ^:hydrate dashboard
"Return the `Dashboard` associated with the `DashboardCard`."
[{:keys [dashboard_id]}]
{:pre [(integer? dashboard_id)]}
(db/sel :one 'metabase.models.dashboard/Dashboard :id dashboard_id))
(defn ^:hydrate series
"Return the `Cards` associated as additional series on this `DashboardCard`."
[{:keys [id]}]
......@@ -118,4 +125,13 @@
(->> (events/publish-event :dashboard-card-create))
(dissoc :actor_id))))))
(defn delete-dashboard-card
"Delete a `DashboardCard`."
[dashboard-card user-id]
{:pre [(map? dashboard-card)
(integer? user-id)]}
(let [{:keys [id]} (dashboard dashboard-card)]
(db/cascade-delete DashboardCard :id (:id dashboard-card))
(events/publish-event :dashboard-remove-cards {:id id :actor_id user-id :dashcards [dashboard-card]})))
(u/require-dox-in-this-namespace)
......@@ -261,7 +261,7 @@
;; ## DELETE /api/dashboard/:id/cards
(expect
[1
nil
{:success true}
0]
;; fetch a dashboard WITH a dashboard card on it
(tu/with-temp Dashboard [{dashboard-id :id} {:name "Test Dashboard"
......@@ -273,11 +273,29 @@
:display "scalar"
:dataset_query {:something "simple"}
:visualization_settings {:global {:title nil}}}]
(tu/with-temp DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id
:card_id card-id}]
[(count (db/sel :many :field [DashboardCard :id] :dashboard_id dashboard-id))
((user->client :rasta) :delete 204 (format "dashboard/%d/cards" dashboard-id) :dashcardId dashcard-id)
(count (db/sel :many :field [DashboardCard :id] :dashboard_id dashboard-id))]))))
(tu/with-temp Card [{series-id1 :id} {:name "Additional Series Card 1"
:creator_id (user->id :rasta)
:public_perms 0
:display "scalar"
:dataset_query {:something "simple"}
:visualization_settings {:global {:title nil}}}]
(tu/with-temp Card [{series-id2 :id} {:name "Additional Series Card 2"
:creator_id (user->id :rasta)
:public_perms 0
:display "scalar"
:dataset_query {:something "simple"}
:visualization_settings {:global {:title nil}}}]
(tu/with-temp DashboardCard [{dashcard-id :id} {:dashboard_id dashboard-id
:card_id card-id}]
(tu/with-temp DashboardCardSeries [_ {:dashboardcard_id dashcard-id
:card_id series-id1
:position 0}]
(tu/with-temp DashboardCardSeries [_ {:dashboardcard_id dashcard-id
:card_id series-id2
:position 1}]
[(count (db/sel :many :field [DashboardCard :id] :dashboard_id dashboard-id))
((user->client :rasta) :delete 200 (format "dashboard/%d/cards" dashboard-id) :dashcardId dashcard-id)
(count (db/sel :many :field [DashboardCard :id] :dashboard_id dashboard-id))]))))))))
;; ## PUT /api/dashboard/:id/cards
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment