Skip to content
Snippets Groups Projects
Commit d21bf5f0 authored by Sameer Al-Sakran's avatar Sameer Al-Sakran Committed by GitHub
Browse files

Merge pull request #5644 from metabase/add-setting-for-disabling-nested-queries

Add Setting to disable nested queries (:no_entry_sign: :bird:)
parents 11636f74 fcccf3ff
Branches
Tags
No related merge requests found
......@@ -60,6 +60,11 @@ const SECTIONS = [
key: "enable-advanced-humanization",
display_name: "Friendly Table and Field Names",
type: "boolean"
},
{
key: "enable-nested-queries",
display_name: "Enable Nested Queries",
type: "boolean"
}
]
},
......
......@@ -12,6 +12,7 @@
[metabase.api
[common :as api]
[table :as table-api]]
[metabase.public-settings :as public-settings]
[metabase.models
[card :refer [Card]]
[database :as database :refer [Database protected-password]]
......@@ -110,12 +111,13 @@
(table-api/card->virtual-table card :include-fields? include-fields?)))
(defn- saved-cards-virtual-db-metadata [& {:keys [include-fields?]}]
(when-let [virtual-tables (seq (cards-virtual-tables :include-fields? include-fields?))]
{:name "Saved Questions"
:id database/virtual-id
:features #{:basic-aggregations}
:tables virtual-tables
:is_saved_questions true}))
(when (public-settings/enable-nested-queries)
(when-let [virtual-tables (seq (cards-virtual-tables :include-fields? include-fields?))]
{:name "Saved Questions"
:id database/virtual-id
:features #{:basic-aggregations}
:tables virtual-tables
:is_saved_questions true})))
;; "Virtual" tables for saved cards simulate the db->schema->table hierarchy by doing fake-db->collection->card
(defn- add-virtual-tables-for-saved-cards [dbs]
......
......@@ -55,6 +55,11 @@
:type :boolean
:default false)
(defsetting enable-nested-queries
"Allow using a saved question as the source for other queries?"
:type :boolean
:default true)
(defsetting enable-query-caching
"Enabling caching will save the results of queries that take a long time to run."
......@@ -117,16 +122,17 @@
:anon_tracking_enabled (anon-tracking-enabled)
:custom_geojson (setting/get :custom-geojson)
:email_configured ((resolve 'metabase.email/email-configured?))
:embedding (enable-embedding)
:enable_query_caching (enable-query-caching)
:enable_nested_queries (enable-nested-queries)
:engines ((resolve 'metabase.driver/available-drivers))
:ga_code "UA-60817802-1"
:google_auth_client_id (setting/get :google-auth-client-id)
:ldap_configured ((resolve 'metabase.integrations.ldap/ldap-configured?))
:has_sample_dataset (db/exists? 'Database, :is_sample true)
:ldap_configured ((resolve 'metabase.integrations.ldap/ldap-configured?))
:map_tile_server_url (map-tile-server-url)
:password_complexity password/active-password-complexity
:public_sharing (enable-public-sharing)
:embedding (enable-embedding)
:report_timezone (setting/get :report-timezone)
:setup_token ((resolve 'metabase.setup/token-value))
:site_name (site-name)
......
......@@ -356,6 +356,20 @@
;; Now fetch the database list. The 'Saved Questions' DB should be last on the list
(last ((user->client :crowberto) :get 200 "database" :include_cards true))))
;; Make sure saved questions are NOT included if the setting is disabled
(expect
nil
(tt/with-temp Card [card (card-with-native-query "Kanye West Quote Views Per Month")]
(tu/with-temporary-setting-values [enable-nested-queries false]
;; run the Card which will populate its result_metadata column
((user->client :crowberto) :post 200 (format "card/%d/query" (u/get-id card)))
;; Now fetch the database list. The 'Saved Questions' DB should NOT be in the list
(some (fn [database]
(when (= (u/get-id database) database/virtual-id)
database))
((user->client :crowberto) :get 200 "database" :include_cards true)))))
;; make sure that GET /api/database?include_cards=true groups pretends COLLECTIONS are SCHEMAS
(tt/expect-with-temp [Collection [stamp-collection {:name "Stamps"}]
Collection [coin-collection {:name "Coins"}]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment