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 permissions checks for the dependencies API (#64965)
metamben8722548f6d6b
diff --git a/e2e/test/scenarios/dependencies/dependency-graph.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-graph.cy.spec.tsindex 9ef236717e0..845e149b0db 100644--- a/e2e/test/scenarios/dependencies/dependency-graph.cy.spec.ts+++ b/e2e/test/scenarios/dependencies/dependency-graph.cy.spec.ts@@ -3,10 +3,12 @@ const { H } = cy;import { WRITABLE_DB_ID } from "e2e/support/cypress_data";import {ADMIN_PERSONAL_COLLECTION_ID,+ ALL_USERS_GROUP_ID,FIRST_COLLECTION_ID,ORDERS_DASHBOARD_ID,SECOND_COLLECTION_ID,} from "e2e/support/cypress_sample_instance_data";+import { DataPermissionValue } from "metabase/admin/permissions/types";import type { IconName } from "metabase/ui";import type {CardId,@@ -524,8 +526,17 @@ describe("scenarios > dependencies > dependency graph", () => {});});- describe.skip("permissions", () => {+ describe("permissions", () => {it("should be able to view database entities without collection access", () => {+ cy.updatePermissionsGraph({+ [ALL_USERS_GROUP_ID]: {+ [WRITABLE_DB_ID]: {+ "view-data": DataPermissionValue.UNRESTRICTED,+ "create-queries": DataPermissionValue.QUERY_BUILDER_AND_NATIVE,+ },+ },+ });+getScoreboardTableId().then((tableId) => {createTableBasedQuestion({ tableId });createTableBasedModel({ tableId });@@ -564,7 +575,7 @@ describe("scenarios > dependencies > dependency graph", () => {cy.findByText("1 question").should("be.visible");cy.findByText("1 model").should("be.visible");cy.findByText("1 metric").should("be.visible");- cy.findByText("1 snippet").should("be.visible");+ cy.findByText(/snippet/).should("not.exist");cy.findByText(/transform/).should("not.exist");});});diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj b/enterprise/backend/src/metabase_enterprise/dependencies/api.cljindex 389e2d6cbf6..43add0deadc 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/api.clj@@ -4,6 +4,7 @@[metabase-enterprise.dependencies.core :as dependencies][metabase-enterprise.dependencies.models.dependency :as dependency][metabase.analyze.core :as analyze]+ [metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.api.routes.common :refer [+auth]][metabase.api.util.handlers :as handlers]@@ -37,8 +38,8 @@broken-transform-ids (keys transform)broken-transforms (when (seq broken-transform-ids)(t2/select :model/Transform :id [:in broken-transform-ids]))]- {:success (and (empty? broken-card-ids)- (empty? broken-transform-ids))+ {:success (and (empty? broken-card-ids)+ (empty? broken-transform-ids)):bad_cards (into [] (comp (filter (fn [card](if (mi/can-read? card)card@@ -56,48 +57,50 @@[_route-params_query-paramsbody :- ::card-body]- (let [database-id (-> body :dataset_query :database)- base-provider (lib-be/application-database-metadata-provider database-id)- original (lib.metadata/card base-provider (:id body))- card (-> original- (assoc :dataset-query (:dataset_query body)- :type (:type body (:type original)))+ (api/read-check :model/Card (:id body))+ (let [database-id (-> body :dataset_query :database)+ base-provider (lib-be/application-database-metadata-provider database-id)+ original (lib.metadata/card base-provider (:id body))+ card (-> original+ (assoc :dataset-query (:dataset_query body)+ :type (:type body (:type original)));; Remove the old `:result-metadata` from the card, it's likely wrong now.- (dissoc :result-metadata)+ (dissoc :result-metadata);; But if the request includes `:result_metadata`, use that. It may be from a native card;; that's been run before saving the card.- (cond-> #_card- (:result_metadata body) (assoc :result-metadata (:result_metadata body))))- edits {:card [card]}- breakages (dependencies/errors-from-proposed-edits base-provider edits)]+ (cond-> #_card+ (:result_metadata body) (assoc :result-metadata (:result_metadata body))))+ edits {:card [card]}+ breakages (dependencies/errors-from-proposed-edits base-provider edits)](broken-cards-response breakages)))(mr/def ::transform-body[:map- [:id {:optional false} ms/PositiveInt]- [:name {:optional true} :string]+ [:id {:optional false} ms/PositiveInt]+ [:name {:optional true} :string];; TODO (Cam 10/8/25) -- no idea what the correct schema for these is supposed to be -- it was just `map` before --;; this is my attempt to guess it- [:source {:optional true} [:maybe [:map- [:type {:optional true} :keyword]- [:query {:optional true} ::queries.schema/query]]]]- [:target {:optional true} [:maybe ms/Map]]])+ [:source {:optional true} [:maybe [:map+ [:type {:optional true} :keyword]+ [:query {:optional true} ::queries.schema/query]]]]+ [:target {:optional true} [:maybe ms/Map]]])(api.macros/defendpoint :post "/check_transform""Check a proposed edit to a transform, and return the card, transform, etc. IDs for things that will break."[_route-params_query-params{:keys [id source target] :as _body} :- ::transform-body]+ (api/read-check :model/Transform id)(if (= (keyword (:type source)):query)- (let [database-id (-> source :query :database)+ (let [database-id (-> source :query :database)base-provider (lib-be/application-database-metadata-provider database-id)- original (lib.metadata/transform base-provider id)- transform (-> original- (cond-> #_transform source (assoc :source source))- (cond-> #_transform target (assoc :target target)))- edits {:transform [transform]}- breakages (dependencies/errors-from-proposed-edits base-provider edits)]+ original (lib.metadata/transform base-provider id)+ transform (-> original+ (cond-> #_transform source (assoc :source source))+ (cond-> #_transform target (assoc :target target)))+ edits {:transform [transform]}+ breakages (dependencies/errors-from-proposed-edits base-provider edits)](broken-cards-response breakages));; if this isn't a sql query, just claim it works{:success true}))@@ -108,20 +111,21 @@_query-params{:keys [id content], snippet-name :name}:- [:map- [:id {:optional false} ms/PositiveInt]- [:name {:optional true} native-query-snippets/NativeQuerySnippetName]- [:content {:optional true} :string]]]- (let [original (t2/select-one :model/NativeQuerySnippet id)- _ (when (and snippet-name- (not= snippet-name (:name original))- (t2/exists? :model/NativeQuerySnippet :name snippet-name))- (throw (ex-info (tru "A snippet with that name already exists. Please pick a different name.")- {:status-code 400})))- snippet (cond-> (m/assoc-some original- :lib/type :metadata/native-query-snippet- :name snippet-name- :content content)- content native-query-snippets/add-template-tags)+ [:id {:optional false} ms/PositiveInt]+ [:name {:optional true} native-query-snippets/NativeQuerySnippetName]+ [:content {:optional true} :string]]]+ (api/read-check :model/NativeQuerySnippet id)+ (let [original (t2/select-one :model/NativeQuerySnippet id)+ _ (when (and snippet-name+ (not= snippet-name (:name original))+ (t2/exists? :model/NativeQuerySnippet :name snippet-name))+ (throw (ex-info (tru "A snippet with that name already exists. Please pick a different name.")+ {:status-code 400})))+ snippet (cond-> (m/assoc-some original+ :lib/type :metadata/native-query-snippet+ :name snippet-name+ :content content)+ content native-query-snippets/add-template-tags)breakages (dependencies/errors-from-proposed-edits {:snippet [snippet]})](broken-cards-response breakages)))@@ -150,12 +154,35 @@(m/map-vals format-subentity)):dependents_count (usages [entity-type id])})-(defn- entity-model [entity-type]- (case entity-type- :table :model/Table- :card :model/Card- :snippet :model/NativeQuerySnippet- :transform :model/Transform))+(def ^:private entity-model+ {:table :model/Table+ :card :model/Card+ :snippet :model/NativeQuerySnippet+ :transform :model/Transform})++(defn- readable-node?+ "Check if the user can read the entity represented by `[entity-type entity-id]`."+ [[entity-type entity-id]]+ (if-let [model (entity-model entity-type)]+ (try+ (mi/can-read? model entity-id)+ (catch Exception e+ (log/debugf e "Couldn't determine if %s with id %s is readble"+ (some-> entity-type name) entity-id)+ false))+ (do+ (log/warn "Cannot determine the model of" (some-> entity-type name))+ false)))++(defn- readable-graph-dependencies+ "Return a permission-aware dependency graph that only includes readable entities."+ []+ (dependency/filtered-graph-dependencies readable-node?))++(defn- readable-graph-dependents+ "Return a permission-aware dependent graph that only includes readable entities."+ []+ (dependency/filtered-graph-dependents readable-node?))(defn- calc-usages"Calculates the count of direct dependents for all nodes in `nodes`, based on `graph`. "@@ -185,10 +212,10 @@(mapcat (fn [[entity-type entity-ids]](->> (cond-> (t2/select (entity-model entity-type):id [:in entity-ids])- (= entity-type :card) (-> (t2/hydrate :creator :dashboard [:collection :is_personal] :moderation_reviews)- (->> (map collection.root/hydrate-root-collection))- (revisions/with-last-edit-info :card))- (= entity-type :table) (t2/hydrate :fields :db)+ (= entity-type :card) (-> (t2/hydrate :creator :dashboard [:collection :is_personal] :moderation_reviews)+ (->> (map collection.root/hydrate-root-collection))+ (revisions/with-last-edit-info :card))+ (= entity-type :table) (t2/hydrate :fields :db)(= entity-type :transform) (t2/hydrate :table-with-db-and-fields))(mapv #(entity-value entity-type % usages))))nodes-by-type)))@@ -202,12 +229,13 @@[_route-params{:keys [id type]} :- [:map[:id {:optional true} ms/PositiveInt]- [:type {:optional true} (ms/enum-decode-keyword [:table :card :snippet :transform])]]]+ [:type {:optional true} (ms/enum-decode-keyword (vec (keys entity-model)))]]]+ (api/read-check (entity-model type) id)(let [starting-nodes [[type id]]- upstream-graph (dependency/graph-dependencies)+ upstream-graph (readable-graph-dependencies);; cache the downstream graph specifically, because between calculating transitive children and calculating;; edges, we'll call this multiple times on the same nodes.- downstream-graph (graph/cached-graph (dependency/graph-dependents))+ downstream-graph (graph/cached-graph (readable-graph-dependents))nodes (into (set starting-nodes)(graph/transitive upstream-graph starting-nodes))edges (graph/calc-edges downstream-graph nodes)]@@ -217,7 +245,7 @@(def ^:private dependents-args[:map[:id ms/PositiveInt]- [:type (ms/enum-decode-keyword [:table :card :snippet :transform])]+ [:type (ms/enum-decode-keyword (vec (keys entity-model)))][:dependent_type (ms/enum-decode-keyword [:table :card :snippet :transform])][:dependent_card_type {:optional true} (ms/enum-decode-keyword[:question :model :metric])]])@@ -230,7 +258,8 @@and :type. For :snippet -> :name. For :transform -> :name."[_route-params{:keys [id type dependent_type dependent_card_type]} :- dependents-args]- (let [downstream-graph (graph/cached-graph (dependency/graph-dependents))+ (api/read-check (entity-model type) id)+ (let [downstream-graph (graph/cached-graph (readable-graph-dependents))nodes (-> (graph/children-of downstream-graph [[type id]])(get [type id]))](->> (expanded-nodes downstream-graph nodes)diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/models/dependency.clj b/enterprise/backend/src/metabase_enterprise/dependencies/models/dependency.cljindex 766dc84fe98..453dab87370 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/models/dependency.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/models/dependency.clj@@ -19,14 +19,14 @@(t2/deftransforms :model/Dependency{:from_entity_type mi/transform-keyword- :to_entity_type mi/transform-keyword})+ :to_entity_type mi/transform-keyword})(defn- deps-children [src-type src-id dst-type dst-id key-seq];; Group all keys with the same type together, so we make O(types) indexed [[t2/select]] calls, not O(n).(transduce (map (fn [[entity-type entity-keys]](let [deps (t2/select :model/Dependencysrc-type entity-type- src-id [:in entity-keys])]+ src-id [:in entity-keys])](u/group-by (juxt src-type src-id)(juxt dst-type dst-id)conj #{}@@ -61,6 +61,28 @@[](->DependencyGraph key-dependencies))+(defn filtered-graph-dependencies+ "Return a dependency graph for finding dependencies (upstream entities), filtered by `node-predicate`.+ The predicate receives entity keys as `[entity-type entity-id]` and should return true for nodes to include."+ [node-predicate]+ (->DependencyGraph+ (fn [key-seq]+ (into {}+ (map (fn [[k v]]+ [k (filterv node-predicate v)]))+ (key-dependencies key-seq)))))++(defn filtered-graph-dependents+ "Return a dependency graph for finding dependents (downstream entities), filtered by `node-predicate`.+ The predicate receives entity keys as `[entity-type entity-id]` and should return true for nodes to include."+ [node-predicate]+ (->DependencyGraph+ (fn [key-seq]+ (into {}+ (map (fn [[k v]]+ [k (filterv node-predicate v)]))+ (key-dependents key-seq)))))+(defn transitive-dependents"Given a map of updated entities `{entity-type [{:id 1, ...} ...]}`, return a map of its transitive dependentsas `{entity-type #{4 5 6}}` - that is, a map from downstream entity type to a set of IDs.@@ -73,9 +95,9 @@**Excludes** the input entities from the list of dependents!"([updated-entities] (transitive-dependents nil updated-entities))([graph updated-entities]- (let [graph (or graph (graph-dependents))+ (let [graph (or graph (graph-dependents))starters (for [[entity-type updates] updated-entities- entity updates+ entity updates:when (:id entity)][entity-type (:id entity)])](->> (graph/transitive graph starters) ; This returns a flat list.@@ -97,9 +119,9 @@to-add (for [[to-entity-type ids] dependencies-by-typeto-entity-id (set/difference ids (current-by-type to-entity-type))]{:from_entity_type entity-type- :from_entity_id entity-id- :to_entity_type to-entity-type- :to_entity_id to-entity-id})]+ :from_entity_id entity-id+ :to_entity_type to-entity-type+ :to_entity_id to-entity-id})](t2/with-transaction [_conn](when (seq to-remove)(t2/delete! :model/Dependency :id [:in to-remove]))diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.cljindex d721314ae97..a50783db518 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj@@ -4,8 +4,11 @@[medley.core :as m][metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata]+ [metabase.native-query-snippets.models.native-query-snippet.permissions :as snippet.perms]+ [metabase.permissions.core :as perms][metabase.queries.models.card :as card]- [metabase.test :as mt]))+ [metabase.test :as mt]+ [metabase.util :as u]))(defn card-with-query"Create a card map with the given name and dataset query."@@ -35,11 +38,29 @@card-meta (lib.metadata/card mp (:id inner-card))](card-with-query "Downstream card" (lib/query mp card-meta))))+(defn wrap-two-cards+ "Construct a card depending on both `card1` and `card2` via a join."+ [card1 card2]+ (let [mp (mt/metadata-provider)+ card1-meta (lib.metadata/card mp (:id card1))+ card2-meta (lib.metadata/card mp (:id card2))+ base-query (lib/query mp card1-meta)+ card1-cols (lib/returned-columns base-query card1-meta)+ card2-cols (lib/returned-columns base-query card2-meta)+ join-clause (-> (lib/join-clause card2-meta)+ (lib/with-join-alias "joined")+ (lib/with-join-conditions+ [(lib/= (first card1-cols)+ (-> (first card2-cols)+ (lib/with-join-alias "joined")))])+ (lib/with-join-fields :all))]+ (card-with-query "Card with join" (lib/join base-query join-clause))))+(deftest check-card-test(testing "POST /api/ee/dependencies/check_card"(mt/with-premium-features #{:dependencies}(mt/with-temp [:model/User user {:email "[email protected]"}]- (mt/with-model-cleanup [:model/Card]+ (mt/with-model-cleanup [:model/Card :model/Dependency](let [card (card/create-card! (basic-card) user)response (mt/user-http-request :rasta :post 200 "ee/dependencies/check_card"(assoc (card/create-card! (basic-card "Product question" :products)@@ -53,7 +74,7 @@(mt/dataset test-data(mt/with-premium-features #{:dependencies}(mt/with-temp [:model/User user {:email "[email protected]"}]- (mt/with-model-cleanup [:model/Card]+ (mt/with-model-cleanup [:model/Card :model/Dependency](let [mp (mt/metadata-provider);; Create base card querying real orders tablebase-card (card/create-card! (basic-card) user)@@ -83,7 +104,7 @@(mt/dataset test-data(mt/with-premium-features #{:dependencies}(mt/with-temp [:model/User user {:email "[email protected]"}]- (mt/with-model-cleanup [:model/Card]+ (mt/with-model-cleanup [:model/Card :model/Dependency](let [mp (mt/metadata-provider)orders-query (lib/query mp (lib.metadata/table mp (mt/id :orders)))base-query (-> orders-query@@ -121,7 +142,7 @@(mt/dataset test-data(mt/with-premium-features #{:dependencies}(mt/with-temp [:model/User user {:email "[email protected]"}]- (mt/with-model-cleanup [:model/Card]+ (mt/with-model-cleanup [:model/Card :model/Dependency](let [mp (mt/metadata-provider);; Create base card querying real orders tablebase-card (card/create-card! (basic-card) user)@@ -158,15 +179,16 @@(testing "POST /api/ee/dependencies/check_transform"(mt/with-premium-features #{:dependencies}(mt/with-temp [:model/Transform {_transform-id :id :as transform} {}]- (let [response (mt/user-http-request :rasta :post 200 "ee/dependencies/check_transform" transform)]+ (let [response (mt/user-http-request :crowberto :post 200 "ee/dependencies/check_transform" transform)](is (= {:bad_cards [], :bad_transforms [], :success true}response)))))))(deftest check-snippet-test(testing "POST /api/ee/dependencies/check_snippet"(mt/with-premium-features #{:dependencies}- (mt/with-temp [:model/NativeQuerySnippet {_snippet-id :id :as snippet} {}]- (let [response (mt/user-http-request :rasta :post 200 "ee/dependencies/check_snippet" snippet)]+ (mt/with-temp [:model/NativeQuerySnippet {_snippet-id :id :as snippet} {:name "test-snippet"+ :content "WHERE ID > 10"}]+ (let [response (mt/user-http-request :crowberto :post 200 "ee/dependencies/check_snippet" snippet)](is (= {:bad_cards [], :bad_transforms [], :success true}response)))))))@@ -177,7 +199,7 @@(mt/with-temp [:model/User user {:email "[email protected]"}:model/NativeQuerySnippet {snippet-id :id snippet-name :name} {:name "filter-snippet":content "WHERE SUBTOTAL > 100"}]- (mt/with-model-cleanup [:model/Card]+ (mt/with-model-cleanup [:model/Card :model/Dependency](let [tag-name (str "snippet: " snippet-name)mp (mt/metadata-provider)native-query (-> (lib/native-query mp (format "SELECT * FROM ORDERS %s" (str "{{" tag-name "}}")))@@ -203,11 +225,11 @@(deftest graph-test(testing "GET /api/ee/dependencies/graph"(mt/with-premium-features #{:dependencies}- (mt/with-model-cleanup [:model/Card]+ (mt/with-model-cleanup [:model/Card :model/Dependency](mt/with-temp [:model/User user {:email "[email protected]"}](let [{card-id-1 :id :as dependency-card} (card/create-card! (basic-card) user){card-id-2 :id} (card/create-card! (wrap-card dependency-card) user)- response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph" :id card-id-2 :type "card")+ response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph" :id card-id-2 :type "card")creator {:email "[email protected]":id (:id user)}](is (=? {:edges@@ -248,7 +270,7 @@(testing "GET /api/ee/dependencies/graph with table as root node"(mt/dataset test-data(mt/with-premium-features #{:dependencies}- (mt/with-model-cleanup [:model/Card]+ (mt/with-model-cleanup [:model/Card :model/Dependency](mt/with-temp [:model/User user {:email "[email protected]"}](let [_card-1 (card/create-card! (basic-card "Card 1" :orders) user)_card-2 (card/create-card! (basic-card "Card 2" :orders) user)@@ -266,7 +288,7 @@(deftest dependents-test(testing "GET /api/ee/dependencies/graph/dependents"(mt/with-premium-features #{:dependencies}- (mt/with-model-cleanup [:model/Card]+ (mt/with-model-cleanup [:model/Card :model/Dependency](mt/with-temp [:model/User user {:email "[email protected]"}](let [{card-id-1 :id :as dependency-card} (card/create-card! (basic-card) user){card-id-2 :id} (card/create-card! (wrap-card dependency-card) user)@@ -293,3 +315,319 @@:id card-id-2:type "card"}]response))))))))++(deftest check-card-permissions-test+ (testing "POST /api/ee/dependencies/check_card requires read permissions on the input card"+ (mt/with-premium-features #{:dependencies}+ (mt/with-non-admin-groups-no-root-collection-perms+ (mt/with-temp [:model/Collection collection {}+ :model/User user {:email "[email protected]"}]+ (mt/with-model-cleanup [:model/Card :model/Dependency]+ (let [card (card/create-card! (assoc (basic-card) :collection_id (u/the-id collection)) user)]+ (testing "Returns 403 when user lacks read permissions"+ (is (= "You don't have permissions to do that."+ (mt/user-http-request :rasta :post 403 "ee/dependencies/check_card"+ (assoc card :name "Modified name")))))+ (testing "Returns 200 when user has read permissions"+ (perms/grant-collection-read-permissions! (perms/all-users-group) collection)+ (is (=? {:success true}+ (mt/user-http-request :rasta :post 200 "ee/dependencies/check_card"+ (assoc card :name "Modified name"))))))))))))++(deftest check-snippet-permissions-test+ (testing "POST /api/ee/dependencies/check_snippet requires native query execution permissions"+ (mt/with-premium-features #{:dependencies}+ (mt/with-non-admin-groups-no-root-collection-perms+ (mt/with-temp [:model/NativeQuerySnippet snippet {:name "test snippet"+ :content "SELECT 1"+ :creator_id (mt/user->id :crowberto)}]+ ;; remove native permissions+ (with-redefs [snippet.perms/has-any-native-permissions? (constantly false)]+ (testing "Returns 403 when user lacks native query execution permissions"+ (is (= "You don't have permissions to do that."+ (mt/user-http-request :rasta :post 403 "ee/dependencies/check_snippet"+ {:id (:id snippet)+ :content "SELECT 2"})))))+ ;; Grant native query permissions+ (testing "Returns 200 when user has native query execution permissions"+ (mt/user-http-request :rasta :post 200 "ee/dependencies/check_snippet"+ {:id (:id snippet)+ :content "SELECT 2"})))))))++(deftest check-transform-permissions-test+ (testing "POST /api/ee/dependencies/check_transform requires read permissions on the input transform"+ (mt/with-premium-features #{:dependencies}+ (mt/with-temp [:model/Transform transform {:name "test transform"}]+ (testing "Returns 403 when user is not an admin (only admins can read transforms)"+ (is (= "You don't have permissions to do that."+ (mt/user-http-request :rasta :post 403 "ee/dependencies/check_transform"+ {:id (:id transform)+ :source (:source transform)+ :target (:target transform)}))))+ (testing "Returns 200 when user is an admin"+ (is (=? {:success true}+ (mt/user-http-request :crowberto :post 200 "ee/dependencies/check_transform"+ {:id (:id transform)+ :source (:source transform)+ :target (:target transform)}))))))))++(deftest graph-permissions-test+ (testing "GET /api/ee/dependencies/graph requires read permissions on the starting entity"+ (mt/with-premium-features #{:dependencies}+ (mt/with-non-admin-groups-no-root-collection-perms+ (mt/with-temp [:model/Collection collection {}+ :model/User user {:email "[email protected]"}]+ (mt/with-model-cleanup [:model/Card :model/Dependency]+ (let [card (card/create-card! (assoc (basic-card) :collection_id (u/the-id collection)) user)]+ (testing "Returns 403 when user lacks read permissions"+ (is (= "You don't have permissions to do that."+ (mt/user-http-request :rasta :get 403 "ee/dependencies/graph"+ :id (:id card)+ :type "card"))))+ (testing "Returns 200 when user has read permissions"+ (perms/grant-collection-read-permissions! (perms/all-users-group) collection)+ (mt/user-http-request :rasta :get 200 "ee/dependencies/graph"+ :id (:id card)+ :type "card")))))))))++(deftest graph-dependents-permissions-test+ (testing "GET /api/ee/dependencies/graph/dependents requires read permissions on the starting entity"+ (mt/with-premium-features #{:dependencies}+ (mt/with-non-admin-groups-no-root-collection-perms+ (mt/with-temp [:model/Collection collection {}+ :model/User user {:email "[email protected]"}]+ (mt/with-model-cleanup [:model/Card :model/Dependency]+ (let [{card-id :id} (card/create-card! (assoc (basic-card) :collection_id (:id collection)) user)]+ (testing "Returns 403 when user lacks read permissions"+ (is (= "You don't have permissions to do that."+ (mt/user-http-request :rasta :get 403 "ee/dependencies/graph/dependents"+ :id card-id+ :type "card"+ :dependent_type "card"+ :dependent_card_type "question"))))+ (testing "Returns 200 when user has read permissions"+ (perms/grant-collection-read-permissions! (perms/all-users-group) collection)+ (mt/user-http-request :rasta :get 200 "ee/dependencies/graph/dependents"+ :id card-id+ :type "card"+ :dependent_type "card"+ :dependent_card_type "question")))))))))++(deftest graph-filtering-test+ (testing "GET /api/ee/dependencies/graph filters out upstream nodes the user cannot read"+ (mt/dataset test-data+ (mt/with-premium-features #{:dependencies}+ (mt/with-non-admin-groups-no-root-collection-perms+ (mt/with-temp [:model/Collection readable-collection {}+ :model/Collection unreadable-collection {}+ :model/User user {:email "[email protected]"}]+ (mt/with-model-cleanup [:model/Card :model/Dependency]+ (let [readable-base (card/create-card! (assoc (basic-card "Readable")+ :collection_id (:id readable-collection)) user)+ unreadable-base (card/create-card! (assoc (basic-card "Unreadable")+ :collection_id (:id unreadable-collection)) user)+ top-card (card/create-card! (assoc (wrap-two-cards readable-base unreadable-base)+ :collection_id (:id readable-collection))+ user)]+ (perms/grant-collection-read-permissions! (perms/all-users-group) readable-collection)+ (testing "User sees complete upstream graph through readable path"+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph"+ :id (:id top-card)+ :type "card")+ nodes (set (map (juxt :type :id) (:nodes response)))+ expected-nodes #{["card" (:id top-card)] ["card" (:id readable-base)] ["table" (mt/id :orders)]}]+ (is (= expected-nodes nodes)+ "Should see top-card, readable-base, and :orders table")))+ (testing "Edges show complete readable dependency chain"+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph"+ :id (:id top-card)+ :type "card")+ edges (set (:edges response))+ expected-edges #{{:from_entity_id (:id top-card)+ :from_entity_type "card"+ :to_entity_id (:id readable-base)+ :to_entity_type "card"}+ {:from_entity_id (:id readable-base)+ :from_entity_type "card"+ :to_entity_id (mt/id :orders)+ :to_entity_type "table"}}]+ (is (= expected-edges edges)+ "Should have edges: top-card->readable-base and readable-base->orders")))))))))))++(deftest graph-dependents-filtering-test+ (testing "GET /api/ee/dependencies/graph/dependents filters out nodes the user cannot read"+ (mt/with-premium-features #{:dependencies}+ (mt/with-non-admin-groups-no-root-collection-perms+ (mt/with-temp [:model/Collection readable-collection {}+ :model/Collection unreadable-collection {}+ :model/User user {:email "[email protected]"}]+ (mt/with-model-cleanup [:model/Card :model/Dependency]+ (let [base-card (card/create-card! (assoc (basic-card) :collection_id (:id readable-collection)) user)+ readable-dependent (card/create-card! (assoc (wrap-card base-card)+ :collection_id (:id readable-collection))+ user)+ unreadable-dependent (card/create-card! (assoc (wrap-card base-card)+ :collection_id (:id unreadable-collection))+ user)]+ (perms/grant-collection-read-permissions! (perms/all-users-group) readable-collection)+ (testing "User sees only readable dependents"+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph/dependents"+ :id (:id base-card)+ :type "card"+ :dependent_type "card"+ :dependent_card_type "question")+ dependent-ids (set (map :id response))]+ (is (contains? dependent-ids (:id readable-dependent)))+ (is (not (contains? dependent-ids (:id unreadable-dependent)))))))))))))++(deftest graph-multi-level-filtering-test+ (testing "GET /api/ee/dependencies/graph includes upstream nodes if ANY path to them is readable"+ (mt/dataset test-data+ (mt/with-premium-features #{:dependencies}+ (mt/with-non-admin-groups-no-root-collection-perms+ (mt/with-temp [:model/Collection readable-collection {}+ :model/Collection unreadable-collection {}+ :model/User user {:email "[email protected]"}]+ (mt/with-model-cleanup [:model/Card :model/Dependency]+ (let [base-card (card/create-card! (assoc (basic-card) :collection_id (:id readable-collection)) user)+ unreadable-middle (card/create-card! (assoc (wrap-card base-card)+ :collection_id (:id unreadable-collection))+ user)+ readable-alternate (card/create-card! (assoc (wrap-card base-card)+ :collection_id (:id readable-collection))+ user)+ end-card (card/create-card! (assoc (wrap-two-cards unreadable-middle readable-alternate)+ :collection_id (:id readable-collection))+ user)]+ (perms/grant-collection-read-permissions! (perms/all-users-group) readable-collection)+ (testing "Diamond pattern: complete upstream graph via readable path"+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph"+ :id (:id end-card)+ :type "card")+ nodes (set (map (juxt :type :id) (:nodes response)))+ expected-nodes #{["card" (:id end-card)] ["card" (:id readable-alternate)]+ ["card" (:id base-card)] ["table" (mt/id :orders)]}]+ (is (= expected-nodes nodes)+ "Should see end-card, readable-alternate, base-card, and :orders table")))+ (testing "Edges show complete readable dependency chain"+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph"+ :id (:id end-card)+ :type "card")+ edges (set (:edges response))+ expected-edges #{{:from_entity_id (:id end-card)+ :from_entity_type "card"+ :to_entity_id (:id readable-alternate)+ :to_entity_type "card"}+ {:from_entity_id (:id readable-alternate)+ :from_entity_type "card"+ :to_entity_id (:id base-card)+ :to_entity_type "card"}+ {:from_entity_id (:id base-card)+ :from_entity_type "card"+ :to_entity_id (mt/id :orders)+ :to_entity_type "table"}}]+ (is (= expected-edges edges)+ "Should have edges through readable path only")))))))))))++(deftest graph-filtering-all-unreadable-test+ (testing "GET /api/ee/dependencies/graph returns only root node when all upstream dependencies are unreadable"+ (mt/dataset test-data+ (mt/with-premium-features #{:dependencies}+ (mt/with-non-admin-groups-no-root-collection-perms+ (mt/with-temp [:model/Collection readable-collection {}+ :model/Collection unreadable-collection {}+ :model/User user {:email "[email protected]"}]+ (mt/with-model-cleanup [:model/Card :model/Dependency]+ (let [unreadable-base (card/create-card! (assoc (basic-card "Unreadable")+ :collection_id (:id unreadable-collection)) user)+ top-card (card/create-card! (assoc (wrap-card unreadable-base)+ :collection_id (:id readable-collection))+ user)]+ (perms/grant-collection-read-permissions! (perms/all-users-group) readable-collection)+ (testing "User sees only the top card in the graph"+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph"+ :id (:id top-card)+ :type "card")+ nodes (set (map (juxt :type :id) (:nodes response)))]+ (is (= #{["card" (:id top-card)]} nodes)+ "Should see only top-card when all dependencies are unreadable")))+ (testing "No edges when all dependencies are filtered"+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph"+ :id (:id top-card)+ :type "card")]+ (is (empty? (:edges response))+ "Should have no edges when all dependencies are filtered out")))))))))))++(deftest graph-snippet-filtering-test+ (testing "GET /api/ee/dependencies/graph/dependents filters snippet dependents based on card permissions"+ (mt/dataset test-data+ (mt/with-premium-features #{:dependencies}+ (mt/with-non-admin-groups-no-root-collection-perms+ (mt/with-temp [:model/Collection readable-collection {}+ :model/Collection unreadable-collection {}+ :model/User user {:email "[email protected]"}+ :model/NativeQuerySnippet {snippet-id :id snippet-name :name} {:name "test-snippet"+ :content "WHERE ID > 10"}]+ (mt/with-model-cleanup [:model/Card :model/Dependency]+ (let [tag-name (str "snippet: " snippet-name)+ mp (mt/metadata-provider)+ native-query (fn []+ (-> (lib/native-query mp (format "SELECT * FROM ORDERS %s" (str "{{" tag-name "}}")))+ (lib/with-template-tags {tag-name {:name tag-name+ :display-name (str "Snippet: " snippet-name)+ :type :snippet+ :snippet-name snippet-name+ :snippet-id snippet-id}})))+ readable-card (card/create-card! {:name "Readable card with snippet"+ :dataset_query (native-query)+ :display :table+ :visualization_settings {}+ :collection_id (:id readable-collection)}+ user)+ unreadable-card (card/create-card! {:name "Unreadable card with snippet"+ :dataset_query (native-query)+ :display :table+ :visualization_settings {}+ :collection_id (:id unreadable-collection)}+ user)]+ (perms/grant-collection-read-permissions! (perms/all-users-group) readable-collection)+ (testing "User sees only readable cards as dependents of the snippet"+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph/dependents"+ :id snippet-id+ :type "snippet"+ :dependent_type "card"+ :dependent_card_type "question")+ dependent-ids (set (map :id response))]+ (is (contains? dependent-ids (:id readable-card))+ "Should see readable card as dependent")+ (is (not (contains? dependent-ids (:id unreadable-card)))+ "Should not see unreadable card as dependent")))))))))))++(deftest graph-table-permission-filtering-test+ (testing "GET /api/ee/dependencies/graph filters out tables when user lacks table permissions"+ (mt/dataset test-data+ (mt/with-premium-features #{:dependencies}+ (mt/with-non-admin-groups-no-root-collection-perms+ (mt/with-temp [:model/Collection readable-collection {}+ :model/User user {:email "[email protected]"}]+ (mt/with-temp-copy-of-db+ (mt/with-model-cleanup [:model/Card :model/Dependency]+ (mt/with-no-data-perms-for-all-users!+ (perms/set-table-permission! (perms/all-users-group) (mt/id :orders) :perms/view-data :blocked)+ (perms/set-table-permission! (perms/all-users-group) (mt/id :orders) :perms/create-queries :no)+ (let [card (card/create-card! (assoc (basic-card "Card on orders")+ :collection_id (:id readable-collection)) user)]+ (perms/grant-collection-read-permissions! (perms/all-users-group) readable-collection)+ (testing "User sees only the card, table is filtered out"+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph"+ :id (:id card)+ :type "card")+ nodes (set (map (juxt :type :id) (:nodes response)))]+ (is (= #{["card" (:id card)]} nodes)+ "Should see only the card, not the unreadable table")))+ (testing "No edges when table is filtered"+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph"+ :id (:id card)+ :type "card")]+ (is (empty? (:edges response))+ "Should have no edges when table is filtered out")))))))))))))diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/models/dependency_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/models/dependency_test.cljindex 4aec0e2dcc5..3b4224851fa 100644--- a/enterprise/backend/test/metabase_enterprise/dependencies/models/dependency_test.clj+++ b/enterprise/backend/test/metabase_enterprise/dependencies/models/dependency_test.clj@@ -47,64 +47,66 @@(mt/dataset test-data(mt/with-temp [:model/User user {:email "[email protected]"}](mt/with-premium-features #{:dependencies}- (let [card1 (card/create-card! (basic-orders) user)]- (is (integer? (:id card1)))- (testing "when creating a new card"- (is (=? #{(depends-on-> :card (:id card1) :table (mt/id :orders))}- (upstream-of :card (:id card1))))+ (mt/with-model-cleanup [:model/Card :model/Dependency]+ (let [card1 (card/create-card! (basic-orders) user)]+ (is (integer? (:id card1)))+ (testing "when creating a new card"+ (is (=? #{(depends-on-> :card (:id card1) :table (mt/id :orders))}+ (upstream-of :card (:id card1))))- (testing "that depends on another card"- (let [card2 (card/create-card! (wrap-card card1) user)]- (is (=? #{(depends-on-> :card (:id card2) :card (:id card1))}- (upstream-of :card (:id card2))))- (testing "but that doesn't affect the upstream deps of the inner card"- (is (=? #{(depends-on-> :card (:id card1) :table (mt/id :orders))}- (upstream-of :card (:id card1))))))))+ (testing "that depends on another card"+ (let [card2 (card/create-card! (wrap-card card1) user)]+ (is (=? #{(depends-on-> :card (:id card2) :card (:id card1))}+ (upstream-of :card (:id card2))))+ (testing "but that doesn't affect the upstream deps of the inner card"+ (is (=? #{(depends-on-> :card (:id card1) :table (mt/id :orders))}+ (upstream-of :card (:id card1))))))))- (testing "when updating an existing card"- (testing "to add a new table dep"- (card/update-card! {:card-before-update card1- :card-updates- {:dataset_query (mt/mbql-query orders- {:joins [{:alias "Products"- :source-table (mt/id :products)- :condition [:= $id &Products.$products.id]}]})}})- (is (=? #{(depends-on-> :card (:id card1) :table (mt/id :orders))- (depends-on-> :card (:id card1) :table (mt/id :products))}- (upstream-of :card (:id card1)))))- (testing "to remove a table dep"- (card/update-card! {:card-before-update (t2/select-one :model/Card :id (:id card1))- :card-updates- {:dataset_query (mt/mbql-query products)}})- (is (=? #{(depends-on-> :card (:id card1) :table (mt/id :products))}- (upstream-of :card (:id card1))))))))))))+ (testing "when updating an existing card"+ (testing "to add a new table dep"+ (card/update-card! {:card-before-update card1+ :card-updates+ {:dataset_query (mt/mbql-query orders+ {:joins [{:alias "Products"+ :source-table (mt/id :products)+ :condition [:= $id &Products.$products.id]}]})}})+ (is (=? #{(depends-on-> :card (:id card1) :table (mt/id :orders))+ (depends-on-> :card (:id card1) :table (mt/id :products))}+ (upstream-of :card (:id card1)))))+ (testing "to remove a table dep"+ (card/update-card! {:card-before-update (t2/select-one :model/Card :id (:id card1))+ :card-updates+ {:dataset_query (mt/mbql-query products)}})+ (is (=? #{(depends-on-> :card (:id card1) :table (mt/id :products))}+ (upstream-of :card (:id card1)))))))))))))(deftest ^:sequential card-deps-graph-test-1-mbql-card-chain(testing "deps graph is connected properly for a chain of MBQL cards"(mt/dataset test-data(mt/with-temp [:model/User user {:email "[email protected]"}](mt/with-premium-features #{:dependencies}- (let [{id1 :id :as card1} (card/create-card! (basic-orders) user)- {id2 :id :as card2} (card/create-card! (wrap-card card1) user)- {id3 :id :as card3} (card/create-card! (wrap-card card2) user)]- (testing "raw deps are recorded correctly"- (is (=? #{(depends-on-> :card id1 :table (mt/id :orders))} (upstream-of :card id1)))- (is (=? #{(depends-on-> :card id2 :card id1)} (upstream-of :card id2)))- (is (=? #{(depends-on-> :card id3 :card id2)} (upstream-of :card id3))))+ (mt/with-model-cleanup [:model/Card :model/Dependency]+ (let [{id1 :id :as card1} (card/create-card! (basic-orders) user)+ {id2 :id :as card2} (card/create-card! (wrap-card card1) user)+ {id3 :id :as card3} (card/create-card! (wrap-card card2) user)]+ (testing "raw deps are recorded correctly"+ (is (=? #{(depends-on-> :card id1 :table (mt/id :orders))} (upstream-of :card id1)))+ (is (=? #{(depends-on-> :card id2 :card id1)} (upstream-of :card id2)))+ (is (=? #{(depends-on-> :card id3 :card id2)} (upstream-of :card id3))))- (testing "transitive deps are computed correctly"- (testing "for each card"- (is (=? {:card #{id2 id3}}- (deps.graph/transitive-dependents {:card [card1]})))- (is (=? {:card #{id3}}- (deps.graph/transitive-dependents {:card [card2]})))- (is (=? {}- (deps.graph/transitive-dependents {:card [card3]}))))- (testing "for the table"- (is (set/subset? #{id1 id2 id3}- (-> {:table [{:id (mt/id :orders)}]}- deps.graph/transitive-dependents- :card)))))))))))+ (testing "transitive deps are computed correctly"+ (testing "for each card"+ (is (=? {:card #{id2 id3}}+ (deps.graph/transitive-dependents {:card [card1]})))+ (is (=? {:card #{id3}}+ (deps.graph/transitive-dependents {:card [card2]})))+ (is (=? {}+ (deps.graph/transitive-dependents {:card [card3]}))))+ (testing "for the table"+ (is (set/subset? #{id1 id2 id3}+ (-> {:table [{:id (mt/id :orders)}]}+ deps.graph/transitive-dependents+ :card))))))))))))(defn- sql-card [metadata-provider sql]{:name "SQL card"@@ -121,68 +123,71 @@(mt/dataset test-data(mt/with-temp [:model/User user {:email "[email protected]"}](mt/with-premium-features #{:dependencies}- (let [mp (mt/metadata-provider)- {id1 :id :as card1} (card/create-card! (sql-card mp "SELECT * FROM orders;") user)- {id2 :id :as card2} (card/create-card! (sql-card mp (str "SELECT * FROM {{#" id1 "}}")) user)- {id3 :id :as card3} (card/create-card! (sql-card mp (str "SELECT * FROM {{#" id2 "}}")) user)]- (testing "raw deps are recorded correctly"- (is (=? #{(depends-on-> :card id1 :table (mt/id :orders))} (upstream-of :card id1)))- (is (=? #{(depends-on-> :card id2 :table (mt/id :orders))- (depends-on-> :card id2 :card id1)} (upstream-of :card id2)))- (is (=? #{(depends-on-> :card id3 :table (mt/id :orders))- (depends-on-> :card id3 :card id2)} (upstream-of :card id3))))- (testing "transitive deps are computed correctly"- (testing "for each card"- (is (=? {:card #{id2 id3}}- (deps.graph/transitive-dependents {:card [card1]})))- (is (=? {:card #{id3}}- (deps.graph/transitive-dependents {:card [card2]})))- (is (=? {}- (deps.graph/transitive-dependents {:card [card3]}))))- (testing "for the table"- (is (set/subset? #{id1 id2 id3}- (-> {:table [{:id (mt/id :orders)}]}- deps.graph/transitive-dependents- :card)))))))))))+ (mt/with-model-cleanup [:model/Card :model/Dependency]+ (let [mp (mt/metadata-provider)+ {id1 :id :as card1} (card/create-card! (sql-card mp "SELECT * FROM orders;") user)+ {id2 :id :as card2} (card/create-card! (sql-card mp (str "SELECT * FROM {{#" id1 "}}")) user)+ {id3 :id :as card3} (card/create-card! (sql-card mp (str "SELECT * FROM {{#" id2 "}}")) user)]+ (testing "raw deps are recorded correctly"+ (is (=? #{(depends-on-> :card id1 :table (mt/id :orders))} (upstream-of :card id1)))+ (is (=? #{(depends-on-> :card id2 :table (mt/id :orders))+ (depends-on-> :card id2 :card id1)} (upstream-of :card id2)))+ (is (=? #{(depends-on-> :card id3 :table (mt/id :orders))+ (depends-on-> :card id3 :card id2)} (upstream-of :card id3))))+ (testing "transitive deps are computed correctly"+ (testing "for each card"+ (is (=? {:card #{id2 id3}}+ (deps.graph/transitive-dependents {:card [card1]})))+ (is (=? {:card #{id3}}+ (deps.graph/transitive-dependents {:card [card2]})))+ (is (=? {}+ (deps.graph/transitive-dependents {:card [card3]}))))+ (testing "for the table"+ (is (set/subset? #{id1 id2 id3}+ (-> {:table [{:id (mt/id :orders)}]}+ deps.graph/transitive-dependents+ :card))))))))))))(deftest ^:sequential card-deps-graph-metric-test(testing "deps graph is connected properly for a question using a metric"(mt/dataset test-data(mt/with-temp [:model/User user {:email "[email protected]"}](mt/with-premium-features #{:dependencies}- (let [metric-card (card/create-card! {:name "Test Metric"- :database_id (mt/id)- :table_id (mt/id :orders)- :display :scalar- :query_type :query- :type :metric- :dataset_query (mt/mbql-query orders {:aggregation [[:count]]})- :visualization_settings {}}- user)- question-card (card/create-card! {:name "Question using Metric"+ (mt/with-model-cleanup [:model/Card :model/Dependency]+ (let [metric-card (card/create-card! {:name "Test Metric":database_id (mt/id)- :display :table- :query_type :query- :type :question- :dataset_query (mt/mbql-query orders- {:aggregation [[:metric (:id metric-card)]]})+ :table_id (mt/id :orders)+ :display :scalar+ :query_type :query+ :type :metric+ :dataset_query (mt/mbql-query orders {:aggregation [[:count]]}):visualization_settings {}}- user)]- (testing "raw deps are recorded correctly for question using metric"- (is (=? #{(depends-on-> :card (:id question-card) :table (mt/id :orders))- (depends-on-> :card (:id question-card) :card (:id metric-card))}- (upstream-of :card (:id question-card)))))))))))+ user)+ question-card (card/create-card! {:name "Question using Metric"+ :database_id (mt/id)+ :display :table+ :query_type :query+ :type :question+ :dataset_query (mt/mbql-query orders+ {:aggregation [[:metric (:id metric-card)]]})+ :visualization_settings {}}+ user)]+ (testing "raw deps are recorded correctly for question using metric"+ (is (=? #{(depends-on-> :card (:id question-card) :table (mt/id :orders))+ (depends-on-> :card (:id question-card) :card (:id metric-card))}+ (upstream-of :card (:id question-card))))))))))))(deftest dependency-analysis-version-test(testing "dependency_analysis_version is updated when entities are created or updated"(testing "cards"- (mt/with-temp [:model/Card card {:dependency_analysis_version 0}]- (is (zero? (t2/select-one-fn :dependency_analysis_version :model/Card (:id card))))- (mt/with-premium-features #{:dependencies}- (card/update-card! {:card-before-update card- :card-updates {:dataset_query (mt/mbql-query orders)}}))- (is (= deps.graph/current-dependency-analysis-version- (t2/select-one-fn :dependency_analysis_version :model/Card (:id card))))))+ (mt/with-model-cleanup [:model/Dependency]+ (mt/with-temp [:model/Card card {:dependency_analysis_version 0}]+ (is (zero? (t2/select-one-fn :dependency_analysis_version :model/Card (:id card))))+ (mt/with-premium-features #{:dependencies}+ (card/update-card! {:card-before-update card+ :card-updates {:dataset_query (mt/mbql-query orders)}}))+ (is (= deps.graph/current-dependency-analysis-version+ (t2/select-one-fn :dependency_analysis_version :model/Card (:id card)))))))(testing "transforms create"(mt/with-premium-features #{:dependencies}(mt/with-temp [:model/Transform transform]@@ -213,7 +218,7 @@(deftest dependency-analysis-version-create-card-test(testing "dependency_analysis_version is updated when a card is created"(mt/with-premium-features #{:dependencies}- (mt/with-model-cleanup [:model/Card]+ (mt/with-model-cleanup [:model/Card :model/Dependency](mt/with-temp [:model/User user](let [card (card/create-card! (basic-orders) user)](is (= deps.graph/current-dependency-analysis-version