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
fix: allow analytics collection perms to be set (#65927)
Edward Pagete996561416f9
diff --git a/enterprise/backend/test/metabase_enterprise/audit_app/permissions_test.clj b/enterprise/backend/test/metabase_enterprise/audit_app/permissions_test.cljindex 5ccb95fa4ba..d8459c1c7f7 100644--- a/enterprise/backend/test/metabase_enterprise/audit_app/permissions_test.clj+++ b/enterprise/backend/test/metabase_enterprise/audit_app/permissions_test.clj@@ -103,7 +103,7 @@(mt/with-temp [:model/PermissionsGroup {group-id :id} {}:model/Database {database-id :id} {}:model/Table view-table {:db_id database-id :name "v_users"}- :model/Collection collection {}]+ :model/Collection collection {:namespace "analytics"}](with-redefs [audit/audit-db-id database-idaudit/default-audit-collection (constantly collection)](testing "Updating permissions for the audit collection also updates audit DB permissions"diff --git a/src/metabase/permissions/models/collection/graph.clj b/src/metabase/permissions/models/collection/graph.cljindex 6e3cab2a155..425c6795cb1 100644--- a/src/metabase/permissions/models/collection/graph.clj+++ b/src/metabase/permissions/models/collection/graph.clj@@ -259,10 +259,12 @@(let [other-ns-ids (when (seq (disj collection-ids :root));; 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+ ;; - 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-> [:or [:not= :namespace (some-> namespace name)]]- (some? namespace) (into [[:= :namespace nil]]))]}))]+ (cond->> [[:not= :namespace (some-> namespace name)]]+ (nil? namespace) (into [:and [:not= :namespace "analytics"]])+ (some? namespace) (into [:or [:= :namespace nil]]))]}))](cond-> graph(seq other-ns-ids) (update :groups update-vals #(apply dissoc % other-ns-ids)))))diff --git a/test/metabase/permissions/models/collection/graph_test.clj b/test/metabase/permissions/models/collection/graph_test.cljindex c3c6ec69a07..e8ca7618bca 100644--- a/test/metabase/permissions/models/collection/graph_test.clj+++ b/test/metabase/permissions/models/collection/graph_test.clj@@ -88,12 +88,32 @@(deftest audit-collections-graph-test(testing "Check that the audit collection has :read for admins (sparse - no :none entries)."(mt/with-non-admin-groups-no-root-collection-perms- (mt/with-temp [:model/Collection collection {}]+ (mt/with-temp [:model/Collection collection {:namespace "analytics"}](with-redefs [audit/default-audit-collection (constantly collection)](is (= {:revision 0:groups {(u/the-id (perms-group/admin)) {:root :write, :COLLECTION :read}}}(replace-collection-ids collection (graph :clear-revisions? true, :collections [collection])))))))))+(deftest cannot-set-audit-permissions-for-non-admins-test+ (clear-graph-revisions!)+ (mt/with-premium-features #{}+ (testing "Cannot set write permissiosn with no feature flag"+ (mt/with-non-admin-groups-no-root-collection-perms+ (mt/with-temp [:model/Collection collection {:namespace "analytics"}]+ (with-redefs [audit/default-audit-collection (constantly collection)]+ (graph/update-graph! {:revision 0 :groups {(u/the-id (perms-group/all-users)) {(u/the-id collection) :write}}})+ (is (= {:revision 0+ :groups {(u/the-id (perms-group/admin)) {:root :write, :COLLECTION :read}}}+ (replace-collection-ids collection (graph :clear-revisions? true, :collections [collection]))))))))+ (testing "Cannot set read permissiosn with no feature flag"+ (mt/with-non-admin-groups-no-root-collection-perms+ (mt/with-temp [:model/Collection collection {:namespace "analytics"}]+ (with-redefs [audit/default-audit-collection (constantly collection)]+ (graph/update-graph! {:revision 0 :groups {(u/the-id (perms-group/all-users)) {(u/the-id collection) :read}}})+ (is (= {:revision 0+ :groups {(u/the-id (perms-group/admin)) {:root :write, :COLLECTION :read}}}+ (replace-collection-ids collection (graph :clear-revisions? true, :collections [collection]))))))))))+(deftest read-perms-test(testing "make sure read perms show up correctly"(mt/with-non-admin-groups-no-root-collection-perms