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
Add support for transforms to collection items (#67832)
John Swanson16c291f7539a
diff --git a/enterprise/backend/test/metabase_enterprise/transforms/api_test.clj b/enterprise/backend/test/metabase_enterprise/transforms/api_test.cljindex 8d74c2baaf1..9f9d0219408 100644--- a/enterprise/backend/test/metabase_enterprise/transforms/api_test.clj+++ b/enterprise/backend/test/metabase_enterprise/transforms/api_test.clj@@ -13,6 +13,7 @@[metabase.driver :as driver][metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata]+ [metabase.permissions.core :as perms][metabase.query-processor :as qp][metabase.test :as mt][metabase.util :as u]@@ -1003,3 +1004,43 @@{:query "WITH category_counts AS (SELECT category, COUNT(*) as cnt FROM products GROUP BY category) SELECT * FROM category_counts"})](is (false? (:is_simple response)))(is (= "Contains a CTE" (:reason response))))))))++;;; ------------------------------------------------------------+;;; Collection Items Integration Tests+;;; ------------------------------------------------------------++(deftest collection-items-include-transforms-test+ (testing "GET /api/collection/:id/items"+ (testing "Includes transforms in collection items"+ (mt/with-premium-features #{:transforms}+ (mt/with-temp [:model/Collection {collection-id :id} {:name "Transforms Collection"+ :namespace :transforms}+ :model/Transform {transform-id :id}+ {:name "Test Transform"+ :description "A test transform"+ :collection_id collection-id}]+ ;; Test 1: Transform appears in unfiltered results+ (let [items (:data (mt/user-http-request :crowberto :get 200+ (format "collection/%d/items" collection-id)))]+ (is (= 1 (count items)))+ (is (= "transform" (:model (first items))))+ (is (= "Test Transform" (:name (first items)))))++ ;; Test 2: Transform appears when filtered by models=transform+ (let [items (:data (mt/user-http-request :crowberto :get 200+ (format "collection/%d/items" collection-id)+ :models "transform"))]+ (is (= 1 (count items)))+ (is (= transform-id (:id (first items)))))++ ;; Test 3: Transform NOT returned when filtering for other models only+ (let [items (:data (mt/user-http-request :crowberto :get 200+ (format "collection/%d/items" collection-id)+ :models "card"))]+ (is (empty? items)))++ ;; Test 4: Non-admin users don't see transforms+ (perms/grant-collection-read-permissions! (perms/all-users-group) collection-id)+ (let [items (:data (mt/user-http-request :rasta :get 200+ (format "collection/%d/items" collection-id)))]+ (is (empty? items))))))))diff --git a/src/metabase/collections_rest/api.clj b/src/metabase/collections_rest/api.cljindex 3b166b17d5e..94e0fe493d2 100644--- a/src/metabase/collections_rest/api.clj+++ b/src/metabase/collections_rest/api.clj@@ -299,7 +299,8 @@"snippet""no_models""timeline"- "table"})+ "table"+ "transform"})(def ^:private ModelString(into [:enum] valid-model-param-values))@@ -489,7 +490,11 @@:from [[:transform :transform]]:where [:and(poison-when-pinned-clause pinned-state)- [:= :collection_id (:id collection)]]})+ [:= :collection_id (:id collection)]+ (when-not api/*is-superuser?*+ [:=+ [:inline 0]+ [:inline 1]])]})(defmethod post-process-collection-children :timeline[_ _options _collection rows]@@ -1099,7 +1104,7 @@"Fetch a sequence of 'child' objects belonging to a Collection, filtered using `options`."[{collection-namespace :namespace, :as collection} :- collection/CollectionWithLocationAndIDOrRoot{:keys [models], :as options} :- CollectionChildrenOptions]- (let [valid-models (for [model-kw (cond-> [:collection :dataset :metric :card :dashboard :pulse :snippet :timeline :document :transform]+ (let [valid-models (for [model-kw (cond-> [:collection :dataset :metric :card :dashboard :pulse :snippet :timeline :document :transform];; Tables in collections are an EE feature (data-studio)(premium-features/has-feature? :data-studio) (conj :table));; only fetch models that are specified by the `model` param; or everything if it's empty