Skip to content
Snippets Groups Projects
Unverified Commit 13da5ff5 authored by Chris Truter's avatar Chris Truter Committed by GitHub
Browse files

Disable Validation API if Analysis is disabled (#46266)

parent 162e24a7
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@
[metabase.api.routes.common :refer [+auth]]
[metabase.models.collection :as collection]
[metabase.models.query-analysis :as query-analysis]
[metabase.public-settings :as public-settings]
[metabase.server.middleware.offset-paging :as mw.offset-paging]
[metabase.util.malli.schema :as ms]
[toucan2.core :as t2]))
......@@ -103,4 +104,14 @@
{:limit mw.offset-paging/*limit*
:offset mw.offset-paging/*offset*})))
(api/define-routes api/+check-superuser +auth)
(defn +check-setting
"Middleware that gates this API behind the associated feature flag"
[handler]
(with-meta
(fn [request respond raise]
(if (public-settings/query-analysis-enabled)
(handler request respond raise)
(respond {:status 429 :body "Query Analysis must be enabled to use the Query Reference Validator"})))
(meta handler)))
(api/define-routes api/+check-superuser +auth +check-setting)
......@@ -107,7 +107,8 @@
:table_id nil
:field_id nil}]
(mt/with-premium-features #{:query-reference-validation}
(mt/call-with-map-params f [card-1 card-2 card-3 card-4 coll-2 coll-3])))))
(mt/with-temporary-setting-values [query-analysis-enabled true]
(mt/call-with-map-params f [card-1 card-2 card-3 card-4 coll-2 coll-3]))))))
(defmacro ^:private with-test-setup
"Creates some non-stale QueryFields and anaphorically provides stale QueryField IDs called `qf-{1-3}` and `qf-1b` and
......@@ -160,6 +161,13 @@
(defn- with-data-keys [{:keys [data] :as resp} ks]
(assoc resp :data (map (fn [d] (select-keys d ks)) data)))
(deftest setting-test
(testing "It requires the query analysis setting"
(with-test-setup
(mt/with-temporary-setting-values [query-analysis-enabled false]
(is (= "Query Analysis must be enabled to use the Query Reference Validator"
(mt/user-http-request :crowberto :get 429 url)))))))
(deftest list-invalid-cards-basic-test
(testing "Only returns cards with problematic field refs"
(with-test-setup
......
......@@ -938,7 +938,7 @@ See [fonts](../configuring-metabase/fonts.md).")
(defsetting query-analysis-enabled
(deferred-tru "Whether or not we analyze any queries at all")
:visibility :internal
:visibility :admin
:export? false
:default true
:type :boolean)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment