diff --git a/src/metabase/api/common.clj b/src/metabase/api/common.clj index 31b47d5d187243db09bb4fc9e3a5d98f8b8f4d8e..06226f682c8f470f9b5333285273df33630bb8e6 100644 --- a/src/metabase/api/common.clj +++ b/src/metabase/api/common.clj @@ -515,9 +515,6 @@ ;;; ------------------------------------------ COLLECTION POSITION HELPER FNS ---------------------------------------- -(defn- update-models-with-new-position [plus-or-minus position-update-clause] -) - (s/defn reconcile-position-for-collection! "Compare `old-position` and `new-position` to determine what needs to be updated based on the position change. Used for fixing card/dashboard/pulse changes that impact other instances in the collection" diff --git a/test/metabase/api/card_test.clj b/test/metabase/api/card_test.clj index bcaab04f509f5234bf967c3807fab845985d282a..3c8d18d77ddfc8cfdbecf6ab41be8dbb3aa2af63 100644 --- a/test/metabase/api/card_test.clj +++ b/test/metabase/api/card_test.clj @@ -580,77 +580,102 @@ (map :collection_position results))) (defn get-name->collection-position - "Call the collection endpoint, looking for instances of `model-str` as `user-kwd` in `collection-id`. Will return a - map with the names of the items as keys and their position as the value" - [user-kwd model-str collection-id] - (name->position ((user->client user-kwd) :get 200 (format "collection/%s/items" (u/get-id collection-id)) :model model-str))) + "Call the collection endpoint for `collection-id` as `user-kwd`. Will return a map with the names of the items as + keys and their position as the value" + [user-kwd collection-or-collection-id] + (name->position ((user->client user-kwd) :get 200 (format "collection/%s/items" (u/get-id collection-or-collection-id))))) -(defmacro with-ordered-models-in-collection +(defmacro with-ordered-items "Macro for creating many sequetial collection_position model instances, putting each in `collection`" - [[model-instance & model-name-syms] collection & body] - `(tt/with-temp* ~(vec (mapcat (fn [idx name-sym] + [collection model-and-name-syms & body] + `(tt/with-temp* ~(vec (mapcat (fn [idx [model-instance name-sym]] [model-instance [name-sym {:name (name name-sym) :collection_id `(u/get-id ~collection) :collection_position idx}]]) - (range 1 (inc (count model-name-syms))) - model-name-syms)) + (iterate inc 1) + (partition-all 2 model-and-name-syms))) ~@body)) +;; Check to make sure we can move a card in a collection of just cards +(expect + {"c" 1 + "a" 2 + "b" 3 + "d" 4} + (tt/with-temp Collection [collection] + (with-ordered-items collection [Card a + Card b + Card c + Card d] + (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) + ((user->client :rasta) :put 200 (str "card/" (u/get-id c)) + {:collection_position 1}) + (get-name->collection-position :rasta collection)))) + ;; Change the position of the 4th card to 1st, all other cards should inc their position (expect {"d" 1 "a" 2 "b" 3 "c" 4} - (tt/with-temp Collection [{coll-id :id :as collection}] - (with-ordered-models-in-collection [Card a b c d] collection + (tt/with-temp Collection [collection] + (with-ordered-items collection [Dashboard a + Dashboard b + Pulse c + Card d] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) ((user->client :rasta) :put 200 (str "card/" (u/get-id d)) - {:collection_position 1, :collection_id coll-id}) - (get-name->collection-position :rasta "card" coll-id)))) + {:collection_position 1}) + (get-name->collection-position :rasta collection)))) -;; Change the position of the 1st card to the 4th, all of the other cards dec +;; Change the position of the 1st card to the 4th, all of the other items dec (expect {"b" 1 "c" 2 "d" 3 "a" 4} - (tt/with-temp Collection [{coll-id :id :as collection}] - (with-ordered-models-in-collection [Card a b c d] collection + (tt/with-temp Collection [collection] + (with-ordered-items collection [Card a + Dashboard b + Pulse c + Dashboard d] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) ((user->client :rasta) :put 200 (str "card/" (u/get-id a)) - {:collection_position 4, :collection_id coll-id}) - (get-name->collection-position :rasta "card" coll-id)))) + {:collection_position 4}) + (get-name->collection-position :rasta collection)))) -;; Change the position of a card from nil to 2nd, should adjust the existing cards +;; Change the position of a card from nil to 2nd, should adjust the existing items (expect {"a" 1 "b" 2 "c" 3 "d" 4} (tt/with-temp* [Collection [{coll-id :id :as collection}] - Card [card-a {:name "a", :collection_id coll-id, :collection_position 1}] + Card [_ {:name "a", :collection_id coll-id, :collection_position 1}] ;; Card b does not start with a collection_position - Card [card-b {:name "b", :collection_id coll-id}] - Card [card-c {:name "c", :collection_id coll-id, :collection_position 2}] - Card [card-d {:name "d", :collection_id coll-id, :collection_position 3}]] + Card [b {:name "b", :collection_id coll-id}] + Dashboard [_ {:name "c", :collection_id coll-id, :collection_position 2}] + Card [_ {:name "d", :collection_id coll-id, :collection_position 3}]] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) - ((user->client :rasta) :put 200 (str "card/" (u/get-id card-b)) - {:collection_position 2, :collection_id coll-id}) - (get-name->collection-position :rasta "card" coll-id))) + ((user->client :rasta) :put 200 (str "card/" (u/get-id b)) + {:collection_position 2}) + (get-name->collection-position :rasta coll-id))) -;; Update an existing card to no longer have a position, should dec cards after it's position +;; Update an existing card to no longer have a position, should dec items after it's position (expect {"a" 1 "b" nil "c" 2 "d" 3} - (tt/with-temp Collection [{coll-id :id :as collection}] - (with-ordered-models-in-collection [Card a b c d] collection + (tt/with-temp Collection [collection] + (with-ordered-items collection [Card a + Card b + Dashboard c + Pulse d] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) ((user->client :rasta) :put 200 (str "card/" (u/get-id b)) - {:collection_position nil, :collection_id coll-id}) - (get-name->collection-position :rasta "card" coll-id)))) + {:collection_position nil}) + (get-name->collection-position :rasta collection)))) ;; Change the collection the card is in, leave the position, should cause old and new collection to have their ;; positions updated @@ -663,16 +688,22 @@ {"e" 1 "g" 2 "h" 3}] - (tt/with-temp* [Collection [{coll-id-1 :id :as collection-1}] - Collection [{coll-id-2 :id :as collection-2}]] - (with-ordered-models-in-collection [Card a b c d] collection-1 - (with-ordered-models-in-collection [Card e f g h] collection-2 + (tt/with-temp* [Collection [collection-1] + Collection [collection-2]] + (with-ordered-items collection-1 [Dashboard a + Card b + Pulse c + Dashboard d] + (with-ordered-items collection-2 [Pulse e + Card f + Card g + Dashboard h] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection-1) (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection-2) ((user->client :rasta) :put 200 (str "card/" (u/get-id f)) - {:collection_id coll-id-1}) - [(get-name->collection-position :rasta "card" coll-id-1) - (get-name->collection-position :rasta "card" coll-id-2)])))) + {:collection_id (u/get-id collection-1)}) + [(get-name->collection-position :rasta collection-1) + (get-name->collection-position :rasta collection-2)])))) ;; Change the collection and the position, causing both collections and the updated card to have their order changed (expect @@ -684,16 +715,22 @@ {"e" 1 "f" 2 "g" 3}] - (tt/with-temp* [Collection [{coll-id-1 :id :as collection-1}] - Collection [{coll-id-2 :id :as collection-2}]] - (with-ordered-models-in-collection [Card a b c d] collection-1 - (with-ordered-models-in-collection [Card e f g h] collection-2 + (tt/with-temp* [Collection [collection-1] + Collection [collection-2]] + (with-ordered-items collection-1 [Pulse a + Pulse b + Dashboard c + Dashboard d] + (with-ordered-items collection-2 [Dashboard e + Dashboard f + Pulse g + Card h] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection-1) (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection-2) ((user->client :rasta) :put 200 (str "card/" (u/get-id h)) - {:collection_position 1, :collection_id coll-id-1}) - [(get-name->collection-position :rasta "card" coll-id-1) - (get-name->collection-position :rasta "card" coll-id-2)])))) + {:collection_position 1, :collection_id (u/get-id collection-1)}) + [(get-name->collection-position :rasta collection-1) + (get-name->collection-position :rasta collection-2)])))) ;; Add a new card to an existing collection at position 1, will cause all existing positions to increment by 1 (expect @@ -706,17 +743,19 @@ "b" 2 "c" 3 "d" 4}] - (tt/with-temp Collection [{coll-id :id :as collection}] + (tt/with-temp Collection [collection] (tu/with-model-cleanup [Card] - (with-ordered-models-in-collection [Card b c d] collection + (with-ordered-items collection [Dashboard b + Pulse c + Card d] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) - [(get-name->collection-position :rasta "card" coll-id) + [(get-name->collection-position :rasta collection) (do ((user->client :rasta) :post 200 "card" (merge (card-with-name-and-query "a") - {:collection_id (u/get-id collection) + {:collection_id (u/get-id collection) :collection_position 1})) - (get-name->collection-position :rasta "card" coll-id))])))) + (get-name->collection-position :rasta collection))])))) ;; Add a new card to the end of an existing collection (expect @@ -729,17 +768,19 @@ "b" 2 "c" 3 "d" 4}] - (tt/with-temp Collection [{coll-id :id :as collection}] + (tt/with-temp Collection [collection] (tu/with-model-cleanup [Card] - (with-ordered-models-in-collection [Card a b c] collection + (with-ordered-items collection [Card a + Dashboard b + Pulse c] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) - [(get-name->collection-position :rasta "card" coll-id) + [(get-name->collection-position :rasta collection) (do ((user->client :rasta) :post 200 "card" (merge (card-with-name-and-query "d") {:collection_id (u/get-id collection) :collection_position 4})) - (get-name->collection-position :rasta "card" coll-id))])))) + (get-name->collection-position :rasta collection))])))) ;; When adding a new card to a collection that does not have a position, it should not change existing positions (expect @@ -752,17 +793,19 @@ "b" 2 "c" 3 "d" nil}] - (tt/with-temp Collection [{coll-id :id :as collection}] + (tt/with-temp Collection [collection] (tu/with-model-cleanup [Card] - (with-ordered-models-in-collection [Card a b c] collection + (with-ordered-items collection [Pulse a + Card b + Dashboard c] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) - [(get-name->collection-position :rasta "card" coll-id) + [(get-name->collection-position :rasta collection) (do ((user->client :rasta) :post 200 "card" (merge (card-with-name-and-query "d") - {:collection_id (u/get-id collection) + {:collection_id (u/get-id collection) :collection_position nil})) - (get-name->collection-position :rasta "card" coll-id))])))) + (get-name->collection-position :rasta collection))])))) (expect {"d" 1 @@ -771,17 +814,17 @@ "c" 4 "e" 5 "f" 6} - (tt/with-temp* [Collection [{coll-id :id :as collection}] - Dashboard [_ {:name "a", :collection_id coll-id, :collection_position 1}] - Dashboard [_ {:name "b", :collection_id coll-id, :collection_position 2}] - Card [_ {:name "c", :collection_id coll-id, :collection_position 3}] - Card [d {:name "d", :collection_id coll-id, :collection_position 4}] - Pulse [_ {:name "e", :collection_id coll-id, :collection_position 5}] - Pulse [_ {:name "f", :collection_id coll-id, :collection_position 6}]] - (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) - ((user->client :rasta) :put 200 (str "card/" (u/get-id d)) - {:collection_position 1, :collection_id coll-id}) - (name->position ((user->client :rasta) :get 200 (format "collection/%s/items" coll-id))))) + (tt/with-temp Collection [collection] + (with-ordered-items collection [Dashboard a + Dashboard b + Card c + Card d + Pulse e + Pulse f] + (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) + ((user->client :rasta) :put 200 (str "card/" (u/get-id d)) + {:collection_position 1, :collection_id (u/get-id collection)}) + (name->position ((user->client :rasta) :get 200 (format "collection/%s/items" (u/get-id collection))))))) ;;; +----------------------------------------------------------------------------------------------------------------+ ;;; | Card updates that impact alerts | diff --git a/test/metabase/api/dashboard_test.clj b/test/metabase/api/dashboard_test.clj index bd2ef813247c570bb171cb92af7c446698fbf67b..107bd4defbe6d5c8a6358b5c9dc769607db0ed79 100644 --- a/test/metabase/api/dashboard_test.clj +++ b/test/metabase/api/dashboard_test.clj @@ -18,6 +18,7 @@ [dashboard-test :as dashboard-test] [permissions :as perms] [permissions-group :as group] + [pulse :refer [Pulse]] [revision :refer [Revision]]] [metabase.test.data.users :refer :all] [metabase.test.util :as tu] @@ -355,6 +356,21 @@ ;;; | UPDATING DASHBOARD COLLECTION POSITIONS | ;;; +----------------------------------------------------------------------------------------------------------------+ +;; Check that we can update a dashboard's position in a collection of only dashboards +(expect + {"a" 1 + "c" 2 + "d" 3 + "b" 4} + (tt/with-temp Collection [collection] + (card-api-test/with-ordered-items collection [Dashboard a + Dashboard b + Dashboard c + Dashboard d] + (perms/grant-collection-readwrite-permissions! (group/all-users) collection) + ((user->client :rasta) :put 200 (str "dashboard/" (u/get-id b)) + {:collection_position 4}) + (card-api-test/get-name->collection-position :rasta collection)))) ;; Check that updating a dashboard at position 3 to position 1 will increment the positions before 3, not after (expect @@ -363,11 +379,14 @@ "b" 3 "d" 4} (tt/with-temp Collection [collection] - (card-api-test/with-ordered-models-in-collection [Dashboard a b c d] collection + (card-api-test/with-ordered-items collection [Card a + Pulse b + Dashboard c + Dashboard d] (perms/grant-collection-readwrite-permissions! (group/all-users) collection) ((user->client :rasta) :put 200 (str "dashboard/" (u/get-id c)) {:collection_position 1}) - (card-api-test/get-name->collection-position :rasta "dashboard" collection)))) + (card-api-test/get-name->collection-position :rasta collection)))) ;; Check that updating position 1 to 3 will cause b and c to be decremented (expect @@ -376,11 +395,14 @@ "a" 3 "d" 4} (tt/with-temp Collection [collection] - (card-api-test/with-ordered-models-in-collection [Dashboard a b c d] collection + (card-api-test/with-ordered-items collection [Dashboard a + Card b + Pulse c + Dashboard d] (perms/grant-collection-readwrite-permissions! (group/all-users) collection) ((user->client :rasta) :put 200 (str "dashboard/" (u/get-id a)) {:collection_position 3}) - (card-api-test/get-name->collection-position :rasta "dashboard" collection)))) + (card-api-test/get-name->collection-position :rasta collection)))) ;; Check that updating position 1 to 4 will cause a through c to be decremented (expect @@ -389,11 +411,14 @@ "d" 3 "a" 4} (tt/with-temp Collection [collection] - (card-api-test/with-ordered-models-in-collection [Dashboard a b c d] collection + (card-api-test/with-ordered-items collection [Dashboard a + Card b + Pulse c + Pulse d] (perms/grant-collection-readwrite-permissions! (group/all-users) collection) ((user->client :rasta) :put 200 (str "dashboard/" (u/get-id a)) {:collection_position 4}) - (card-api-test/get-name->collection-position :rasta "dashboard" collection)))) + (card-api-test/get-name->collection-position :rasta collection)))) ;; Check that updating position 4 to 1 will cause a through c to be incremented (expect @@ -402,11 +427,14 @@ "b" 3 "c" 4} (tt/with-temp Collection [collection] - (card-api-test/with-ordered-models-in-collection [Dashboard a b c d] collection + (card-api-test/with-ordered-items collection [Card a + Pulse b + Card c + Dashboard d] (perms/grant-collection-readwrite-permissions! (group/all-users) collection) ((user->client :rasta) :put 200 (str "dashboard/" (u/get-id d)) {:collection_position 1}) - (card-api-test/get-name->collection-position :rasta "dashboard" collection)))) + (card-api-test/get-name->collection-position :rasta collection)))) ;; Check that moving a dashboard to another collection will fixup both collections (expect @@ -420,17 +448,23 @@ "h" 5}] (tt/with-temp* [Collection [collection-1] Collection [collection-2]] - (card-api-test/with-ordered-models-in-collection [Dashboard a b c d] collection-1 - (card-api-test/with-ordered-models-in-collection [Dashboard e f g h] collection-2 + (card-api-test/with-ordered-items collection-1 [Dashboard a + Card b + Card c + Pulse d] + (card-api-test/with-ordered-items collection-2 [Pulse e + Pulse f + Dashboard g + Card h] (perms/grant-collection-readwrite-permissions! (group/all-users) collection-1) (perms/grant-collection-readwrite-permissions! (group/all-users) collection-2) ;; Move the first dashboard in collection-1 to collection-1 ((user->client :rasta) :put 200 (str "dashboard/" (u/get-id a)) {:collection_position 1, :collection_id (u/get-id collection-2)}) ;; "a" should now be gone from collection-1 and all the existing dashboards bumped down in position - [(card-api-test/get-name->collection-position :rasta "dashboard" collection-1) + [(card-api-test/get-name->collection-position :rasta collection-1) ;; "a" is now first, all other dashboards in collection-2 bumped down 1 - (card-api-test/get-name->collection-position :rasta "dashboard" collection-2)])))) + (card-api-test/get-name->collection-position :rasta collection-2)])))) ;; Check that adding a new card at position 3 will cause the existing card at 3 to be incremented (expect @@ -443,15 +477,17 @@ "d" 4}] (tt/with-temp Collection [collection] (tu/with-model-cleanup [Dashboard] - (card-api-test/with-ordered-models-in-collection [Dashboard a b d] collection + (card-api-test/with-ordered-items collection [Card a + Pulse b + Card d] (perms/grant-collection-readwrite-permissions! (group/all-users) collection) - [(card-api-test/get-name->collection-position :rasta "dashboard" collection) + [(card-api-test/get-name->collection-position :rasta collection) (do ((user->client :rasta) :post 200 "dashboard" {:name "c" :parameters [{}] :collection_id (u/get-id collection) :collection_position 3}) - (card-api-test/get-name->collection-position :rasta "dashboard" collection))])))) + (card-api-test/get-name->collection-position :rasta collection))])))) ;; Check that adding a new card without a position, leaves the existing positions unchanged (expect @@ -464,14 +500,16 @@ "d" 3}] (tt/with-temp Collection [collection] (tu/with-model-cleanup [Dashboard] - (card-api-test/with-ordered-models-in-collection [Dashboard a b d] collection + (card-api-test/with-ordered-items collection [Dashboard a + Card b + Pulse d] (perms/grant-collection-readwrite-permissions! (group/all-users) collection) - [(card-api-test/get-name->collection-position :rasta "dashboard" collection) + [(card-api-test/get-name->collection-position :rasta collection) (do ((user->client :rasta) :post 200 "dashboard" {:name "c" :parameters [{}] :collection_id (u/get-id collection)}) - (card-api-test/get-name->collection-position :rasta "dashboard" collection))])))) + (card-api-test/get-name->collection-position :rasta collection))])))) ;;; +----------------------------------------------------------------------------------------------------------------+ diff --git a/test/metabase/api/pulse_test.clj b/test/metabase/api/pulse_test.clj index 66ea671f98bdc450f28678eceb02672b10f0f8aa..a2e40472b434c29a7f5439427c90efecea854747 100644 --- a/test/metabase/api/pulse_test.clj +++ b/test/metabase/api/pulse_test.clj @@ -10,6 +10,7 @@ [metabase.models [card :refer [Card]] [collection :refer [Collection]] + [dashboard :refer [Dashboard]] [database :refer [Database]] [permissions :as perms] [permissions-group :as perms-group] @@ -422,6 +423,22 @@ ;;; | UPDATING PULSE COLLECTION POSITIONS | ;;; +----------------------------------------------------------------------------------------------------------------+ +;; Check that we can update a pulse's position in a collection only pulses +(expect + {"d" 1 + "a" 2 + "b" 3 + "c" 4} + (tt/with-temp Collection [{coll-id :id :as collection}] + (card-api-test/with-ordered-items collection [Pulse a + Pulse b + Pulse c + Pulse d] + (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) + ((user->client :rasta) :put 200 (str "pulse/" (u/get-id d)) + {:collection_position 1}) + (card-api-test/get-name->collection-position :rasta coll-id)))) + ;; Change the position of b to 4, will dec c and d (expect {"a" 1 @@ -429,11 +446,14 @@ "d" 3 "b" 4} (tt/with-temp Collection [{coll-id :id :as collection}] - (card-api-test/with-ordered-models-in-collection [Pulse a b c d] collection + (card-api-test/with-ordered-items collection [Card a + Pulse b + Card c + Dashboard d] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) ((user->client :rasta) :put 200 (str "pulse/" (u/get-id b)) {:collection_position 4}) - (card-api-test/get-name->collection-position :rasta "pulse" coll-id)))) + (card-api-test/get-name->collection-position :rasta coll-id)))) ;; Change the position of d to the 2, should inc b and c (expect @@ -442,37 +462,46 @@ "b" 3 "c" 4} (tt/with-temp Collection [{coll-id :id :as collection}] - (card-api-test/with-ordered-models-in-collection [Pulse a b c d] collection + (card-api-test/with-ordered-items collection [Card a + Card b + Dashboard c + Pulse d] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) ((user->client :rasta) :put 200 (str "pulse/" (u/get-id d)) {:collection_position 2}) - (card-api-test/get-name->collection-position :rasta "pulse" coll-id)))) + (card-api-test/get-name->collection-position :rasta coll-id)))) -;; Change the position of the a to the 4th, will decrement all existing pulses +;; Change the position of a to the 4th, will decrement all existing items (expect {"b" 1 "c" 2 "d" 3 "a" 4} (tt/with-temp Collection [{coll-id :id :as collection}] - (card-api-test/with-ordered-models-in-collection [Pulse a b c d] collection + (card-api-test/with-ordered-items collection [Pulse a + Dashboard b + Card c + Pulse d] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) ((user->client :rasta) :put 200 (str "pulse/" (u/get-id a)) {:collection_position 4}) - (card-api-test/get-name->collection-position :rasta "pulse" coll-id)))) + (card-api-test/get-name->collection-position :rasta coll-id)))) -;; Change the position of the d to the 1st, will increment all existing pulses +;; Change the position of the d to the 1st, will increment all existing items (expect {"d" 1 "a" 2 "b" 3 "c" 4} (tt/with-temp Collection [{coll-id :id :as collection}] - (card-api-test/with-ordered-models-in-collection [Pulse a b c d] collection + (card-api-test/with-ordered-items collection [Dashboard a + Dashboard b + Card c + Pulse d] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) ((user->client :rasta) :put 200 (str "pulse/" (u/get-id d)) {:collection_position 1}) - (card-api-test/get-name->collection-position :rasta "pulse" coll-id)))) + (card-api-test/get-name->collection-position :rasta coll-id)))) ;; Check that no position change, but changing collections still triggers a fixup of both collections ;; Moving `c` from collection-1 to collection-2, `c` is now at position 3 in collection 2 @@ -487,14 +516,20 @@ "h" 5}] (tt/with-temp* [Collection [collection-1] Collection [collection-2]] - (card-api-test/with-ordered-models-in-collection [Pulse a b c d] collection-1 - (card-api-test/with-ordered-models-in-collection [Pulse e f g h] collection-2 + (card-api-test/with-ordered-items collection-1 [Pulse a + Card b + Pulse c + Dashboard d] + (card-api-test/with-ordered-items collection-2 [Card e + Card f + Dashboard g + Dashboard h] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection-1) (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection-2) ((user->client :rasta) :put 200 (str "pulse/" (u/get-id c)) {:collection_id (u/get-id collection-2)}) - [(card-api-test/get-name->collection-position :rasta "pulse" (u/get-id collection-1)) - (card-api-test/get-name->collection-position :rasta "pulse" (u/get-id collection-2))])))) + [(card-api-test/get-name->collection-position :rasta (u/get-id collection-1)) + (card-api-test/get-name->collection-position :rasta (u/get-id collection-2))])))) ;; Check that moving a pulse to another collection, with a changed position will fixup both collections ;; Moving `b` to collection 2, giving it a position of 1 @@ -509,14 +544,20 @@ "h" 5}] (tt/with-temp* [Collection [collection-1] Collection [collection-2]] - (card-api-test/with-ordered-models-in-collection [Pulse a b c d] collection-1 - (card-api-test/with-ordered-models-in-collection [Pulse e f g h] collection-2 + (card-api-test/with-ordered-items collection-1 [Pulse a + Pulse b + Dashboard c + Card d] + (card-api-test/with-ordered-items collection-2 [Card e + Card f + Pulse g + Dashboard h] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection-1) (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection-2) ((user->client :rasta) :put 200 (str "pulse/" (u/get-id b)) {:collection_id (u/get-id collection-2), :collection_position 1}) - [(card-api-test/get-name->collection-position :rasta "pulse" (u/get-id collection-1)) - (card-api-test/get-name->collection-position :rasta "pulse" (u/get-id collection-2))])))) + [(card-api-test/get-name->collection-position :rasta (u/get-id collection-1)) + (card-api-test/get-name->collection-position :rasta (u/get-id collection-2))])))) ;; Add a new pulse at position 2, causing existing pulses to be incremented (expect @@ -530,10 +571,12 @@ (tt/with-temp* [Collection [{coll-id :id :as collection}] Card [card-1]] (card-api-test/with-cards-in-readable-collection [card-1] - (card-api-test/with-ordered-models-in-collection [Pulse a c d] collection + (card-api-test/with-ordered-items collection [Card a + Dashboard c + Pulse d] (tu/with-model-cleanup [Pulse] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) - [(card-api-test/get-name->collection-position :rasta "pulse" coll-id) + [(card-api-test/get-name->collection-position :rasta coll-id) (do ((user->client :rasta) :post 200 "pulse" {:name "b" :collection_id (u/get-id collection) :cards [{:id (u/get-id card-1) @@ -542,7 +585,7 @@ :channels [daily-email-channel] :skip_if_empty false :collection_position 2}) - (card-api-test/get-name->collection-position :rasta "pulse" coll-id))]))))) + (card-api-test/get-name->collection-position :rasta coll-id))]))))) ;; Add a new pulse without a position, should leave existing positions unchanged (expect @@ -556,10 +599,12 @@ (tt/with-temp* [Collection [{coll-id :id :as collection}] Card [card-1]] (card-api-test/with-cards-in-readable-collection [card-1] - (card-api-test/with-ordered-models-in-collection [Pulse a c d] collection + (card-api-test/with-ordered-items collection [Pulse a + Card c + Dashboard d] (tu/with-model-cleanup [Pulse] (perms/grant-collection-readwrite-permissions! (perms-group/all-users) collection) - [(card-api-test/get-name->collection-position :rasta "pulse" coll-id) + [(card-api-test/get-name->collection-position :rasta coll-id) (do ((user->client :rasta) :post 200 "pulse" {:name "b" :collection_id (u/get-id collection) :cards [{:id (u/get-id card-1) @@ -567,7 +612,7 @@ :include_xls false}] :channels [daily-email-channel] :skip_if_empty false}) - (card-api-test/get-name->collection-position :rasta "pulse" coll-id))]))))) + (card-api-test/get-name->collection-position :rasta coll-id))]))))) ;;; +----------------------------------------------------------------------------------------------------------------+ ;;; | DELETE /api/pulse/:id |