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
UXW-2576 show tenant collections in the trash (#67124)
John Swansond5c3f459ba28
diff --git a/enterprise/backend/test/metabase_enterprise/tenants/api_test.clj b/enterprise/backend/test/metabase_enterprise/tenants/api_test.cljindex 8c6308a861d..01490c77999 100644--- a/enterprise/backend/test/metabase_enterprise/tenants/api_test.clj+++ b/enterprise/backend/test/metabase_enterprise/tenants/api_test.clj@@ -638,3 +638,23 @@{:archived true})(testing "card is archived"(is (true? (t2/select-one-fn :archived :model/Card :id card-id))))))))))++(deftest shared-tenant-collections-appear-in-trash-test+ (testing "GET /api/collection/:id/items for trash collection"+ (testing "archived collections with shared-tenant-collection and tenant-specific namespaces appear in trash"+ (mt/with-premium-features #{:tenants}+ (mt/with-temporary-setting-values [use-tenants true]+ (mt/with-temp [:model/Collection {normal-id :id} {:name "Normal Collection"}+ :model/Collection {shared-id :id} {:name "Shared Tenant Collection"+ :namespace "shared-tenant-collection"}+ :model/Collection {tenant-id :id} {:name "Tenant Specific Collection"+ :namespace "tenant-specific"}]+ ;; Archive all three collections+ (doseq [id [normal-id shared-id tenant-id]]+ (mt/user-http-request :crowberto :put 200 (str "collection/" id) {:archived true}))+ (let [trash-items (->> (mt/user-http-request :crowberto :get 200 (str "collection/" (collection/trash-collection-id) "/items"))+ :data+ (map :name)+ (into #{}))]+ (is (= #{"Normal Collection" "Shared Tenant Collection" "Tenant Specific Collection"}+ trash-items)))))))))diff --git a/src/metabase/collections_rest/api.clj b/src/metabase/collections_rest/api.cljindex ed5fb72f2af..7ecfb0f0e43 100644--- a/src/metabase/collections_rest/api.clj+++ b/src/metabase/collections_rest/api.clj@@ -720,7 +720,7 @@[:= :archived true][:= :id (collection/trash-collection-id)]][:and [:= :archived false] [:not= :id (collection/trash-collection-id)]])]- (perms/audit-namespace-clause :namespace (u/qualified-name collection-namespace))+ (perms/namespace-clause :namespace (u/qualified-name collection-namespace) (collection/is-trash? collection))(snippets-collection-filter-clause));; We get from the effective-children-query a normal set of columns selected:;; want to make it fit the others to make UNION ALL workdiff --git a/src/metabase/permissions/core.clj b/src/metabase/permissions/core.cljindex 3027d7a5b14..0e0db076886 100644--- a/src/metabase/permissions/core.clj+++ b/src/metabase/permissions/core.clj@@ -71,7 +71,7 @@visible-table-filter-with-cteselect-tables-and-groups-granting-perm][metabase.permissions.models.permissions- audit-namespace-clause+ namespace-clausecan-read-audit-helpercurrent-user-has-application-permissions?grant-application-permissions!diff --git a/src/metabase/permissions/models/collection/graph.clj b/src/metabase/permissions/models/collection/graph.cljindex 425c6795cb1..d5731acf393 100644--- a/src/metabase/permissions/models/collection/graph.clj+++ b/src/metabase/permissions/models/collection/graph.clj@@ -110,7 +110,8 @@:from [:collection]:where [:and[:or [:= :type nil] [:not= :type [:inline "trash"]]]- (perms/audit-namespace-clause :namespace (u/qualified-name collection-namespace))+ (perms/namespace-clause+ :namespace (u/qualified-name collection-namespace))[:not :archived][:= :personal_owner_id nil](let [ids-without-root (disj collection-ids :root)]@@ -260,7 +261,6 @@;; This query selects collection IDs that don't match the target namespace:;; - If target namespace is non-nil: collections with different non-nil namespaces OR nil namespaces;; - If target namespace is nil: collections with any non-nil namespace (except the 'analytics' namespace)- ;; this replicates the behavior of [[perms/audit-namespace-clause]](t2/select-pks-set :model/Collection {:where [:and [:in :id (disj collection-ids :root)](cond->> [[:not= :namespace (some-> namespace name)]](nil? namespace) (into [:and [:not= :namespace "analytics"]])diff --git a/src/metabase/permissions/models/permissions.clj b/src/metabase/permissions/models/permissions.cljindex b616e18873f..8a9fc47702a 100644--- a/src/metabase/permissions/models/permissions.clj+++ b/src/metabase/permissions/models/permissions.clj@@ -170,6 +170,7 @@[metabase.permissions.util :as perms.u][metabase.premium-features.core :as premium-features :refer [defenterprise]][metabase.remote-sync.core :as remote-sync]+ [metabase.settings.core :as setting][metabase.util :as u][metabase.util.honey-sql-2 :as h2x][metabase.util.i18n :refer [tru]]@@ -406,12 +407,18 @@;;;; Audit Permissions helper fns-(defn audit-namespace-clause+(defn namespace-clause"SQL clause to filter namespaces depending on if audit app is enabled or not, and if the namespace is the default one."- [namespace-keyword namespace-val]- (if (and (nil? namespace-val) (premium-features/enable-audit-app?))- [:or [:= namespace-keyword nil] [:= namespace-keyword "analytics"]]- [:= namespace-keyword namespace-val]))+ [namespace-keyword namespace-val & [include-tenant-namespaces?]]+ [:or+ [:= namespace-keyword namespace-val]+ (when (and (nil? namespace-val)+ (premium-features/enable-audit-app?))+ [:= namespace-keyword "analytics"])+ (when (and include-tenant-namespaces? (nil? namespace-val) (setting/get :use-tenants))+ [:= namespace-keyword "shared-tenant-collection"])+ (when (and include-tenant-namespaces? (nil? namespace-val) (setting/get :use-tenants))+ [:= namespace-keyword "tenant-specific"])]);;; TODO -- this is a predicate function that returns truthy or falsey, it should end in a `?` -- Cam(mu/defn can-read-audit-helperdiff --git a/src/metabase/search/permissions.clj b/src/metabase/search/permissions.cljindex de8b85fe044..0164ec42ee0 100644--- a/src/metabase/search/permissions.clj+++ b/src/metabase/search/permissions.clj@@ -44,9 +44,7 @@;; legacy search so it performs the same on MySQL;; TODO(edpaget 2025-12-04): this should be a default value of the search context and then search can be restricted;; to different namespaces via parameters.- [:or (perms/audit-namespace-clause :collection.namespace nil)- [:= :collection.namespace "tenant-specific"]- [:= :collection.namespace "shared-tenant-collection"]]])+ (perms/namespace-clause :collection.namespace nil true)])(mu/defn permitted-tables-clause"Build the WHERE clause and optional CTEs for table permission filtering.