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
Drop the table publication checks for data apps (#86097)
Alexander Polyankin9a54c10c3f8f
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex 3a13f644582..ff293fca62d 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -3388,7 +3388,6 @@api-scopeapp-dbcollections- data-appsdatabase-routingdriverevents@@ -3903,7 +3902,6 @@:model/Database:model/Field:model/Measure- :model/Segment:model/Table}:model-exports #{:model/DataApp}}@@ -4296,7 +4294,6 @@api-scopeapp-dbaudit-app- data-appsdriverliblib.bediff --git a/enterprise/backend/src/metabase_enterprise/data_apps/checks.clj b/enterprise/backend/src/metabase_enterprise/data_apps/checks.cljindex adc16acd850..b15b7ceff25 100644--- a/enterprise/backend/src/metabase_enterprise/data_apps/checks.clj+++ b/enterprise/backend/src/metabase_enterprise/data_apps/checks.clj@@ -1,7 +1,7 @@(ns metabase-enterprise.data-apps.checks"The checks that hold a data app's requests to the Library and its own collection. A dev preview, which has no app on- the instance, reads the Library alone and runs ad-hoc implicit actions; an app may also use the cards and run the- actions in its collection."+ the instance, uses Library metrics but no saved card and runs ad-hoc implicit actions; an app may also use the cards+ and run the actions in its collection."(:require[clojure.set :as set][clojure.string :as str]@@ -59,8 +59,7 @@(defenterprise-schema check-adhoc-query :- :nil"Throws a 400 unless `query`, as the `/api/dataset` endpoints normalize it, is an MBQL query without explicit joins or- custom columns that reads only tables published to the Library, through foreign keys too, Library metrics, and- segments and measures of published tables; an app's query may also build on the cards in its collection."+ custom columns that uses only Library metrics; an app's query may also build on the cards in its collection.":feature :data-apps[data-app :- ::data-apps.schema/data-app-infoquery :- ::lib-be.schema/maybe-legacy-or-internal-query]@@ -81,19 +80,7 @@(throw (data-app-error (tru "A data app can use only the cards in its own collection, not the cards {0}."(format-ids external))))))(when-let [external (some-> metric-ids data-apps.db/external-metric-ids not-empty)]- (throw (data-app-error (tru "A data app can use only metrics from the Library, not the metrics {0}." (format-ids external)))))- (when-let [external (some-> (not-empty (set/union (set (lib/all-source-table-ids query))- (set (lib/all-implicitly-joined-table-ids query))))- data-apps.db/external-table-ids- not-empty)]- (throw (data-app-error (tru "A data app can read only tables published to the Library, not the tables {0}."- (format-ids external)))))- (when-let [external (some-> (lib/all-segment-ids query) data-apps.db/external-segment-ids not-empty)]- (throw (data-app-error (tru "A data app can use only segments of tables published to the Library, not the segments {0}."- (format-ids external)))))- (when-let [external (some-> (lib/all-measure-ids query) data-apps.db/external-measure-ids not-empty)]- (throw (data-app-error (tru "A data app can use only measures of tables published to the Library, not the measures {0}."- (format-ids external))))))+ (throw (data-app-error (tru "A data app can use only metrics from the Library, not the metrics {0}." (format-ids external))))))nil)(defenterprise-schema check-card :- :nil@@ -112,19 +99,6 @@(str card-id)))))))nil)-(defn- published-table?- "Whether the table with `table-id` is published to the Library."- [table-id]- (empty? (data-apps.db/external-table-ids #{table-id})))--(defn- check-published-field- "Throws a 400 unless the field with `field-id` belongs to a table published to the Library, after a read check of- the field."- [field-id]- (when-not (published-table? (:table_id (api/read-check :model/Field field-id)))- (throw (data-app-error (tru "A data app can read only fields of tables published to the Library, not the field {0}."- (str field-id))))))-(defenterprise-schema check-action :- :nil"Throws a 400 unless `data-app` is an app and the action with `action-id` is in its collection, after a read check ofthe action; a dev preview runs ad-hoc actions alone."@@ -139,20 +113,14 @@nil)(defenterprise-schema check-adhoc-action :- :nil- "Throws a 400 unless `data-app` is a dev preview and the ad-hoc `action` is an implicit action of no model on a table- published to the Library, after a read check of the table."+ "Throws a 400 unless `data-app` is a dev preview and the ad-hoc `action` is an implicit action of no model on a table.":feature :data-apps[data-app :- ::data-apps.schema/data-app-infoaction :- ::actions.schema/action.adhoc](when-not (preview? data-app)(throw (data-app-error (tru "A data app can run only the actions in its own collection, not ad-hoc ones."))))- (let [table-id (:table_id action)]- (when-not (and (= :implicit (keyword (:type action))) (nil? (:model_id action)) table-id)- (throw (data-app-error (tru "A data app''s dev preview can run only implicit actions on a table."))))- (api/read-check :model/Table table-id)- (when-not (published-table? table-id)- (throw (data-app-error (tru "A data app can write only to tables published to the Library, not the table {0}."- (str table-id))))))+ (when-not (and (= :implicit (keyword (:type action))) (nil? (:model_id action)) (:table_id action))+ (throw (data-app-error (tru "A data app''s dev preview can run only implicit actions on a table."))))nil)(defenterprise-schema data-app-actions :- [:sequential ::actions.schema/action]@@ -162,37 +130,6 @@actions :- [:sequential ::actions.schema/action]](filterv (partial in-app-collection? data-app) actions))-(defenterprise-schema check-table :- :nil- "Throws a 400 unless the table with `table-id` is published to the Library, after a read check of the table."- :feature :data-apps- [_data-app :- ::data-apps.schema/data-app-info- table-id :- ::lib.schema.id/table]- (api/read-check :model/Table table-id)- (when-not (published-table? table-id)- (throw (data-app-error (tru "A data app can read only tables published to the Library, not the table {0}." (str table-id)))))- nil)--(defenterprise-schema check-field :- :nil- "Throws a 400 unless the field with `field-id` belongs to a table published to the Library, after a read check of- the field."- :feature :data-apps- [_data-app :- ::data-apps.schema/data-app-info- field-id :- ::lib.schema.id/field]- (check-published-field field-id)- nil)--(defenterprise-schema check-database :- :nil- "Throws a 400 unless the database with `database-id` has a table published to the Library, after a read check of the- database."- :feature :data-apps- [_data-app :- ::data-apps.schema/data-app-info- database-id :- ::lib.schema.id/database]- (api/read-check :model/Database database-id)- (when-not (some #(= database-id (:db_id %)) (data-apps.db/published-tables))- (throw (data-app-error (tru "A data app can read only databases with tables published to the Library, not the database {0}."- (str database-id)))))- nil)-(def ^:private sdk-user-key-values"The user key-values, as `[namespace key]`, that the SDK reads and writes inside a data app."#{["last_download_format" "download_format_preference"]})diff --git a/enterprise/backend/src/metabase_enterprise/data_apps/db.clj b/enterprise/backend/src/metabase_enterprise/data_apps/db.cljindex c985b32bf0a..9a363d5fae5 100644--- a/enterprise/backend/src/metabase_enterprise/data_apps/db.clj+++ b/enterprise/backend/src/metabase_enterprise/data_apps/db.clj@@ -193,35 +193,6 @@[:= :report_card.type "metric"][:= :collection.type collection/library-metrics-collection-type]]})))-(mu/defn external-table-ids :- [:set ::lib.schema.id/table]- "Among `table-ids`, those of no Table published to the Library."- [table-ids :- [:set {:min 1} ::lib.schema.id/table]]- (set/difference table-ids (t2/select-pks-set :model/Table {:from [(warehouse-schema-overlay/table-query)]- :where [:and [:in :id table-ids] [:= :is_published true]]})))--(mu/defn published-tables :- [:sequential :metabase.warehouse-schema.schema/table]- "The Tables published to the Library, with their databases and schemas."- []- (t2/select [:model/Table :id :db_id :schema]- {:from [(warehouse-schema-overlay/table-query)]- :where [:= :is_published true]}))--(mu/defn external-segment-ids :- [:set ::lib.schema.id/segment]- "Among `segment-ids`, those of no Segment of a Table published to the Library."- [segment-ids :- [:set {:min 1} ::lib.schema.id/segment]]- (set/difference segment-ids (t2/select-fn-set :id [:model/Segment :segment.id]- {:join [(warehouse-schema-overlay/table-query {:alias :table})- [:= :table.id :segment.table_id]]- :where [:and [:in :segment.id segment-ids] [:= :table.is_published true]]})))--(mu/defn external-measure-ids :- [:set ::lib.schema.id/measure]- "Among `measure-ids`, those of no Measure of a Table published to the Library."- [measure-ids :- [:set {:min 1} ::lib.schema.id/measure]]- (set/difference measure-ids (t2/select-fn-set :id [:model/Measure :measure.id]- {:join [(warehouse-schema-overlay/table-query {:alias :table})- [:= :table.id :measure.table_id]]- :where [:and [:in :measure.id measure-ids] [:= :table.is_published true]]})))-(defn destination-database-ids"The IDs among `database-ids` of the databases that are routing destinations."[database-ids]diff --git a/enterprise/backend/src/metabase_enterprise/sandbox/api/table.clj b/enterprise/backend/src/metabase_enterprise/sandbox/api/table.cljindex 382d0fbe032..8d0406bf8ff 100644--- a/enterprise/backend/src/metabase_enterprise/sandbox/api/table.clj+++ b/enterprise/backend/src/metabase_enterprise/sandbox/api/table.clj@@ -6,7 +6,6 @@[metabase.api-scope.data-app :as api-scope][metabase.api.common :as api][metabase.api.macros :as api.macros]- [metabase.data-apps.core :as data-apps][metabase.permissions.core :as perms][metabase.premium-features.core :refer [defenterprise]][metabase.util :as u]@@ -86,10 +85,7 @@:- [:map {:closed true}[:include_sensitive_fields {:default false} [:maybe ms/BooleanValue]][:include_hidden_fields {:default false} [:maybe ms/BooleanValue]]- [:include_editable_data_model {:default false} [:maybe ms/BooleanValue]]]- _body- request]- (some-> (data-apps/request-data-app request) (data-apps/check-table id))+ [:include_editable_data_model {:default false} [:maybe ms/BooleanValue]]]](fetch-table-query-metadata id {:include-sensitive-fields? include_sensitive_fields:include-hidden-fields? include_hidden_fields:include-editable-data-model? include_editable_data_model}))diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/checks_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/checks_test.cljindex 2d498dec0d4..f7fa3df44b9 100644--- a/enterprise/backend/test/metabase_enterprise/data_apps/checks_test.clj+++ b/enterprise/backend/test/metabase_enterprise/data_apps/checks_test.clj@@ -8,7 +8,6 @@[metabase.collections.core :as collections][metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata]- [metabase.lib.schema.id :as lib.schema.id][metabase.search.test-util :as search.tu][metabase.test :as mt][metabase.util.json :as json]@@ -33,10 +32,7 @@(def ^:private error-formats"The format of the error message for each kind of entity a data app may not use."{:cards "A data app can use only the cards in its own collection, not the cards %s."- :metrics "A data app can use only metrics from the Library, not the metrics %s."- :tables "A data app can read only tables published to the Library, not the tables %s."- :segments "A data app can use only segments of tables published to the Library, not the segments %s."- :measures "A data app can use only measures of tables published to the Library, not the measures %s."})+ :metrics "A data app can use only metrics from the Library, not the metrics %s."})(defn- error-message"The error message for a data app's use of the entities of `kind` with `ids`."@@ -78,22 +74,21 @@(some #(when (= (mt/id :categories :name) (:id %)) %) (lib/breakoutable-columns query)))(defn- do-with-app-card!- "Call `f` with the ID of a card on the published VENUES table in the collection of the data app of- [[do-with-app-collection]], and with that collection's ID."+ "Call `f` with the ID of a card on the VENUES table in the collection of the data app of [[do-with-app-collection]],+ and with that collection's ID."[f](do-with-app-collection(fn [collection-id]- (data-apps.tu/with-published-tables! [(mt/id :venues)]- (mt/with-temp [:model/Card {card-id :id} {:name "Venues"- :collection_id collection-id- :dataset_query (data-apps.tu/venues-query)}]- (f card-id collection-id))))))+ (mt/with-temp [:model/Card {card-id :id} {:name "Venues"+ :collection_id collection-id+ :dataset_query (data-apps.tu/venues-query)}]+ (f card-id collection-id)))))-(deftest app-card-and-published-table-run-test+(deftest app-card-and-table-run-test(do-with-app-card!(fn [card-id _collection-id](doseq [[label query] [["the app's card" (lib/limit (card-query card-id) 1)]- ["a published table" (lib/limit (table-query :venues) 1)]]]+ ["a table" (lib/limit (table-query :venues) 1)]]](testing (str "a query on " label " runs, pivots, compiles and has metadata")(is (= "completed" (:status (run-query 202 query))))(is (= "completed" (:status (mt/user-http-request :crowberto :post 202 "dataset/pivot" as-data-app@@ -122,41 +117,29 @@(is (= "You don't have permissions to do that."(mt/user-http-request :rasta :post 403 "dataset" as-data-app (card-query card-id))))))))-(deftest unpublished-tables-are-refused-test+(deftest unpublished-tables-are-read-test(do-with-app-card!(fn [card-id _collection-id]- (testing "every endpoint refuses a query on an unpublished table"- (is (= (error-message :tables (mt/id :categories)) (run-query 400 (table-query :categories))))- (doseq [endpoint ["dataset/pivot" "dataset/native" "dataset/query_metadata"]]- (is (= (error-message :tables (mt/id :categories)) (mt/user-http-request :crowberto :post 400 endpoint as-data-app- (table-query :categories)))- endpoint))- (is (= (error-message :tables (mt/id :categories)) (mt/user-http-request :crowberto :post 400 "dataset/csv" as-data-app- {:query (table-query :categories)}))))- (testing "a table reached through a foreign key is refused, from a published table or the app's card"- (doseq [[label query] [["in a preview" (table-query :venues)] ["in the app" (card-query card-id)]]]- (let [query (lib/breakout query (category-name query))]- (is (= (error-message :tables (mt/id :categories))- (run-query 400 query (if (= label "in a preview") as-preview as-data-app)))- label))))- (testing "it is read once it is published"- (data-apps.tu/with-published-tables! [(mt/id :categories)]- (let [query (table-query :venues)]- (is (= "completed" (:status (run-query 202 (-> query (lib/breakout (category-name query)) (lib/limit 1))))))))))))+ (testing "an app and its dev preview read a table not published to the Library"+ (doseq [options [as-data-app as-preview]]+ (is (= "completed" (:status (run-query 202 (lib/limit (table-query :categories) 1) options))))))+ (testing "and reach it through a foreign key, from a table or the app's card"+ (doseq [[options query] [[as-preview (table-query :venues)] [as-data-app (card-query card-id)]]]+ (is (= "completed" (:status (run-query 202 (-> query (lib/breakout (category-name query)) (lib/limit 1))+ options)))))))))(deftest explicit-joins-and-custom-columns-are-refused-test(do-with-app-card!(fn [card-id _collection-id]- (data-apps.tu/with-published-tables! [(mt/id :categories)]- (let [mp (mt/metadata-provider)]- (doseq [query [(table-query :venues) (card-query card-id)]]- (testing "an explicit join, even of a published table"- (is (= "A data app cannot run queries that join tables explicitly."- (run-query 400 (lib/join query (lib/join-clause (lib.metadata/table mp (mt/id :categories))))))))- (testing "a custom column"- (is (= "A data app cannot run queries with custom columns."- (run-query 400 (lib/expression query "Double price"- (lib/* (lib.metadata/field mp (mt/id :venues :price)) 2))))))))))))+ (let [mp (mt/metadata-provider)]+ (doseq [query [(table-query :venues) (card-query card-id)]]+ (testing "an explicit join"+ (is (= "A data app cannot run queries that join tables explicitly."+ (run-query 400 (lib/join query (lib/join-clause (lib.metadata/table mp (mt/id :categories))))))))+ (testing "a custom column"+ (is (= "A data app cannot run queries with custom columns."+ (run-query 400 (lib/expression query "Double price"+ (lib/* (lib.metadata/field mp (mt/id :venues :price)) 2)))))))))))(deftest other-cards-are-refused-test(do-with-app-card!@@ -184,21 +167,16 @@(testing "an app without a collection can use no card, not even one in the root collection"(is (= (error-message :cards elsewhere-id)(run-query 400 (card-query elsewhere-id) (as-app "wasps")))))- (testing "it still reads published tables"+ (testing "it still reads tables"(is (= "completed" (:status (run-query 202 (lib/limit (table-query :venues) 1) (as-app "wasps"))))))))))(deftest missing-entities-are-refused-test(do-with-app-card!(fn [_card-id _collection-id](testing "an ID of no entity gets the refusal an entity the app may not use gets, so it tells nothing of what exists"- (doseq [[kind query] [[:tables {:database (mt/id) :type :query :query {:source-table 999999999}}]- [:cards {:database (mt/id) :type :query :query {:source-table "card__999999999"}}]+ (doseq [[kind query] [[:cards {:database (mt/id) :type :query :query {:source-table "card__999999999"}}][:metrics {:database (mt/id) :type :query :query {:source-table (mt/id :venues)- :aggregation [[:metric 999999999]]}}]- [:segments {:database (mt/id) :type :query :query {:source-table (mt/id :venues)- :filter [:segment 999999999]}}]- [:measures {:database (mt/id) :type :query :query {:source-table (mt/id :venues)- :aggregation [[:measure 999999999]]}}]]]+ :aggregation [[:metric 999999999]]}}]]](is (= (error-message kind 999999999) (run-query 400 query)) (name kind)))))))(deftest native-query-is-refused-test@@ -254,13 +232,9 @@(let [mp (mt/metadata-provider)with-segment #(lib/filter % (lib.metadata/segment mp segment-id))with-measure #(lib/aggregate % (lib.metadata/measure mp measure-id))]- (testing "a segment or measure of an unpublished table is refused, even from a published table"- (is (= (error-message :segments segment-id) (run-query 400 (with-segment (table-query :venues)))))- (is (= (error-message :measures measure-id) (run-query 400 (with-measure (table-query :venues))))))- (testing "a segment or measure of a published table runs"- (data-apps.tu/with-published-tables! [(mt/id :categories)]- (doseq [query [(with-segment categories) (with-measure categories)]]- (is (= "completed" (:status (run-query 202 query)))))))))))))+ (testing "a segment or measure of a table not published to the Library runs"+ (doseq [query [(with-segment categories) (with-measure categories)]]+ (is (= "completed" (:status (run-query 202 query))))))))))))(deftest card-endpoints-run-app-card-test(do-with-app-card!@@ -370,16 +344,15 @@(defn- do-with-rename-action!"Call `f` with the ID of a temp implicit action, on no model, that updates a category, in the collection with- `collection-id`, with the category Table published to the Library."+ `collection-id`."[collection-id f]- (data-apps.tu/with-published-tables! [(mt/id :categories)]- (mt/with-temp [:model/Action {action-id :id} {:name "Update category"- :type :implicit- :collection_id collection-id}- :model/ImplicitAction _ {:action_id action-id- :kind "row/update"- :table_id (mt/id :categories)}]- (f action-id))))+ (mt/with-temp [:model/Action {action-id :id} {:name "Update category"+ :type :implicit+ :collection_id collection-id}+ :model/ImplicitAction _ {:action_id action-id+ :kind "row/update"+ :table_id (mt/id :categories)}]+ (f action-id)))(def ^:private category-parameters{:id 1 :name "African"})@@ -429,19 +402,15 @@(mt/user-http-request :crowberto :post 200 (format "action/%d/execute" elsewhere-id){:parameters category-parameters})))))))))))-(deftest preview-runs-only-adhoc-implicit-actions-on-published-tables-test+(deftest preview-runs-only-adhoc-implicit-actions-test(mt/with-actions-test-data-and-actions-enabled(do-with-app-collection(fn [collection-id](let [adhoc {:name "Rename" :type "implicit" :kind "row/update" :table_id (mt/id :categories)}]- (testing "a dev preview runs no ad-hoc action on an unpublished table"- (is (= (format "A data app can write only to tables published to the Library, not the table %d." (mt/id :categories))- (mt/user-http-request :crowberto :post 400 "action/execute" as-preview- {:action adhoc :parameters category-parameters}))))(do-with-rename-action!collection-id(fn [action-id]- (testing "a dev preview runs an ad-hoc implicit action on a published table"+ (testing "a dev preview runs an ad-hoc implicit action on a table not published to the Library"(is (=? {:rows-updated some?}(mt/user-http-request :crowberto :post 200 "action/execute" as-preview{:action adhoc :parameters category-parameters}))))@@ -496,170 +465,61 @@(mt/user-http-request :crowberto :post 400 (format "action/%d/execute" elsewhere-id) (as-app "wasps"){:parameters category-parameters})))))))))))-(deftest table-and-field-endpoints-check-published-tables-test+(deftest table-and-field-endpoints-read-unpublished-tables-test(do-with-app-collection(fn [_collection-id]- (data-apps.tu/with-published-tables! [(mt/id :venues)]- (let [venues (mt/id :venues)- id (mt/id :venues :id)- vname (mt/id :venues :name)- checkins (mt/id :checkins)- date (mt/id :checkins :date)]- (testing "a published table and its fields are readable"- (doseq [url [(format "table/%d" venues)- (format "table/%d/query_metadata" venues)- (format "table/%d/fks" venues)- (format "field/%d" vname)- (format "field/%d/summary" vname)- (format "field/%d/values" vname)- (format "field/%d/search/%d?value=Re" vname vname)- (format "field/%d/remapping/%d?value=1" id vname)- (format "field/%d/related" vname)]]- (mt/user-http-request :crowberto :get 200 url as-data-app)))- (testing "an unpublished table and its fields are refused"- (doseq [url [(format "table/%d" checkins)- (format "table/%d/query_metadata" checkins)- (format "table/%d/fks" checkins)]]- (is (= (format "A data app can read only tables published to the Library, not the table %d." checkins)- (mt/user-http-request :crowberto :get 400 url as-data-app))- url))- (doseq [url [(format "field/%d" date)- (format "field/%d/summary" date)- (format "field/%d/values" date)- (format "field/%d/related" date)- (format "field/%d/search/%d?value=Re" vname date)- (format "field/%d/remapping/%d?value=1" id date)]]- (is (= (format "A data app can read only fields of tables published to the Library, not the field %d." date)- (mt/user-http-request :crowberto :get 400 url as-data-app))- url)))- (testing "a request that is not a data app's still reads an unpublished table"- (mt/user-http-request :crowberto :get 200 (format "table/%d" checkins))))))))--(deftest database-endpoints-narrow-to-published-tables-test+ (let [users (mt/id :users)+ id (mt/id :users :id)+ uname (mt/id :users :name)]+ (testing "a data app reads a table not published to the Library and its fields"+ (doseq [url [(format "table/%d" users)+ (format "table/%d/query_metadata" users)+ (format "table/%d/fks" users)+ (format "field/%d" uname)+ (format "field/%d/summary" uname)+ (format "field/%d/values" uname)+ (format "field/%d/search/%d?value=Re" uname uname)+ (format "field/%d/remapping/%d?value=1" id uname)+ (format "field/%d/related" uname)]]+ (mt/user-http-request :crowberto :get 200 url as-data-app)))))))++(deftest database-endpoints-list-unpublished-tables-test(do-with-app-collection(fn [_collection-id]- (mt/with-temp [:model/Database db {:engine :h2 :details {}}- :model/Table published {:db_id (:id db) :name "PUBLISHED" :schema "PUBLIC"}- :model/Table unpublished {:db_id (:id db) :name "UNPUBLISHED" :schema "PRIVATE"}- :model/Database other {:engine :h2 :details {}}- :model/Table _ {:db_id (:id other) :name "ELSEWHERE" :schema "PUBLIC"}]- (data-apps.tu/with-published-tables! [(:id published)]- (let [list-dbs (fn [url] (:data (mt/user-http-request :crowberto :get 200 url as-data-app)))- listed (fn [dbs] (some #(when (= (:id db) (:id %)) %) dbs))]- (testing "the database list holds the database with a published table, with only that table and its schema"- (is (= [(:id published)] (map :id (:tables (listed (list-dbs "database?include=tables"))))))- (is (= ["PUBLIC"] (:schemas (listed (list-dbs "database?include=schemas"))))))- (testing "but not a database without published tables, nor the saved-questions virtual database"- (doseq [id [(:id other) lib.schema.id/saved-questions-virtual-database-id]]- (is (not-any? #(= id (:id %)) (list-dbs "database?saved=true")) id)))- (testing "a database with a published table lists only that table and its schema"- (is (= [(:id published)]- (map :id (:tables (mt/user-http-request :crowberto :get 200 (format "database/%d?include=tables" (:id db))- as-data-app)))))- (is (= ["PUBLIC"] (mt/user-http-request :crowberto :get 200 (format "database/%d/schemas" (:id db)) as-data-app)))- (is (= [(:id published)]- (map :id (mt/user-http-request :crowberto :get 200 (format "database/%d/schema/PUBLIC" (:id db)) as-data-app))))- (is (= "Not found."- (mt/user-http-request :crowberto :get 404 (format "database/%d/schema/PRIVATE" (:id db)) as-data-app))))- (testing "a database without published tables is refused"- (doseq [url ["database/%d" "database/%d/schemas" "database/%d/schema/PUBLIC"]]- (is (= (format "A data app can read only databases with tables published to the Library, not the database %d."- (:id other))- (mt/user-http-request :crowberto :get 400 (format url (:id other)) as-data-app))- url)))- (testing "a request that is not a data app's still lists the unpublished table"- (is (= [(:id unpublished)]- (map :id (mt/user-http-request :crowberto :get 200 (format "database/%d/schema/PRIVATE" (:id db)))))))))))))--(deftest database-endpoints-without-published-tables-test- (do-with-app-collection- (fn [_collection-id]- (mt/with-temp [:model/Database db {:engine :h2 :details {}}- :model/Table _ {:db_id (:id db) :name "UNPUBLISHED" :schema "PUBLIC"}]- (testing "a database whose tables are all unpublished is not listed"- (is (not-any? #(= (:id db) (:id %))- (:data (mt/user-http-request :crowberto :get 200 "database?include=tables" as-data-app)))))- (testing "and is refused by its ID"- (is (= (format "A data app can read only databases with tables published to the Library, not the database %d." (:id db))- (mt/user-http-request :crowberto :get 400 (format "database/%d" (:id db)) as-data-app))))))))--(defn- do-with-zebras!- "Call `f` with a temp table published to the Library, one unpublished, a metric in the Library and one outside it, all- named Zebra, as `{:published :unpublished :metric :outside-metric}`."- [f]- (data-apps.tu/do-with-library!- (fn [{:keys [metrics-id]}]- (mt/with-temp [:model/Database db {:engine :h2 :details {}}- :model/Table published {:db_id (:id db) :name "ZEBRA_PUBLISHED" :display_name "Zebra published"}- :model/Table unpublished {:db_id (:id db) :name "ZEBRA_UNPUBLISHED" :display_name "Zebra unpublished"}- :model/Card metric {:name "Zebra metric"- :type :metric- :collection_id metrics-id- :dataset_query (lib/aggregate (data-apps.tu/venues-query) (lib/count))}- :model/Card outside-metric {:name "Zebra outside metric"- :type :metric- :dataset_query (lib/aggregate (data-apps.tu/venues-query) (lib/count))}]- (data-apps.tu/with-published-tables! [(:id published)]- (f {:published published :unpublished unpublished :metric metric :outside-metric outside-metric}))))))--(defn- search-found- "The `[model id]` pairs of what a search for zebras finds, as the request with `options` does."- [options & params]- (set (map (juxt :model :id) (:data (apply mt/user-http-request :crowberto :get 200 "search" options :q "zebra" params)))))--(deftest search-finds-library-content-test- (search.tu/with-appdb-search-and-legacy-search- (search.tu/with-sync-search-indexing- (do-with-app-collection- (fn [_collection-id]- (mt/with-premium-features #{:data-apps :library}- (do-with-zebras!- (fn [{:keys [published unpublished metric outside-metric]}]- (let [published ["table" (:id published)]- unpublished ["table" (:id unpublished)]- metric ["metric" (:id metric)]- outside-metric ["metric" (:id outside-metric)]]- (testing "a data app finds the Library's content, and nothing else"- (let [found (search-found as-data-app)]- (is (contains? found published))- (is (contains? found metric))- (is (not-any? found [unpublished outside-metric]))))- (testing "the models it asks for narrow the search"- (let [found (search-found as-data-app :models "metric")]- (is (contains? found metric))- (is (not (contains? found published))))- (let [found (search-found as-data-app :models "table")]- (is (contains? found published))- (is (not-any? found [unpublished metric]))))- (testing "a request that is not a data app's finds the unpublished table and the outside metric too"- (let [found (search-found {})]- (is (contains? found unpublished))- (is (contains? found outside-metric)))))))))))))--(deftest search-without-library-finds-nothing-test+ (mt/with-temp [:model/Database db {:engine :h2 :details {}}+ :model/Table table {:db_id (:id db) :name "UNPUBLISHED" :schema "PUBLIC"}]+ (let [listed (fn [url] (some #(when (= (:id db) (:id %)) %)+ (:data (mt/user-http-request :crowberto :get 200 url as-data-app))))]+ (testing "the database list holds a database whose tables are not published to the Library, with them"+ (is (= [(:id table)] (map :id (:tables (listed "database?include=tables")))))+ (is (= ["PUBLIC"] (:schemas (listed "database?include=schemas"))))))+ (testing "the database endpoints read it and list its table and schema"+ (is (= [(:id table)]+ (map :id (:tables (mt/user-http-request :crowberto :get 200 (format "database/%d?include=tables" (:id db))+ as-data-app)))))+ (is (= ["PUBLIC"] (mt/user-http-request :crowberto :get 200 (format "database/%d/schemas" (:id db)) as-data-app)))+ (is (= [(:id table)]+ (map :id (mt/user-http-request :crowberto :get 200 (format "database/%d/schema/PUBLIC" (:id db))+ as-data-app)))))))))++(deftest search-is-not-narrowed-test(search.tu/with-appdb-search-and-legacy-search(search.tu/with-sync-search-indexing(do-with-app-collection(fn [_collection-id](mt/with-premium-features #{:data-apps :library}- (do-with-zebras!- (fn [{:keys [published metric]}]- (mt/with-dynamic-fn-redefs [collections/library-collection (constantly nil)]- (testing "without a Library, a data app finds not even a published table or a Library metric"- (is (not-any? (search-found as-data-app) [["table" (:id published)] ["metric" (:id metric)]]))))))))))))--(deftest search-without-published-tables-finds-nothing-test- (search.tu/with-appdb-search-and-legacy-search- (search.tu/with-sync-search-indexing- (do-with-app-collection- (fn [_collection-id]- (mt/with-premium-features #{:data-apps :library}- (mt/with-temp [:model/Database db {:engine :h2 :details {}}- :model/Table unpublished {:db_id (:id db) :name "ZEBRA_UNPUBLISHED" :display_name "Zebra unpublished"}]- (data-apps.tu/do-with-library!- (fn [_library]- (testing "with a Library that does not publish the table, a data app does not find it"- (is (not (contains? (search-found as-data-app) ["table" (:id unpublished)])))))))))))))+ (data-apps.tu/do-with-library!+ (fn [_library]+ (mt/with-temp [:model/Database db {:engine :h2 :details {}}+ :model/Table table {:db_id (:id db) :name "ZEBRA_UNPUBLISHED" :display_name "Zebra unpublished"}+ :model/Card metric {:name "Zebra outside metric"+ :type :metric+ :dataset_query (lib/aggregate (data-apps.tu/venues-query) (lib/count))}]+ (testing "a data app finds a table not published to the Library and a metric outside it"+ (let [found (set (map (juxt :model :id)+ (:data (mt/user-http-request :crowberto :get 200 "search" as-data-app :q "zebra"))))]+ (is (contains? found ["table" (:id table)]))+ (is (contains? found ["metric" (:id metric)])))))))))))))(deftest user-key-value-endpoints-allow-only-sdk-keys-test(do-with-app-collectiondiff --git a/src/metabase/data_apps/core.clj b/src/metabase/data_apps/core.cljindex c7f5c7d5fe7..ded38b48bd0 100644--- a/src/metabase/data_apps/core.clj+++ b/src/metabase/data_apps/core.clj@@ -95,30 +95,6 @@actions :- [:sequential ::actions.schema/action]]actions)-(defenterprise-schema check-table :- :nil- "Throws a 400 unless `data-app` may read the table with `table-id`, after a read check of the table; does nothing- without the data-apps feature."- metabase-enterprise.data-apps.checks- [_data-app :- ::data-apps.schema/data-app-info- _table-id :- ::lib.schema.id/table]- nil)--(defenterprise-schema check-field :- :nil- "Throws a 400 unless `data-app` may read the field with `field-id`, after a read check of the field; does nothing- without the data-apps feature."- metabase-enterprise.data-apps.checks- [_data-app :- ::data-apps.schema/data-app-info- _field-id :- ::lib.schema.id/field]- nil)--(defenterprise-schema check-database :- :nil- "Throws a 400 unless `data-app` may read the database with `database-id`, after a read check of the database; does- nothing without the data-apps feature."- metabase-enterprise.data-apps.checks- [_data-app :- ::data-apps.schema/data-app-info- _database-id :- ::lib.schema.id/database]- nil)-(defenterprise-schema check-user-key-value :- :nil"Throws a 400 unless `data-app` may use the user key-value `k` in `nmspace`; does nothing without the data-appsfeature."diff --git a/src/metabase/search/api.clj b/src/metabase/search/api.cljindex 208281a2df5..138cf6347c5 100644--- a/src/metabase/search/api.clj+++ b/src/metabase/search/api.clj@@ -7,9 +7,7 @@[metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.api.open-api :as open-api]- [metabase.collections.core :as collections][metabase.config.core :as config]- [metabase.data-apps.core :as data-apps][metabase.permissions.core :as perms][metabase.request.core :as request][metabase.search.config :as search.config]@@ -300,21 +298,6 @@:include-metadata? include-metadata:display-type (set display-type)}))-(defn- data-app-search-params- "`query-params` narrowed, for a data-app `request`, to the Library's tables and metrics among the models it asks for;- without a Library or such a model, the search looks for tables in the Trash, which holds none."- [request query-params]- (if (data-apps/request-data-app request)- (let [models (cond->> ["table" "metric"]- (seq (:models query-params)) (filterv (set (:models query-params))))- library (when (seq models) (collections/library-collection))]- (if library- (assoc query-params :models models :collection (:id library))- (-> query-params- (dissoc :ids)- (assoc :models ["table"] :collection (collections/trash-collection-id)))))- query-params))-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-query-params-use-kebab-case:metabase/validate-defendpoint-has-response-schema]}(api.macros/defendpoint :get "/"@@ -353,9 +336,7 @@A search query that has both filters applied will only return models and cards."{:scope api-scope/data-app}[_route-params- query-params :- search-request-schema- _body- request]+ query-params :- search-request-schema](api/check-valid-page-params (request/limit) (request/offset));; tuning/diagnostic knobs are admin-only: explain re-executes the vector scan and counts the whole index;; table per request, and the scan-budget knobs let a request inflate its own cost@@ -364,7 +345,7 @@(some? (:vector_search_explain query-params)))(api/check-superuser))(try- (u/prog1 (search/search (params->search-context (data-app-search-params request query-params)))+ (u/prog1 (search/search (params->search-context query-params))(analytics/inc! :metabase-search/response-ok)(analytics/observe! :metabase-search/response-results (:total <>)))(catch Exception ediff --git a/src/metabase/warehouse_schema/table.clj b/src/metabase/warehouse_schema/table.cljindex 28a7748941a..fa06df20c3d 100644--- a/src/metabase/warehouse_schema/table.clj+++ b/src/metabase/warehouse_schema/table.clj@@ -198,7 +198,7 @@(defn database-schemas"Returns a list of all the schemas with tables found for the database `id`. Excludes schemas with no tables."- [id {:keys [include-editable-data-model? include-hidden? can-query? exclude-unpublished-tables?]}]+ [id {:keys [include-editable-data-model? include-hidden? can-query?]}](let [filter-schemas (fn [schemas](if include-editable-data-model?(->> schemas@@ -207,12 +207,10 @@(map :schema))(filter (partial can-read-schema? id) schemas)))filter-schemas-by-tables (fn [schemas]- (if (or can-query? exclude-unpublished-tables?)+ (if can-query?(let [tables (warehouse-schema.db/active-tables-for-database id)_ (perms/prime-table-perms-cache {:db-ids #{id}})- filtered-tables (cond->> tables- can-query? (filter mi/can-query?)- exclude-unpublished-tables? (filter :is_published))+ filtered-tables (filter mi/can-query? tables)allowed-schemas (set (map :schema filtered-tables))](filter #(contains? allowed-schemas %) schemas))schemas))]@@ -231,7 +229,7 @@`include-editable-data-model?` routes the filtering through data-model permissions instead."([db-id schema](schema-tables-list db-id schema {}))- ([db-id schema {:keys [include-hidden? include-editable-data-model? can-query? include-measures? exclude-unpublished-tables?]}]+ ([db-id schema {:keys [include-hidden? include-editable-data-model? can-query? include-measures?]}](when-not include-editable-data-model?(api/read-check :model/Database db-id)(api/check-403 (can-read-schema? db-id schema)))@@ -242,8 +240,7 @@filtered-tables (cond->> (if include-editable-data-model?(filter-tables-by-data-model-perms candidate-tables)(filter mi/can-read? candidate-tables))- can-query? (filter mi/can-query?)- exclude-unpublished-tables? (filter :is_published))+ can-query? (filter mi/can-query?))hydration-keys (cond-> [](premium-features/any-transforms-enabled?) (conj :transform)include-measures? (conj :measures))]diff --git a/src/metabase/warehouse_schema_rest/api/field.clj b/src/metabase/warehouse_schema_rest/api/field.cljindex f490555e386..33e5b8d4043 100644--- a/src/metabase/warehouse_schema_rest/api/field.clj+++ b/src/metabase/warehouse_schema_rest/api/field.clj@@ -4,7 +4,6 @@[metabase.api-scope.data-app :as api-scope][metabase.api.common :as api][metabase.api.macros :as api.macros]- [metabase.data-apps.core :as data-apps][metabase.events.core :as events][metabase.lib.schema.metadata :as lib.schema.metadata][metabase.models.interface :as mi]@@ -59,10 +58,7 @@[{:keys [id]} :- [:map {:closed true}[:id ms/PositiveInt]]{include-editable-data-model? :include_editable_data_model} :- [:map {:closed true}- [:include_editable_data_model {:default false} ms/BooleanValue]]- _body- request]- (some-> (data-apps/request-data-app request) (data-apps/check-field id))+ [:include_editable_data_model {:default false} ms/BooleanValue]]](schema.field/get-field id {:include-editable-data-model? include-editable-data-model?}))(api.macros/defendpoint :post "/table-ids" :- [:map@@ -236,11 +232,7 @@"Get the count and distinct count of `Field` with ID."{:scope api-scope/data-app}[{:keys [id]} :- [:map {:closed true}- [:id ms/PositiveInt]]- _query-params- _body- request]- (some-> (data-apps/request-data-app request) (data-apps/check-field id))+ [:id ms/PositiveInt]]](let [field (api/read-check :model/Field id)][[:count (metadata-from-qp/field-count field)][:distincts (metadata-from-qp/field-distinct-count field)]]))@@ -308,11 +300,7 @@`:list`, checks whether we should create FieldValues for this Field; if so, creates and returns them."{:scope api-scope/data-app}[{:keys [id]} :- [:map {:closed true}- [:id ms/PositiveInt]]- _query-params- _body- request]- (some-> (data-apps/request-data-app request) (data-apps/check-field id))+ [:id ms/PositiveInt]]](let [field (api/query-check (warehouse-schema-rest.db/field id))](parameters.field/field->values field)))@@ -406,12 +394,7 @@[:id ms/PositiveInt][:search-id ms/PositiveInt]]{:keys [value]} :- [:map {:closed true}- [:value {:optional true} ms/NonBlankString]]- _body- request]- (when-let [data-app (data-apps/request-data-app request)]- (data-apps/check-field data-app id)- (data-apps/check-field data-app search-id))+ [:value {:optional true} ms/NonBlankString]]](when-not value(api/check-400 (request/limit) "Limit required if value is omitted"))(let [field (api/check-404 (warehouse-schema-rest.db/field id))@@ -431,12 +414,7 @@[:id ms/PositiveInt][:remapped-id ms/PositiveInt]]{:keys [value]} :- [:map {:closed true}- [:value ms/NonBlankString]]- _body- request]- (when-let [data-app (data-apps/request-data-app request)]- (data-apps/check-field data-app id)- (data-apps/check-field data-app remapped-id))+ [:value ms/NonBlankString]]](let [field (-> (warehouse-schema-rest.db/field id) api/check-404 api/read-check)remapped-field (-> (warehouse-schema-rest.db/field remapped-id) api/check-404 api/read-check)value (parameters.field/parse-query-param-value-for-field field value)]@@ -450,9 +428,5 @@"Return related entities."{:scope api-scope/data-app}[{:keys [id]} :- [:map {:closed true}- [:id ms/PositiveInt]]- _query-params- _body- request]- (some-> (data-apps/request-data-app request) (data-apps/check-field id))+ [:id ms/PositiveInt]]](-> (warehouse-schema-rest.db/field id) api/read-check xrays/related))diff --git a/src/metabase/warehouse_schema_rest/api/table.clj b/src/metabase/warehouse_schema_rest/api/table.cljindex 0e84980d16a..ba53b513e33 100644--- a/src/metabase/warehouse_schema_rest/api/table.clj+++ b/src/metabase/warehouse_schema_rest/api/table.clj@@ -135,10 +135,7 @@[:id ms/PositiveInt]]{:keys [include_editable_data_model]}:- [:map {:closed true}- [:include_editable_data_model {:optional true} [:maybe :boolean]]]- _body- request]- (some-> (data-apps/request-data-app request) (data-apps/check-table id))+ [:include_editable_data_model {:optional true} [:maybe :boolean]]]](let [api-perm-check-fn (if include_editable_data_modelschema.table/check-data-model-permsapi/read-check)]@@ -328,10 +325,7 @@:- [:map {:closed true}[:include_sensitive_fields {:default false} [:maybe ms/BooleanValue]][:include_hidden_fields {:default false} [:maybe ms/BooleanValue]]- [:include_editable_data_model {:default false} [:maybe ms/BooleanValue]]]- _body- request]- (some-> (data-apps/request-data-app request) (data-apps/check-table id))+ [:include_editable_data_model {:default false} [:maybe ms/BooleanValue]]]](schema.table/fetch-table-query-metadata id {:include-sensitive-fields? include_sensitive_fields:include-hidden-fields? include_hidden_fields:include-editable-data-model? include_editable_data_model}))@@ -376,11 +370,7 @@"Get all foreign keys whose destination is a `Field` that belongs to this `Table`."{:scope api-scope/data-app}[{:keys [id]} :- [:map {:closed true}- [:id ms/PositiveInt]]- _query-params- _body- request]- (some-> (data-apps/request-data-app request) (data-apps/check-table id))+ [:id ms/PositiveInt]]](api/read-check :model/Table id)(when-let [field-ids (seq (warehouse-schema-rest.db/active-unretired-field-ids-for-table id))](for [origin-field (warehouse-schema-rest.db/active-fields-targeting field-ids)diff --git a/src/metabase/warehouses_rest/api.clj b/src/metabase/warehouses_rest/api.cljindex 75e2f2768c6..bcbe762522a 100644--- a/src/metabase/warehouses_rest/api.clj+++ b/src/metabase/warehouses_rest/api.clj@@ -8,7 +8,6 @@[metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.config.core :as config]- [metabase.data-apps.core :as data-apps][metabase.database-routing.core :as database-routing][metabase.driver :as driver][metabase.driver.connection :as driver.conn]@@ -65,12 +64,11 @@(defn- add-tables"Hydrate tables for each database. An optional `can-query?` filter keeps only the tables the user can query."- [dbs & {:keys [can-query? exclude-unpublished-tables?]}]+ [dbs & {:keys [can-query?]}](let [all-tables (warehouses-rest.db/active-visible-tables-for-databases (map :id dbs))_ (perms/prime-table-perms-cache {:db-ids (into #{} (map :id) dbs)})filtered-tables (cond->> (filter mi/can-read? all-tables)- can-query? (filter mi/can-query?)- exclude-unpublished-tables? (filter :is_published))+ can-query? (filter mi/can-query?))db-id->tables (group-by :db_id filtered-tables)](for [db dbs](assoc db :tables (get db-id->tables (:id db) [])))))@@ -81,12 +79,11 @@rules the single-DB `/api/database/:id/schemas` endpoint applies. One SQLquery covers the whole list so this is cheaper than the N round-trips aclient would otherwise make to populate a database-picker dropdown."- [dbs & {:keys [exclude-unpublished-tables?]}]+ [dbs](if (empty? dbs)dbs(let [db-ids (map :id dbs)- rows (cond->> (warehouses-rest.db/active-visible-schemas-for-databases db-ids)- exclude-unpublished-tables? (filter :is_published))+ rows (warehouses-rest.db/active-visible-schemas-for-databases db-ids)schemas-by-db (reduce(fn [m {:keys [db_id schema]}](update m db_id (fnil conj []) schema))@@ -103,14 +100,6 @@vec)](assoc db :schemas readable))))))-(defn- keep-databases-with-published-tables- "`dbs` narrowed to those with an active, visible table published to the Library."- [dbs]- (let [db-ids (into #{}- (comp (filter :is_published) (map :db_id))- (warehouses-rest.db/active-visible-tables-for-databases (map :id dbs)))]- (filter (comp db-ids :id) dbs)))-(mu/defn- add-native-perms-info :- [:maybe[:sequential[:map@@ -302,8 +291,7 @@exclude-uneditable-details?include-only-uploadable?router-database-id- can-query?- exclude-unpublished-tables?]}]+ can-query?]}](let [filter-on-router-database-id (when (some->> router-database-id(perms/user-has-permission-for-database? api/*current-user-id* :perms/manage-database :yes))router-database-id)@@ -316,16 +304,14 @@;; everything below walks the list one database at a time_ (perms/prime-database-perms-cache {:db-ids (into #{} (map :id) dbs)})](cond-> (-> dbs add-native-perms-info add-transforms-perms-info)- exclude-unpublished-tables? keep-databases-with-published-tables- include-tables? (add-tables :can-query? can-query? :exclude-unpublished-tables? exclude-unpublished-tables?)- include-schemas? (add-schemas :exclude-unpublished-tables? exclude-unpublished-tables?)+ include-tables? (add-tables :can-query? can-query?)+ include-schemas? add-schemascan-query? (#(filter mi/can-query? %))true add-can-upload-to-dbstrue (t2/hydrate :router_user_attribute)include-editable-data-model? filter-databases-by-data-model-permsexclude-uneditable-details? (#(filter (some-fn :is_attached_dwh mi/can-write?) %))- (and include-saved-questions-db?- (not exclude-unpublished-tables?)) (add-saved-questions-virtual-database :include-tables? include-saved-questions-tables?)+ include-saved-questions-db? (add-saved-questions-virtual-database :include-tables? include-saved-questions-tables?);; Perms checks for uploadable DBs are handled by exclude-uneditable-details? (see below)include-only-uploadable? (#(filter uploadable-db? %)))))@@ -381,9 +367,7 @@[:exclude_uneditable_details {:default false} [:maybe :boolean]][:include_only_uploadable {:default false} [:maybe :boolean]][:router_database_id {:optional true} [:maybe ms/PositiveInt]]- [:can-query {:optional true} [:maybe :boolean]]]- _body- request]+ [:can-query {:optional true} [:maybe :boolean]]]](let [include-tables? (= include "tables")include-schemas? (= include "schemas")include-saved-questions-tables? (and saved include-tables?)@@ -398,8 +382,7 @@:include-stubs? include_stubs:include-only-uploadable? include_only_uploadable:router-database-id router_database_id- :can-query? can-query- :exclude-unpublished-tables? (some? (data-apps/request-data-app request)))+ :can-query? can-query)[])]{:data db-list-res:total (count db-list-res)}))@@ -430,7 +413,7 @@(defn- get-database-hydrate-include"If URL param `?include=` was passed to `GET /api/database/:id`, hydrate the Database appropriately."- [db include exclude-unpublished-tables?]+ [db include](if-not includedb(-> (case include@@ -440,7 +423,6 @@(cond->> tables; filter hidden tablestrue (filter (every-pred (complement :visibility_type) mi/can-read?))- exclude-unpublished-tables? (filter :is_published)true (map (fn [table] (update table :schema str))); filter hidden fields(= include "tables.fields") (map #(update % :fields filter-sensitive-fields))@@ -459,11 +441,11 @@(defn- present-database"Get a single Database with `id`."- [db {:keys [include include-editable-data-model? exclude-unpublished-tables?]}]+ [db {:keys [include include-editable-data-model?]}](cond-> dbtrue (t2/hydrate :router_user_attribute)true add-expanded-schedules- true (get-database-hydrate-include include exclude-unpublished-tables?)+ true (get-database-hydrate-include include)true add-can-uploadinclude-editable-data-model? check-db-data-model-perms(mi/can-write? db) (assoc :can-manage true)))@@ -499,18 +481,14 @@:- [:map {:closed true}[:include {:optional true} [:maybe [:enum "tables" "tables.fields"]]][:include_editable_data_model {:optional true} ms/MaybeBooleanValue]- [:exclude_uneditable_details {:optional true} ms/MaybeBooleanValue]]- _body- request]- (some-> (data-apps/request-data-app request) (data-apps/check-database id))+ [:exclude_uneditable_details {:optional true} ms/MaybeBooleanValue]]](present-database(warehouses/get-database id {:include-editable-data-model? include_editable_data_model:exclude-uneditable-details? exclude_uneditable_details:include-destination-databases? true}){:include include:include-editable-data-model? include_editable_data_model- :exclude-uneditable-details? exclude_uneditable_details- :exclude-unpublished-tables? (some? (data-apps/request-data-app request))}))+ :exclude-uneditable-details? exclude_uneditable_details}));; TODO (Cam 10/28/25) -- fix this endpoint route to use kebab-case for consistency with the rest of our REST API;;@@ -1297,14 +1275,10 @@can-query]} :- [:map {:closed true}[:include_editable_data_model {:default false} [:maybe ms/BooleanValue]][:include_hidden {:default false} [:maybe ms/BooleanValue]]- [:can-query {:optional true} [:maybe :boolean]]]- _body- request]- (some-> (data-apps/request-data-app request) (data-apps/check-database id))+ [:can-query {:optional true} [:maybe :boolean]]]](schema.table/database-schemas id {:include-editable-data-model? include_editable_data_model:include-hidden? include_hidden- :can-query? can-query- :exclude-unpublished-tables? (some? (data-apps/request-data-app request))}))+ :can-query? can-query}));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to;; use our API + we will need it when we make auto-TypeScript-signature generation happen@@ -1361,18 +1335,14 @@[:include_hidden {:default false} [:maybe ms/BooleanValue]][:include_editable_data_model {:default false} [:maybe ms/BooleanValue]][:can-query {:optional true} [:maybe :boolean]]- [:include_measures {:optional true} [:maybe :boolean]]]- _body- request]- (some-> (data-apps/request-data-app request) (data-apps/check-database id))+ [:include_measures {:optional true} [:maybe :boolean]]]](api/check-404 (seq (schema.table/schema-tables-listidschema{:include-hidden? include_hidden:include-editable-data-model? include_editable_data_model:can-query? can-query- :include-measures? include_measures- :exclude-unpublished-tables? (some? (data-apps/request-data-app request))}))))+ :include-measures? include_measures}))));; TODO (Cam 10/28/25) -- fix this endpoint so it uses kebab-case for query parameters for consistency with the rest;; of the REST API@@ -1401,15 +1371,11 @@[:include_hidden {:default false} [:maybe ms/BooleanValue]][:include_editable_data_model {:default false} [:maybe ms/BooleanValue]][:can-query {:optional true} [:maybe :boolean]]- [:include_measures {:optional true} [:maybe :boolean]]]- _body- request]- (some-> (data-apps/request-data-app request) (data-apps/check-database id))+ [:include_measures {:optional true} [:maybe :boolean]]]](let [opts {:include-hidden? include_hidden:include-editable-data-model? include_editable_data_model:can-query? can-query- :include-measures? include_measures- :exclude-unpublished-tables? (some? (data-apps/request-data-app request))}]+ :include-measures? include_measures}](api/check-404 (seq (if (str/blank? schema)(concat (schema.table/schema-tables-list id nil opts)(schema.table/schema-tables-list id "" opts))diff --git a/src/metabase/warehouses_rest/db.clj b/src/metabase/warehouses_rest/db.cljindex 35a66c16271..720deae0343 100644--- a/src/metabase/warehouses_rest/db.clj+++ b/src/metabase/warehouses_rest/db.clj@@ -27,9 +27,9 @@[:%lower.display_name :asc]]}))(mu/defn active-visible-schemas-for-databases- "The Database id, schema and published state of each active, visible Table of the Databases with `database-ids`."+ "The Database id and schema of each active, visible Table of the Databases with `database-ids`."[database-ids :- [:sequential ::lib.schema.id/database]]- (t2/select [:model/Table :db_id :schema :is_published]+ (t2/select [:model/Table :db_id :schema]:db_id [:in database-ids]:active true:visibility_type nil