The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
[git] Validate remote sync settings before marking collections remote (#74118)
Braden Shepherdson2e6d0924275a
diff --git a/enterprise/backend/src/metabase_enterprise/remote_sync/api.clj b/enterprise/backend/src/metabase_enterprise/remote_sync/api.cljindex 936e9a61f91..5f4daa603b9 100644--- a/enterprise/backend/src/metabase_enterprise/remote_sync/api.clj+++ b/enterprise/backend/src/metabase_enterprise/remote_sync/api.clj@@ -160,6 +160,12 @@(let [effective-type (or remote-sync-type (settings/remote-sync-type))](api/check-400 (not (and (seq collections) (= :read-only effective-type)))"Cannot change synced collections when remote-sync-type is read-only."))+ (try+ (settings/check-and-update-remote-settings! (dissoc settings :collections))+ (catch Exception e+ (throw (ex-info (or (ex-message e) "Invalid settings")+ {:error (ex-message e)+ :status-code 400} e))))(when (seq collections)(try(remote-sync.core/bulk-set-remote-sync collections)@@ -167,12 +173,6 @@(throw (ex-info (or (ex-message e) "Invalid collection settings"){:error (ex-message e):status-code 400} e)))))- (try- (settings/check-and-update-remote-settings! (dissoc settings :collections))- (catch Exception e- (throw (ex-info (or (ex-message e) "Invalid settings")- {:error (ex-message e)- :status-code 400} e))))(events/publish-event! :event/remote-sync-settings-update{:details {:remote-sync-type remote-sync-type}:user-id api/*current-user-id*})diff --git a/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj b/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.cljindex 75f1f835def..d8563e399f6 100644--- a/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj+++ b/enterprise/backend/test/metabase_enterprise/remote_sync/api_test.clj@@ -1132,6 +1132,19 @@(is (= "Transforms" (:name (first dirty-items))))(is (= "delete" (:sync_status (first dirty-items))))))))))+(deftest settings-collections-not-marked-synced-when-settings-validation-fails-test+ (testing "PUT /api/ee/remote-sync/settings does not mark collections as synced when settings validation fails"+ (mt/with-temporary-setting-values [remote-sync-type :read-write]+ (mt/with-temp [:model/Collection {coll-id :id} {:name "Test Collection" :location "/" :is_remote_synced false}]+ (with-redefs [settings/check-and-update-remote-settings!+ (fn [_] (throw (ex-info "Authentication is required" {:status-code 400})))+ impl/finish-remote-config! (constantly nil)]+ (mt/user-http-request :crowberto :put 400 "ee/remote-sync/settings"+ {:remote-sync-url "https://github.com/test/private-repo.git"+ :remote-sync-type :read-write+ :collections {coll-id true}})+ (is (false? (:is_remote_synced (t2/select-one :model/Collection :id coll-id)))))))))+;; ---------- API-level guard sweep --------------------------------------------------------------;;;; Boundary tests verifying that every mutating remote-sync HTTP endpoint surfaces the guard's