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
Address DWH and RLCS corner case (#85450)
Ethan McCueb5df766e5942
diff --git a/e2e/test/scenarios/permissions/view-data.cy.spec.js b/e2e/test/scenarios/permissions/view-data.cy.spec.jsindex 9ac6b961a8e..82187141be6 100644--- a/e2e/test/scenarios/permissions/view-data.cy.spec.js+++ b/e2e/test/scenarios/permissions/view-data.cy.spec.js@@ -3,9 +3,40 @@ import { SAMPLE_DB_ID, USER_GROUPS } from "e2e/support/cypress_data";import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";import { ORDERS_QUESTION_ID } from "e2e/support/cypress_sample_instance_data";-const { ORDERS_ID } = SAMPLE_DATABASE;+const {+ ACCOUNTS_ID,+ ANALYTIC_EVENTS_ID,+ FEEDBACK_ID,+ INVOICES_ID,+ ORDERS_ID,+ PEOPLE_ID,+ PRODUCTS_ID,+ REVIEWS_ID,+} = SAMPLE_DATABASE;const { ALL_USERS_GROUP, COLLECTION_GROUP } = USER_GROUPS;+const SAMPLE_DB_TABLE_IDS = {+ ACCOUNTS_ID,+ ANALYTIC_EVENTS_ID,+ FEEDBACK_ID,+ INVOICES_ID,+ ORDERS_ID,+ PEOPLE_ID,+ PRODUCTS_ID,+ REVIEWS_ID,+};++const SAMPLE_DB_TABLE_NAMES = [+ "Accounts",+ "Analytic Events",+ "Feedback",+ "Invoices",+ "Orders",+ "People",+ "Products",+ "Reviews",+];+const DATA_ACCESS_PERM_IDX = 0;const CREATE_QUERIES_PERM_IDX = 1;const DOWNLOAD_PERM_IDX = 2;@@ -806,6 +837,59 @@ describe("scenarios > admin > permissions > view data > sandboxed", () => {H.assertPermissionTable(expectedFinalPermissions);});++ it("should keep existing row and column security when sandboxing the last table in a schema", () => {+ Object.values(SAMPLE_DB_TABLE_IDS)+ .filter((tableId) => tableId !== ORDERS_ID)+ .forEach((tableId) => {+ cy.sandboxTable({ group_id: ALL_USERS_GROUP, table_id: tableId });+ });++ cy.intercept("PUT", "/api/permissions/graph").as("saveGraph");+ cy.visit(+ `/admin/permissions/data/group/${ALL_USERS_GROUP}/database/${SAMPLE_DB_ID}/schema/PUBLIC`,+ );++ H.modifyPermission(+ "Orders",+ DATA_ACCESS_PERM_IDX,+ "Row and column security",+ );++ H.modal().within(() => {+ cy.findByText("Configure row and column security for this table");+ cy.findByText("Pick a column").click();+ });+ H.popover().findByText("User ID").click();+ H.modal().findByPlaceholderText("Pick a user attribute").click();+ H.popover().findByText("attr_uid").click();+ H.modal().button("Save").click();++ H.savePermissions();+ cy.wait("@saveGraph").its("response.statusCode").should("eq", 200);++ cy.request("GET", "/api/mt/gtap").then(({ body: sandboxes }) => {+ const sandboxedTableIds = sandboxes+ .filter((sandbox) => sandbox.group_id === ALL_USERS_GROUP)+ .map((sandbox) => sandbox.table_id)+ .sort((a, b) => a - b);++ expect(sandboxedTableIds).to.deep.equal(+ Object.values(SAMPLE_DB_TABLE_IDS).sort((a, b) => a - b),+ );+ });++ cy.reload();+ H.assertPermissionTable(+ SAMPLE_DB_TABLE_NAMES.map((name) => [+ name,+ "Row and column security",+ "Query builder only",+ "1 million rows",+ "No",+ ]),+ );+ });});describe("scenarios > admin > permissions > view data > reproductions", () => {diff --git a/enterprise/backend/src/metabase_enterprise/sandbox/models/permissions/delete_sandboxes.clj b/enterprise/backend/src/metabase_enterprise/sandbox/models/permissions/delete_sandboxes.cljindex ab944a0a42f..c3d65b9ef73 100644--- a/enterprise/backend/src/metabase_enterprise/sandbox/models/permissions/delete_sandboxes.clj+++ b/enterprise/backend/src/metabase_enterprise/sandbox/models/permissions/delete_sandboxes.clj@@ -11,16 +11,24 @@[changes {:keys [group_id db_id schema table_id]}](let [view-data-changes (get-in changes [group_id db_id :view-data])](cond- (nil? view-data-changes) false+ (nil? view-data-changes)+ false+;; DB-level change (keyword like :unrestricted) → delete all sandboxes for this group+db- (keyword? view-data-changes) true+ (keyword? view-data-changes)+ (not= view-data-changes :sandboxed)+:else(let [schema-changes (or (get view-data-changes (or schema ""))(get view-data-changes schema))](cond- (nil? schema-changes) false+ (nil? schema-changes)+ false+;; Schema-level change → delete all sandboxes for this group+db+schema- (keyword? schema-changes) true+ (keyword? schema-changes)+ (not= schema-changes :sandboxed)+:else;; Table-level change → delete unless the new value is :sandboxed(let [table-change (get schema-changes table_id)]diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/api/permissions_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/api/permissions_test.cljindex 526de1eefcb..d64fe88dc92 100644--- a/enterprise/backend/test/metabase_enterprise/sandbox/api/permissions_test.clj+++ b/enterprise/backend/test/metabase_enterprise/sandbox/api/permissions_test.clj@@ -111,6 +111,30 @@(testing "GTAP should not have been deleted"(is (t2/exists? :model/Sandbox :group_id (u/the-id (perms-group/all-users)), :table_id (mt/id :venues))))))))))+(deftest collapsed-sandboxed-perms-dont-delete-gtaps-test+ (testing "PUT /api/permissions/graph"+ (testing (str "sandboxing the last unsandboxed table makes the frontend collapse the schema (or DB) to `sandboxed`, "+ "which should keep the existing sandboxes rather than delete them")+ (doseq [[message updated-db-perms] {"schema-level sandboxed" {"PUBLIC" "sandboxed"}+ "DB-level sandboxed" "sandboxed"}]+ (testing message+ (met/with-gtaps! {:gtaps {:venues {}}}+ (mt/with-model-cleanup [:model/Sandbox]+ (let [graph (-> (mt/user-http-request :crowberto :get 200 "permissions/graph")+ (assoc-in (db-graph-keypath &group) updated-db-perms)+ (assoc :sandboxes [{:group_id (u/the-id &group)+ :table_id (mt/id :checkins)}]))]+ (mt/user-http-request :crowberto :put 200 "permissions/graph" graph)+ (testing "the existing sandbox is kept"+ (is (t2/exists? :model/Sandbox :group_id (u/the-id &group) :table_id (mt/id :venues))))+ (testing "the newly added sandbox is saved"+ (is (t2/exists? :model/Sandbox :group_id (u/the-id &group) :table_id (mt/id :checkins))))+ (testing "the graph reports both tables as sandboxed"+ (is (=? {(mt/id :venues) :sandboxed+ (mt/id :checkins) :sandboxed}+ (get-in (data-perms.graph/api-graph)+ [:groups (u/the-id &group) (mt/id) :view-data "PUBLIC"]))))))))))))+(defn- fake-persist-card! [card](let [persisted-info (persisted-info/turn-on-model! (mt/user->id :rasta) card)](t2/update! :model/PersistedInfo {:card_id (u/the-id card)}