Skip to content

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

Gate data apps remote sync logic under a token feature (#81946)

Timofey Kachalov33ebc8e67116
diff --git a/enterprise/backend/src/metabase_enterprise/data_apps/sync.clj b/enterprise/backend/src/metabase_enterprise/data_apps/sync.clj
index 728330615a9..44f04edfcc1 100644
--- a/enterprise/backend/src/metabase_enterprise/data_apps/sync.clj
+++ b/enterprise/backend/src/metabase_enterprise/data_apps/sync.clj
@@ -15,6 +15,7 @@
[clojure.string :as str]
[metabase-enterprise.data-apps.config :as data-app.config]
[metabase-enterprise.data-apps.db :as data-apps.db]
+ [metabase.premium-features.core :as premium-features]
[metabase.settings.core :as setting]
[metabase.util.i18n :refer [tru]]
[metabase.util.log :as log]
@@ -224,14 +225,19 @@
Never throws, so it can't break the surrounding remote-sync import: a thrown
failure is logged and swallowed, and a malformed `data_app.yaml` is logged and
its app simply doesn't appear. Returns the [[import-from-snapshot!]] result, or
- nil if the sync threw."
+ nil if the sync threw.
+
+ A no-op returning nil when the `:data-apps-preview` feature is absent: without
+ it an instance behaves exactly as if data apps did not exist — no rows,
+ collections, or permission groups are materialized, and nothing is pruned."
[snapshot]
- (try
- (let [{:keys [config-errors] :as result} (import-from-snapshot! snapshot)]
- (when (seq config-errors)
- (log/warnf "[data-app] %d data_app.yaml config(s) skipped: %s"
- (count config-errors) (str/join "; " config-errors)))
- result)
- (catch Throwable e
- (log/warnf "[data-app] sync from remote-sync snapshot failed: %s" (ex-message e))
- nil)))
+ (when (premium-features/enable-data-apps?)
+ (try
+ (let [{:keys [config-errors] :as result} (import-from-snapshot! snapshot)]
+ (when (seq config-errors)
+ (log/warnf "[data-app] %d data_app.yaml config(s) skipped: %s"
+ (count config-errors) (str/join "; " config-errors)))
+ result)
+ (catch Throwable e
+ (log/warnf "[data-app] sync from remote-sync snapshot failed: %s" (ex-message e))
+ nil))))
diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/api_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/api_test.clj
index ca77e97b87c..b60c6a084eb 100644
--- a/enterprise/backend/test/metabase_enterprise/data_apps/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_apps/api_test.clj
@@ -245,18 +245,19 @@
"the bad config neither aborts nor prunes its sibling apps, and doesn't materialize itself")))))
(deftest sync-from-snapshot!-never-throws-test
- (testing "a malformed data_app.yaml is isolated into :config-errors; the app just doesn't appear, the sync doesn't throw"
- (mt/with-model-cleanup [:model/DataApp]
- (let [result (data-app.sync/sync-from-snapshot!
- (snapshot {"data_apps/x/data_app.yaml" "name: [unterminated"}))]
- (is (seq (:config-errors result)))
- (is (empty? (t2/select-fn-set :name :model/DataApp))))))
- (testing "a clean sync materializes the app with no config errors"
- (mt/with-model-cleanup [:model/DataApp]
- (let [result (data-app.sync/sync-from-snapshot!
- (snapshot (app-files "a" {:name "A" :path "index.js" :bundle "A"})))]
- (is (empty? (:config-errors result)))
- (is (= #{"a"} (t2/select-fn-set :name :model/DataApp)))))))
+ (mt/with-premium-features #{:data-apps-preview}
+ (testing "a malformed data_app.yaml is isolated into :config-errors; the app just doesn't appear, the sync doesn't throw"
+ (mt/with-model-cleanup [:model/DataApp]
+ (let [result (data-app.sync/sync-from-snapshot!
+ (snapshot {"data_apps/x/data_app.yaml" "name: [unterminated"}))]
+ (is (seq (:config-errors result)))
+ (is (empty? (t2/select-fn-set :name :model/DataApp))))))
+ (testing "a clean sync materializes the app with no config errors"
+ (mt/with-model-cleanup [:model/DataApp]
+ (let [result (data-app.sync/sync-from-snapshot!
+ (snapshot (app-files "a" {:name "A" :path "index.js" :bundle "A"})))]
+ (is (empty? (:config-errors result)))
+ (is (= #{"a"} (t2/select-fn-set :name :model/DataApp))))))))
;;; ----------------------------------------------------- API -----------------------------------------------------
diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/sync_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/sync_test.clj
index b188da28bf9..51923829a13 100644
--- a/enterprise/backend/test/metabase_enterprise/data_apps/sync_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_apps/sync_test.clj
@@ -30,6 +30,23 @@
(when description (format "description: %s\n" description)))
(format "data_apps/%s/%s" dir path) bundle})
+(deftest sync-from-snapshot-is-gated-by-the-data-apps-feature-test
+ (testing "the remote-sync entry point does nothing without the :data-apps-preview feature —
+ an instance then behaves exactly as if data apps did not exist"
+ (let [files (app-files "a" {:name "A" :path "index.js" :bundle "V1"})]
+ (mt/with-premium-features #{}
+ (mt/with-model-cleanup [:model/DataApp]
+ (is (nil? (data-app.sync/sync-from-snapshot! (snapshot files)))
+ "returns nil rather than a sync result")
+ (is (not (t2/exists? :model/DataApp :name "a"))
+ "materializes no data app")))
+ (mt/with-premium-features #{:data-apps-preview}
+ (mt/with-model-cleanup [:model/DataApp]
+ (is (=? {:synced 1 :changed 1}
+ (data-app.sync/sync-from-snapshot! (snapshot files)))
+ "with the feature it materializes the app as usual")
+ (is (t2/exists? :model/DataApp :name "a")))))))
+
(deftest changed-count-tracks-content-not-sha-bumps-test
(mt/with-model-cleanup [:model/DataApp]
(let [files (app-files "a" {:name "A" :path "index.js" :bundle "V1"})]
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 ff589311a33..1d9220ac185 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
@@ -17,16 +17,18 @@
(comment metabase-enterprise.data-apps.models.data-app/keep-me)
(defn- import! [files]
- (let [source (test-helpers/create-mock-source :initial-files files)
- task-id (t2/insert-returning-pk! :model/RemoteSyncTask
- {:sync_task_type "import" :initiated_by (mt/user->id :rasta)})
- ;; force: the mock source reports a constant version, so without this the
- ;; second import in a test would hit the "version unchanged" skip branch
- result (impl/import! (source.p/snapshot source) task-id :force? true)]
- ;; calling import! directly leaves the task "running"; mark it ended so a
- ;; subsequent import in the same test isn't blocked by the running-task guard
- (t2/update! :model/RemoteSyncTask task-id {:ended_at :%now})
- result))
+ ;; the import's data-app materialization is gated on :data-apps-preview; enable it so apps sync.
+ (mt/with-premium-features #{:data-apps-preview}
+ (let [source (test-helpers/create-mock-source :initial-files files)
+ task-id (t2/insert-returning-pk! :model/RemoteSyncTask
+ {:sync_task_type "import" :initiated_by (mt/user->id :rasta)})
+ ;; force: the mock source reports a constant version, so without this the
+ ;; second import in a test would hit the "version unchanged" skip branch
+ result (impl/import! (source.p/snapshot source) task-id :force? true)]
+ ;; calling import! directly leaves the task "running"; mark it ended so a
+ ;; subsequent import in the same test isn't blocked by the running-task guard
+ (t2/update! :model/RemoteSyncTask task-id {:ended_at :%now})
+ result)))
(deftest import-materializes-data-apps-test
(testing "a remote-sync import materializes data apps from data_apps/ alongside serdes content"
diff --git a/src/metabase/server/routes/index.clj b/src/metabase/server/routes/index.clj
index a35cc008507..befa7fa4839 100644
--- a/src/metabase/server/routes/index.clj
+++ b/src/metabase/server/routes/index.clj
@@ -9,6 +9,7 @@
[metabase.appearance.core :as appearance]
[metabase.config.core :as config]
[metabase.initialization-status.core :as init-status]
+ [metabase.premium-features.core :as premium-features]
[metabase.settings.core :as setting]
[metabase.system.core :as system]
[metabase.users.settings :as users-settings]
@@ -127,4 +128,16 @@
(def public "/public index.html entrypoint." (partial entrypoint "public" :embeddable))
(def embed "/embed index.html entrypoint." (partial entrypoint "embed" :embeddable))
(def embed-sdk "/embed/sdk/v1 index.html entrypoint." (partial entrypoint "embed-sdk" :embeddable))
-(def data-app "/embed/apps/:name iframe entrypoint." (partial entrypoint "data-app" :embeddable))
+(def ^:private data-app-shell
+ "Raw `/embed/apps/:name` iframe HTML entrypoint, before feature gating."
+ (partial entrypoint "data-app" :embeddable))
+
+(defn data-app
+ "`/embed/apps/:name` iframe entrypoint. Served only when the `:data-apps-preview` feature is
+ enabled; without it, responds nil so routing falls through to the generic embed handler — the
+ instance then behaves exactly as if data apps did not exist, keeping the feature gate with the
+ data-app entrypoint rather than in the top-level route table."
+ [request respond raise]
+ (if (premium-features/enable-data-apps?)
+ (data-app-shell request respond raise)
+ (respond nil)))
diff --git a/test/metabase/server/routes_test.clj b/test/metabase/server/routes_test.clj
index 5617acd2e49..898d5786a6d 100644
--- a/test/metabase/server/routes_test.clj
+++ b/test/metabase/server/routes_test.clj
@@ -2,6 +2,8 @@
(:require
[clojure.string :as str]
[clojure.test :refer :all]
+ [metabase.server.routes.index :as index]
+ [metabase.test :as mt]
[metabase.test.http-client :as client]))
(deftest test-public-routes
@@ -25,3 +27,22 @@
:headers
(get "Location"))
"/api/embed/card/token-string/query/csv?"))))
+
+(deftest data-app-entrypoint-is-gated-by-the-data-apps-feature-test
+ (testing "the /embed/apps/:name entrypoint is served only with :data-apps-preview; without it it
+ responds nil so routing falls through to the generic embed handler — exactly as if data
+ apps did not exist"
+ ;; Stub the raw shell so the test needs no built frontend HTML; the feature gate lives in
+ ;; `index/data-app` itself, which is what we're exercising here.
+ (with-redefs [index/data-app-shell (fn [_req respond _raise] (respond {:status 200 :body "DATA-APP"}))]
+ (let [serve (fn []
+ (let [p (promise)]
+ (index/data-app {} #(deliver p %) #(deliver p %))
+ @p))]
+ ;; `enable-data-apps?` also requires the EE code to be present (`config/ee-available?`), so the
+ ;; served path exists only on EE; on OSS the entrypoint always falls through.
+ (mt/when-ee-evailable
+ (mt/with-premium-features #{:data-apps-preview}
+ (is (= "DATA-APP" (:body (serve))) "with the feature, serves the data-app shell")))
+ (mt/with-premium-features #{}
+ (is (nil? (serve)) "without the feature, responds nil so routing falls through"))))))