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 sub-collections toggle to stick when permissions selector is closed / Handle permissions dirty state gracefully (#65928)
Andersona33f7f45ee8d
diff --git a/e2e/test/scenarios/collections/collections-reproductions.cy.spec.ts b/e2e/test/scenarios/collections/collections-reproductions.cy.spec.tsnew file mode 100644index 00000000000..f24ac48499b--- /dev/null+++ b/e2e/test/scenarios/collections/collections-reproductions.cy.spec.ts@@ -0,0 +1,289 @@+const { H } = cy;+import {+ ADMIN_PERSONAL_COLLECTION_ID,+ FIRST_COLLECTION_ID,+ ORDERS_COUNT_QUESTION_ID,+ ORDERS_QUESTION_ID,+} from "e2e/support/cypress_sample_instance_data";+import type { CollectionId } from "metabase-types/api";++describe("issue 20911", () => {+ const COLLECTION_ACCESS_PERMISSION_INDEX = 0;+ const FIRST_COLLECTION = "First collection";++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ cy.intercept("GET", "/api/collection/graph").as("getGraph");+ });++ it("should allow to change sub-collections permissions after access change (metabase#20911)", () => {+ cy.visit("/collection/root/permissions");+ cy.wait("@getGraph");+ H.assertPermissionTable([+ ["Administrators", "Curate"],+ ["All Users", "No access"],+ ["collection", "Curate"],+ ["data", "No access"],+ ["nosql", "No access"],+ ["readonly", "View"],+ ]);+ H.modifyPermission(+ "collection",+ COLLECTION_ACCESS_PERMISSION_INDEX,+ "No access",+ // @ts-expect-error js function being used in ts file+ false,+ );+ H.modifyPermission(+ "collection",+ COLLECTION_ACCESS_PERMISSION_INDEX,+ "No access",+ // @ts-expect-error js function being used in ts file+ true,+ );+ H.modal().within(() => {+ cy.button("Save").click();+ });++ H.navigationSidebar().within(() => {+ cy.findByText(FIRST_COLLECTION).click();+ });+ H.getCollectionActions().within(() => {+ cy.icon("ellipsis").click();+ });+ H.popover().within(() => {+ cy.icon("lock").click();+ });+ H.assertPermissionTable([+ ["Administrators", "Curate"],+ ["All Users", "No access"],+ ["collection", "No access"],+ ["data", "No access"],+ ["nosql", "No access"],+ ["readonly", "View"],+ ]);++ cy.signInAsNormalUser();+ cy.visit("/collection/root");+ cy.get("main").findByText("You don't have permissions to do that.");++ cy.visit(`/collection/${FIRST_COLLECTION_ID}`);+ cy.get("main").findByText("Sorry, you don’t have permission to see that.");+ });+});++describe("issue 24660", () => {+ const collectionName = "Parent";++ const questions = {+ [ORDERS_QUESTION_ID]: "Orders",+ [ORDERS_COUNT_QUESTION_ID]: "Orders, Count",+ };++ function createParentCollectionAndMoveQuestionToIt(questionId: number) {+ return H.createCollection({+ name: collectionName,+ parent_id: null,+ }).then(({ body: { id } }) => {+ cy.request("PUT", `/api/card/${questionId}`, {+ collection_id: id,+ });+ });+ }++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ createParentCollectionAndMoveQuestionToIt(ORDERS_QUESTION_ID);+ createParentCollectionAndMoveQuestionToIt(ORDERS_COUNT_QUESTION_ID);+ });++ it("should properly show contents of different collections with the same name (metabase#24660)", () => {+ H.startNewQuestion();+ H.miniPickerBrowseAll().click();+ H.entityPickerModal().within(() => {+ cy.findAllByText(collectionName).first().click();++ cy.findByText(questions[ORDERS_QUESTION_ID]).should("exist");+ cy.findByText(questions[ORDERS_COUNT_QUESTION_ID]).should("not.exist");+ cy.realType("{esc}");+ });++ cy.findByPlaceholderText("Search for tables and more...").click();+ H.miniPicker().within(() => {+ cy.findByText("Our analytics").click();+ cy.findAllByText(collectionName).first().click();+ cy.findByText(questions[ORDERS_QUESTION_ID]).should("exist");+ cy.findByText(questions[ORDERS_COUNT_QUESTION_ID]).should("not.exist");+ });+ });+});++describe("issue 30235", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ H.activateToken("pro-self-hosted");+ });++ it("should allow to turn to official collection after moving it from personal to root parent collection (metabase#30235)", () => {+ const COLLECTION_NAME = "C30235";++ H.createCollection({+ name: COLLECTION_NAME,+ parent_id: ADMIN_PERSONAL_COLLECTION_ID,+ }).then(({ body: { id } }) => {+ cy.visit(`/collection/${id}`);++ H.moveOpenedCollectionTo("Our analytics");++ H.openCollectionMenu();++ H.popover().within(() => {+ cy.findByText("Make collection official").should("be.visible");+ cy.findByText("Edit permissions").should("be.visible");+ });+ });+ });+});++describe("issue 58231", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ H.activateToken("bleeding-edge");+ });++ it("should allow to edit permissions for Usage Analytics collection (metabase#58231)", () => {+ cy.visit("/collection/2-usage-analytics");++ cy.findByTestId("collection-menu")+ .findByLabelText("Edit permissions")+ .should("be.visible")+ .click();++ H.modal()+ .findByText("Permissions for Usage analytics")+ .should("be.visible");+ });+});++describe("issue 56567", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ H.activateToken("bleeding-edge");+ });++ const withTestCollections = (+ callback: (+ collectionAId: CollectionId,+ collectionBId: CollectionId,+ ) => void,+ ) => {+ H.createCollection({+ name: "A",+ }).then(({ body: collectionA }) => {+ const collectionAId = collectionA.id;++ H.createCollection({+ name: "B",+ parent_id: collectionA.id,+ }).then(({ body: collectionB }) => {+ const collectionBId = collectionB.id;+ callback(collectionAId, collectionBId);+ });+ });+ };++ const getTestPermissionsTable = (allUsersPermission: string) => [+ ["Administrators", "Curate"],+ ["All Users", allUsersPermission],+ ["collection", "Curate"],+ ["data", "No access"],+ ["nosql", "No access"],+ ["readonly", "View"],+ ];++ it("should propagate permission to sub-collections when 'Also change sub-collections' is checked (metabase#56567)", () => {+ withTestCollections((collectionAId, collectionBId) => {+ cy.visit(`/admin/permissions/collections/${collectionAId}`);++ H.assertPermissionTable(getTestPermissionsTable("No access"));++ cy.visit(`/admin/permissions/collections/${collectionBId}`);++ H.assertPermissionTable(getTestPermissionsTable("No access"));++ cy.visit(`/collection/${collectionAId}-a/permissions`);++ // opens up the permissions select+ H.getPermissionRowPermissions("All Users").click();++ // checks the 'Also change sub-collections' toggle+ H.popover().findByRole("switch").click();+ H.popover().findByRole("switch").should("be.checked");++ // selected desired permission+ H.popover().findByText("View").click();++ // opens up the permissions select again+ H.getPermissionRowPermissions("All Users").click();++ // ensures the toggle is still checked+ H.popover().findByRole("switch").should("be.checked");++ cy.intercept("PUT", "/api/collection/graph?skip-graph=true").as(+ "savePermissions",+ );+ cy.button("Save").click();+ cy.wait("@savePermissions");++ // Checks permissions for collection A is set to "View" as expected+ cy.visit(`/admin/permissions/collections/${collectionBId}`);+ H.assertPermissionTable(getTestPermissionsTable("View"));++ // Check the permission set to collection A was propagated to collection B+ cy.visit(`/admin/permissions/collections/${collectionBId}`);+ H.assertPermissionTable(getTestPermissionsTable("View"));+ });+ });++ it("should NOT propagate permission to sub-collections when 'Also change sub-collections' is unchecked", () => {+ withTestCollections((collectionAId, collectionBId) => {+ cy.visit(`/admin/permissions/collections/${collectionBId}`);++ H.assertPermissionTable(getTestPermissionsTable("No access"));++ cy.visit(`/collection/${collectionAId}-a/permissions`);++ // opens up the permissions select+ H.getPermissionRowPermissions("All Users").click();++ // selected desired permission without checking 'Also change sub-collections'+ H.popover().findByText("View").click();++ // opens up the permissions select again+ H.getPermissionRowPermissions("All Users").click();++ // ensures the toggle is not checked+ H.popover().findByRole("switch").should("not.be.checked");++ cy.intercept("PUT", "/api/collection/graph?skip-graph=true").as(+ "savePermissions",+ );+ cy.button("Save").click();+ cy.wait("@savePermissions");++ // Checks permissions for collection A is set to "View" as expected+ cy.visit(`/admin/permissions/collections/${collectionAId}`);+ H.assertPermissionTable(getTestPermissionsTable("View"));++ // Check the permission set to collection A was NOT propagated to collection B+ cy.visit(`/admin/permissions/collections/${collectionBId}`);+ H.assertPermissionTable(getTestPermissionsTable("No access"));+ });+ });+});diff --git a/e2e/test/scenarios/permissions/admin-permissions.cy.spec.js b/e2e/test/scenarios/permissions/admin-permissions.cy.spec.jsdeleted file mode 100644index 711de338954..00000000000--- a/e2e/test/scenarios/permissions/admin-permissions.cy.spec.js+++ /dev/null@@ -1,762 +0,0 @@-const { H } = cy;-import { SAMPLE_DB_ID, USER_GROUPS } from "e2e/support/cypress_data";-import {- ORDERS_DASHBOARD_ID,- ORDERS_QUESTION_ID,-} from "e2e/support/cypress_sample_instance_data";--const { ALL_USERS_GROUP, ADMIN_GROUP, COLLECTION_GROUP, DATA_GROUP } =- USER_GROUPS;--const COLLECTION_ACCESS_PERMISSION_INDEX = 0;--const NATIVE_QUERIES_PERMISSION_INDEX = 0;--describe("scenarios > admin > permissions", { tags: "@OSS" }, () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("shows hidden tables", () => {- H.DataModel.visit({ databaseId: SAMPLE_DB_ID });- cy.icon("eye_crossed_out").eq(0).click();-- cy.visit(- `admin/permissions/data/group/${ALL_USERS_GROUP}/database/${SAMPLE_DB_ID}`,- );-- H.assertPermissionTable([- ["Accounts", "No"],- ["Analytic Events", "No"],- ["Feedback", "No"],- ["Invoices", "No"],- ["Orders", "No"],- ["People", "No"],- ["Products", "No"],- ["Reviews", "No"],- ]);- });-- it("should not show view data column on OSS", () => {- cy.visit(`/admin/permissions/data/group/${ALL_USERS_GROUP}`);-- cy.findByTestId("permission-table").within(() => {- cy.findByText("Database name").should("exist");- cy.findByText("View data").should("not.exist");- cy.findByText("Create queries").should("exist");- });- });-- it("should display error on failed save", () => {- // revoke some permissions- cy.visit(`/admin/permissions/data/group/${ALL_USERS_GROUP}`);- cy.icon("close").first().click();- cy.findAllByRole("option").contains("Query builder and native").click();-- // stub out the PUT and save- cy.intercept("PUT", "/api/permissions/graph", (req) => {- req.reply(500, "Server error");- });- // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage- cy.contains("Save changes").click();- cy.contains("button", "Yes").click();-- // see error modal- // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage- cy.contains("Server error");- // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage- cy.contains("There was an error saving");- });-- context("collection permissions", () => {- it("warns about leaving with unsaved changes", () => {- cy.visit("/admin/permissions/collections");-- H.selectSidebarItem("First collection");-- H.modifyPermission(- "All Users",- COLLECTION_ACCESS_PERMISSION_INDEX,- "View",- true,- );-- // Navigation to other collection should not show any warnings- H.selectSidebarItem("Our analytics");-- H.modal().should("not.exist");-- // Switching to data permissions page- cy.get("label").contains("Data").click();-- H.modal().within(() => {- cy.findByText("Discard your changes?");- cy.findByText(- "Your changes haven't been saved, so you'll lose them if you navigate away.",- );-- cy.button("Cancel").click();- });-- cy.url().should("include", "/admin/permissions/collections/root");-- // Switching to data permissions page again- cy.get("label").contains("Data").click();-- H.modal().button("Discard changes").click();-- cy.url().should("include", "/admin/permissions/data/group");- });-- it("allows to view and edit permissions", () => {- cy.visit("/admin/permissions/collections");-- const collections = ["Our analytics", "First collection"];- H.assertSidebarItems(collections);-- H.selectSidebarItem("First collection");- H.assertSidebarItems([...collections, "Second collection"]);-- H.selectSidebarItem("Second collection");-- H.assertPermissionTable([- ["Administrators", "Curate"],- ["All Users", "No access"],- ["collection", "Curate"],- ["data", "No access"],- ["nosql", "No access"],- ["readonly", "View"],- ]);-- H.modifyPermission(- "All Users",- COLLECTION_ACCESS_PERMISSION_INDEX,- "View",- true,- );-- // Navigate to children- H.selectSidebarItem("Third collection");-- H.assertPermissionTable([- ["Administrators", "Curate"],- ["All Users", "View"], // Check permission has been propagated- ["collection", "Curate"],- ["data", "No access"],- ["nosql", "No access"],- ["readonly", "View"],- ]);-- // Navigate to parent- H.selectSidebarItem("First collection");-- H.assertPermissionTable([- ["Administrators", "Curate"],- ["All Users", "No access"],- ["collection", "Curate"],- ["data", "No access"],- ["nosql", "No access"],- ["readonly", "View"],- ]);-- H.modifyPermission(- "All Users",- COLLECTION_ACCESS_PERMISSION_INDEX,- "Curate",- false,- );-- H.selectSidebarItem("Second collection");-- H.assertPermissionTable([- ["Administrators", "Curate"],- ["All Users", "View"], // Check permission has not been propagated- ["collection", "Curate"],- ["data", "No access"],- ["nosql", "No access"],- ["readonly", "View"],- ]);-- cy.button("Save changes").click();-- H.modal().within(() => {- cy.findByText("Save permissions?");- cy.findByText("Are you sure you want to do this?");- cy.button("Yes").click();- });-- // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage- cy.findByText("Save changes").should("not.exist");-- H.assertPermissionTable([- ["Administrators", "Curate"],- ["All Users", "View"],- ["collection", "Curate"],- ["data", "No access"],- ["nosql", "No access"],- ["readonly", "View"],- ]);- });- });-- it("don't propagate permissions by checkbox without access select", () => {- cy.visit("/admin/permissions/collections");-- const collections = ["Our analytics", "First collection"];- H.assertSidebarItems(collections);-- H.selectSidebarItem("First collection");- H.assertSidebarItems([...collections, "Second collection"]);-- H.selectSidebarItem("Second collection");-- H.assertPermissionTable([- ["Administrators", "Curate"],- ["All Users", "No access"],- ["collection", "Curate"],- ["data", "No access"],- ["nosql", "No access"],- ["readonly", "View"],- ]);-- H.modifyPermission(- "All Users",- COLLECTION_ACCESS_PERMISSION_INDEX,- "View",- false,- );-- H.modifyPermission(- "All Users",- COLLECTION_ACCESS_PERMISSION_INDEX,- null,- true,- );-- // Navigate to children- H.selectSidebarItem("Third collection");-- H.assertPermissionTable([- ["Administrators", "Curate"],- ["All Users", "No access"], // Check permission hasn't been propagated- ["collection", "Curate"],- ["data", "No access"],- ["nosql", "No access"],- ["readonly", "View"],- ]);- });-- it("show selected option for the collection with children", () => {- cy.visit("/admin/permissions/collections");-- const collections = ["Our analytics", "First collection"];- H.assertSidebarItems(collections);-- H.selectSidebarItem("First collection");- H.assertSidebarItems([...collections, "Second collection"]);-- H.selectSidebarItem("Second collection");- H.selectPermissionRow("All Users", COLLECTION_ACCESS_PERMISSION_INDEX);- H.assertPermissionOptions(["Curate", "View", "No access"]);-- H.selectSidebarItem("Third collection");- H.selectPermissionRow("All Users", COLLECTION_ACCESS_PERMISSION_INDEX);-- H.assertPermissionOptions(["Curate", "View"]);- });-- context("data permissions", () => {- it("warns about leaving with unsaved changes", () => {- cy.visit("/admin/permissions");-- H.selectSidebarItem("All Users");-- H.modifyPermission(- "Sample Database",- NATIVE_QUERIES_PERMISSION_INDEX,- "Query builder and native",- );-- // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage- cy.findByText("You've made changes to permissions.");-- // Switching to databases focus should not show any warnings- cy.get("label").contains("Databases").click();-- cy.url().should("include", "/admin/permissions/data/database");- H.modal().should("not.exist");-- // Switching to collection permissions page- cy.get("label").contains("Collection").click();-- H.modal().within(() => {- cy.findByText("Discard your changes?");- cy.findByText(- "Your changes haven't been saved, so you'll lose them if you navigate away.",- );-- cy.button("Cancel").click();- });-- cy.url().should("include", "/admin/permissions/data/database");-- // Switching to collection permissions page again- cy.get("label").contains("Collection").click();-- H.modal().button("Discard changes").click();-- cy.url().should("include", "/admin/permissions/collections");- });-- context("group focused view", () => {- it("shows filterable list of groups", () => {- cy.visit("/admin/permissions");-- // no groups selected initially and it shows an empty state- // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage- cy.findByText("Select a group to see its data permissions");-- const groups = [- "Administrators",- "All Users",- "collection",- "data",- "nosql",- "readonly",- ];-- H.assertSidebarItems(groups);-- // filter groups- cy.findByPlaceholderText("Search for a group").type("a");-- const filteredGroups = [- "Administrators",- "All Users",- "data",- "readonly",- ];-- // client filter debounce- cy.wait(300);-- H.assertSidebarItems(filteredGroups);- });-- it("allows to only view Administrators permissions", () => {- cy.visit("/admin/permissions");-- H.selectSidebarItem("Administrators");-- cy.url().should(- "include",- `/admin/permissions/data/group/${ADMIN_GROUP}`,- );-- // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage- cy.findByText("Permissions for the Administrators group");- // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage- cy.findByText("1 person");-- H.assertPermissionTable([- ["Sample Database", "Query builder and native"],- ]);-- // Drill down to tables permissions- cy.findByTextEnsureVisible("Sample Database").click();-- H.assertPermissionTable([- ["Accounts", "Query builder and native"],- ["Analytic Events", "Query builder and native"],- ["Feedback", "Query builder and native"],- ["Invoices", "Query builder and native"],- ["Orders", "Query builder and native"],- ["People", "Query builder and native"],- ["Products", "Query builder and native"],- ["Reviews", "Query builder and native"],- ]);- });-- it("should show a modal when a revision changes while an admin is editing", () => {- cy.intercept("/api/permissions/graph/group/1").as("graph");- cy.visit("/admin/permissions");-- H.selectSidebarItem("collection");-- H.modifyPermission(- "Sample Database",- NATIVE_QUERIES_PERMISSION_INDEX,- "Query builder and native",- );-- cy.get("@graph").then((data) => {- cy.request("PUT", "/api/permissions/graph", {- groups: {},- revision: data.response.body.revision,- }).then(() => {- H.selectSidebarItem("data");-- H.modal().findByText("Someone just changed permissions");- });- });- });- });-- context("database focused view", () => {- it("should show a modal when a revision changes while an admin is editing", () => {- cy.intercept("/api/permissions/graph/group/1").as("graph");- cy.visit("/admin/permissions/");-- H.selectSidebarItem("collection");-- H.modifyPermission(- "Sample Database",- NATIVE_QUERIES_PERMISSION_INDEX,- "Query builder and native",- );-- cy.get("@graph").then((data) => {- cy.request("PUT", "/api/permissions/graph", {- groups: {},- revision: data.response.body.revision,- }).then(() => {- cy.get("label").contains("Databases").click();- H.selectSidebarItem("Sample Database");-- H.modal().findByText("Someone just changed permissions");- });- });- });- });- });-});--describe("scenarios > admin > permissions", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");- });-- it("Visualization and Settings query builder buttons are not visible for questions that use blocked data sources", () => {- cy.updatePermissionsGraph({- [ALL_USERS_GROUP]: {- [SAMPLE_DB_ID]: {- "view-data": "blocked",- },- },- [COLLECTION_GROUP]: {- [SAMPLE_DB_ID]: {- "view-data": "blocked",- },- },- });-- cy.signIn("nodata");- H.visitQuestion(ORDERS_QUESTION_ID);-- H.queryBuilderMain().findByText(- "Sorry, you don't have permission to run this query.",- );- H.queryBuilderFooter()- .findByTestId("viz-settings-button")- .should("not.exist");- H.queryBuilderFooter().findByText("Visualization").should("not.exist");- });-- it("shows permission error for cards that use blocked data sources", () => {- cy.updatePermissionsGraph({- [ALL_USERS_GROUP]: {- [SAMPLE_DB_ID]: {- "view-data": "blocked",- },- },- [COLLECTION_GROUP]: {- [SAMPLE_DB_ID]: {- "view-data": "blocked",- },- },- });-- cy.signIn("nodata");- H.visitDashboard(ORDERS_DASHBOARD_ID);-- // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage- cy.findByText("Sorry, you don't have permission to see this card.");- });-});--describe("scenarios > admin > permissions", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("shows permissions help", () => {- cy.visit("/admin/permissions");-- // Data permissions w/o `legacy-no-self-service` in graph- cy.get("main").within(() => {- cy.findByText("Permissions help").as("permissionHelpButton").click();- cy.get("@permissionHelpButton").should("not.exist");- });-- cy.findByLabelText("Permissions help reference").within(() => {- cy.findByText("Data permissions");-- cy.findByText("Database ‘View data’ levels").click();- cy.findByTestId("database-view-data-level").should(- "not.contain",- /No self-service/,- );- cy.findByText("Database ‘View data’ levels").click();-- cy.findByText(/Schema or table ‘View data’ levels/).click();- cy.findByTestId("schema-table-level").should(- "not.contain",- /No self-service/,- );- cy.findByText(/Schema or table ‘View data’ levels/).click();-- cy.findByText("‘Create queries’ levels");-- cy.findByLabelText("Close").click();- });-- // Data permissions w/ `legacy-no-self-service` in graph- cy.visit("/admin/permissions");-- cy.intercept("GET", `/api/permissions/graph/group/${ALL_USERS_GROUP}`, {- statusCode: 200,- body: {- revision: 1,- groups: {- 1: {- 1: {- "view-data": "legacy-no-self-service",- "create-queries": "query-builder-and-native",- download: { schemas: "full" },- },- },- },- },- });-- cy.get("main").within(() => {- cy.findByText("Permissions help").as("permissionHelpButton").click();- cy.get("@permissionHelpButton").should("not.exist");- });-- cy.findByLabelText("Permissions help reference")- .as("permissionsHelpContent")- .within(() => {- cy.findByText("Database ‘View data’ levels").click();- cy.findAllByText(/No self-service/);- cy.findByLabelText("Close").click();- });-- cy.get("main").within(() => {- cy.findByText("Collections").click();- cy.get("@permissionHelpButton").click();- });-- // Collection permissions- cy.get("@permissionsHelpContent").within(() => {- cy.findByText("Collection permissions");- cy.findByText("Collections Permission Levels");- });-- // The help reference keeps being open when switching tabs- cy.get("main").within(() => {- cy.findByText("Data").click();- });-- cy.get("@permissionsHelpContent").within(() => {- cy.findByText("Data permissions");- });- });-- it("should show a dismissable modal and banner showing split permisson changes (#metabase#45073", () => {- // We need a way to pass true values for these settings in CI. Generally in CI, these values will always be false- // because we always start with a fresh instance. However, to test the flow of someone who has upgraded from 49 -> current- // we set them to false and ensure a modal is shown explaining the new permissions structure- const tempState = {- "show-updated-permission-modal": true,- "show-updated-permission-banner": true,- };-- // When the app calls for session properties, give them a modified API response- cy.intercept("/api/session/properties", (req) => {- req.continue((res) => {- res.body = { ...res.body, ...tempState };- });- }).as("sessionProps");-- // These calls are setting the permission to false, so update the local state. When the settings are refreshed- // from the browser, they will get the new values from local state- cy.intercept("api/setting/show-updated-permission-modal", () => {- tempState["show-updated-permission-modal"] = false;- });-- cy.intercept("api/setting/show-updated-permission-banner", () => {- tempState["show-updated-permission-banner"] = false;- });-- cy.visit("/admin/permissions/");- cy.wait("@sessionProps");-- cy.findByRole("dialog", { name: /permissions may look different/ })- .findByRole("button", { name: "Got it" })- .click();- cy.wait("@sessionProps");-- cy.findByRole("menuitem", { name: "All Users" }).click();- cy.findByRole("alert").should(- "contain.text",- "Your data permissions may look different",- );- cy.findByRole("alert").findByRole("button").click();-- //Cypress will error if the page refreshes while it's also intercepting a request- cy.wait("@sessionProps");-- cy.reload();-- cy.findByRole("dialog", { name: /permissions may look different/ }).should(- "not.exist",- );- cy.findByRole("alert").should("not.exist");- });-- it("split permisson change modal should dismiss even if network request fails", () => {- // We need a way to pass true values for these settings in CI. Generally in CI, these values will always be false- // because we always start with a fresh instance. However, to test the flow of someone who has upgraded from 49 -> current- // we set them to false and ensure a modal is shown explaining the new permissions structure- const tempState = {- "show-updated-permission-modal": true,- };-- // When the app calls for session properties, give them a modified API response- cy.intercept("/api/session/properties", (req) => {- req.continue((res) => {- res.body = { ...res.body, ...tempState };- });- }).as("sessionProps");-- // These calls are setting the permission to false, so update the local state. When the settings are refreshed- // from the browser, they will get the new values from local state- cy.intercept("api/setting/show-updated-permission-modal", {- statusCode: 500,- });-- cy.visit("/admin/permissions/");- cy.wait("@sessionProps");-- cy.findByRole("dialog", { name: /permissions may look different/ })- .findByRole("button", { name: "Got it" })- .click();- cy.wait("@sessionProps");-- cy.findByRole("menuitem", { name: "All Users" }).click();- });-});--describe("scenarios > admin > permissions", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- context("partial updates", () => {- it("partial data permission updates should not remove permissions from other unmodified groups", () => {- // check the we have an expected initial state- cy.visit(`admin/permissions/data/group/${DATA_GROUP}`);- H.assertPermissionTable([- ["Sample Database", "Query builder and native"],- ]);-- // make a change to the permissions of another group- H.selectSidebarItem("nosql");- H.assertPermissionTable([["Sample Database", "Query builder only"]]);- H.modifyPermission(- "Sample Database",- NATIVE_QUERIES_PERMISSION_INDEX,- "No",- );-- // observe the save change request and assert that we don't get back- // values for groups we did not modify- cy.intercept("PUT", "/api/permissions/graph").as("updateGraph");-- // save changes- cy.button("Save changes").click();- H.modal().within(() => {- cy.button("Yes").click();- });-- cy.wait("@updateGraph").then((interception) => {- const requestGroupIds = Object.keys(interception.request.body.groups);- const responseGroupIds = Object.keys(interception.response.body.groups);- expect(requestGroupIds).to.deep.equal(responseGroupIds);- });-- // make sure that our other group's permission data did not get changed- H.selectSidebarItem("data");- H.assertPermissionTable([- ["Sample Database", "Query builder and native"],- ]);- });-- it("partial collection permission updates should not prevent user from making further changes", () => {- cy.visit("/admin/permissions/collections");-- H.selectSidebarItem("First collection");-- H.modifyPermission(- "All Users",- COLLECTION_ACCESS_PERMISSION_INDEX,- "View",- true,- );-- cy.intercept("PUT", "/api/collection/graph?skip-graph=true").as(- "updateGraph",- );-- cy.button("Save changes").click();- H.modal().within(() => {- cy.button("Yes").click();- });-- cy.wait("@updateGraph").then((interception) => {- cy.log("should skip graph in request and response");- expect(interception.response.body).to.not.haveOwnProperty("groups");- });-- H.selectSidebarItem("First collection");-- H.modifyPermission(- "nosql",- COLLECTION_ACCESS_PERMISSION_INDEX,- "Curate",- true,- );-- cy.button("Save changes").click();- H.modal().within(() => {- cy.button("Yes").click();- });-- cy.wait("@updateGraph").then((interception) => {- cy.log("should not send previously saved edits");- expect(interception.request.body.groups).to.not.haveOwnProperty(- USER_GROUPS.ALL_USERS_GROUP,- );-- cy.log("should not fail when making multiple rounds of edits");- expect(interception.response.statusCode).to.equal(200);- });- });- });-});diff --git a/frontend/src/metabase/admin/permissions/components/CollectionPermissionsModal/CollectionPermissionsModal.jsx b/frontend/src/metabase/admin/permissions/components/CollectionPermissionsModal/CollectionPermissionsModal.jsxindex c4640f3a8f6..d6121165da2 100644--- a/frontend/src/metabase/admin/permissions/components/CollectionPermissionsModal/CollectionPermissionsModal.jsx+++ b/frontend/src/metabase/admin/permissions/components/CollectionPermissionsModal/CollectionPermissionsModal.jsx@@ -10,7 +10,7 @@ import ModalContent from "metabase/common/components/ModalContent";import CS from "metabase/css/core/index.css";import Collections from "metabase/entities/collections";import Groups from "metabase/entities/groups";-import { connect } from "metabase/lib/redux";+import { connect, useSelector } from "metabase/lib/redux";import * as Urls from "metabase/lib/urls";import {@@ -82,6 +82,9 @@ const CollectionPermissionsModal = ({updateCollectionPermission,saveCollectionPermissions,}) => {+ const originalPermissionsState = useSelector(+ ({ admin }) => admin.permissions.originalCollectionPermissions,+ );useEffect(() => {initialize(namespace);}, [initialize, namespace]);@@ -114,9 +117,10 @@ const CollectionPermissionsModal = ({collection,value,shouldPropagate: toggleState,+ originalPermissionsState,});},- [collection, updateCollectionPermission],+ [collection, updateCollectionPermission, originalPermissionsState],);return (diff --git a/frontend/src/metabase/admin/permissions/components/PermissionsSelect/PermissionsSelect.jsx b/frontend/src/metabase/admin/permissions/components/PermissionsSelect/PermissionsSelect.jsxindex fda9a77a534..3597fa7b583 100644--- a/frontend/src/metabase/admin/permissions/components/PermissionsSelect/PermissionsSelect.jsx+++ b/frontend/src/metabase/admin/permissions/components/PermissionsSelect/PermissionsSelect.jsx@@ -49,11 +49,15 @@ export const PermissionsSelect = memo(function PermissionsSelect({warning,isHighlighted,}) {- const [toggleState, setToggleState] = useState(false);+ const [toggleState, setToggleState] = useState(null);const selectedOption = options.find((option) => option.value === value);const selectableOptions = hasChildren? options: options.filter((option) => option !== selectedOption);+ const onToggleChange = (checked) => {+ setToggleState(checked);+ onChange(selectedOption.value, checked);+ };const selectedOptionValue = (<PermissionsSelectRoot@@ -93,10 +97,9 @@ export const PermissionsSelect = memo(function PermissionsSelect({return (<PopoverWithTriggerdisabled={isDisabled}- triggerElement={selectedOptionValue}- onClose={() => setToggleState(false)}targetOffsetX={16}targetOffsetY={8}+ triggerElement={selectedOptionValue}>{({ onClose }) => (<Fragment>@@ -134,7 +137,11 @@ export const PermissionsSelect = memo(function PermissionsSelect({{hasChildren && (<ToggleContainer><ToggleLabel>{toggleLabel}</ToggleLabel>- <Toggle small value={toggleState} onChange={setToggleState} />+ <Toggle+ small+ value={toggleState || false}+ onChange={onToggleChange}+ /></ToggleContainer>)}</Fragment>diff --git a/frontend/src/metabase/admin/permissions/pages/CollectionPermissionsPage/CollectionPermissionsPage.tsx b/frontend/src/metabase/admin/permissions/pages/CollectionPermissionsPage/CollectionPermissionsPage.tsxindex 40f051fa24f..825d3306235 100644--- a/frontend/src/metabase/admin/permissions/pages/CollectionPermissionsPage/CollectionPermissionsPage.tsx+++ b/frontend/src/metabase/admin/permissions/pages/CollectionPermissionsPage/CollectionPermissionsPage.tsx@@ -7,8 +7,13 @@ import _ from "underscore";import { CollectionPermissionsHelp } from "metabase/admin/permissions/components/CollectionPermissionsHelp";import Collections from "metabase/entities/collections";import Groups from "metabase/entities/groups";-import { connect } from "metabase/lib/redux";-import type { Collection, CollectionId, GroupId } from "metabase-types/api";+import { connect, useSelector } from "metabase/lib/redux";+import type {+ Collection,+ CollectionId,+ CollectionPermissions,+ GroupId,+} from "metabase-types/api";import type { State } from "metabase-types/store";import {@@ -58,7 +63,8 @@ type UpdateCollectionPermissionParams = {groupId: GroupId;collection: Collection;value: unknown;- shouldPropagate: boolean;+ shouldPropagate: boolean | null;+ originalPermissionsState: CollectionPermissions;};type CollectionPermissionsPageProps = {@@ -92,6 +98,10 @@ function CollectionsPermissionsPageView({initialize,route,}: CollectionPermissionsPageProps) {+ const originalPermissionsState = useSelector(+ ({ admin }) => admin.permissions.originalCollectionPermissions,+ );+useEffect(() => {initialize();}, [initialize]);@@ -101,16 +111,17 @@ function CollectionsPermissionsPageView({item: { id: GroupId },_permission: unknown,value: unknown,- toggleState: boolean,+ toggleState: boolean | null,) => {updateCollectionPermission({groupId: item.id,collection,value,shouldPropagate: toggleState,+ originalPermissionsState,});},- [collection, updateCollectionPermission],+ [collection, updateCollectionPermission, originalPermissionsState],);return (@@ -121,6 +132,7 @@ function CollectionsPermissionsPageView({onSave={savePermissions}onLoad={() => loadPermissions()}helpContent={<CollectionPermissionsHelp />}+ key={collection?.id}><PermissionsSidebar {...sidebar} onSelect={navigateToItem} />diff --git a/frontend/src/metabase/admin/permissions/permissions.js b/frontend/src/metabase/admin/permissions/permissions.jsindex 97e06604d87..5653a5c1d97 100644--- a/frontend/src/metabase/admin/permissions/permissions.js+++ b/frontend/src/metabase/admin/permissions/permissions.js@@ -1,6 +1,7 @@-import { assocIn, merge } from "icepick";+import { assocIn, getIn, merge } from "icepick";import { push } from "react-router-redux";import { t } from "ttag";+import { isBoolean } from "underscore";import {inferAndUpdateEntityPermissions,@@ -437,19 +438,36 @@ const collectionPermissions = handleActions(},[UPDATE_COLLECTION_PERMISSION]: {next: (state, { payload }) => {- const { groupId, collection, value, shouldPropagate } = payload;- let newPermissions = assocIn(state, [groupId, collection.id], value);+ const {+ collection,+ groupId,+ originalPermissionsState,+ shouldPropagate,+ value,+ } = payload;+ let newPermissionsState = assocIn(+ state,+ [groupId, collection.id],+ value,+ );- if (shouldPropagate) {+ /**+ * Check if shouldPropagate is explicitly set (true or false) vs unset (null or undefined).+ * If it's a boolean, we either propagate the new value or restore the original. When not a boolean, we do nothing.+ */+ if (isBoolean(shouldPropagate)) {for (const descendent of getDecendentCollections(collection)) {- newPermissions = assocIn(- newPermissions,+ newPermissionsState = assocIn(+ newPermissionsState,[groupId, descendent.id],- value,+ shouldPropagate+ ? value+ : getIn(originalPermissionsState, [groupId, descendent.id]),);}}- return newPermissions;++ return newPermissionsState;},},[SAVE_COLLECTION_PERMISSIONS]: {