Skip to content

Commit

Permalink
[Feature branch] Split data access and query builder access (metabase…
Browse files Browse the repository at this point in the history
…#41581)

Co-authored-by: Noah Moss <[email protected]>
Co-authored-by: Noah Moss <[email protected]>
Co-authored-by: Nick Fitzpatrick <[email protected]>
Co-authored-by: John Swanson <[email protected]>
Co-authored-by: Sloan Sparger <[email protected]>
Co-authored-by: Sloan Sparger <[email protected]>
  • Loading branch information
6 people authored Apr 19, 2024
1 parent e6fa8f9 commit 79583b9
Show file tree
Hide file tree
Showing 164 changed files with 6,679 additions and 2,917 deletions.
70 changes: 59 additions & 11 deletions e2e/snapshot-creators/default.cy.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import {
SAMPLE_DB_TABLES,
METABASE_SECRET_KEY,
} from "e2e/support/cypress_data";
import { snapshot, restore, withSampleDatabase } from "e2e/support/helpers";
import {
snapshot,
restore,
withSampleDatabase,
setTokenFeatures,
describeEE,
deleteToken,
} from "e2e/support/helpers";

const {
STATIC_ORDERS_ID,
Expand Down Expand Up @@ -63,6 +70,29 @@ describe("snapshots", () => {
});
});

describeEE("default-ee", () => {
it("default-ee", () => {
restore("blank");
setup();
updateSettings();
setTokenFeatures("all");
addUsersAndGroups(true);
createCollections();
withSampleDatabase(SAMPLE_DATABASE => {
ensureTableIdsAreCorrect(SAMPLE_DATABASE);
hideNewSampleTables(SAMPLE_DATABASE);
createQuestionsAndDashboards(SAMPLE_DATABASE);
createModels(SAMPLE_DATABASE);
cy.writeFile(
"e2e/support/cypress_sample_database.json",
SAMPLE_DATABASE,
);
});
deleteToken();
snapshot("default-ee");
});
});

function setup() {
cy.request("GET", "/api/session/properties").then(
({ body: properties }) => {
Expand Down Expand Up @@ -102,26 +132,28 @@ describe("snapshots", () => {
});
}

function addUsersAndGroups() {
function addUsersAndGroups(isEE = false) {
const lowest_read_data_permission = isEE ? "blocked" : "unrestricted";

// groups
cy.request("POST", "/api/permissions/group", { name: "collection" }).then(
({ body }) => {
expect(body.id).to.eq(COLLECTION_GROUP); // 4
expect(body.id).to.eq(COLLECTION_GROUP); // 3
},
);
cy.request("POST", "/api/permissions/group", { name: "data" }).then(
({ body }) => {
expect(body.id).to.eq(DATA_GROUP); // 5
expect(body.id).to.eq(DATA_GROUP); // 4
},
);
cy.request("POST", "/api/permissions/group", { name: "readonly" }).then(
({ body }) => {
expect(body.id).to.eq(READONLY_GROUP); // 6
expect(body.id).to.eq(READONLY_GROUP); // 5
},
);
cy.request("POST", "/api/permissions/group", { name: "nosql" }).then(
({ body }) => {
expect(body.id).to.eq(NOSQL_GROUP); // 7
expect(body.id).to.eq(NOSQL_GROUP); // 6
},
);

Expand All @@ -135,19 +167,35 @@ describe("snapshots", () => {

cy.updatePermissionsGraph({
[ALL_USERS_GROUP]: {
[SAMPLE_DB_ID]: { data: { schemas: "none", native: "none" } },
[SAMPLE_DB_ID]: {
// set the data permission so the UI doesn't warn us that "all users has higher permissions than X"
"view-data": lowest_read_data_permission,
"create-queries": "no",
},
},
[DATA_GROUP]: {
[SAMPLE_DB_ID]: { data: { schemas: "all", native: "write" } },
[SAMPLE_DB_ID]: {
"view-data": "unrestricted",
"create-queries": "query-builder-and-native",
},
},
[NOSQL_GROUP]: {
[SAMPLE_DB_ID]: { data: { schemas: "all", native: "none" } },
[SAMPLE_DB_ID]: {
"view-data": "unrestricted",
"create-queries": "query-builder",
},
},
[COLLECTION_GROUP]: {
[SAMPLE_DB_ID]: { data: { schemas: "none", native: "none" } },
[SAMPLE_DB_ID]: {
"view-data": lowest_read_data_permission,
"create-queries": "no",
},
},
[READONLY_GROUP]: {
[SAMPLE_DB_ID]: { data: { schemas: "none", native: "none" } },
[SAMPLE_DB_ID]: {
"view-data": lowest_read_data_permission,
"create-queries": "no",
},
},
});

Expand Down
15 changes: 9 additions & 6 deletions e2e/support/commands/permissions/sandboxTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ Cypress.Commands.add(
const attr = Object.keys(attribute_remappings).join(", "); // Account for the possiblity of passing multiple user attributes

cy.log(`Sandbox "${name}" table on "${attr}"`);
cy.updatePermissionsSchemas({
schemas: {
[schema]: {
[table_id]: { query: "segmented", read: "all" },
cy.updatePermissionsGraph({
[group_id]: {
[db_id]: {
"view-data": {
[schema]: {
[table_id]: "sandboxed",
},
},
"create-queries": "query-builder",
},
},
user_group: group_id,
database_id: db_id,
});
cy.request("POST", "/api/mt/gtap", {
attribute_remappings,
Expand Down
16 changes: 16 additions & 0 deletions e2e/support/helpers/e2e-enterprise-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,19 @@ export const setTokenFeatures = featuresScope => {
},
});
};

export const deleteToken = () => {
if (!isEE) {
throw new Error(
"You must run Metabase® Enterprise Edition™ for token to make sense.\nMake sure you have `MB_EDITION=ee` in your environment variables.",
);
}
return cy.request({
method: "PUT",
url: "/api/setting/premium-embedding-token",
failOnStatusCode: false,
body: {
value: null,
},
});
};
22 changes: 19 additions & 3 deletions e2e/test/scenarios/actions/model-actions.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,19 @@ describe(
// to test database picker behavior in the action editor
setActionsEnabledForDB(SAMPLE_DB_ID);

setTokenFeatures("all");
cy.updatePermissionsGraph({
[USER_GROUPS.ALL_USERS_GROUP]: {
[WRITABLE_DB_ID]: { data: { schemas: "none", native: "none" } },
[WRITABLE_DB_ID]: {
"view-data": "blocked",
"create-queries": "no",
},
},
[USER_GROUPS.DATA_GROUP]: {
[WRITABLE_DB_ID]: { data: { schemas: "all", native: "write" } },
[WRITABLE_DB_ID]: {
"view-data": "unrestricted",
"create-queries": "query-builder-and-native",
},
},
});

Expand Down Expand Up @@ -809,7 +816,16 @@ describe(
cy.updatePermissionsGraph(
{
[USER_GROUPS.ALL_USERS_GROUP]: {
[WRITABLE_DB_ID]: { data: { schemas: "all", native: "write" } },
[WRITABLE_DB_ID]: {
"view-data": "impersonated",
"create-queries": "query-builder-and-native",
},
},
// By default, all groups get `unrestricted` access that will override the impersonation.
[USER_GROUPS.COLLECTION_GROUP]: {
[WRITABLE_DB_ID]: {
"view-data": "blocked",
},
},
},
[
Expand Down
13 changes: 4 additions & 9 deletions e2e/test/scenarios/collections/uploads.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ describe("permissions", () => {
cy.updatePermissionsGraph({
1: {
[WRITABLE_DB_ID]: {
data: {
schemas: "block",
},
"view-data": "blocked",
},
},
});
Expand Down Expand Up @@ -300,16 +298,13 @@ describe("permissions", () => {
cy.updatePermissionsGraph({
[ALL_USERS_GROUP]: {
[WRITABLE_DB_ID]: {
data: {
schemas: "block",
},
"view-data": "blocked",
},
},
[NOSQL_GROUP]: {
[WRITABLE_DB_ID]: {
data: {
schemas: "all",
},
"view-data": "unrestricted",
"create-queries": "query-builder",
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ describe("scenarios > dashboard > filters", { tags: "@slow" }, () => {

describeEE("scenarios > dashboard > filters", () => {
beforeEach(() => {
restore();
restore("default-ee");
cy.signInAsAdmin();
setTokenFeatures("all");
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { USER_GROUPS, SAMPLE_DB_ID } from "e2e/support/cypress_data";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import { ORDERS_DASHBOARD_ID } from "e2e/support/cypress_sample_instance_data";
const { ALL_USERS_GROUP, COLLECTION_GROUP } = USER_GROUPS;
import {
describeEE,
restore,
Expand All @@ -11,12 +13,26 @@ const { PRODUCTS_ID, PRODUCTS } = SAMPLE_DATABASE;

describeEE("issue 29076", () => {
beforeEach(() => {
restore();
restore("default-ee");

cy.intercept("/api/dashboard/*/dashcard/*/card/*/query").as("cardQuery");

cy.signInAsAdmin();
setTokenFeatures("all");
cy.updatePermissionsGraph({
[ALL_USERS_GROUP]: {
[SAMPLE_DB_ID]: {
"view-data": "blocked",
"create-queries": "no",
},
},
[COLLECTION_GROUP]: {
[SAMPLE_DB_ID]: {
"view-data": "unrestricted",
"create-queries": "query-builder",
},
},
});
cy.sandboxTable({
table_id: PRODUCTS_ID,
attribute_remappings: {
Expand All @@ -32,7 +48,6 @@ describeEE("issue 29076", () => {

// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText("Orders").click();
cy.wait("@cardQuery");
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText("Visualization").should("be.visible");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ const dashboardDetails = {
if (test === "nosql") {
cy.updatePermissionsGraph({
[COLLECTION_GROUP]: {
1: { data: { schemas: "all", native: "none" } },
1: {
"view-data": "unrestricted",
"create-queries": "query-builder",
},
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ describe("scenarios > filters > sql filters > values source", () => {

describeEE("scenarios > filters > sql filters > values source", () => {
beforeEach(() => {
restore();
restore("default-ee");
cy.signInAsAdmin();
setTokenFeatures("all");
cy.intercept("POST", "/api/dataset/parameter/values").as("parameterValues");
Expand All @@ -361,7 +361,10 @@ describeEE("scenarios > filters > sql filters > values source", () => {
it("should sandbox parameter values in questions", () => {
cy.updatePermissionsGraph({
[COLLECTION_GROUP]: {
[SAMPLE_DB_ID]: { data: { schemas: "all" } },
[SAMPLE_DB_ID]: {
"view-data": "unrestricted",
"create-queries": "query-builder",
},
},
});

Expand Down
7 changes: 6 additions & 1 deletion e2e/test/scenarios/native/native-database-source.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
popover,
addPostgresDatabase,
POPOVER_ELEMENT,
setTokenFeatures,
} from "e2e/support/helpers";

const PG_DB_ID = 2;
Expand Down Expand Up @@ -180,9 +181,13 @@ describe(

cy.signOut();
cy.signInAsAdmin();
setTokenFeatures("all");
cy.updatePermissionsGraph({
[DATA_GROUP]: {
[SAMPLE_DB_ID]: { data: { schemas: "none", native: "none" } },
[SAMPLE_DB_ID]: {
"view-data": "blocked",
"create-queries": "no",
},
},
});

Expand Down
15 changes: 12 additions & 3 deletions e2e/test/scenarios/native/native.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,20 @@ describe("no native access", { tags: ["@external", "@quarantine"] }, () => {
cy.intercept("/api/database?saved=true").as("database");
cy.updatePermissionsGraph({
[USER_GROUPS.ALL_USERS_GROUP]: {
[WRITABLE_DB_ID]: { data: { schemas: "none", native: "none" } },
[WRITABLE_DB_ID]: {
"view-data": "blocked",
"create-queries": "no",
},
},
[USER_GROUPS.NOSQL_GROUP]: {
[SAMPLE_DB_ID]: { data: { schemas: "all", native: "write" } },
[WRITABLE_DB_ID]: { data: { schemas: "all", native: "none" } },
[SAMPLE_DB_ID]: {
"view-data": "unrestricted",
"create-queries": "query-builder-and-native",
},
[WRITABLE_DB_ID]: {
"view-data": "unrestricted",
"create-queries": "query-builder",
},
},
});

Expand Down
Loading

0 comments on commit 79583b9

Please sign in to comment.