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
hide sample db from embedding onboarding picker (#71304)
Nicolò Pretto92c07ddea1d3
diff --git a/e2e/test/scenarios/embedding/embedding-hub/embedding-hub.cy.spec.ts b/e2e/test/scenarios/embedding/embedding-hub/embedding-hub.cy.spec.tsindex 008c40cd4b9..c92942495a8 100644--- a/e2e/test/scenarios/embedding/embedding-hub/embedding-hub.cy.spec.ts+++ b/e2e/test/scenarios/embedding/embedding-hub/embedding-hub.cy.spec.ts@@ -3,7 +3,8 @@ import { ALL_EXTERNAL_USERS_GROUP_ID } from "e2e/support/cypress_sample_instanceconst { H } = cy;-const { STATIC_ORDERS_ID, STATIC_PEOPLE_ID } = SAMPLE_DB_TABLES;+const { STATIC_ORDERS_ID } = SAMPLE_DB_TABLES;+const NON_SAMPLE_DB_NAME = "QA Postgres12";describe("scenarios - embedding hub", () => {describe("checklist", () => {@@ -781,7 +782,7 @@ describe("scenarios - embedding hub", () => {});it("shows autocomplete suggestions for organization_id based on selected field values", () => {- H.restore("setup");+ H.restore("postgres-12");cy.signInAsAdmin();H.activateToken("bleeding-edge");@@ -821,7 +822,7 @@ describe("scenarios - embedding hub", () => {cy.log("pick orders table");H.main().findByText("Pick a table").click();- H.miniPicker().findByText("Sample Database").click();+ H.miniPicker().findByText(NON_SAMPLE_DB_NAME).click();H.miniPicker().findByText("Orders").click();H.main().findByPlaceholderText("Pick a column").click();@@ -844,7 +845,7 @@ describe("scenarios - embedding hub", () => {// are only populated when the user goes through the "Select data" step// in the UI. Without it, the data permissions description won't show.it("shows RLS data permissions description in summary", () => {- H.restore("setup");+ H.restore("postgres-12");cy.signInAsAdmin();H.activateToken("bleeding-edge");@@ -884,7 +885,7 @@ describe("scenarios - embedding hub", () => {cy.log("pick Orders table and User ID column");H.main().findByText("Pick a table").click();- H.miniPicker().findByText("Sample Database").click();+ H.miniPicker().findByText(NON_SAMPLE_DB_NAME).click();H.miniPicker().findByText("Orders").click();H.main().findByPlaceholderText("Pick a column").click();@@ -927,7 +928,7 @@ describe("scenarios - embedding hub", () => {});it("should create sandboxes for multiple tables via row-level security setup", () => {- H.restore("setup");+ H.restore("postgres-12");cy.signInAsAdmin();H.activateToken("bleeding-edge");@@ -987,8 +988,10 @@ describe("scenarios - embedding hub", () => {cy.log("Our analytics should be hidden in the table picker");H.miniPicker().findByText("Our analytics").should("not.exist");+ cy.log("Sample Database should be hidden in the table picker");+ H.miniPicker().findByText("Sample Database").should("not.exist");- H.miniPicker().findByText("Sample Database").click();+ H.miniPicker().findByText(NON_SAMPLE_DB_NAME).click();H.miniPicker().findByText("Orders").click();H.main().findByPlaceholderText("Pick a column").click();@@ -998,7 +1001,7 @@ describe("scenarios - embedding hub", () => {H.main().findByText("Add table").click();H.main().findAllByText("Pick a table").first().click();- H.miniPicker().findByText("Sample Database").click();+ H.miniPicker().findByText(NON_SAMPLE_DB_NAME).click();cy.log("orders should be hidden as it's already selected");H.miniPicker().findByText("Orders").should("not.exist");@@ -1026,57 +1029,60 @@ describe("scenarios - embedding hub", () => {// 1. The admin permissions UI is complex and would add significant test time// 2. This test focuses on the onboarding flow, not the permissions UIcy.log("access policies should be created");- cy.request("GET", "/api/mt/gtap").should((response) => {- const policies = response.body;- expect(policies.length).to.be.at.least(2);-- const orderPolicy = policies.find(- (policy: { table_id: number }) =>- policy.table_id === STATIC_ORDERS_ID,- );-- const peoplePolicy = policies.find(- (policy: { table_id: number }) =>- policy.table_id === STATIC_PEOPLE_ID,- );-- expect(orderPolicy).to.exist;- expect(peoplePolicy).to.exist;-- expect(orderPolicy.attribute_remappings).to.have.property(- "organization_id",- );-- expect(peoplePolicy.attribute_remappings).to.have.property(- "organization_id",- );- });-- cy.request(- "GET",- `/api/permissions/graph/group/${ALL_EXTERNAL_USERS_GROUP_ID}`,- ).should((response) => {- const graph = response.body;-- const permissions = graph.groups[ALL_EXTERNAL_USERS_GROUP_ID!][1];- expect(permissions).to.exist;-- // deep.equal ensures only the selected tables have permissions —- // non-selected tables should be blocked (omitted from the response)- expect(permissions["view-data"]).to.deep.equal({- PUBLIC: {- [STATIC_ORDERS_ID]: "sandboxed",- [STATIC_PEOPLE_ID]: "sandboxed",- },- });-- expect(permissions["create-queries"]).to.deep.equal({- PUBLIC: {- [STATIC_ORDERS_ID]: "query-builder",- [STATIC_PEOPLE_ID]: "query-builder",- },- });- });+ H.getTableId({ databaseId: WRITABLE_DB_ID, name: "orders" }).then(+ (ordersTableId) => {+ H.getTableId({ databaseId: WRITABLE_DB_ID, name: "people" }).then(+ (peopleTableId) => {+ cy.request("GET", "/api/mt/gtap").should((response) => {+ const policies = response.body;+ expect(policies.length).to.be.at.least(2);++ const orderPolicy = policies.find(+ (policy: { table_id: number }) =>+ policy.table_id === ordersTableId,+ );++ const peoplePolicy = policies.find(+ (policy: { table_id: number }) =>+ policy.table_id === peopleTableId,+ );++ expect(orderPolicy).to.exist;+ expect(peoplePolicy).to.exist;++ expect(orderPolicy.attribute_remappings).to.have.property(+ "organization_id",+ );++ expect(peoplePolicy.attribute_remappings).to.have.property(+ "organization_id",+ );+ });++ cy.request(+ "GET",+ `/api/permissions/graph/group/${ALL_EXTERNAL_USERS_GROUP_ID}`,+ ).should((response) => {+ const graph = response.body;++ const permissions =+ graph.groups[ALL_EXTERNAL_USERS_GROUP_ID!][WRITABLE_DB_ID];+ expect(permissions).to.exist;++ expect(permissions["view-data"].public).to.deep.equal({+ [ordersTableId]: "sandboxed",+ [peopleTableId]: "sandboxed",+ });++ expect(permissions["create-queries"].public).to.deep.equal({+ [ordersTableId]: "query-builder",+ [peopleTableId]: "query-builder",+ });+ });+ },+ );+ },+ );H.main().findByRole("listitem", {@@ -1088,7 +1094,7 @@ describe("scenarios - embedding hub", () => {});it("should update existing sandboxes when changing column selection", () => {- H.restore("setup");+ H.restore("postgres-12");cy.signInAsAdmin();H.activateToken("bleeding-edge");@@ -1116,21 +1122,42 @@ describe("scenarios - embedding hub", () => {});cy.log("create an existing sandbox for Orders table via API");- cy.request("GET", "/api/permissions/group").then((response) => {- const allExternalUsersGroup = response.body.find(- (g: { magic_group_type: string }) =>- g.magic_group_type === "all-external-users",- );-- cy.request("POST", "/api/mt/gtap", {- table_id: STATIC_ORDERS_ID,- group_id: allExternalUsersGroup.id,- card_id: null,- attribute_remappings: {- organization_id: ["dimension", ["field", 2, null]], // USER_ID field- },- });- });+ H.getTableId({ databaseId: WRITABLE_DB_ID, name: "orders" }).then(+ (ordersTableId) => {+ cy.wrap(ordersTableId).as("ordersTableId");++ H.getFieldId({ tableId: ordersTableId, name: "user_id" }).then(+ (userIdFieldId) => {+ H.getFieldId({ tableId: ordersTableId, name: "product_id" }).then(+ (productIdFieldId) => {+ cy.wrap(productIdFieldId).as("productIdFieldId");++ cy.request("GET", "/api/permissions/group").then(+ (response) => {+ const allExternalUsersGroup = response.body.find(+ (g: { magic_group_type: string }) =>+ g.magic_group_type === "all-external-users",+ );++ cy.request("POST", "/api/mt/gtap", {+ table_id: ordersTableId,+ group_id: allExternalUsersGroup.id,+ card_id: null,+ attribute_remappings: {+ organization_id: [+ "dimension",+ ["field", userIdFieldId, null],+ ],+ },+ });+ },+ );+ },+ );+ },+ );+ },+ );cy.visit("/admin/embedding/setup-guide/permissions");@@ -1161,7 +1188,7 @@ describe("scenarios - embedding hub", () => {cy.log("Select the same Orders table");H.main().findByText("Pick a table").click();- H.miniPicker().findByText("Sample Database").click();+ H.miniPicker().findByText(NON_SAMPLE_DB_NAME).click();H.miniPicker().findByText("Orders").click();cy.log("select Product ID column instead of User ID");@@ -1176,23 +1203,26 @@ describe("scenarios - embedding hub", () => {H.undoToast().should("not.exist");cy.log("sandbox should be updated and not created");- cy.request("GET", "/api/mt/gtap").should((response) => {- const policies = response.body;+ cy.get<number>("@ordersTableId").then((ordersTableId) => {+ cy.get<number>("@productIdFieldId").then((productIdFieldId) => {+ cy.request("GET", "/api/mt/gtap").should((response) => {+ const policies = response.body;- const orderPolicies = policies.filter(- (policy: { table_id: number }) =>- policy.table_id === STATIC_ORDERS_ID,- );+ const orderPolicies = policies.filter(+ (policy: { table_id: number }) =>+ policy.table_id === ordersTableId,+ );- // should only have one sandbox for Orders table- expect(orderPolicies.length).to.equal(1);+ // should only have one sandbox for Orders table+ expect(orderPolicies.length).to.equal(1);- const [orderPolicy] = orderPolicies;- const tenantFieldRef = orderPolicy.attribute_remappings.organization_id;+ const [orderPolicy] = orderPolicies;+ const tenantFieldRef =+ orderPolicy.attribute_remappings.organization_id;- // attribute_remappings should reference field 3 (PRODUCT_ID),- // not field 2 (USER_ID)- expect(tenantFieldRef[1][1]).to.equal(3);+ expect(tenantFieldRef[1][1]).to.equal(productIdFieldId);+ });+ });});H.main()diff --git a/frontend/src/metabase/embedding/embedding-hub/components/SetupPermissionsAndTenantsPage/RlsDataSelector/TableColumnCard.tsx b/frontend/src/metabase/embedding/embedding-hub/components/SetupPermissionsAndTenantsPage/RlsDataSelector/TableColumnCard.tsxindex daea56a6979..c1da120c000 100644--- a/frontend/src/metabase/embedding/embedding-hub/components/SetupPermissionsAndTenantsPage/RlsDataSelector/TableColumnCard.tsx+++ b/frontend/src/metabase/embedding/embedding-hub/components/SetupPermissionsAndTenantsPage/RlsDataSelector/TableColumnCard.tsx@@ -113,8 +113,12 @@ export const TableColumnCard = ({selectedTableIds.includes(pickerItem.id);const isOurAnalytics =pickerItem.model === "collection" && pickerItem.id === "root";+ const isSampleDatabase =+ pickerItem.model === "database" &&+ "is_sample" in pickerItem &&+ pickerItem.is_sample === true;- return isAlreadySelected || isOurAnalytics;+ return isAlreadySelected || isOurAnalytics || isSampleDatabase;},[selectedTableIds],);