Skip to content

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

Allow remote syncing only the Library, transforms and other app namespaces unless custom collections are on (#84889)

Alexander Polyankin665818fa3fd0
diff --git a/e2e/support/helpers/e2e-data-app-helpers.ts b/e2e/support/helpers/e2e-data-app-helpers.ts
index f8f3d52e515..2454670e8f0 100644
--- a/e2e/support/helpers/e2e-data-app-helpers.ts
+++ b/e2e/support/helpers/e2e-data-app-helpers.ts
@@ -17,7 +17,7 @@ import type {
} from "metabase-types/api";
import { isObject } from "metabase-types/guards";
-import { createApiKey, createTestNativeQuery } from "./api";
+import { createApiKey, createTestNativeQuery, updateSetting } from "./api";
import type { DataAppTestEnv } from "./data-app-test-env";
import { getIframeBody } from "./e2e-embedding-helpers";
import {
@@ -618,6 +618,7 @@ export function pullExampleDataApps({
}: { goodAppCards?: ResourceEntity[] } = {}) {
setupGitSync();
copySyncedCollectionFixture();
+ updateSetting("remote-sync-custom-collections-enabled", true);
copySyncedDataAppsFixture();
if (goodAppCards) {
writeDataAppResources(LOCAL_GIT_PATH, {
@@ -672,6 +673,7 @@ function commitDataApp(
if (initializeRepo) {
setupGitSync();
copySyncedCollectionFixture();
+ updateSetting("remote-sync-custom-collections-enabled", true);
}
// A copy only adds, so a file the author deleted would stay in the repository.
cy.task("removeDataAppPaths", { paths: [collectionsDir] });
diff --git a/e2e/support/helpers/e2e-remote-sync-helpers.ts b/e2e/support/helpers/e2e-remote-sync-helpers.ts
index acf731edc34..6588d961c74 100644
--- a/e2e/support/helpers/e2e-remote-sync-helpers.ts
+++ b/e2e/support/helpers/e2e-remote-sync-helpers.ts
@@ -75,7 +75,7 @@ export const commitToRepo = (
export function configureGit(
syncType: "read-write" | "read-only",
syncUrl = "file://" + LOCAL_GIT_PATH + "/.git",
- collections?: Record<number, boolean>,
+ collections?: Record<string, boolean>,
) {
cy.request("PUT", "/api/ee/remote-sync/settings", {
"remote-sync-branch": "main",
diff --git a/e2e/test/scenarios/admin/remote-sync-setup.cy.spec.ts b/e2e/test/scenarios/admin/remote-sync-setup.cy.spec.ts
index ad5479d44c4..d5f9a5235e0 100644
--- a/e2e/test/scenarios/admin/remote-sync-setup.cy.spec.ts
+++ b/e2e/test/scenarios/admin/remote-sync-setup.cy.spec.ts
@@ -1,3 +1,5 @@
+import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
+
const { H } = cy;
const LOCAL_GIT_URL = "file://" + H.LOCAL_GIT_PATH + "/.git";
@@ -25,7 +27,7 @@ describe("Remote Sync first-time setup", () => {
});
it("sets up git sync from scratch, creating Library and syncing it with transforms", () => {
- H.updateSetting("remote-sync-collections-enabled", false);
+ H.updateSetting("remote-sync-custom-collections-enabled", false);
cy.visit("/admin/settings/remote-sync");
cy.findByLabelText(/repository url/i)
@@ -82,15 +84,14 @@ describe("Remote Sync first-time setup", () => {
});
it("opens branch picker after push while collections to sync are hidden", () => {
- H.updateSetting("remote-sync-collections-enabled", false);
- H.configureGitWithNewSyncedCollection("read-write");
+ H.updateSetting("remote-sync-custom-collections-enabled", false);
+ H.createLibrary().then(({ body: library }) => {
+ H.configureGit("read-write", LOCAL_GIT_URL, { [library.id]: true });
+ });
H.createBranchViaSettings("first-branch");
+ H.publishTables({ table_ids: [SAMPLE_DATABASE.PRODUCTS_ID] });
cy.visit("/collection/root");
- H.moveCollectionItemToSyncedCollection(
- "Orders, Count",
- "Test Synced Collection",
- );
H.clickPushOption();
H.modal()
.button(/Push changes/)
diff --git a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts b/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
index 1093010a27e..64b4e8621aa 100644
--- a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
+++ b/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
@@ -40,7 +40,7 @@ const setup = (snapshot = "default") => {
H.resetSnowplow();
cy.signInAsAdmin();
H.activateToken("pro-self-hosted");
- H.updateSetting("remote-sync-collections-enabled", true);
+ H.updateSetting("remote-sync-custom-collections-enabled", true);
H.setupGitSync();
H.interceptTask();
};
diff --git a/e2e/test/scenarios/data-apps/group-access.cy.spec.ts b/e2e/test/scenarios/data-apps/group-access.cy.spec.ts
index e8b5aad6eb4..6497439bbbd 100644
--- a/e2e/test/scenarios/data-apps/group-access.cy.spec.ts
+++ b/e2e/test/scenarios/data-apps/group-access.cy.spec.ts
@@ -14,6 +14,7 @@ describe("scenarios > data apps > group access (EMB-2415)", () => {
H.setupGitSync();
H.copySyncedCollectionFixture();
+ H.updateSetting("remote-sync-custom-collections-enabled", true);
H.writeDataAppResources(H.LOCAL_GIT_PATH, {
collection: H.dataAppRepresentations.collection(
diff --git a/e2e/test/scenarios/data-apps/sync.cy.spec.ts b/e2e/test/scenarios/data-apps/sync.cy.spec.ts
index c391d5607ca..5c142863b90 100644
--- a/e2e/test/scenarios/data-apps/sync.cy.spec.ts
+++ b/e2e/test/scenarios/data-apps/sync.cy.spec.ts
@@ -16,6 +16,7 @@ describe("scenarios > data apps > repo sync", () => {
it("materializes each app with its bundle, then removes an app whose files are removed from the repo on the next sync", () => {
H.copySyncedCollectionFixture();
+ H.updateSetting("remote-sync-custom-collections-enabled", true);
H.copySyncedDataAppsFixture();
H.commitToRepo("Add data apps");
H.configureGitAndPullChanges("read-write");
diff --git a/e2e/test/scenarios/data-apps/user-access.cy.spec.ts b/e2e/test/scenarios/data-apps/user-access.cy.spec.ts
index c7ce75dd8ca..ea5837cc535 100644
--- a/e2e/test/scenarios/data-apps/user-access.cy.spec.ts
+++ b/e2e/test/scenarios/data-apps/user-access.cy.spec.ts
@@ -14,6 +14,7 @@ describe("scenarios > data apps > authentication", () => {
beforeEach(() => {
H.setupGitSync();
H.copySyncedCollectionFixture();
+ H.updateSetting("remote-sync-custom-collections-enabled", true);
H.copySyncedDataAppsFixture();
cy.task("writeDataAppFiles", {
files: {
diff --git a/e2e/test/scenarios/embedding/tenant-users-sidecar.cy.spec.ts b/e2e/test/scenarios/embedding/tenant-users-sidecar.cy.spec.ts
index 4a47fba053e..568f81fa4e8 100644
--- a/e2e/test/scenarios/embedding/tenant-users-sidecar.cy.spec.ts
+++ b/e2e/test/scenarios/embedding/tenant-users-sidecar.cy.spec.ts
@@ -136,6 +136,7 @@ describe("scenarios > sidecar > tenant users", () => {
// Setup git sync
H.setupGitSync();
H.copySyncedCollectionFixture();
+ H.updateSetting("remote-sync-custom-collections-enabled", true);
H.commitToRepo();
// Make shared tenant collections synced
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/core.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/core.clj
index 0cdb88cae38..c555a5fec57 100644
--- a/enterprise/backend/src/metabase_enterprise/remote_sync/core.clj
+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/core.clj
@@ -38,6 +38,15 @@
(or (= (settings/remote-sync-type) :read-write)
(not (collections/remote-synced-collection? collection))))
+(defenterprise collection-syncable?
+ "Whether `collection` can be remote-synced: a Collection of a namespace remote sync syncs, the Library and every Collection inside it, and any other once custom collections are on."
+ :feature :none
+ [{:keys [location] :as collection}]
+ (or (not (settings/custom-collection? collection))
+ (settings/remote-sync-custom-collections-enabled)
+ (= collections/library-collection-type
+ (some-> location collections/location-path->ids first collections/root-collection-type-by-id))))
+
(defenterprise table-editable?
"Determines if a table's metadata should be editable.
@@ -456,6 +465,9 @@
(when (some spec/data-apps-namespace-collection? sync-on)
(throw (ex-info (tru "A data app''s collection is synced with its app and can''t be marked as synced.")
{:status-code 400})))
+ (doseq [collection sync-on
+ :when (not (:is_remote_synced collection))]
+ (collections/assert-remote-syncable (assoc collection :is_remote_synced true)))
(try
(t2/with-transaction [_]
(when (seq sync-on)
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj
index ed30c2c1298..a1b4b2d624b 100644
--- a/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj
+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/db.clj
@@ -462,6 +462,11 @@
[]
(t2/select-pks-vec :model/Collection :is_remote_synced true))
+(mu/defn remote-synced-root-collections
+ "The `:namespace` and `:type` of the remote-synced top-level Collections."
+ []
+ (t2/select [:model/Collection :id :namespace :type] :is_remote_synced true :location "/"))
+
(mu/defn unarchived-remote-synced-root-collection-ids
"The IDs of the unarchived remote-synced root Collections."
[]
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/init.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/init.clj
index 235a91b4651..55bf9e64ba1 100644
--- a/enterprise/backend/src/metabase_enterprise/remote_sync/init.clj
+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/init.clj
@@ -42,47 +42,46 @@
(defn- remote-sync-init []
;; Only stale rows: a fresh open row may belong to a worker on another node sharing this app DB.
(remote-sync.task/supersede-stale-tasks!)
- (settings/pin-remote-sync-collections-enabled!)
+ (when (and (not (settings/remote-sync-enabled)) (collection/has-remote-synced-collection?))
+ (log/info "Remote sync is disabled but a remote-synced collection exists. Marking collections as not remote-sync.")
+ (collection/clear-remote-synced-collection!))
+ (settings/pin-remote-sync-custom-collections-enabled!)
(events/convert-legacy-transforms-root!)
- (if (settings/remote-sync-enabled)
- (do
- (when (= :read-only (settings/remote-sync-type))
- (let [branch (settings/remote-sync-branch)]
- (when (str/blank? branch)
- (throw (ex-info "Remote sync is enabled with read-only type, but no branch is set." {})))
- (when (remote-sync.object/dirty?)
- (if (some-> (settings/remote-sync-allow) (str/includes? "overwrite-unpublished"))
- (impl/async-import! branch true {}
- :on-success (fn [task-id _result]
- (impl/publish-sync-event! :event/remote-sync-import task-id
- {:branch branch :auto true} nil)))
- (throw (ex-info "Remote sync is enabled with read-only type, but there are unpublished changes. To force an overwrite, set `MB_REMOTE_SYNC_ALLOW=overwrite-unpublished`" {}))))))
- ;; Read-only instances are skipped: a dirty ledger would fail the check above, and their next full pull
- ;; rebuilds the ledger anyway.
- (when (and (= :read-write (settings/remote-sync-type))
- (settings/library-is-remote-synced?))
- (let [n (events/backfill-glossary-tracking!)]
- (when (pos? n)
- (log/infof "Tracking %d existing glossary entries for remote sync" n))))
- (when (= :read-write (settings/remote-sync-type))
- (let [n (events/backfill-action-tracking!)]
- (when (pos? n)
- (log/infof "Tracking %d existing actions for remote sync" n)))
- (let [n (events/backfill-data-app-tracking!)]
- (when (pos? n)
- (log/infof "Tracking %d existing data apps for remote sync" n))))
- (when-not (collection/has-remote-synced-collection?)
- (if (nil? (settings/remote-sync-branch))
- (log/warn "Remote sync is enabled but no remote-sync branch is set. Cannot do initial import.")
- (let [branch (settings/remote-sync-branch)]
- (log/info "Remote sync is enabled but no remote-sync collection exists. Importing")
+ (when (settings/remote-sync-enabled)
+ (when (= :read-only (settings/remote-sync-type))
+ (let [branch (settings/remote-sync-branch)]
+ (when (str/blank? branch)
+ (throw (ex-info "Remote sync is enabled with read-only type, but no branch is set." {})))
+ (when (remote-sync.object/dirty?)
+ (if (some-> (settings/remote-sync-allow) (str/includes? "overwrite-unpublished"))
(impl/async-import! branch true {}
:on-success (fn [task-id _result]
(impl/publish-sync-event! :event/remote-sync-import task-id
- {:branch branch :auto true} nil)))))))
- (when (collection/has-remote-synced-collection?)
- (log/info "Remote sync is disabled but a remote-synced collection exists. Marking collections as not remote-sync.")
- (collection/clear-remote-synced-collection!))))
+ {:branch branch :auto true} nil)))
+ (throw (ex-info "Remote sync is enabled with read-only type, but there are unpublished changes. To force an overwrite, set `MB_REMOTE_SYNC_ALLOW=overwrite-unpublished`" {}))))))
+ ;; Read-only instances are skipped: a dirty ledger would fail the check above, and their next full pull
+ ;; rebuilds the ledger anyway.
+ (when (and (= :read-write (settings/remote-sync-type))
+ (settings/library-is-remote-synced?))
+ (let [n (events/backfill-glossary-tracking!)]
+ (when (pos? n)
+ (log/infof "Tracking %d existing glossary entries for remote sync" n))))
+ (when (= :read-write (settings/remote-sync-type))
+ (let [n (events/backfill-action-tracking!)]
+ (when (pos? n)
+ (log/infof "Tracking %d existing actions for remote sync" n)))
+ (let [n (events/backfill-data-app-tracking!)]
+ (when (pos? n)
+ (log/infof "Tracking %d existing data apps for remote sync" n))))
+ (when-not (collection/has-remote-synced-collection?)
+ (if (nil? (settings/remote-sync-branch))
+ (log/warn "Remote sync is enabled but no remote-sync branch is set. Cannot do initial import.")
+ (let [branch (settings/remote-sync-branch)]
+ (log/info "Remote sync is enabled but no remote-sync collection exists. Importing")
+ (impl/async-import! branch true {}
+ :on-success (fn [task-id _result]
+ (impl/publish-sync-event! :event/remote-sync-import task-id
+ {:branch branch :auto true} nil))))))))
(SystemReader/setInstance (create-isolated-system-reader))
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/settings.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/settings.clj
index 58e6bf62dea..77064048f05 100644
--- a/enterprise/backend/src/metabase_enterprise/remote_sync/settings.clj
+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/settings.clj
@@ -1,11 +1,13 @@
(ns metabase-enterprise.remote-sync.settings
(:require
[clojure.string :as str]
+ [metabase-enterprise.remote-sync.db :as remote-sync.db]
[metabase-enterprise.remote-sync.guards :as guards]
[metabase-enterprise.remote-sync.source.git :as git]
[metabase.collections.models.collection :as collection]
[metabase.settings.core :as setting :refer [defsetting]]
- [metabase.util.i18n :refer [deferred-tru]]
+ [metabase.startup.core :as startup]
+ [metabase.util.i18n :refer [deferred-tru tru]]
[toucan2.core :as t2]))
(set! *warn-on-reflection* true)
@@ -104,19 +106,52 @@
:encryption :no
:default false)
-(defsetting remote-sync-collections-enabled
- (deferred-tru "Whether git sync settings let admins choose collections to sync, besides the Library and transforms.")
+(def ^:private syncable-namespaces
+ "The Collection namespaces remote sync syncs without custom collections."
+ #{(name collection/transforms-ns) (name collection/snippets-ns) (name collection/data-actions-ns) (name collection/data-apps-ns)})
+
+(defn custom-collection?
+ "Whether `collection` is one remote sync syncs only with custom collections on: outside the namespaces it syncs and not of a Library type."
+ [collection]
+ (not (or (contains? syncable-namespaces (some-> (:namespace collection) name))
+ (contains? collection/library-collection-types (:type collection)))))
+
+(defn- custom-collections-synced?
+ "Whether a top-level custom collection is remote-synced."
+ []
+ (boolean (some custom-collection? (remote-sync.db/remote-synced-root-collections))))
+
+(defn check-custom-collections-unsynced!
+ "Throws when a top-level custom collection is remote-synced."
+ []
+ (when (custom-collections-synced?)
+ (throw (ex-info (tru "Stop syncing the collections besides the Library, transforms, snippets and data apps before turning off remote-sync-custom-collections-enabled.")
+ {:status-code 400}))))
+
+(defsetting remote-sync-custom-collections-enabled
+ (deferred-tru "Whether remote sync can sync collections besides the Library, transforms, snippets and data apps. When off, no other collection can be marked as synced, and a pull or a serialization import refuses content with other synced collections, so set `MB_REMOTE_SYNC_CUSTOM_COLLECTIONS_ENABLED=true` on an instance that pulls or imports such content. It can only be turned off once no other collection is synced.")
:type :boolean
:visibility :admin
:export? false
:encryption :no
- :default false)
-
-(defn pin-remote-sync-collections-enabled!
- "Stores [[remote-sync-collections-enabled]] when nothing has set it yet, enabled only where remote sync is already configured."
+ :default false
+ :setter (fn [new-value]
+ (when-not (if (string? new-value) (setting/string->boolean new-value) new-value)
+ (check-custom-collections-unsynced!))
+ (setting/set-value-of-type! :boolean :remote-sync-custom-collections-enabled new-value)))
+
+(defmethod startup/def-startup-validation! ::remote-sync-custom-collections-enabled
+ [_]
+ (when (and (remote-sync-enabled)
+ (not= :default (setting/get-raw-value-source :remote-sync-custom-collections-enabled))
+ (not (remote-sync-custom-collections-enabled)))
+ (check-custom-collections-unsynced!)))
+
+(defn pin-remote-sync-custom-collections-enabled!
+ "Stores [[remote-sync-custom-collections-enabled]] when nothing has set it yet, enabled only where custom collections are already synced."
[]
- (when (= :default (setting/get-raw-value-source :remote-sync-collections-enabled))
- (remote-sync-collections-enabled! (remote-sync-enabled))))
+ (when (= :default (setting/get-raw-value-source :remote-sync-custom-collections-enabled))
+ (remote-sync-custom-collections-enabled! (custom-collections-synced?))))
(defsetting remote-sync-check-changes-cache-ttl-seconds
(deferred-tru "Time-to-live in seconds for the remote changes check cache. Default is 60 seconds.")
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 0986c49c07a..7113f031291 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj
@@ -17,6 +17,7 @@
[metabase-enterprise.remote-sync.spec :as spec]
[metabase-enterprise.remote-sync.test-helpers :as test-helpers]
[metabase.driver.settings :as driver.settings]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.settings.core :as setting]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]
@@ -52,6 +53,7 @@
(f))))
(use-fixtures :each
+ remote-sync.tu/allow-remote-synced-collections
test-helpers/clean-remote-sync-state
(fn [f]
(mt/with-premium-features #{:remote-sync}
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/cache_api_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/cache_api_test.clj
index b188b4a9022..4cc75fecea5 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/cache_api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/cache_api_test.clj
@@ -2,8 +2,11 @@
(:require
[clojure.test :refer :all]
[metabase-enterprise.remote-sync.settings :as rs-settings]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]))
+(use-fixtures :each remote-sync.tu/allow-remote-synced-collections)
+
(deftest cache-policy-on-read-only-remote-synced-dashboard-test
(testing "Setting a cache policy on a dashboard in a remote-synced collection should succeed even when remote-sync-type is read-only"
(mt/with-model-cleanup [:model/CacheConfig]
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/card_api_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/card_api_test.clj
index 74be138a6fb..83aafb8b8bb 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/card_api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/card_api_test.clj
@@ -2,12 +2,14 @@
{:clj-kondo/config '{:linters {:deprecated-var {:exclude {metabase.test.data/mbql-query {:namespaces [metabase-enterprise.remote-sync.card-api-test]}}}}}}
(:require
[clojure.test :refer :all]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[toucan2.core :as t2]))
-(use-fixtures :each (fn [f]
- (mt/with-temporary-setting-values [remote-sync-type :read-write]
- (f))))
+(use-fixtures :each
+ remote-sync.tu/allow-remote-synced-collections (fn [f]
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (f))))
(deftest bulk-move-into-remote-synced-with-non-remote-synced-deps-test
(testing "POST /api/card/collections rejects bulk-moving a card with non-remote-synced dependencies into a remote-synced collection (GHY-3791)"
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/collection_api_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/collection_api_test.clj
index 05fad75f132..124ca24e10f 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/collection_api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/collection_api_test.clj
@@ -9,12 +9,14 @@
[metabase-enterprise.remote-sync.test-helpers :as test-helpers]
[metabase.collections.models.collection :as collection]
[metabase.events.core :as events]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[metabase.util :as u]
[metabase.util.yaml :as yaml]
[toucan2.core :as t2]))
(use-fixtures :each
+ remote-sync.tu/allow-remote-synced-collections
(fn [f]
(mt/with-temporary-setting-values [settings/remote-sync-type :read-write]
(f))))
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 af9b37d9255..e482a04caff 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
@@ -21,11 +21,14 @@
[metabase.collections.models.collection :as collection]
[metabase.collections.test-utils :refer [with-library-synced]]
[metabase.events.core :as events]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]
[metabase.util :as u]
[toucan2.core :as t2]))
+(use-fixtures :each remote-sync.tu/allow-remote-synced-collections)
+
(use-fixtures :once (fixtures/initialize :db))
(defn- noop-update-status!
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/core_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/core_test.clj
index def0e24bd9b..a332a4060fd 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/core_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/core_test.clj
@@ -10,6 +10,7 @@
[metabase.collections.models.collection :as collection]
[metabase.collections.test-utils :refer [with-library with-library-synced with-library-not-synced]]
[metabase.events.core :as events]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]
[toucan2.core :as t2]))
@@ -17,7 +18,8 @@
(use-fixtures :once (fixtures/initialize :db))
;; Disabling a collection now marks its RemoteSyncObject rows rather than deleting them, so rows seeded by
;; a test outlive it without this — leaking dirty state into every later test.
-(use-fixtures :each rs.test/clean-object)
+(use-fixtures :each
+ remote-sync.tu/allow-remote-synced-collections rs.test/clean-object)
;; bulk-set-remote-sync tests
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/custom_collections_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/custom_collections_test.clj
new file mode 100644
index 00000000000..6445ff5b2d8
--- /dev/null
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/custom_collections_test.clj
@@ -0,0 +1,125 @@
+(ns metabase-enterprise.remote-sync.custom-collections-test
+ (:require
+ [clojure.test :refer :all]
+ [metabase-enterprise.remote-sync.impl :as impl]
+ [metabase-enterprise.remote-sync.settings :as settings]
+ [metabase-enterprise.remote-sync.source :as source]
+ [metabase-enterprise.remote-sync.source.protocol :as source.p]
+ [metabase-enterprise.remote-sync.test-helpers :as test-helpers]
+ [metabase.collections.models.collection :as collection]
+ [metabase.startup.core :as startup]
+ [metabase.test :as mt]
+ [toucan2.core :as t2]))
+
+(set! *warn-on-reflection* true)
+
+(use-fixtures :each
+ test-helpers/clean-remote-sync-state
+ (fn [f]
+ (mt/with-premium-features #{:remote-sync}
+ (f))))
+
+(defn- do-without-library
+ [thunk]
+ (let [library-ids (t2/select-pks-vec :model/Collection :type collection/library-collection-type)
+ library (when (seq library-ids)
+ (t2/select :model/Collection {:where [:or
+ [:in :id library-ids]
+ [:like :location (str "/" (first library-ids) "/%")]]}))]
+ (t2/delete! :model/Collection :id [:in (map :id library)])
+ (try
+ (thunk)
+ (finally
+ (t2/delete! :model/Collection :type [:in (vec collection/library-collection-types)])
+ (when (seq library)
+ (t2/insert! :model/Collection library))))))
+
+(deftest rejects-custom-synced-collection-test
+ (mt/with-model-cleanup [:model/Collection]
+ (mt/with-temporary-setting-values [remote-sync-url nil]
+ (is (thrown-with-msg? clojure.lang.ExceptionInfo #"syncs only the Library"
+ (t2/insert! :model/Collection {:name "Custom" :location "/" :is_remote_synced true})))
+ (mt/with-premium-features #{:remote-sync :tenants}
+ (mt/with-temporary-setting-values [use-tenants true]
+ (is (thrown-with-msg? clojure.lang.ExceptionInfo #"syncs only the Library"
+ (t2/insert! :model/Collection {:name "Tenant" :location "/" :namespace "shared-tenant-collection"
+ :is_remote_synced true})))))
+ (mt/with-temp [:model/Collection {coll-id :id} {:location "/"}]
+ (is (thrown-with-msg? clojure.lang.ExceptionInfo #"syncs only the Library"
+ (t2/update! :model/Collection coll-id {:type "remote-synced"})))))))
+
+(deftest keeps-synced-collections-editable-test
+ (mt/with-temp [:model/Collection {coll-id :id} {:location "/"}]
+ (t2/query {:update :collection :set {:is_remote_synced true} :where [:= :id coll-id]})
+ (t2/update! :model/Collection coll-id {:name "Renamed"})
+ (is (= "Renamed" (t2/select-one-fn :name :model/Collection :id coll-id)))
+ (t2/update! :model/Collection coll-id {:is_remote_synced false})
+ (is (false? (t2/select-one-fn :is_remote_synced :model/Collection :id coll-id)))))
+
+(deftest allows-library-and-other-namespaces-test
+ (mt/with-temp [:model/Collection {snippets-id :id} {:location "/" :namespace "snippets" :is_remote_synced true}]
+ (is (true? (t2/select-one-fn :is_remote_synced :model/Collection :id snippets-id))))
+ (do-without-library
+ (fn []
+ (let [library (collection/create-library-collection!)
+ data (t2/select-one :model/Collection :type collection/library-data-collection-type)]
+ (t2/update! :model/Collection (:id library) {:is_remote_synced true})
+ (t2/update! :model/Collection (:id data) {:is_remote_synced true})
+ (is (true? (t2/select-one-fn :is_remote_synced :model/Collection :id (:id data))))
+ (mt/with-temp [:model/Collection {inner-id :id} {:location (str (:location data) (:id data) "/") :type nil :is_remote_synced true}]
+ (is (true? (t2/select-one-fn :is_remote_synced :model/Collection :id inner-id))))))))
+
+(deftest allows-custom-synced-collection-when-enabled-test
+ (mt/with-temporary-setting-values [remote-sync-custom-collections-enabled true]
+ (mt/with-temp [:model/Collection {coll-id :id} {:location "/" :is_remote_synced true}]
+ (is (true? (t2/select-one-fn :is_remote_synced :model/Collection :id coll-id))))))
+
+(deftest settings-reject-custom-collection-test
+ (mt/with-dynamic-fn-redefs [settings/check-git-settings! (constantly nil)
+ source/source-from-settings (constantly (test-helpers/create-mock-source))
+ impl/finish-remote-config! (constantly nil)]
+ (mt/with-temporary-setting-values [remote-sync-url "https://github.com/test/repo.git" remote-sync-type :read-write]
+ (mt/with-temp [:model/Collection {coll-id :id} {:location "/"}]
+ (mt/user-http-request :crowberto :put 400 "ee/remote-sync/settings" {:collections {coll-id true}})
+ (is (false? (t2/select-one-fn :is_remote_synced :model/Collection :id coll-id)))))))
+
+(deftest turning-off-requires-no-custom-synced-collections-test
+ (mt/with-temporary-setting-values [remote-sync-custom-collections-enabled true]
+ (mt/with-temp [:model/Collection {coll-id :id} {:location "/" :is_remote_synced true}]
+ (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Stop syncing the collections"
+ (settings/remote-sync-custom-collections-enabled! false)))
+ (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Stop syncing the collections"
+ (settings/remote-sync-custom-collections-enabled! "false")))
+ (mt/user-http-request :crowberto :put 400 "setting/remote-sync-custom-collections-enabled" {:value false})
+ (is (true? (settings/remote-sync-custom-collections-enabled)))
+ (t2/update! :model/Collection coll-id {:is_remote_synced false})
+ (settings/remote-sync-custom-collections-enabled! false)
+ (is (false? (settings/remote-sync-custom-collections-enabled))))))
+
+(deftest env-var-requires-no-custom-synced-collections-test
+ (mt/with-temporary-setting-values [remote-sync-url "https://github.com/test/repo.git"
+ remote-sync-custom-collections-enabled true]
+ (mt/with-temp [:model/Collection _ {:location "/" :is_remote_synced true}]
+ (mt/with-temp-env-var-value! [mb-remote-sync-custom-collections-enabled "false"]
+ (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Stop syncing the collections"
+ (startup/def-startup-validation! ::settings/remote-sync-custom-collections-enabled)))))))
+
+(deftest stored-value-requires-no-custom-synced-collections-test
+ (mt/with-temporary-setting-values [remote-sync-url "https://github.com/test/repo.git"
+ remote-sync-custom-collections-enabled true]
+ (mt/with-temp [:model/Collection _ {:location "/" :is_remote_synced true}]
+ (mt/with-temporary-raw-setting-values [remote-sync-custom-collections-enabled "false"]
+ (is (thrown-with-msg? clojure.lang.ExceptionInfo #"Stop syncing the collections"
+ (startup/def-startup-validation! ::settings/remote-sync-custom-collections-enabled)))))))
+
+(deftest pull-rejects-custom-collection-test
+ (mt/with-temporary-setting-values [remote-sync-url "https://github.com/test/repo.git" remote-sync-type :read-only
+ remote-sync-branch "main"]
+ (let [mock-source (test-helpers/create-mock-source
+ :initial-files {"main" {"collections/main/custom.yaml"
+ (test-helpers/generate-collection-yaml "customCollectionxxxx1" "Custom"
+ :is-remote-synced true)}})
+ task-id (t2/insert-returning-pk! :model/RemoteSyncTask {:sync_task_type "import" :initiated_by (mt/user->id :rasta)})]
+ (is (=? {:status :error :message #"Import failed: could not save Collection `Custom`.*syncs only the Library.*"}
+ (impl/import! (source.p/snapshot mock-source) task-id)))
+ (is (not (t2/exists? :model/Collection :entity_id "customCollectionxxxx1"))))))
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/dashboard_api_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/dashboard_api_test.clj
index 06515ea17d6..a14f1907671 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/dashboard_api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/dashboard_api_test.clj
@@ -3,12 +3,14 @@
(:require
[clojure.string :as str]
[clojure.test :refer :all]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[toucan2.core :as t2]))
-(use-fixtures :each (fn [f]
- (mt/with-temporary-setting-values [remote-sync-type :read-write]
- (f))))
+(use-fixtures :each
+ remote-sync.tu/allow-remote-synced-collections (fn [f]
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (f))))
(deftest api-update-dashboard-collection-id-remote-synced-dependency-checking-success-test
(testing "PUT /api/dashboard/:id with collection_id in remote-synced succeeds when all dependencies are in remote-synced"
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/data_apps_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/data_apps_test.clj
index 4b7c76473a3..72b3650e3a9 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/data_apps_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/data_apps_test.clj
@@ -20,6 +20,7 @@
[metabase.lib.core :as lib]
[metabase.lib.metadata :as lib.metadata]
[metabase.permissions.core :as perms]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.search.test-util :as search.tu]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]
@@ -30,7 +31,8 @@
(set! *warn-on-reflection* true)
(use-fixtures :once (fixtures/initialize :db))
-(use-fixtures :each test-helpers/clean-remote-sync-state test-helpers/commit-with-temp)
+(use-fixtures :each
+ remote-sync.tu/allow-remote-synced-collections test-helpers/clean-remote-sync-state test-helpers/commit-with-temp)
(def ^:private sales-eid "w8YkMQBwU4kOD0-pZ1nJk")
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 907c667f029..85d45d84247 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/events_test.clj
@@ -12,12 +12,15 @@
[metabase.collections.models.collection :as collection]
[metabase.collections.test-utils :refer [with-library-synced]]
[metabase.events.core :as events]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]
[metabase.test.util.thread-local :as tu.thread-local]
[metabase.util :as u]
[toucan2.core :as t2]))
+(use-fixtures :each remote-sync.tu/allow-remote-synced-collections)
+
(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
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 23ebdbd4f19..c4a541f9ec6 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/glossary_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/glossary_test.clj
@@ -15,6 +15,7 @@
[metabase.collections.test-utils :as collections.tu]
[metabase.events.core :as events]
[metabase.glossary.core :as glossary.core]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.search.core :as search]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]
@@ -33,9 +34,10 @@
(finally
(t2/delete! :model/RemoteSyncObject))))
-(use-fixtures :each (fn [f]
- (mt/with-dynamic-fn-redefs [search/reindex! (constantly nil)]
- (clean-remote-sync-state f)))
+(use-fixtures :each
+ remote-sync.tu/allow-remote-synced-collections (fn [f]
+ (mt/with-dynamic-fn-redefs [search/reindex! (constantly nil)]
+ (clean-remote-sync-state f)))
test-helpers/commit-with-temp)
(defn- rso [entry]
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/impl_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/impl_test.clj
index d937f0362bb..ef2284430ca 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/impl_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/impl_test.clj
@@ -16,6 +16,7 @@
[metabase.collections.models.collection :as collection]
[metabase.models.serialization :as serdes]
[metabase.models.serialization.resolve :as resolve]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.search.core :as search]
[metabase.settings.core :as setting]
[metabase.test :as mt]
@@ -27,9 +28,10 @@
(use-fixtures :once (fixtures/initialize :db))
;; `reindex!` below is ok in a parallel test since it's not actually executing anything
-(use-fixtures :each (fn [f]
- (mt/with-dynamic-fn-redefs [search/reindex! (constantly nil)]
- (test-helpers/clean-remote-sync-state f))))
+(use-fixtures :each
+ remote-sync.tu/allow-remote-synced-collections (fn [f]
+ (mt/with-dynamic-fn-redefs [search/reindex! (constantly nil)]
+ (test-helpers/clean-remote-sync-state f))))
;; import! tests
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/incremental_export_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/incremental_export_test.clj
index f9853309c02..aaa7868d980 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/incremental_export_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/incremental_export_test.clj
@@ -12,13 +12,15 @@
[metabase-enterprise.remote-sync.models.remote-sync-object :as remote-sync.object]
[metabase-enterprise.remote-sync.source.protocol :as source.p]
[metabase-enterprise.remote-sync.test-helpers :as rs.test]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]
[metabase.util.yaml :as yaml]
[toucan2.core :as t2]))
(use-fixtures :once (fixtures/initialize :db))
-(use-fixtures :each rs.test/clean-remote-sync-state rs.test/commit-with-temp)
+(use-fixtures :each
+ remote-sync.tu/allow-remote-synced-collections rs.test/clean-remote-sync-state rs.test/commit-with-temp)
(defn- venues-query []
{:database (mt/id) :type :query :query {:source-table (mt/id :venues)}})
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/incremental_import_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/incremental_import_test.clj
index 5ea61458a9a..0c06f8d1eab 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/incremental_import_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/incremental_import_test.clj
@@ -29,6 +29,7 @@
[metabase-enterprise.remote-sync.source.protocol :as source.p]
[metabase-enterprise.remote-sync.spec :as spec]
[metabase-enterprise.remote-sync.test-helpers :as rs.test]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.search.core :as search]
[metabase.search.test-util :as search.tu]
[metabase.test :as mt]
@@ -36,7 +37,8 @@
[toucan2.core :as t2]))
(use-fixtures :once (fixtures/initialize :db))
-(use-fixtures :each rs.test/clean-remote-sync-state rs.test/commit-with-temp)
+(use-fixtures :each
+ remote-sync.tu/allow-remote-synced-collections rs.test/clean-remote-sync-state rs.test/commit-with-temp)
;;; ------------------------------------------------- State capture --------------------------------------------------
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/init_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/init_test.clj
index eb23365b334..df69df205aa 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/init_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/init_test.clj
@@ -10,6 +10,7 @@
[metabase-enterprise.remote-sync.test-helpers :as th]
[metabase.collections.models.collection :as collection]
[metabase.collections.test-utils :as collections.tu]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.settings.core :as setting]
[metabase.startup.core :as startup]
[metabase.test :as mt]
@@ -19,7 +20,8 @@
(set! *warn-on-reflection* true)
(use-fixtures :once (fixtures/initialize :db))
-(use-fixtures :each th/clean-remote-sync-state)
+(use-fixtures :each
+ remote-sync.tu/allow-remote-synced-collections th/clean-remote-sync-state)
(defn- capture-async-import! []
(let [calls (atom [])]
@@ -43,20 +45,21 @@
(#'init/remote-sync-init)
(is (empty? @calls)))))))
-(deftest pin-remote-sync-collections-enabled-test
- (testing "First startup stores whether remote sync was already configured, so existing setups keep choosing collections"
- (doseq [[url expected] [["https://github.com/foo/bar.git" true] [nil false]]]
- (testing (pr-str url)
- (mt/with-temporary-setting-values [:remote-sync-url url
- :remote-sync-collections-enabled nil]
- (settings/pin-remote-sync-collections-enabled!)
- (is (= :database (setting/get-raw-value-source :remote-sync-collections-enabled)))
- (is (= expected (settings/remote-sync-collections-enabled)))))))
+(deftest pin-remote-sync-custom-collections-enabled-test
+ (testing "First startup stores whether custom collections are already synced"
+ (doseq [synced? [true false]]
+ (testing (pr-str synced?)
+ (mt/with-temporary-setting-values [:remote-sync-url "https://github.com/foo/bar.git"
+ :remote-sync-custom-collections-enabled nil]
+ (mt/with-temp [:model/Collection _ {:location "/" :is_remote_synced synced?}]
+ (settings/pin-remote-sync-custom-collections-enabled!)
+ (is (= :database (setting/get-raw-value-source :remote-sync-custom-collections-enabled)))
+ (is (= synced? (settings/remote-sync-custom-collections-enabled))))))))
(testing "Later startups keep stored value"
(mt/with-temporary-setting-values [:remote-sync-url nil
- :remote-sync-collections-enabled true]
- (settings/pin-remote-sync-collections-enabled!)
- (is (true? (settings/remote-sync-collections-enabled))))))
+ :remote-sync-custom-collections-enabled true]
+ (settings/pin-remote-sync-custom-collections-enabled!)
+ (is (true? (settings/remote-sync-custom-collections-enabled))))))
(deftest remote-sync-init-read-only-without-branch-throws-test
(testing "Read-only with enabled sync but no branch throws"
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/metric_dimension_api_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/metric_dimension_api_test.clj
index 2f8bcfb5ba7..e9b5eae58b5 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/metric_dimension_api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/metric_dimension_api_test.clj
@@ -10,6 +10,7 @@
[metabase.lib.core :as lib]
[metabase.lib.metadata :as lib.metadata]
[metabase.metrics.core :as metrics]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]
[metabase.util :as u]
@@ -17,9 +18,10 @@
(use-fixtures :once (fixtures/initialize :db :web-server :test-users))
-(use-fixtures :each (fn [thunk]
- (mt/with-temporary-setting-values [remote-sync-type :read-write]
- (thunk))))
+(use-fixtures :each
+ remote-sync.tu/allow-remote-synced-collections (fn [thunk]
+ (mt/with-temporary-setting-values [remote-sync-type :read-write]
+ (thunk))))
(defn- metric-query []
(let [mp (mt/metadata-provider)]
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/permissions_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/permissions_test.clj
index 8bcd4edc239..f1ff5f45952 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/permissions_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/permissions_test.clj
@@ -7,9 +7,12 @@
[metabase.collections.test-utils :as collections.tu]
[metabase.lib.core :as lib]
[metabase.models.interface :as mi]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[toucan2.core :as t2]))
+(use-fixtures :each remote-sync.tu/allow-remote-synced-collections)
+
(defn- text->prose-mirror-ast
"Convert text to a simple ProseMirror AST for document content."
[text]
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/snippets_api_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/snippets_api_test.clj
index 82a8f501642..330edb2f565 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/snippets_api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/snippets_api_test.clj
@@ -7,12 +7,15 @@
[metabase.permissions.models.data-permissions :as data-perms]
[metabase.permissions.models.permissions :as perms]
[metabase.permissions.models.permissions-group :as perms-group]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[metabase.util :as u]
[toucan2.core :as t2]))
;;; ------------------------------------------- Create Snippet API Tests -------------------------------------------
+(use-fixtures :each remote-sync.tu/allow-remote-synced-collections)
+
(deftest create-snippet-blocked-in-read-only-mode-test
(testing "POST /api/native-query-snippet"
(testing "Creating a snippet is blocked when library is synced and mode is read-only"
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 19378fbddc5..d92ba18e886 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/snippets_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/snippets_test.clj
@@ -22,6 +22,7 @@
[metabase.collections.test-utils :as collections.tu]
[metabase.events.core :as events]
[metabase.models.serialization :as serdes]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.search.core :as search]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]
@@ -39,9 +40,10 @@
(finally
(t2/delete! :model/RemoteSyncObject))))
-(use-fixtures :each (fn [f]
- (mt/with-dynamic-fn-redefs [search/reindex! (constantly nil)]
- (clean-remote-sync-state f))))
+(use-fixtures :each
+ remote-sync.tu/allow-remote-synced-collections (fn [f]
+ (mt/with-dynamic-fn-redefs [search/reindex! (constantly nil)]
+ (clean-remote-sync-state f))))
;;; ------------------------------------------- Event Handler Tests -------------------------------------------
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 25e84dddcf7..12942b98179 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/spec_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/spec_test.clj
@@ -8,11 +8,14 @@
[metabase-enterprise.transforms-python.core :as transforms-python]
[metabase.collections.test-utils :as collections.tu]
[metabase.models.interface :as mi]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[toucan2.core :as t2]))
(set! *warn-on-reflection* true)
+(use-fixtures :each remote-sync.tu/allow-remote-synced-collections)
+
;;; ------------------------------------------------ Spec Validation Tests ---------------------------------------------
(deftest all-specs-have-required-keys-test
diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/stats_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/stats_test.clj
index 029d6105b7c..756d9982949 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/stats_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/stats_test.clj
@@ -7,11 +7,14 @@
[metabase.collections.models.collection :as collection]
[metabase.lib.core :as lib]
[metabase.lib.metadata :as lib.metadata]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[metabase.util :as u]))
(set! *warn-on-reflection* true)
+(use-fixtures :each remote-sync.tu/allow-remote-synced-collections)
+
(defmacro ^:private with-remote-sync
[& body]
`(mt/with-empty-h2-app-db!
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 a58a4d90c91..21a67a885be 100644
--- a/enterprise/backend/test/metabase_enterprise/remote_sync/transforms_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/transforms_test.clj
@@ -14,6 +14,7 @@
[metabase-enterprise.transforms-python.core :as transforms-python]
[metabase.collections.models.collection :as collection]
[metabase.events.core :as events]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.search.core :as search]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]
@@ -22,7 +23,8 @@
(use-fixtures :once (fixtures/initialize :db))
-(use-fixtures :each test-helpers/commit-with-temp
+(use-fixtures :each
+ remote-sync.tu/allow-remote-synced-collections test-helpers/commit-with-temp
(fn [f]
(mt/with-dynamic-fn-redefs [search/reindex! (constantly nil)]
(test-helpers/clean-remote-sync-state f))))
diff --git a/enterprise/backend/test/metabase_enterprise/snippet_collections/api/native_query_snippet_test.clj b/enterprise/backend/test/metabase_enterprise/snippet_collections/api/native_query_snippet_test.clj
index 72540faf691..61b915271e8 100644
--- a/enterprise/backend/test/metabase_enterprise/snippet_collections/api/native_query_snippet_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/snippet_collections/api/native_query_snippet_test.clj
@@ -7,10 +7,13 @@
[metabase.permissions.models.data-permissions :as data-perms]
[metabase.permissions.models.permissions :as perms]
[metabase.permissions.models.permissions-group :as perms-group]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[metabase.util :as u]
[toucan2.core :as t2]))
+(use-fixtures :each remote-sync.tu/allow-remote-synced-collections)
+
(def ^:private root-collection (assoc collection/root-collection :name "Root Collection", :namespace "snippets"))
(defn- test-perms!
diff --git a/enterprise/backend/test/metabase_enterprise/snippet_collections/models/native_query_snippet/permissions_test.clj b/enterprise/backend/test/metabase_enterprise/snippet_collections/models/native_query_snippet/permissions_test.clj
index 8c673544275..8c8ee2397a9 100644
--- a/enterprise/backend/test/metabase_enterprise/snippet_collections/models/native_query_snippet/permissions_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/snippet_collections/models/native_query_snippet/permissions_test.clj
@@ -10,9 +10,12 @@
[metabase.permissions.models.data-permissions :as data-perms]
[metabase.permissions.models.permissions :as perms]
[metabase.permissions.models.permissions-group :as perms-group]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[toucan2.core :as t2]))
+(use-fixtures :each remote-sync.tu/allow-remote-synced-collections)
+
(def ^:private root-collection (assoc collection/root-collection :name "Root Collection", :namespace "snippets"))
(defn- test-perms! [& {:keys [has-perms-for-obj? has-perms-for-id? grant-collection-perms! revoke-collection-perms!]}]
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.setup.spec.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.setup.spec.tsx
index 8009e59c9c4..17eab20625e 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.setup.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.setup.spec.tsx
@@ -48,7 +48,7 @@ const setupEndpoints = ({
remoteSyncBranch = "main",
remoteSyncAutoImport = false,
remoteSyncTransforms = false,
- remoteSyncCollectionsEnabled,
+ remoteSyncCustomCollectionsEnabled,
// Unjustified type cast. FIXME
libraryCollection = null as Collection | null,
// Unjustified type cast. FIXME
@@ -68,7 +68,7 @@ const setupEndpoints = ({
remoteSyncBranch?: string;
remoteSyncAutoImport?: boolean;
remoteSyncTransforms?: boolean;
- remoteSyncCollectionsEnabled?: boolean;
+ remoteSyncCustomCollectionsEnabled?: boolean;
libraryCollection?: Collection | null;
dirty?: any[];
rootCollectionItems?: CollectionItem[];
@@ -86,7 +86,8 @@ const setupEndpoints = ({
"remote-sync-branch": remoteSyncBranch,
"remote-sync-auto-import": remoteSyncAutoImport,
"remote-sync-transforms": remoteSyncTransforms,
- "remote-sync-collections-enabled": remoteSyncCollectionsEnabled,
+ "remote-sync-custom-collections-enabled":
+ remoteSyncCustomCollectionsEnabled,
"development-mode?": isDevInstance,
});
@@ -125,13 +126,13 @@ const createStoreState = ({
isDevInstance = false,
remoteSyncEnabled = false,
remoteSyncType = "read-only" as const,
- remoteSyncCollectionsEnabled = true,
+ remoteSyncCustomCollectionsEnabled = true,
}: {
isAdmin?: boolean;
isDevInstance?: boolean;
remoteSyncEnabled?: boolean;
remoteSyncType?: "read-only" | "read-write";
- remoteSyncCollectionsEnabled?: boolean;
+ remoteSyncCustomCollectionsEnabled?: boolean;
} = {}) => {
return createMockState({
currentUser: createMockUser({ is_superuser: isAdmin }),
@@ -139,7 +140,8 @@ const createStoreState = ({
"development-mode?": isDevInstance,
"remote-sync-enabled": remoteSyncEnabled,
"remote-sync-type": remoteSyncType,
- "remote-sync-collections-enabled": remoteSyncCollectionsEnabled,
+ "remote-sync-custom-collections-enabled":
+ remoteSyncCustomCollectionsEnabled,
}),
});
};
@@ -152,7 +154,7 @@ interface SetupOpts {
remoteSyncType?: "read-only" | "read-write";
remoteSyncBranch?: string;
remoteSyncTransforms?: boolean;
- remoteSyncCollectionsEnabled?: boolean;
+ remoteSyncCustomCollectionsEnabled?: boolean;
libraryCollection?: Collection | null;
dirty?: any[];
rootCollectionItems?: CollectionItem[];
@@ -174,7 +176,7 @@ export const setup = ({
remoteSyncType = "read-only",
remoteSyncBranch = "main",
remoteSyncTransforms = false,
- remoteSyncCollectionsEnabled = true,
+ remoteSyncCustomCollectionsEnabled = true,
libraryCollection = null,
dirty = [],
rootCollectionItems = [],
@@ -196,7 +198,7 @@ export const setup = ({
remoteSyncType,
remoteSyncBranch,
remoteSyncTransforms,
- remoteSyncCollectionsEnabled,
+ remoteSyncCustomCollectionsEnabled,
libraryCollection,
dirty,
rootCollectionItems,
@@ -214,7 +216,7 @@ export const setup = ({
isDevInstance,
remoteSyncEnabled,
remoteSyncType,
- remoteSyncCollectionsEnabled,
+ remoteSyncCustomCollectionsEnabled,
}),
},
);
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.tsx
index 57524222998..76ead6fc507 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.tsx
@@ -56,7 +56,7 @@ export const RemoteSyncSettingsForm = ({
const { data: settingDetails } = useGetAdminSettingsDetailsQuery();
const isRemoteSyncEnabled = !!useSetting(REMOTE_SYNC_KEY);
const isCollectionsSyncEnabled = !!useSetting(
- "remote-sync-collections-enabled",
+ "remote-sync-custom-collections-enabled",
);
const { data: dirtyData } = useGetRemoteSyncChangesQuery(undefined, {
refetchOnMountOrArgChange: true,
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.unit.spec.tsx
index d0aa6a91b85..c5a957f62f8 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.unit.spec.tsx
@@ -994,11 +994,11 @@ describe("RemoteSyncSettingsForm", () => {
expect(screen.getByText("Collections to sync")).toBeInTheDocument();
});
- it("should not display collections section in admin variant when remote-sync-collections-enabled is off", async () => {
+ it("should not display collections section in admin variant when remote-sync-custom-collections-enabled is off", async () => {
setup({
remoteSyncEnabled: false,
remoteSyncType: "read-write",
- remoteSyncCollectionsEnabled: false,
+ remoteSyncCustomCollectionsEnabled: false,
});
await waitFor(() => {
@@ -1013,7 +1013,7 @@ describe("RemoteSyncSettingsForm", () => {
setup({
remoteSyncEnabled: false,
remoteSyncType: "read-write",
- remoteSyncCollectionsEnabled: false,
+ remoteSyncCustomCollectionsEnabled: false,
libraryCollection: null,
hasLibraryFeature: true,
createdLibraryCollection: createMockLibraryCollection({ id: 555 }),
diff --git a/frontend/src/metabase-types/api/settings.ts b/frontend/src/metabase-types/api/settings.ts
index c8076901d0f..941c62dfb70 100644
--- a/frontend/src/metabase-types/api/settings.ts
+++ b/frontend/src/metabase-types/api/settings.ts
@@ -805,7 +805,7 @@ export interface EnterpriseSettings extends Settings {
"remote-sync-type"?: RemoteSyncType | null;
"remote-sync-auto-import"?: boolean | null;
"remote-sync-transforms"?: boolean | null;
- "remote-sync-collections-enabled"?: boolean | null;
+ "remote-sync-custom-collections-enabled"?: boolean | null;
"login-page-illustration"?: IllustrationSettingValue;
"login-page-illustration-custom"?: string;
"landing-page-illustration"?: IllustrationSettingValue;
diff --git a/src/metabase/collections/core.clj b/src/metabase/collections/core.clj
index 8884cdb2967..802154de959 100644
--- a/src/metabase/collections/core.clj
+++ b/src/metabase/collections/core.clj
@@ -20,6 +20,7 @@
update-collection!]
[metabase.collections.models.collection
archive-or-unarchive-collection!
+ assert-remote-syncable
has-remote-synced-collection?
check-for-remote-sync-update
check-non-remote-synced-dependencies
@@ -31,6 +32,7 @@
instance-analytics-collection-type
library-collection
library-collection-type
+ library-collection-types
library-dashboards-collection-type
library-dashboards-collection?
library-data-collection-type
@@ -43,6 +45,7 @@
remote-synced-collection
remote-synced-collection?
remote-synced-dependents
+ root-collection-type-by-id
shared-tenant-collection?
slugify
transforms-ns
diff --git a/src/metabase/collections/models/collection.clj b/src/metabase/collections/models/collection.clj
index d166c5ca3b1..17b75ac00c4 100644
--- a/src/metabase/collections/models/collection.clj
+++ b/src/metabase/collections/models/collection.clj
@@ -609,6 +609,13 @@
(tru "A Collection placed in a remote-synced Collection must also be remote-synced."))]
(throw (ex-info msg {:status-code 400, :errors {:location msg}})))))))
+(defn assert-remote-syncable
+ "Throws when `collection` is remote-synced but remote sync can't sync it."
+ [{:keys [is_remote_synced] :as collection}]
+ (when (and is_remote_synced (not (remote-sync/collection-syncable? collection)))
+ (let [msg (tru "Remote sync syncs only the Library, transforms, snippets and data apps unless remote-sync-custom-collections-enabled is on.")]
+ (throw (ex-info msg {:status-code 400, :errors {:is_remote_synced msg}})))))
+
(defenterprise check-library-content
"Checks contents of a library collection before saving it. The OSS implementation is a no-op."
metabase-enterprise.library.validation
@@ -1918,7 +1925,8 @@
(assoc :slug (slugify collection-name))
(cond->
(= type "remote-synced") (-> (assoc :is_remote_synced true) (dissoc :type))))
- (assert-valid-remote-synced-parent <>)))
+ (assert-valid-remote-synced-parent <>)
+ (assert-remote-syncable <>)))
(defn- copy-collection-permissions!
"Grant read permissions to destination Collections for every Group with read permissions for a source Collection,
@@ -2139,7 +2147,9 @@
(= type "remote-synced") (-> (assoc :is_remote_synced true) (dissoc :type))
collection-name (assoc :slug (slugify collection-name)))
(when-not *clearing-remote-sync*
- (assert-valid-remote-synced-parent (merge collection-before-updates <>))))))
+ (assert-valid-remote-synced-parent (merge collection-before-updates <>))
+ (when (contains? <> :is_remote_synced)
+ (assert-remote-syncable (merge collection-before-updates <>)))))))
;;; ----------------------------------------------------- DELETE -----------------------------------------------------
diff --git a/src/metabase/remote_sync/core.clj b/src/metabase/remote_sync/core.clj
index 3ae0077364d..37fd64d0fd8 100644
--- a/src/metabase/remote_sync/core.clj
+++ b/src/metabase/remote_sync/core.clj
@@ -77,3 +77,9 @@
[(:id inst)
(boolean (contains? remote-synced-coll-ids (:collection_id inst)))]))
instances))))
+
+(defenterprise collection-syncable?
+ "Whether `collection` can be remote-synced, never on OSS."
+ metabase-enterprise.remote-sync.core
+ [_collection]
+ false)
diff --git a/test/metabase/bookmarks/api_test.clj b/test/metabase/bookmarks/api_test.clj
index c80f20da11a..9bfb6abfe4e 100644
--- a/test/metabase/bookmarks/api_test.clj
+++ b/test/metabase/bookmarks/api_test.clj
@@ -5,10 +5,13 @@
[metabase.bookmarks.db :as bookmarks.db]
[metabase.models.interface :as mi]
[metabase.permissions.core :as perms]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[metabase.util :as u]
[toucan2.core :as t2]))
+(use-fixtures :each remote-sync.tu/allow-remote-synced-collections)
+
(deftest bookmarks-test
(mt/initialize-if-needed! :db)
(testing "POST /api/bookmark/:model/:model-id"
diff --git a/test/metabase/collections/create_test.clj b/test/metabase/collections/create_test.clj
index bfb89619bd0..7e4a912e69f 100644
--- a/test/metabase/collections/create_test.clj
+++ b/test/metabase/collections/create_test.clj
@@ -9,11 +9,14 @@
[clojure.test :refer :all]
[metabase.api.common :as api]
[metabase.collections.create :as collections.create]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[toucan2.core :as t2]))
(set! *warn-on-reflection* true)
+(use-fixtures :each remote-sync.tu/allow-remote-synced-collections)
+
(deftest apply-defaults-to-collection-test
(testing "Child inherits :namespace from a non-default-namespace parent"
(mt/with-temp [:model/Collection parent {:name "Snippet Parent" :namespace "snippets"}]
diff --git a/test/metabase/collections/models/collection_test.clj b/test/metabase/collections/models/collection_test.clj
index de89c1f8a86..c8434f8878d 100644
--- a/test/metabase/collections/models/collection_test.clj
+++ b/test/metabase/collections/models/collection_test.clj
@@ -17,6 +17,7 @@
[metabase.models.interface :as mi]
[metabase.models.serialization :as serdes]
[metabase.permissions.core :as perms]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]
[metabase.util :as u]
@@ -24,6 +25,8 @@
[metabase.util.malli.schema :as ms]
[toucan2.core :as t2]))
+(use-fixtures :each remote-sync.tu/allow-remote-synced-collections)
+
(use-fixtures :once (fixtures/initialize :db :test-users :test-users-personal-collections))
(defn- lucky-collection-children-location []
diff --git a/test/metabase/collections_rest/api_test.clj b/test/metabase/collections_rest/api_test.clj
index a611d88e2ae..d0a9d1f3eee 100644
--- a/test/metabase/collections_rest/api_test.clj
+++ b/test/metabase/collections_rest/api_test.clj
@@ -18,6 +18,7 @@
[metabase.permissions.models.collection.graph-test :as graph.test]
[metabase.queries-rest.api.card-test :as api.card-test]
[metabase.queries.models.card :as card]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.request.core :as request]
[metabase.revisions.models.revision :as revision]
[metabase.test :as mt]
@@ -30,6 +31,8 @@
(set! *warn-on-reflection* true)
+(use-fixtures :each remote-sync.tu/allow-remote-synced-collections)
+
(use-fixtures :once (fixtures/initialize :db :web-server :test-users :test-users-personal-collections :row-lock))
(defmacro ^:private with-collection-hierarchy!
diff --git a/test/metabase/documents/api/document_test.clj b/test/metabase/documents/api/document_test.clj
index df38bb8ba7f..3d62366410d 100644
--- a/test/metabase/documents/api/document_test.clj
+++ b/test/metabase/documents/api/document_test.clj
@@ -12,11 +12,14 @@
[metabase.lib.metadata :as lib.metadata]
[metabase.permissions.core :as perms]
[metabase.permissions.models.data-permissions :as data-perms]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]
[metabase.util.malli.fn :as mu.fn]
[toucan2.core :as t2]))
+(use-fixtures :each remote-sync.tu/allow-remote-synced-collections)
+
(use-fixtures :once (fixtures/initialize :db :test-users :test-users-personal-collections))
(deftest post-document-basic-creation-test
diff --git a/test/metabase/queries/models/card_test.clj b/test/metabase/queries/models/card_test.clj
index 0141c54504f..cb1d64666ff 100644
--- a/test/metabase/queries/models/card_test.clj
+++ b/test/metabase/queries/models/card_test.clj
@@ -26,6 +26,7 @@
[metabase.query-processor.card :as qp.card]
[metabase.query-processor.card-test :as qp.card-test]
[metabase.query-processor.preprocess :as qp.preprocess]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.search.ingestion :as search.ingestion]
[metabase.stale-test :as stale-test]
[metabase.staleness.core :as staleness]
@@ -37,6 +38,8 @@
(set! *warn-on-reflection* true)
+(use-fixtures :each remote-sync.tu/allow-remote-synced-collections)
+
(deftest dashboard-count-test
(testing "Check that the :dashboard_count delay returns the correct count of Dashboards a Card is in"
(mt/with-temp [:model/Card {card-id :id} {}
diff --git a/test/metabase/remote_sync/init_test.clj b/test/metabase/remote_sync/init_test.clj
index f2cae97e0cc..b3d762f1aac 100644
--- a/test/metabase/remote_sync/init_test.clj
+++ b/test/metabase/remote_sync/init_test.clj
@@ -3,10 +3,13 @@
(:require
[clojure.test :refer :all]
[metabase.remote-sync.init]
+ [metabase.remote-sync.test-util :as remote-sync.tu]
[metabase.test :as mt]
[metabase.test.fixtures :as fixtures]
[toucan2.core :as t2]))
+(use-fixtures :each remote-sync.tu/allow-remote-synced-collections)
+
(use-fixtures :once (fixtures/initialize :db))
(deftest is-remote-synced-hydration-test
diff --git a/test/metabase/remote_sync/test_util.clj b/test/metabase/remote_sync/test_util.clj
new file mode 100644
index 00000000000..43fb43383de
--- /dev/null
+++ b/test/metabase/remote_sync/test_util.clj
@@ -0,0 +1,11 @@
+(ns metabase.remote-sync.test-util
+ "Test utilities for remote sync."
+ (:require
+ [metabase.remote-sync.core :as remote-sync]
+ [metabase.test :as mt]))
+
+(defn allow-remote-synced-collections
+ "Test fixture that lets every collection be remote-synced, as with custom collections on."
+ [thunk]
+ (mt/with-dynamic-fn-redefs [remote-sync/collection-syncable? (constantly true)]
+ (thunk)))