Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

GHY-4650: Remote Sync: creating a public link doesn't mark the dashboard as changed (#83018)

Eric Normand7e45872ff047
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/events.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/events.clj
index d387c17df6d..ac1f4cb5013 100644
--- a/enterprise/backend/src/metabase_enterprise/remote_sync/events.clj
+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/events.clj
@@ -231,6 +231,11 @@
existing-entry (remote-sync.db/rso model-type model-id)
status (spec/determine-status model-spec topic object)]
(cond
+ ;; a synced item on a read-only instance can still change (e.g. an admin's public link), but that change can
+ ;; never be pushed, so tracking it would only block the next pull
+ (not (spec/model-editable? (:model-key model-spec) object))
+ nil
+
eligible?
(do
(log/infof "Creating remote sync object entry for %s %s (status: %s)"
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj
index 82be60f11ca..b6ad81c2769 100644
--- a/enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj
+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/spec.clj
@@ -83,7 +83,7 @@
:identity :entity-id
:delete-after [:model/Collection] ; has collection_id FK
:events {:prefix :event/card
- :types [:create :update :delete]}
+ :types [:create :update :delete :public-link-created :public-link-deleted]}
:eligibility {:type :collection
:collection :remote-synced}
:archived-key :archived
@@ -101,7 +101,7 @@
:identity :entity-id
:delete-after [:model/Collection] ; has collection_id FK
:events {:prefix :event/dashboard
- :types [:create :update :delete]}
+ :types [:create :update :delete :public-link-created :public-link-deleted]}
:eligibility {:type :collection
:collection :remote-synced}
:archived-key :archived
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj
index 157b97240c7..900af73a477 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj
@@ -13,6 +13,7 @@
[metabase-enterprise.remote-sync.source :as source]
[metabase-enterprise.remote-sync.source.git :as source.git]
[metabase-enterprise.remote-sync.source.protocol :as source.p]
+ [metabase-enterprise.remote-sync.spec :as spec]
[metabase-enterprise.remote-sync.test-helpers :as test-helpers]
[metabase.driver.settings :as driver.settings]
[metabase.settings.core :as setting]
@@ -1108,6 +1109,119 @@
(is (= 1 (count dirty-items)))
(is (= "Test Card" (:name (first dirty-items)))))))))
+(defn- mark-pushed!
+ "Records `model-id` as synced with the file path and content hash of its current serialized form, the state
+ a push leaves it in."
+ [model-type model-id collection-id]
+ (let [{:keys [path content-hash]} (source/row->file-info {:model_type model-type :model_id model-id})]
+ (t2/delete! :model/RemoteSyncObject :model_type model-type :model_id model-id)
+ (t2/insert! :model/RemoteSyncObject {:model_type model-type
+ :model_id model-id
+ :model_name "pushed"
+ :model_collection_id collection-id
+ :status "synced"
+ :status_changed_at (t/offset-date-time)
+ :file_path path
+ :content_hash content-hash})))
+
+(defn- dirty-ids [model]
+ (->> (mt/user-http-request :crowberto :get 200 "ee/remote-sync/dirty")
+ :dirty
+ (filter #(= model (:model %)))
+ (map :id)
+ set))
+
+(deftest public-link-marks-dashboard-dirty-test
+ (testing "GHY-4650: creating or revoking a dashboard's public link lists the dashboard in GET /dirty"
+ (test-helpers/with-clean-object
+ (mt/with-temporary-setting-values [enable-public-sharing true
+ remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection coll {:name "Remote Collection" :is_remote_synced true :location "/"}
+ :model/Dashboard dash {:name "Shared Dashboard" :collection_id (:id coll)}]
+ (mark-pushed! "Dashboard" (:id dash) (:id coll))
+ (is (not (contains? (dirty-ids "dashboard") (:id dash))))
+ (testing "create"
+ (mt/user-http-request :crowberto :post 200 (format "dashboard/%d/public_link" (:id dash)))
+ (is (contains? (dirty-ids "dashboard") (:id dash))))
+ (mark-pushed! "Dashboard" (:id dash) (:id coll))
+ (testing "revoke"
+ (mt/user-http-request :crowberto :delete 204 (format "dashboard/%d/public_link" (:id dash)))
+ (is (contains? (dirty-ids "dashboard") (:id dash)))))))))
+
+(deftest public-link-marks-card-dirty-test
+ (testing "GHY-4650: creating or revoking a card's public link lists the card in GET /dirty"
+ (test-helpers/with-clean-object
+ (mt/with-temporary-setting-values [enable-public-sharing true
+ remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection coll {:name "Remote Collection" :is_remote_synced true :location "/"}
+ :model/Card card {:name "Shared Card" :collection_id (:id coll)}]
+ (mark-pushed! "Card" (:id card) (:id coll))
+ (is (not (contains? (dirty-ids "card") (:id card))))
+ (testing "create"
+ (mt/user-http-request :crowberto :post 200 (format "card/%d/public_link" (:id card)))
+ (is (contains? (dirty-ids "card") (:id card))))
+ (mark-pushed! "Card" (:id card) (:id coll))
+ (testing "revoke"
+ (mt/user-http-request :crowberto :delete 204 (format "card/%d/public_link" (:id card)))
+ (is (contains? (dirty-ids "card") (:id card)))))))))
+
+(defn- fail-first-tracking-write!
+ "Calls `thunk` with the remote sync event handler rigged to throw on its first call only."
+ [thunk]
+ (let [original (mt/original-fn #'spec/determine-status)
+ failed? (atom false)]
+ (mt/with-dynamic-fn-redefs [spec/determine-status (fn [& args]
+ (if (compare-and-set! failed? false true)
+ (throw (ex-info "simulated tracking failure" {}))
+ (apply original args)))]
+ (thunk))))
+
+(deftest public-link-change-survives-handler-failure-test
+ (testing "GHY-4650: when tracking fails, the link change rolls back, so a retry changes the link and marks the item dirty"
+ (test-helpers/with-clean-object
+ (mt/with-temporary-setting-values [enable-public-sharing true
+ remote-sync-type :read-write]
+ (doseq [[model endpoint] [["dashboard" "dashboard/%d/public_link"]
+ ["card" "card/%d/public_link"]]]
+ (testing model
+ (mt/with-temp [:model/Collection coll {:name "Remote Collection" :is_remote_synced true :location "/"}
+ (if (= model "dashboard") :model/Dashboard :model/Card) entity {:name "Shared" :collection_id (:id coll)}]
+ (let [model-type (if (= model "dashboard") "Dashboard" "Card")
+ url (format endpoint (:id entity))]
+ (testing "create"
+ (mark-pushed! model-type (:id entity) (:id coll))
+ (fail-first-tracking-write!
+ (fn []
+ (mt/user-http-request :crowberto :post 500 url)
+ (mt/user-http-request :crowberto :post 200 url)))
+ (is (contains? (dirty-ids model) (:id entity))))
+ (testing "revoke"
+ (mark-pushed! model-type (:id entity) (:id coll))
+ (fail-first-tracking-write!
+ (fn []
+ (mt/user-http-request :crowberto :delete 500 url)
+ (mt/user-http-request :crowberto :delete 204 url)))
+ (is (contains? (dirty-ids model) (:id entity))))))))))))
+
+(deftest public-link-on-read-only-instance-is-not-dirty-test
+ (testing "GHY-4650: a public link change on a read-only instance does not mark the synced item dirty, since it cannot be pushed"
+ (test-helpers/with-clean-object
+ (mt/with-temporary-setting-values [enable-public-sharing true
+ remote-sync-type :read-only]
+ (mt/with-temp [:model/Collection coll {:name "Remote Collection" :is_remote_synced true :location "/"}
+ :model/Dashboard dash {:name "Shared Dashboard" :collection_id (:id coll)}
+ :model/Card card {:name "Shared Card" :collection_id (:id coll)}]
+ (mark-pushed! "Dashboard" (:id dash) (:id coll))
+ (mark-pushed! "Card" (:id card) (:id coll))
+ (mt/user-http-request :crowberto :post 200 (format "dashboard/%d/public_link" (:id dash)))
+ (mt/user-http-request :crowberto :post 200 (format "card/%d/public_link" (:id card)))
+ (is (not (contains? (dirty-ids "dashboard") (:id dash))))
+ (is (not (contains? (dirty-ids "card") (:id card))))
+ (mt/user-http-request :crowberto :delete 204 (format "dashboard/%d/public_link" (:id dash)))
+ (mt/user-http-request :crowberto :delete 204 (format "card/%d/public_link" (:id card)))
+ (is (not (contains? (dirty-ids "dashboard") (:id dash))))
+ (is (not (contains? (dirty-ids "card") (:id card)))))))))
+
(deftest dirty-requires-superuser-test
(testing "GET /api/ee/remote-sync/dirty requires superuser permissions"
(is (= "You don't have permissions to do that."
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/content_hash_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/content_hash_test.clj
index cd680f4d226..af9b37d9255 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/content_hash_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/content_hash_test.clj
@@ -161,44 +161,47 @@
(deftest null-baseline-update-marks-dirty-test
(testing "An update with no recorded baseline hash still marks dirty — exports the first time (GHY-3933)"
- (mt/with-temp [:model/Collection coll {:is_remote_synced true :name "RS"}
- :model/Card card {:name "C" :dataset_query (mt/mbql-query venues) :collection_id (:id coll)}]
- (t2/delete! :model/RemoteSyncObject)
- (t2/insert! :model/RemoteSyncObject {:model_type "Card" :model_id (:id card) :model_name "C"
- :status "synced" :status_changed_at (t/offset-date-time)})
- (events/publish-event! :event/card-update {:object card :previous-object card :user-id (mt/user->id :rasta)})
- (is (= "update" (:status (t2/select-one :model/RemoteSyncObject :model_type "Card" :model_id (:id card))))
- "A null content_hash baseline must be treated as dirty"))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection coll {:is_remote_synced true :name "RS"}
+ :model/Card card {:name "C" :dataset_query (mt/mbql-query venues) :collection_id (:id coll)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (t2/insert! :model/RemoteSyncObject {:model_type "Card" :model_id (:id card) :model_name "C"
+ :status "synced" :status_changed_at (t/offset-date-time)})
+ (events/publish-event! :event/card-update {:object card :previous-object card :user-id (mt/user->id :rasta)})
+ (is (= "update" (:status (t2/select-one :model/RemoteSyncObject :model_type "Card" :model_id (:id card))))
+ "A null content_hash baseline must be treated as dirty")))))
(deftest changed-content-marks-dirty-test
(testing "A real change to serialized content marks dirty (GHY-3933)"
- (mt/with-temp [:model/Collection coll {:is_remote_synced true :name "RS"}
- :model/Card card {:name "Original" :dataset_query (mt/mbql-query venues) :collection_id (:id coll)}]
- (t2/delete! :model/RemoteSyncObject)
- (t2/insert! :model/RemoteSyncObject {:model_type "Card" :model_id (:id card) :model_name "Original"
- :status "synced"
- :content_hash (source/row->content-hash {:model_type "Card" :model_id (:id card)})
- :status_changed_at (t/offset-date-time)})
- (t2/update! :model/Card (:id card) {:name "Renamed"})
- (events/publish-event! :event/card-update {:object (t2/select-one :model/Card :id (:id card))
- :previous-object card
- :user-id (mt/user->id :rasta)})
- (is (= "update" (:status (t2/select-one :model/RemoteSyncObject :model_type "Card" :model_id (:id card))))
- "A changed serialization must mark the row dirty"))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection coll {:is_remote_synced true :name "RS"}
+ :model/Card card {:name "Original" :dataset_query (mt/mbql-query venues) :collection_id (:id coll)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (t2/insert! :model/RemoteSyncObject {:model_type "Card" :model_id (:id card) :model_name "Original"
+ :status "synced"
+ :content_hash (source/row->content-hash {:model_type "Card" :model_id (:id card)})
+ :status_changed_at (t/offset-date-time)})
+ (t2/update! :model/Card (:id card) {:name "Renamed"})
+ (events/publish-event! :event/card-update {:object (t2/select-one :model/Card :id (:id card))
+ :previous-object card
+ :user-id (mt/user->id :rasta)})
+ (is (= "update" (:status (t2/select-one :model/RemoteSyncObject :model_type "Card" :model_id (:id card))))
+ "A changed serialization must mark the row dirty")))))
(deftest revert-to-baseline-resyncs-test
(testing "An update whose content matches the synced baseline clears a stale dirty flag (GHY-3933)"
- (mt/with-temp [:model/Collection coll {:is_remote_synced true :name "RS"}
- :model/Card card {:name "C" :dataset_query (mt/mbql-query venues) :collection_id (:id coll)}]
- (t2/delete! :model/RemoteSyncObject)
- (t2/insert! :model/RemoteSyncObject {:model_type "Card" :model_id (:id card) :model_name "C"
- :status "update"
- :content_hash (source/row->content-hash {:model_type "Card" :model_id (:id card)})
- :status_changed_at (t/offset-date-time)})
- (events/publish-event! :event/card-update {:object card :previous-object card :user-id (mt/user->id :rasta)})
- (is (= "synced" (:status (t2/select-one :model/RemoteSyncObject :model_type "Card" :model_id (:id card))))
- "Content matching the baseline must clear a stale dirty flag")
- (is (not (sync-object/dirty?))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection coll {:is_remote_synced true :name "RS"}
+ :model/Card card {:name "C" :dataset_query (mt/mbql-query venues) :collection_id (:id coll)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (t2/insert! :model/RemoteSyncObject {:model_type "Card" :model_id (:id card) :model_name "C"
+ :status "update"
+ :content_hash (source/row->content-hash {:model_type "Card" :model_id (:id card)})
+ :status_changed_at (t/offset-date-time)})
+ (events/publish-event! :event/card-update {:object card :previous-object card :user-id (mt/user->id :rasta)})
+ (is (= "synced" (:status (t2/select-one :model/RemoteSyncObject :model_type "Card" :model_id (:id card))))
+ "Content matching the baseline must clear a stale dirty flag")
+ (is (not (sync-object/dirty?)))))))
;;; ------------------------------------------- mark-rows-synced! -------------------------------------------
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj
index 489dc856fc0..469b6fc4e5b 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj
@@ -19,7 +19,6 @@
[toucan2.core :as t2]))
(use-fixtures :once (fixtures/initialize :db))
-
(defn- mark-synced!
"Populate the RemoteSyncObject table with synced rows for `imported-data` (a `:by-entity-id` map), as a
successful import does — used to set up a synced baseline before firing an event."
@@ -32,94 +31,99 @@
(deftest card-create-event-creates-entry-test
(testing "card-create event creates remote sync object entry with create status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Card remote-sync-card {:name "Test Card"
- :dataset_query (mt/mbql-query venues)
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/card-create
- {:object remote-sync-card :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Card"
- :model_id (:id remote-sync-card)
- :status "create"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Card remote-sync-card {:name "Test Card"
+ :dataset_query (mt/mbql-query venues)
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/card-create
+ {:object remote-sync-card :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Card"
+ :model_id (:id remote-sync-card)
+ :status "create"}
+ (first entries))))))))
(deftest card-update-event-creates-entry-test
(testing "card-update event creates or updates remote sync object entry with update status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Card remote-sync-card {:name "Test Card"
- :dataset_query (mt/mbql-query venues)
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/card-update
- {:object remote-sync-card :previous-object remote-sync-card :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Card"
- :model_id (:id remote-sync-card)
- :status "update"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Card remote-sync-card {:name "Test Card"
+ :dataset_query (mt/mbql-query venues)
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/card-update
+ {:object remote-sync-card :previous-object remote-sync-card :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Card"
+ :model_id (:id remote-sync-card)
+ :status "update"}
+ (first entries))))))))
(deftest card-update-archived-sets-delete-test
(testing "card-update event with archived=true sets delete status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Card remote-sync-card {:name "Test Card"
- :dataset_query (mt/mbql-query venues)
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/card-update
- {:object (assoc remote-sync-card :archived true)
- :previous-object remote-sync-card
- :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Card"
- :model_id (:id remote-sync-card)
- :status "delete"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Card remote-sync-card {:name "Test Card"
+ :dataset_query (mt/mbql-query venues)
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/card-update
+ {:object (assoc remote-sync-card :archived true)
+ :previous-object remote-sync-card
+ :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Card"
+ :model_id (:id remote-sync-card)
+ :status "delete"}
+ (first entries))))))))
(deftest card-delete-event-creates-entry-test
(testing "card-delete event creates remote sync object entry with delete status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Card remote-sync-card {:name "Test Card"
- :dataset_query (mt/mbql-query venues)
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/card-delete
- {:object remote-sync-card :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Card"
- :model_id (:id remote-sync-card)
- :status "delete"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Card remote-sync-card {:name "Test Card"
+ :dataset_query (mt/mbql-query venues)
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/card-delete
+ {:object remote-sync-card :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Card"
+ :model_id (:id remote-sync-card)
+ :status "delete"}
+ (first entries))))))))
(deftest card-multiple-events-update-same-object-test
(testing "multiple card events do not update object when status is create"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Card remote-sync-card {:name "Test Card"
- :dataset_query (mt/mbql-query venues)
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (let [clock-t1 (t/mock-clock (t/instant "2024-01-01T10:00:00Z") (t/zone-id "UTC"))]
- (t/with-clock clock-t1
- (events/publish-event! :event/card-create
- {:object remote-sync-card :user-id (mt/user->id :rasta)}))
- (let [initial-entry (t2/select-one :model/RemoteSyncObject
- :model_type "Card"
- :model_id (:id remote-sync-card))]
- (let [clock-t2 (t/mock-clock (t/instant "2024-01-01T11:00:00Z") (t/zone-id "UTC"))]
- (t/with-clock clock-t2
- (events/publish-event! :event/card-update
- {:object remote-sync-card :previous-object remote-sync-card :user-id (mt/user->id :rasta)})))
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (let [update-entry (first entries)]
- (is (= (:id initial-entry) (:id update-entry)))
- (is (= "create" (:status update-entry)))
- (is (= (:status_changed_at initial-entry) (:status_changed_at update-entry))))))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Card remote-sync-card {:name "Test Card"
+ :dataset_query (mt/mbql-query venues)
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (let [clock-t1 (t/mock-clock (t/instant "2024-01-01T10:00:00Z") (t/zone-id "UTC"))]
+ (t/with-clock clock-t1
+ (events/publish-event! :event/card-create
+ {:object remote-sync-card :user-id (mt/user->id :rasta)}))
+ (let [initial-entry (t2/select-one :model/RemoteSyncObject
+ :model_type "Card"
+ :model_id (:id remote-sync-card))]
+ (let [clock-t2 (t/mock-clock (t/instant "2024-01-01T11:00:00Z") (t/zone-id "UTC"))]
+ (t/with-clock clock-t2
+ (events/publish-event! :event/card-update
+ {:object remote-sync-card :previous-object remote-sync-card :user-id (mt/user->id :rasta)})))
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (let [update-entry (first entries)]
+ (is (= (:id initial-entry) (:id update-entry)))
+ (is (= "create" (:status update-entry)))
+ (is (= (:status_changed_at initial-entry) (:status_changed_at update-entry)))))))))))
(deftest card-event-in-normal-collection-no-entry-test
(testing "card events in non-remote-sync collections don't create entries"
@@ -135,191 +139,241 @@
(deftest dashboard-create-event-creates-entry-test
(testing "dashboard-create event creates remote sync object entry with create status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Dashboard dashboard {:name "Test Dashboard"
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/dashboard-create
- {:object dashboard :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Dashboard"
- :model_id (:id dashboard)
- :status "create"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Dashboard dashboard {:name "Test Dashboard"
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/dashboard-create
+ {:object dashboard :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Dashboard"
+ :model_id (:id dashboard)
+ :status "create"}
+ (first entries))))))))
(deftest dashboard-update-event-creates-entry-test
(testing "dashboard-update event creates or updates remote sync object entry"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Dashboard dashboard {:name "Test Dashboard"
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/dashboard-update
- {:object dashboard :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Dashboard"
- :model_id (:id dashboard)
- :status "update"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Dashboard dashboard {:name "Test Dashboard"
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/dashboard-update
+ {:object dashboard :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Dashboard"
+ :model_id (:id dashboard)
+ :status "update"}
+ (first entries))))))))
+
+(deftest public-link-events-create-update-entry-test
+ (testing "GHY-4650: on a read-write instance, public-link events mark the card or dashboard as updated"
+ (doseq [[model topics] {:model/Card [:event/card-public-link-created :event/card-public-link-deleted]
+ :model/Dashboard [:event/dashboard-public-link-created :event/dashboard-public-link-deleted]}
+ topic topics]
+ (testing topic
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ model instance {:name "Shared" :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! topic {:object instance :object-id (:id instance) :user-id (mt/user->id :rasta)})
+ (is (=? [{:model_type (name model)
+ :model_id (:id instance)
+ :status "update"}]
+ (t2/select :model/RemoteSyncObject)))))))))
+
+(deftest events-on-read-only-instance-do-not-track-synced-items-test
+ (testing "On a read-only instance, no event marks a synced item dirty, since that change can never be pushed"
+ (mt/with-temporary-setting-values [remote-sync-type :read-only]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Dashboard dashboard {:name "Test Dashboard" :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/dashboard-update {:object dashboard :user-id (mt/user->id :rasta)})
+ (is (empty? (t2/select :model/RemoteSyncObject)))))))
+
+(deftest public-link-events-on-read-only-instance-test
+ (testing "GHY-4650: on a read-only instance, public-link events leave synced cards and dashboards untracked"
+ (doseq [[model topics] {:model/Card [:event/card-public-link-created :event/card-public-link-deleted]
+ :model/Dashboard [:event/dashboard-public-link-created :event/dashboard-public-link-deleted]}
+ topic topics]
+ (testing topic
+ (mt/with-temporary-setting-values [remote-sync-type :read-only]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ model instance {:name "Shared" :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! topic {:object instance :object-id (:id instance) :user-id (mt/user->id :rasta)})
+ (is (empty? (t2/select :model/RemoteSyncObject)))))))))
(deftest dashboard-update-archived-sets-delete-test
(testing "dashboard-update event with archived=true sets delete status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Dashboard dashboard {:name "Test Dashboard"
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/dashboard-update
- {:object (assoc dashboard :archived true)
- :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Dashboard"
- :model_id (:id dashboard)
- :status "delete"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Dashboard dashboard {:name "Test Dashboard"
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/dashboard-update
+ {:object (assoc dashboard :archived true)
+ :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Dashboard"
+ :model_id (:id dashboard)
+ :status "delete"}
+ (first entries))))))))
(deftest dashboard-delete-event-creates-entry-test
(testing "dashboard-delete event creates remote sync object entry with delete status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Dashboard dashboard {:name "Test Dashboard"
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/dashboard-delete
- {:object dashboard :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Dashboard"
- :model_id (:id dashboard)
- :status "delete"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Dashboard dashboard {:name "Test Dashboard"
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/dashboard-delete
+ {:object dashboard :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Dashboard"
+ :model_id (:id dashboard)
+ :status "delete"}
+ (first entries))))))))
(deftest document-create-event-creates-entry-test
(testing "document-create event creates remote sync object entry with create status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Document document {:collection_id (u/the-id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/document-create
- {:object document :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Document"
- :model_id (:id document)
- :status "create"}
- (first entries)))))))
-
-(deftest document-update-event-creates-entry-test
- (testing "document-update event creates or updates remote sync object entry with update status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Document document {:collection_id (u/the-id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/document-update
- {:object document :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Document"
- :model_id (:id document)
- :status "update"}
- (first entries)))))))
-
-(deftest document-update-archived-sets-delete-test
- (testing "document-update event with archived=true sets delete status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Document document {:collection_id (u/the-id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/document-update
- {:object (assoc document :archived true)
- :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Document"
- :model_id (:id document)
- :status "delete"}
- (first entries)))))))
-
-(deftest document-delete-event-creates-entry-test
- (testing "document-delete event creates remote sync object entry with delete status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Document document {:collection_id (u/the-id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/document-delete
- {:object document :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Document"
- :model_id (:id document)
- :status "delete"}
- (first entries)))))))
-
-(deftest snippet-create-event-creates-entry-test
- (testing "snippet-create event creates remote sync object entry with create status when Library is synced"
- (with-library-synced
- (mt/with-temp [:model/Collection snippet-collection {:name "Snippets" :namespace "snippets"}
- :model/NativeQuerySnippet snippet {:name "Test Snippet"
- :content "SELECT 1"
- :collection_id (:id snippet-collection)}]
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Document document {:collection_id (u/the-id remote-sync-collection)}]
(t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/snippet-create
- {:object snippet :user-id (mt/user->id :rasta)})
+ (events/publish-event! :event/document-create
+ {:object document :user-id (mt/user->id :rasta)})
(let [entries (t2/select :model/RemoteSyncObject)]
(is (= 1 (count entries)))
- (is (=? {:model_type "NativeQuerySnippet"
- :model_id (:id snippet)
+ (is (=? {:model_type "Document"
+ :model_id (:id document)
:status "create"}
(first entries))))))))
-(deftest snippet-update-event-creates-entry-test
- (testing "snippet-update event creates or updates remote sync object entry with update status when Library is synced"
- (with-library-synced
- (mt/with-temp [:model/Collection snippet-collection {:name "Snippets" :namespace "snippets"}
- :model/NativeQuerySnippet snippet {:name "Test Snippet"
- :content "SELECT 1"
- :collection_id (:id snippet-collection)}]
+(deftest document-update-event-creates-entry-test
+ (testing "document-update event creates or updates remote sync object entry with update status"
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Document document {:collection_id (u/the-id remote-sync-collection)}]
(t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/snippet-update
- {:object snippet :user-id (mt/user->id :rasta)})
+ (events/publish-event! :event/document-update
+ {:object document :user-id (mt/user->id :rasta)})
(let [entries (t2/select :model/RemoteSyncObject)]
(is (= 1 (count entries)))
- (is (=? {:model_type "NativeQuerySnippet"
- :model_id (:id snippet)
+ (is (=? {:model_type "Document"
+ :model_id (:id document)
:status "update"}
(first entries))))))))
-(deftest snippet-update-archived-sets-delete-test
- (testing "snippet-update event with archived=true sets delete status when Library is synced"
- (with-library-synced
- (mt/with-temp [:model/Collection snippet-collection {:name "Snippets" :namespace "snippets"}
- :model/NativeQuerySnippet snippet {:name "Test Snippet"
- :content "SELECT 1"
- :collection_id (:id snippet-collection)}]
+(deftest document-update-archived-sets-delete-test
+ (testing "document-update event with archived=true sets delete status"
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Document document {:collection_id (u/the-id remote-sync-collection)}]
(t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/snippet-update
- {:object (assoc snippet :archived true)
+ (events/publish-event! :event/document-update
+ {:object (assoc document :archived true)
:user-id (mt/user->id :rasta)})
(let [entries (t2/select :model/RemoteSyncObject)]
(is (= 1 (count entries)))
- (is (=? {:model_type "NativeQuerySnippet"
- :model_id (:id snippet)
+ (is (=? {:model_type "Document"
+ :model_id (:id document)
:status "delete"}
(first entries))))))))
-(deftest snippet-delete-event-creates-entry-test
- (testing "snippet-delete event creates remote sync object entry with delete status when Library is synced"
- (with-library-synced
- (mt/with-temp [:model/Collection snippet-collection {:name "Snippets" :namespace "snippets"}
- :model/NativeQuerySnippet snippet {:name "Test Snippet"
- :content "SELECT 1"
- :collection_id (:id snippet-collection)}]
+(deftest document-delete-event-creates-entry-test
+ (testing "document-delete event creates remote sync object entry with delete status"
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Document document {:collection_id (u/the-id remote-sync-collection)}]
(t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/snippet-delete
- {:object snippet :user-id (mt/user->id :rasta)})
+ (events/publish-event! :event/document-delete
+ {:object document :user-id (mt/user->id :rasta)})
(let [entries (t2/select :model/RemoteSyncObject)]
(is (= 1 (count entries)))
- (is (=? {:model_type "NativeQuerySnippet"
- :model_id (:id snippet)
+ (is (=? {:model_type "Document"
+ :model_id (:id document)
:status "delete"}
(first entries))))))))
+(deftest snippet-create-event-creates-entry-test
+ (testing "snippet-create event creates remote sync object entry with create status when Library is synced"
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (with-library-synced
+ (mt/with-temp [:model/Collection snippet-collection {:name "Snippets" :namespace "snippets"}
+ :model/NativeQuerySnippet snippet {:name "Test Snippet"
+ :content "SELECT 1"
+ :collection_id (:id snippet-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/snippet-create
+ {:object snippet :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "NativeQuerySnippet"
+ :model_id (:id snippet)
+ :status "create"}
+ (first entries)))))))))
+
+(deftest snippet-update-event-creates-entry-test
+ (testing "snippet-update event creates or updates remote sync object entry with update status when Library is synced"
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (with-library-synced
+ (mt/with-temp [:model/Collection snippet-collection {:name "Snippets" :namespace "snippets"}
+ :model/NativeQuerySnippet snippet {:name "Test Snippet"
+ :content "SELECT 1"
+ :collection_id (:id snippet-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/snippet-update
+ {:object snippet :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "NativeQuerySnippet"
+ :model_id (:id snippet)
+ :status "update"}
+ (first entries)))))))))
+
+(deftest snippet-update-archived-sets-delete-test
+ (testing "snippet-update event with archived=true sets delete status when Library is synced"
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (with-library-synced
+ (mt/with-temp [:model/Collection snippet-collection {:name "Snippets" :namespace "snippets"}
+ :model/NativeQuerySnippet snippet {:name "Test Snippet"
+ :content "SELECT 1"
+ :collection_id (:id snippet-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/snippet-update
+ {:object (assoc snippet :archived true)
+ :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "NativeQuerySnippet"
+ :model_id (:id snippet)
+ :status "delete"}
+ (first entries)))))))))
+
+(deftest snippet-delete-event-creates-entry-test
+ (testing "snippet-delete event creates remote sync object entry with delete status when Library is synced"
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (with-library-synced
+ (mt/with-temp [:model/Collection snippet-collection {:name "Snippets" :namespace "snippets"}
+ :model/NativeQuerySnippet snippet {:name "Test Snippet"
+ :content "SELECT 1"
+ :collection_id (:id snippet-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/snippet-delete
+ {:object snippet :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "NativeQuerySnippet"
+ :model_id (:id snippet)
+ :status "delete"}
+ (first entries)))))))))
+
(deftest snippet-event-when-library-not-synced-no-entry-test
(testing "snippet events don't create entries when Library is not synced"
(when-let [library (collection/library-collection)]
@@ -629,22 +683,23 @@
(deftest new-card-moved-out-of-remote-synced-collection-test
(testing "new card moved out of remote-synced collection is no longer tracked"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Collection normal-collection {:name "Normal"}
- :model/Card card {:name "Test Card"
- :dataset_query (mt/mbql-query venues)
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/card-create
- {:object card :user-id (mt/user->id :rasta)})
- (let [initial-entry (t2/select-one :model/RemoteSyncObject :model_type "Card" :model_id (:id card))]
- (is (= "create" (:status initial-entry)))
- (events/publish-event! :event/card-update
- {:object (assoc card :collection_id (:id normal-collection))
- :previous-object card
- :user-id (mt/user->id :rasta)})
- (let [update-entry (t2/select-one :model/RemoteSyncObject :model_type "Card" :model_id (:id card))]
- (is (nil? update-entry)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Collection normal-collection {:name "Normal"}
+ :model/Card card {:name "Test Card"
+ :dataset_query (mt/mbql-query venues)
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/card-create
+ {:object card :user-id (mt/user->id :rasta)})
+ (let [initial-entry (t2/select-one :model/RemoteSyncObject :model_type "Card" :model_id (:id card))]
+ (is (= "create" (:status initial-entry)))
+ (events/publish-event! :event/card-update
+ {:object (assoc card :collection_id (:id normal-collection))
+ :previous-object card
+ :user-id (mt/user->id :rasta)})
+ (let [update-entry (t2/select-one :model/RemoteSyncObject :model_type "Card" :model_id (:id card))]
+ (is (nil? update-entry))))))))
(deftest existing-dashboard-moved-out-of-remote-synced-collection-test
(testing "existing dashboard moved out of remote-synced collection is marked as removed"
@@ -664,20 +719,21 @@
(deftest new-dashboard-moved-out-of-remote-synced-collection-test
(testing "new dashboard moved out of remote-synced collection is no longer tracked"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Collection normal-collection {:name "Normal"}
- :model/Dashboard dashboard {:name "Test Dashboard"
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/dashboard-create
- {:object dashboard :user-id (mt/user->id :rasta)})
- (let [initial-entry (t2/select-one :model/RemoteSyncObject :model_type "Dashboard" :model_id (:id dashboard))]
- (is (= "create" (:status initial-entry)))
- (events/publish-event! :event/dashboard-update
- {:object (assoc dashboard :collection_id (:id normal-collection))
- :user-id (mt/user->id :rasta)})
- (let [update-entry (t2/select-one :model/RemoteSyncObject :model_type "Dashboard" :model_id (:id dashboard))]
- (is (nil? update-entry)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Collection normal-collection {:name "Normal"}
+ :model/Dashboard dashboard {:name "Test Dashboard"
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/dashboard-create
+ {:object dashboard :user-id (mt/user->id :rasta)})
+ (let [initial-entry (t2/select-one :model/RemoteSyncObject :model_type "Dashboard" :model_id (:id dashboard))]
+ (is (= "create" (:status initial-entry)))
+ (events/publish-event! :event/dashboard-update
+ {:object (assoc dashboard :collection_id (:id normal-collection))
+ :user-id (mt/user->id :rasta)})
+ (let [update-entry (t2/select-one :model/RemoteSyncObject :model_type "Dashboard" :model_id (:id dashboard))]
+ (is (nil? update-entry))))))))
(deftest existing-document-moved-out-of-remote-synced-collection-test
(testing "existing document moved out of remote-synced collection is marked as removed"
@@ -696,19 +752,20 @@
(deftest new-document-moved-out-of-remote-synced-collection-test
(testing "new document moved out of remote-synced collection is no longer tracked"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Collection normal-collection {:name "Normal"}
- :model/Document document {:collection_id (u/the-id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/document-create
- {:object document :user-id (mt/user->id :rasta)})
- (let [initial-entry (t2/select-one :model/RemoteSyncObject :model_type "Document" :model_id (:id document))]
- (is (= "create" (:status initial-entry)))
- (events/publish-event! :event/document-update
- {:object (assoc document :collection_id (:id normal-collection))
- :user-id (mt/user->id :rasta)})
- (let [update-entry (t2/select-one :model/RemoteSyncObject :model_type "Document" :model_id (:id document))]
- (is (nil? update-entry)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Collection normal-collection {:name "Normal"}
+ :model/Document document {:collection_id (u/the-id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/document-create
+ {:object document :user-id (mt/user->id :rasta)})
+ (let [initial-entry (t2/select-one :model/RemoteSyncObject :model_type "Document" :model_id (:id document))]
+ (is (= "create" (:status initial-entry)))
+ (events/publish-event! :event/document-update
+ {:object (assoc document :collection_id (:id normal-collection))
+ :user-id (mt/user->id :rasta)})
+ (let [update-entry (t2/select-one :model/RemoteSyncObject :model_type "Document" :model_id (:id document))]
+ (is (nil? update-entry))))))))
(deftest existing-collection-type-changed-from-remote-synced-test
(testing "existing collection type changed from remote-synced is marked as removed"
@@ -785,93 +842,98 @@
(deftest timeline-create-event-creates-entry-test
(testing "timeline-create event creates remote sync object entry with create status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Timeline timeline {:name "Test Timeline"
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/timeline-create
- {:object timeline :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Timeline"
- :model_id (:id timeline)
- :status "create"}
- (first entries)))))))
-
-(deftest timeline-event-api-create-tracks-timeline-test
- (testing "timeline-create event with a Timeline object creates a remote sync entry (fixed behavior)"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Timeline timeline {:name "Test Timeline"
- :collection_id (:id remote-sync-collection)}
- :model/TimelineEvent timeline-event {:name "Test Event"
- :timestamp (t/offset-date-time)
- :timezone "UTC"
- :time_matters false
- :timeline_id (:id timeline)}]
- (t2/delete! :model/RemoteSyncObject)
- (testing "publishing with a TimelineEvent (old buggy behavior) does NOT create a sync entry"
- (events/publish-event! :event/timeline-create
- {:object timeline-event :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 0 (count entries))
- "TimelineEvent lacks collection_id, so no sync entry should be created")))
- (testing "publishing with a Timeline (correct behavior) creates a sync entry"
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Timeline timeline {:name "Test Timeline"
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
(events/publish-event! :event/timeline-create
{:object timeline :user-id (mt/user->id :rasta)})
(let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries))
- "Should create exactly one remote sync entry")
+ (is (= 1 (count entries)))
(is (=? {:model_type "Timeline"
- :model_id (:id timeline)
- :status "create"}
- (first entries))
- "Remote sync entry should track the Timeline, not the TimelineEvent"))))))
+ :model_id (:id timeline)
+ :status "create"}
+ (first entries))))))))
+
+(deftest timeline-event-api-create-tracks-timeline-test
+ (testing "timeline-create event with a Timeline object creates a remote sync entry (fixed behavior)"
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Timeline timeline {:name "Test Timeline"
+ :collection_id (:id remote-sync-collection)}
+ :model/TimelineEvent timeline-event {:name "Test Event"
+ :timestamp (t/offset-date-time)
+ :timezone "UTC"
+ :time_matters false
+ :timeline_id (:id timeline)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (testing "publishing with a TimelineEvent (old buggy behavior) does NOT create a sync entry"
+ (events/publish-event! :event/timeline-create
+ {:object timeline-event :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 0 (count entries))
+ "TimelineEvent lacks collection_id, so no sync entry should be created")))
+ (testing "publishing with a Timeline (correct behavior) creates a sync entry"
+ (events/publish-event! :event/timeline-create
+ {:object timeline :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries))
+ "Should create exactly one remote sync entry")
+ (is (=? {:model_type "Timeline"
+ :model_id (:id timeline)
+ :status "create"}
+ (first entries))
+ "Remote sync entry should track the Timeline, not the TimelineEvent")))))))
(deftest timeline-update-event-creates-entry-test
(testing "timeline-update event creates remote sync object entry with update status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Timeline timeline {:name "Test Timeline"
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/timeline-update
- {:object timeline :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Timeline"
- :model_id (:id timeline)
- :status "update"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Timeline timeline {:name "Test Timeline"
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/timeline-update
+ {:object timeline :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Timeline"
+ :model_id (:id timeline)
+ :status "update"}
+ (first entries))))))))
(deftest timeline-update-archived-sets-delete-test
(testing "timeline-update event with archived timeline sets delete status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Timeline timeline {:name "Test Timeline"
- :collection_id (:id remote-sync-collection)
- :archived true}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/timeline-update
- {:object timeline :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Timeline"
- :model_id (:id timeline)
- :status "delete"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Timeline timeline {:name "Test Timeline"
+ :collection_id (:id remote-sync-collection)
+ :archived true}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/timeline-update
+ {:object timeline :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Timeline"
+ :model_id (:id timeline)
+ :status "delete"}
+ (first entries))))))))
(deftest timeline-delete-event-creates-entry-test
(testing "timeline-delete event creates remote sync object entry with delete status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Timeline timeline {:name "Test Timeline"
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/timeline-delete
- {:object timeline :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Timeline"
- :model_id (:id timeline)
- :status "delete"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Timeline timeline {:name "Test Timeline"
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/timeline-delete
+ {:object timeline :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Timeline"
+ :model_id (:id timeline)
+ :status "delete"}
+ (first entries))))))))
(deftest timeline-event-in-normal-collection-no-entry-test
(testing "timeline events in normal collections don't create remote sync entries"
@@ -904,60 +966,63 @@
(deftest new-timeline-moved-out-of-remote-synced-collection-test
(testing "new timeline moved out of remote-synced collection is no longer tracked"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Collection normal-collection {:name "Normal Collection"}
- :model/Timeline timeline {:name "Test Timeline"
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/timeline-create
- {:object timeline :user-id (mt/user->id :rasta)})
- (is (= 1 (count (t2/select :model/RemoteSyncObject))))
- (events/publish-event! :event/timeline-update
- {:object (assoc timeline :collection_id (:id normal-collection))
- :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 0 (count entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Collection normal-collection {:name "Normal Collection"}
+ :model/Timeline timeline {:name "Test Timeline"
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/timeline-create
+ {:object timeline :user-id (mt/user->id :rasta)})
+ (is (= 1 (count (t2/select :model/RemoteSyncObject))))
+ (events/publish-event! :event/timeline-update
+ {:object (assoc timeline :collection_id (:id normal-collection))
+ :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 0 (count entries))))))))
(deftest soft-delete-then-hard-delete-preserves-dirty-status-test
(testing "doc that is soft-deleted then hard-deleted should maintain dirty status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Document doc {:name "Test Doc"
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- ;; Trash the doc
- (t2/update! :model/Document (:id doc) {:archived true})
- (events/publish-event! :event/document-update
- {:object (assoc doc :archived true)
- :user-id (mt/user->id :rasta)})
- (let [soft-delete-entry (t2/select-one :model/RemoteSyncObject :model_type "Document" :model_id (:id doc))]
- (is (= "delete" (:status soft-delete-entry))))
- ;; Permanently delete from trash
- (t2/delete! :model/Document (:id doc))
- (events/publish-event! :event/document-delete
- {:object doc :user-id (mt/user->id :rasta)})
- ;; The remote sync object entry should still exist with delete status
- ;; so the collection remains dirty
- (let [hard-delete-entry (t2/select-one :model/RemoteSyncObject :model_type "Document" :model_id (:id doc))]
- (is (= "delete" (:status hard-delete-entry)))
- (is (not (nil? hard-delete-entry)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Document doc {:name "Test Doc"
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ ;; Trash the doc
+ (t2/update! :model/Document (:id doc) {:archived true})
+ (events/publish-event! :event/document-update
+ {:object (assoc doc :archived true)
+ :user-id (mt/user->id :rasta)})
+ (let [soft-delete-entry (t2/select-one :model/RemoteSyncObject :model_type "Document" :model_id (:id doc))]
+ (is (= "delete" (:status soft-delete-entry))))
+ ;; Permanently delete from trash
+ (t2/delete! :model/Document (:id doc))
+ (events/publish-event! :event/document-delete
+ {:object doc :user-id (mt/user->id :rasta)})
+ ;; The remote sync object entry should still exist with delete status
+ ;; so the collection remains dirty
+ (let [hard-delete-entry (t2/select-one :model/RemoteSyncObject :model_type "Document" :model_id (:id doc))]
+ (is (= "delete" (:status hard-delete-entry)))
+ (is (not (nil? hard-delete-entry))))))))
;;; Table Event Tests
(deftest table-update-event-creates-entry-for-published-table-test
(testing "table-update event creates remote sync object entry for published table in remote-synced collection"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Table table {:name "Test Table"
- :is_published true
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/table-update
- {:object table :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Table"
- :model_id (:id table)
- :status "update"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Table table {:name "Test Table"
+ :is_published true
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/table-update
+ {:object table :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Table"
+ :model_id (:id table)
+ :status "update"}
+ (first entries))))))))
(deftest table-update-event-no-entry-for-unpublished-table-test
(testing "table-update event doesn't create entry for unpublished table"
@@ -985,20 +1050,21 @@
(deftest table-update-archived-sets-delete-test
(testing "table-update event with archived_at sets delete status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Table table {:name "Test Table"
- :is_published true
- :collection_id (:id remote-sync-collection)}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/table-update
- {:object (assoc table :archived_at (t/offset-date-time))
- :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Table"
- :model_id (:id table)
- :status "delete"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Table table {:name "Test Table"
+ :is_published true
+ :collection_id (:id remote-sync-collection)}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/table-update
+ {:object (assoc table :archived_at (t/offset-date-time))
+ :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Table"
+ :model_id (:id table)
+ :status "delete"}
+ (first entries))))))))
(deftest table-unpublished-marks-as-removed-test
(testing "table that becomes unpublished is marked as removed"
@@ -1060,84 +1126,88 @@
(deftest segment-create-event-creates-entry-test
(testing "segment-create event creates remote sync object entry for segment in published table in remote-synced collection"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Table table {:name "Test Table"
- :is_published true
- :collection_id (:id remote-sync-collection)}
- :model/Segment segment {:name "Test Segment"
- :table_id (:id table)
- :definition {:source-table (:id table)
- :filter [:> [:field 1 nil] 0]}}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/segment-create
- {:object segment :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Segment"
- :model_id (:id segment)
- :status "create"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Table table {:name "Test Table"
+ :is_published true
+ :collection_id (:id remote-sync-collection)}
+ :model/Segment segment {:name "Test Segment"
+ :table_id (:id table)
+ :definition {:source-table (:id table)
+ :filter [:> [:field 1 nil] 0]}}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/segment-create
+ {:object segment :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Segment"
+ :model_id (:id segment)
+ :status "create"}
+ (first entries))))))))
(deftest segment-update-event-creates-entry-test
(testing "segment-update event creates remote sync object entry with update status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Table table {:name "Test Table"
- :is_published true
- :collection_id (:id remote-sync-collection)}
- :model/Segment segment {:name "Test Segment"
- :table_id (:id table)
- :definition {:source-table (:id table)
- :filter [:> [:field 1 nil] 0]}}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/segment-update
- {:object segment :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Segment"
- :model_id (:id segment)
- :status "update"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Table table {:name "Test Table"
+ :is_published true
+ :collection_id (:id remote-sync-collection)}
+ :model/Segment segment {:name "Test Segment"
+ :table_id (:id table)
+ :definition {:source-table (:id table)
+ :filter [:> [:field 1 nil] 0]}}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/segment-update
+ {:object segment :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Segment"
+ :model_id (:id segment)
+ :status "update"}
+ (first entries))))))))
(deftest segment-update-archived-sets-delete-test
(testing "segment-update event with archived=true sets delete status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Table table {:name "Test Table"
- :is_published true
- :collection_id (:id remote-sync-collection)}
- :model/Segment segment {:name "Test Segment"
- :table_id (:id table)
- :definition {:source-table (:id table)
- :filter [:> [:field 1 nil] 0]}}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/segment-update
- {:object (assoc segment :archived true)
- :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Segment"
- :model_id (:id segment)
- :status "delete"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Table table {:name "Test Table"
+ :is_published true
+ :collection_id (:id remote-sync-collection)}
+ :model/Segment segment {:name "Test Segment"
+ :table_id (:id table)
+ :definition {:source-table (:id table)
+ :filter [:> [:field 1 nil] 0]}}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/segment-update
+ {:object (assoc segment :archived true)
+ :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Segment"
+ :model_id (:id segment)
+ :status "delete"}
+ (first entries))))))))
(deftest segment-delete-event-creates-entry-test
(testing "segment-delete event creates remote sync object entry with delete status"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Table table {:name "Test Table"
- :is_published true
- :collection_id (:id remote-sync-collection)}
- :model/Segment segment {:name "Test Segment"
- :table_id (:id table)
- :definition {:source-table (:id table)
- :filter [:> [:field 1 nil] 0]}}]
- (t2/delete! :model/RemoteSyncObject)
- (events/publish-event! :event/segment-delete
- {:object segment :user-id (mt/user->id :rasta)})
- (let [entries (t2/select :model/RemoteSyncObject)]
- (is (= 1 (count entries)))
- (is (=? {:model_type "Segment"
- :model_id (:id segment)
- :status "delete"}
- (first entries)))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Table table {:name "Test Table"
+ :is_published true
+ :collection_id (:id remote-sync-collection)}
+ :model/Segment segment {:name "Test Segment"
+ :table_id (:id table)
+ :definition {:source-table (:id table)
+ :filter [:> [:field 1 nil] 0]}}]
+ (t2/delete! :model/RemoteSyncObject)
+ (events/publish-event! :event/segment-delete
+ {:object segment :user-id (mt/user->id :rasta)})
+ (let [entries (t2/select :model/RemoteSyncObject)]
+ (is (= 1 (count entries)))
+ (is (=? {:model_type "Segment"
+ :model_id (:id segment)
+ :status "delete"}
+ (first entries))))))))
(deftest segment-event-in-normal-collection-no-entry-test
(testing "segment events in non-remote-synced collections don't create entries"
@@ -1173,32 +1243,33 @@
(deftest existing-segment-table-unpublished-marks-as-removed-test
(testing "existing segment is marked as removed when its table is unpublished"
- (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
- :model/Table table {:name "Test Table"
- :is_published true
- :collection_id (:id remote-sync-collection)}
- :model/Segment segment {:name "Test Segment"
- :table_id (:id table)
- :definition {:source-table (:id table)
- :filter [:> [:field 1 nil] 0]}}]
- (t2/delete! :model/RemoteSyncObject)
- ;; First create a synced entry
- (t2/insert! :model/RemoteSyncObject {:model_type "Segment"
- :model_id (:id segment)
- :model_name "Test Segment"
- :model_table_id (:id table)
- :model_table_name "Test Table"
- :status "synced"
- :status_changed_at (t/offset-date-time)})
- (let [initial-entry (t2/select-one :model/RemoteSyncObject :model_type "Segment" :model_id (:id segment))]
- (is (= "synced" (:status initial-entry)))
- ;; Now "unpublish" the table by simulating an update where the segment's table is no longer in sync scope
- (events/publish-event! :event/segment-update
- {:object (assoc segment :table_id (:id table))
- :user-id (mt/user->id :rasta)})
- ;; Since table is still published, should be "update"
- (let [update-entry (t2/select-one :model/RemoteSyncObject :model_type "Segment" :model_id (:id segment))]
- (is (= "update" (:status update-entry))))))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection remote-sync-collection {:is_remote_synced true :name "Remote-Sync"}
+ :model/Table table {:name "Test Table"
+ :is_published true
+ :collection_id (:id remote-sync-collection)}
+ :model/Segment segment {:name "Test Segment"
+ :table_id (:id table)
+ :definition {:source-table (:id table)
+ :filter [:> [:field 1 nil] 0]}}]
+ (t2/delete! :model/RemoteSyncObject)
+ ;; First create a synced entry
+ (t2/insert! :model/RemoteSyncObject {:model_type "Segment"
+ :model_id (:id segment)
+ :model_name "Test Segment"
+ :model_table_id (:id table)
+ :model_table_name "Test Table"
+ :status "synced"
+ :status_changed_at (t/offset-date-time)})
+ (let [initial-entry (t2/select-one :model/RemoteSyncObject :model_type "Segment" :model_id (:id segment))]
+ (is (= "synced" (:status initial-entry)))
+ ;; Now "unpublish" the table by simulating an update where the segment's table is no longer in sync scope
+ (events/publish-event! :event/segment-update
+ {:object (assoc segment :table_id (:id table))
+ :user-id (mt/user->id :rasta)})
+ ;; Since table is still published, should be "update"
+ (let [update-entry (t2/select-one :model/RemoteSyncObject :model_type "Segment" :model_id (:id segment))]
+ (is (= "update" (:status update-entry)))))))))
(deftest ^:parallel segment-event-derivation-test
(testing "segment events properly derive from :metabase/event"
@@ -1341,22 +1412,23 @@
(deftest handler-first-lock-preserves-removal-test
(testing "the handler holds the entry's row lock when the disable arrives: the disable blocks until the
handler commits, then records the removal last, so it survives (GHY-4189)"
- (do-with-unsync-race-fixture
- (fn [coll-id card]
- (let [reached (promise)
- release (promise)]
- ;; Park at the FOR UPDATE read, i.e. while the handler holds the entry's row lock (the
- ;; handler-first ordering).
- (with-redefs [t2/select-one (once-parking-select-one! rso-locking-select? reached release)]
- (let [handler (fire-card-update! card)]
- (is (true? (deref reached 10000 false)) "handler parked holding the row lock")
- (let [disable (future (remote-sync.core/bulk-set-remote-sync {coll-id false}))]
- (is (= ::blocked (deref disable 300 ::blocked))
- "the disable blocks on the row lock the handler holds")
- (deliver release true)
- (deref disable 10000 nil)
- (deref handler 10000 nil)))))
- (assert-removal-survived coll-id card)))))
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (do-with-unsync-race-fixture
+ (fn [coll-id card]
+ (let [reached (promise)
+ release (promise)]
+ ;; Park at the FOR UPDATE read, i.e. while the handler holds the entry's row lock (the
+ ;; handler-first ordering).
+ (with-redefs [t2/select-one (once-parking-select-one! rso-locking-select? reached release)]
+ (let [handler (fire-card-update! card)]
+ (is (true? (deref reached 10000 false)) "handler parked holding the row lock")
+ (let [disable (future (remote-sync.core/bulk-set-remote-sync {coll-id false}))]
+ (is (= ::blocked (deref disable 300 ::blocked))
+ "the disable blocks on the row lock the handler holds")
+ (deliver release true)
+ (deref disable 10000 nil)
+ (deref handler 10000 nil)))))
+ (assert-removal-survived coll-id card))))))
(deftest field-update-no-rso-when-no-fus-row-test
(testing "field-update on an eligible field with NO FUS row, and no TableUserSettings row either, creates no
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/glossary_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/glossary_test.clj
index bb67069a1ba..1f52c747398 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/glossary_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/glossary_test.clj
@@ -54,7 +54,7 @@
(deftest create-event-tracks-entry-when-library-synced-test
(collections.tu/with-library-synced
- (mt/with-temporary-setting-values [remote-sync-enabled true]
+ (mt/with-temporary-setting-values [remote-sync-enabled true remote-sync-type :read-write]
(mt/with-model-cleanup [:model/Glossary]
(let [entry (glossary.core/create-entry! (mt/user->id :rasta) {:term "ARR" :definition "Annual recurring revenue"})]
(is (=? {:status "create" :model_name "ARR"} (rso entry))))))))
@@ -68,7 +68,7 @@
(deftest update-event-marks-synced-entry-for-update-test
(collections.tu/with-library-synced
- (mt/with-temporary-setting-values [remote-sync-enabled true]
+ (mt/with-temporary-setting-values [remote-sync-enabled true remote-sync-type :read-write]
(mt/with-temp [:model/Glossary entry {:term "ARR" :definition "Annual recurring revenue"}]
(with-rso! entry "synced")
(testing "saving the same term and definition again stays synced"
@@ -80,7 +80,7 @@
(deftest delete-event-test
(collections.tu/with-library-synced
- (mt/with-temporary-setting-values [remote-sync-enabled true]
+ (mt/with-temporary-setting-values [remote-sync-enabled true remote-sync-type :read-write]
(testing "deleting a synced entry marks it for deletion and keeps the tracked name"
(mt/with-temp [:model/Glossary entry {:term "ARR" :definition "Annual recurring revenue"}]
(with-rso! entry "synced")
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/snippets_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/snippets_test.clj
index b4eb487856b..42534e6589f 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/snippets_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/snippets_test.clj
@@ -48,7 +48,7 @@
(deftest snippet-event-creates-sync-object-when-library-synced-test
(testing "Creating a snippet creates a RemoteSyncObject entry when Library is remote-synced"
(collections.tu/with-library-synced
- (mt/with-temporary-setting-values [remote-sync-enabled true]
+ (mt/with-temporary-setting-values [remote-sync-enabled true remote-sync-type :read-write]
(mt/with-temp [:model/NativeQuerySnippet snippet {:name "Test Snippet" :content "SELECT 1"}]
(events/publish-event! :event/snippet-create {:object snippet :user-id (mt/user->id :rasta)})
(is (t2/exists? :model/RemoteSyncObject
@@ -70,7 +70,7 @@
(deftest snippet-event-updates-sync-object-test
(testing "Updating a snippet updates the RemoteSyncObject entry when Library is synced"
(collections.tu/with-library-synced
- (mt/with-temporary-setting-values [remote-sync-enabled true]
+ (mt/with-temporary-setting-values [remote-sync-enabled true remote-sync-type :read-write]
(mt/with-temp [:model/NativeQuerySnippet snippet {:name "Test Snippet" :content "SELECT 1"}]
;; Delete auto-created entry from snippet creation event and set up test state
(t2/delete! :model/RemoteSyncObject :model_type "NativeQuerySnippet" :model_id (:id snippet))
@@ -89,7 +89,7 @@
(deftest archived-snippet-marked-for-deletion-test
(testing "Archiving a snippet marks it for deletion when Library is synced"
(collections.tu/with-library-synced
- (mt/with-temporary-setting-values [remote-sync-enabled true]
+ (mt/with-temporary-setting-values [remote-sync-enabled true remote-sync-type :read-write]
(mt/with-temp [:model/NativeQuerySnippet snippet {:name "Test Snippet" :content "SELECT 1"}]
;; Delete auto-created entry from snippet creation event and set up test state
(t2/delete! :model/RemoteSyncObject :model_type "NativeQuerySnippet" :model_id (:id snippet))
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/spec_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/spec_test.clj
index 06a54387207..3bdace2e1a3 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/spec_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/spec_test.clj
@@ -58,8 +58,9 @@
"events :prefix should be a keyword")
(is (vector? (get-in spec [:events :types]))
"events :types should be a vector")
- (is (every? #{:create :update :delete :publish :unpublish} (get-in spec [:events :types]))
- "events :types should only contain :create, :update, :delete, :publish, :unpublish")))))
+ (is (every? #{:create :update :delete :publish :unpublish :public-link-created :public-link-deleted}
+ (get-in spec [:events :types]))
+ "events :types should only contain :create, :update, :delete, :publish, :unpublish, :public-link-created, :public-link-deleted")))))
(deftest all-specs-have-valid-tracking-test
(testing "Every spec has valid tracking configuration"
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/transforms_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/transforms_test.clj
index 14e98d418cd..7f1ab446289 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/transforms_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/transforms_test.clj
@@ -30,7 +30,8 @@
(testing "Creating a transform creates a RemoteSyncObject entry when remote-sync-transforms is enabled"
(mt/with-premium-features #{:transforms-basic}
(mt/with-temporary-setting-values [remote-sync-transforms true
- remote-sync-enabled true]
+ remote-sync-enabled true
+ remote-sync-type :read-write]
(mt/with-temp [:model/Collection {coll-id :id} {:name "Transforms Collection" :namespace collection/transforms-ns}
:model/Transform transform {:name "Test Transform" :collection_id coll-id}]
(events/publish-event! :event/transform-create {:object transform})
@@ -56,7 +57,8 @@
(testing "Updating a transform updates the RemoteSyncObject entry when setting is enabled"
(mt/with-premium-features #{:transforms-basic}
(mt/with-temporary-setting-values [remote-sync-transforms true
- remote-sync-enabled true]
+ remote-sync-enabled true
+ remote-sync-type :read-write]
(mt/with-temp [:model/Collection {coll-id :id} {:name "Transforms Collection" :namespace collection/transforms-ns}
:model/Transform transform {:name "Test Transform" :collection_id coll-id}
:model/RemoteSyncObject _rso {:model_type "Transform"
@@ -108,7 +110,8 @@
(testing "Creating a transform tag creates a RemoteSyncObject entry when transform sync is enabled"
(mt/with-premium-features #{:transforms-basic}
(mt/with-temporary-setting-values [remote-sync-transforms true
- remote-sync-enabled true]
+ remote-sync-enabled true
+ remote-sync-type :read-write]
(mt/with-temp [:model/TransformTag tag {:name "Test Tag"}]
(events/publish-event! :event/transform-tag-create {:object tag})
(is (t2/exists? :model/RemoteSyncObject
@@ -610,7 +613,8 @@ serdes/meta:
(testing "Creating a PythonLibrary creates a RemoteSyncObject entry when remote-sync-transforms is enabled"
(mt/with-premium-features #{:transforms-basic}
(mt/with-temporary-setting-values [remote-sync-transforms true
- remote-sync-enabled true]
+ remote-sync-enabled true
+ remote-sync-type :read-write]
(let [library (t2/insert-returning-instance! :model/PythonLibrary {:path "common.py" :source "# test"})]
(is (t2/exists? :model/RemoteSyncObject
:model_type "PythonLibrary"
@@ -632,7 +636,8 @@ serdes/meta:
(testing "Updating a PythonLibrary updates the RemoteSyncObject entry when setting is enabled"
(mt/with-premium-features #{:transforms-basic}
(mt/with-temporary-setting-values [remote-sync-transforms true
- remote-sync-enabled true]
+ remote-sync-enabled true
+ remote-sync-type :read-write]
(let [library (t2/insert-returning-instance! :model/PythonLibrary {:path "common.py" :source "# test"})]
(t2/update! :model/RemoteSyncObject {:model_type "PythonLibrary" :model_id (:id library)}
{:status "synced"})
@@ -732,7 +737,8 @@ serdes/meta:
(testing "Import updates local PythonLibrary when remote has same entity_id"
(mt/with-premium-features #{:transforms-basic}
(mt/with-temporary-setting-values [remote-sync-transforms true
- remote-sync-enabled true]
+ remote-sync-enabled true
+ remote-sync-type :read-write]
(mt/with-model-cleanup [:model/RemoteSyncTask]
(let [task-id (t2/insert-returning-pk! :model/RemoteSyncTask {:sync_task_type "import" :initiated_by (mt/user->id :rasta)})
local-library (t2/insert-returning-instance! :model/PythonLibrary {:path "common.py" :source "# local version"})
@@ -1066,7 +1072,8 @@ serdes/meta:
(testing "Creating, updating and deleting a transform test tracks it when remote-sync-transforms is enabled"
(mt/with-premium-features #{:transforms-basic}
(mt/with-temporary-setting-values [remote-sync-transforms true
- remote-sync-enabled true]
+ remote-sync-enabled true
+ remote-sync-type :read-write]
(mt/with-temp [:model/Transform {transform-id :id} {:name "Orders Summary"}
:model/TransformTest {test-id :id} {:transform_id transform-id :name "My test"}]
(is (= "create" (:status (transform-test-rso test-id))))
@@ -1083,7 +1090,8 @@ serdes/meta:
(testing "Deleting a transform marks its tests for deletion, so their files leave the branch with its own"
(mt/with-premium-features #{:transforms-basic}
(mt/with-temporary-setting-values [remote-sync-transforms true
- remote-sync-enabled true]
+ remote-sync-enabled true
+ remote-sync-type :read-write]
(mt/with-temp [:model/Transform {transform-id :id} {:name "Orders Summary"}
:model/TransformTest {test-id :id} {:transform_id transform-id :name "My test"}]
(t2/update! :model/RemoteSyncObject (:id (transform-test-rso test-id))
diff --git a/src/metabase/dashboards_rest/api.clj b/src/metabase/dashboards_rest/api.clj
index 3325521b2d2..6b29b7a54f2 100644
--- a/src/metabase/dashboards_rest/api.clj
+++ b/src/metabase/dashboards_rest/api.clj
@@ -1194,12 +1194,15 @@
(let [existing-public-uuid (dashboards-rest.db/dashboard-public-uuid dashboard-id)
uuid (or existing-public-uuid
(u/prog1 (str (random-uuid))
- (events/publish-event! :event/dashboard-public-link-created
- {:object-id dashboard-id
- :user-id api/*current-user-id*})
- (dashboards-rest.db/update-dashboard! dashboard-id
- {:public_uuid <>
- :made_public_by_id api/*current-user-id*})))]
+ ;; one transaction, so a failing handler cannot leave a saved link that a retry never reports
+ (t2/with-transaction [_conn]
+ (dashboards-rest.db/update-dashboard! dashboard-id
+ {:public_uuid <>
+ :made_public_by_id api/*current-user-id*})
+ (events/publish-event! :event/dashboard-public-link-created
+ {:object (dashboards-rest.db/dashboard dashboard-id)
+ :object-id dashboard-id
+ :user-id api/*current-user-id*}))))]
{:uuid uuid}))
;; TODO (Cam 10/28/25) -- fix this endpoint route to use kebab-case for consistency with the rest of our REST API
@@ -1216,12 +1219,14 @@
(perms/check-has-application-permission :setting)
(public-sharing.validation/check-public-sharing-enabled)
(api/check-exists? :model/Dashboard :id dashboard-id, :public_uuid [:not= nil], :archived false)
- (dashboards-rest.db/update-dashboard! dashboard-id
- {:public_uuid nil
- :made_public_by_id nil})
- (events/publish-event! :event/dashboard-public-link-deleted
- {:object-id dashboard-id
- :user-id api/*current-user-id*})
+ (t2/with-transaction [_conn]
+ (dashboards-rest.db/update-dashboard! dashboard-id
+ {:public_uuid nil
+ :made_public_by_id nil})
+ (events/publish-event! :event/dashboard-public-link-deleted
+ {:object (dashboards-rest.db/dashboard dashboard-id)
+ :object-id dashboard-id
+ :user-id api/*current-user-id*}))
{:status 204, :body nil})
;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to
diff --git a/src/metabase/events/schema.clj b/src/metabase/events/schema.clj
index 2adf7255003..f479e668a6a 100644
--- a/src/metabase/events/schema.clj
+++ b/src/metabase/events/schema.clj
@@ -76,15 +76,22 @@
[:user-id [:maybe pos-int?]]
[:object-id [:maybe pos-int?]]])
-(mr/def ::publicize
+(mr/def ::publicize-dashboard
[:map {:closed true}
[:user-id pos-int?]
- [:object-id pos-int?]])
+ [:object-id pos-int?]
+ [:object [:fn #(t2/instance-of? :model/Dashboard %)]]])
+
+(mr/def ::publicize-card
+ [:map {:closed true}
+ [:user-id pos-int?]
+ [:object-id pos-int?]
+ [:object [:fn #(t2/instance-of? :model/Card %)]]])
-(mr/def :event/dashboard-public-link-created ::publicize)
-(mr/def :event/dashboard-public-link-deleted ::publicize)
-(mr/def :event/card-public-link-created ::publicize)
-(mr/def :event/card-public-link-deleted ::publicize)
+(mr/def :event/dashboard-public-link-created ::publicize-dashboard)
+(mr/def :event/dashboard-public-link-deleted ::publicize-dashboard)
+(mr/def :event/card-public-link-created ::publicize-card)
+(mr/def :event/card-public-link-deleted ::publicize-card)
;; user events
diff --git a/src/metabase/queries/events/schema.clj b/src/metabase/queries/events/schema.clj
index 3a94bc2720e..f2f0576df2d 100644
--- a/src/metabase/queries/events/schema.clj
+++ b/src/metabase/queries/events/schema.clj
@@ -31,12 +31,11 @@
[:user-id [:maybe pos-int?]]
[:context {:optional true} :any]])
-(mr/def :event/card-public-link-created
+(mr/def ::publicize
[:map {:closed true}
[:user-id pos-int?]
- [:object-id pos-int?]])
+ [:object-id pos-int?]
+ [:object [:fn #(t2/instance-of? :model/Card %)]]])
-(mr/def :event/card-public-link-deleted
- [:map {:closed true}
- [:user-id pos-int?]
- [:object-id pos-int?]])
+(mr/def :event/card-public-link-created ::publicize)
+(mr/def :event/card-public-link-deleted ::publicize)
diff --git a/src/metabase/queries_rest/api/card.clj b/src/metabase/queries_rest/api/card.clj
index 82b1aff5f1c..fa0638c70e7 100644
--- a/src/metabase/queries_rest/api/card.clj
+++ b/src/metabase/queries_rest/api/card.clj
@@ -884,12 +884,15 @@
(let [{existing-public-uuid :public_uuid} (queries-rest.db/card-public-uuid-columns card-id)
uuid (or existing-public-uuid
(u/prog1 (str (random-uuid))
- (events/publish-event! :event/card-public-link-created
- {:object-id card-id
- :user-id api/*current-user-id*})
- (queries-rest.db/update-card! card-id
- {:public_uuid <>
- :made_public_by_id api/*current-user-id*})))]
+ ;; one transaction, so a failing handler cannot leave a saved link that a retry never reports
+ (t2/with-transaction [_conn]
+ (queries-rest.db/update-card! card-id
+ {:public_uuid <>
+ :made_public_by_id api/*current-user-id*})
+ (events/publish-event! :event/card-public-link-created
+ {:object (queries-rest.db/card card-id)
+ :object-id card-id
+ :user-id api/*current-user-id*}))))]
{:uuid uuid}))
;; TODO (Cam 10/28/25) -- fix this endpoint route to use kebab-case for consistency with the rest of our REST API
@@ -905,13 +908,15 @@
[:card-id ms/PositiveInt]]]
(perms/check-has-application-permission :setting)
(public-sharing.validation/check-public-sharing-enabled)
- (api/check-exists? :model/Card :id card-id, :public_uuid [:not= nil])
- (queries-rest.db/update-card! card-id
- {:public_uuid nil
- :made_public_by_id nil})
- (events/publish-event! :event/card-public-link-deleted
- {:object-id card-id
- :user-id api/*current-user-id*})
+ (api/check-exists? :model/Card :id card-id, :public_uuid [:not= nil], :archived false)
+ (t2/with-transaction [_conn]
+ (queries-rest.db/update-card! card-id
+ {:public_uuid nil
+ :made_public_by_id nil})
+ (events/publish-event! :event/card-public-link-deleted
+ {:object (queries-rest.db/card card-id)
+ :object-id card-id
+ :user-id api/*current-user-id*}))
{:status 204, :body nil})
;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to
diff --git a/test/metabase/queries_rest/api/card_test.clj b/test/metabase/queries_rest/api/card_test.clj
index 733eff985ad..a6bfafca9c6 100644
--- a/test/metabase/queries_rest/api/card_test.clj
+++ b/test/metabase/queries_rest/api/card_test.clj
@@ -3321,7 +3321,12 @@
(mt/user-http-request :rasta :delete 403 (format "card/%d/public_link" (u/the-id card)))))))
(testing "Endpoint should 404 if Card doesn't exist"
(is (= "Not found."
- (mt/user-http-request :crowberto :delete 404 (format "card/%d/public_link" Integer/MAX_VALUE))))))))
+ (mt/user-http-request :crowberto :delete 404 (format "card/%d/public_link" Integer/MAX_VALUE)))))
+ (testing "GHY-4650: Endpoint should 404 if Card is archived, as for dashboards"
+ (mt/with-temp [:model/Card card (assoc (shared-card) :archived true)]
+ (is (= "Not found."
+ (mt/user-http-request :crowberto :delete 404 (format "card/%d/public_link" (u/the-id card)))))
+ (is (some? (t2/select-one-fn :public_uuid :model/Card :id (u/the-id card)))))))))
(deftest share-card-audit-log-test
(testing "POST /api/card/:id/public_link creates audit log entry"