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
Replace upload-permission e2e tests with unit coverage (#82973)
Nemanja Glumac1139be54dd23
diff --git a/e2e/test/scenarios/collections/uploads.cy.spec.js b/e2e/test/scenarios/collections/uploads.cy.spec.jsindex 22fe2d24397..a7ae6d4b307 100644--- a/e2e/test/scenarios/collections/uploads.cy.spec.js+++ b/e2e/test/scenarios/collections/uploads.cy.spec.js@@ -1,10 +1,8 @@const { H } = cy;-import { USER_GROUPS, WRITABLE_DB_ID } from "e2e/support/cypress_data";+import { WRITABLE_DB_ID } from "e2e/support/cypress_data";import { FIRST_COLLECTION_ID } from "e2e/support/cypress_sample_instance_data";import { FIXTURE_PATH, VALID_CSV_FILES } from "e2e/support/helpers";-const { NOSQL_GROUP, ALL_USERS_GROUP } = USER_GROUPS;-describe("CSV Uploading", { tags: ["@external", "@actions"] }, () => {beforeEach(() => {cy.intercept("POST", "/api/dataset").as("dataset");@@ -260,82 +258,6 @@ describe("CSV Uploading", { tags: ["@external", "@actions"] }, () => {});});-describe("permissions", { tags: "@external" }, () => {- it("should not show you upload buttons if you are a sandboxed user", () => {- H.restore("postgres-12");- cy.signInAsAdmin();-- H.activateToken("pro-self-hosted");- H.enableUploads("postgres");-- //Deny access for all users to writable DB- cy.updatePermissionsGraph({- 1: {- [WRITABLE_DB_ID]: {- "view-data": "blocked",- },- },- });-- cy.request("GET", `/api/database/${WRITABLE_DB_ID}/schema/public`).then(- ({ body: tables }) => {- cy.request("GET", `/api/database/${WRITABLE_DB_ID}/fields`).then(- ({ body: fields }) => {- // Sandbox a table so that the sandboxed user will have read access to a table- cy.sandboxTable({- table_id: tables[0].id,- attribute_remappings: {- attr_uid: ["dimension", ["field", fields[0].id, null]],- },- });- },- );- },- );-- cy.signInAsSandboxedUser();- cy.visit("/collection/root");- // No upload icon should appear for the sandboxed user- cy.findByTestId("collection-menu").within(() => {- cy.get(".Icon-calendar").should("exist");- cy.findByLabelText("Upload data").should("not.exist");- });- });-- it("should show you upload buttons if you have unrestricted access to the upload schema", () => {- H.restore("postgres-12");- cy.signInAsAdmin();-- H.activateToken("pro-self-hosted");- H.enableUploads("postgres");-- cy.updatePermissionsGraph({- [ALL_USERS_GROUP]: {- [WRITABLE_DB_ID]: {- "view-data": "blocked",- },- },- [NOSQL_GROUP]: {- [WRITABLE_DB_ID]: {- "view-data": "unrestricted",- "create-queries": "query-builder",- },- },- });-- cy.updateCollectionGraph({- [NOSQL_GROUP]: { root: "write" },- });-- cy.signIn("nosql");- cy.visit("/collection/root");- cy.findByTestId("collection-menu").within(() => {- cy.findByLabelText("Upload data").should("exist");- cy.findByRole("img", { name: /upload/i }).should("exist");- });- });-});-describe("Upload Table Cleanup/Management", { tags: "@external" }, () => {beforeEach(() => {cy.intercept("GET", "/api/ee/upload-management/tables").as(diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/upload_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/upload_test.cljindex da8bd8f8e2e..2baf6262ca0 100644--- a/enterprise/backend/test/metabase_enterprise/sandbox/upload_test.clj+++ b/enterprise/backend/test/metabase_enterprise/sandbox/upload_test.clj@@ -68,3 +68,19 @@(is (= nil(:based_on_upload (get-card))(:based_on_upload (get-collection-item))))))))))))++(deftest can-upload-false-for-sandboxed-user-test+ (mt/test-drivers (mt/normal-drivers-with-feature :uploads)+ (mt/dataset dataset+ (met/with-gtaps-for-user! :rasta {:gtaps {:venues {}}}+ (upload-test/with-uploads-enabled!+ (testing "Sanity check: an unsandboxed admin can upload to the same database"+ (is (true? (:can_upload (mt/user-http-request :crowberto :get 200 (str "database/" (mt/id)))))))+ (testing "GET /api/database/:id"+ (is (false? (:can_upload (mt/user-http-request :rasta :get 200 (str "database/" (mt/id)))))))+ (testing "GET /api/database"+ (is (false? (->> (mt/user-http-request :rasta :get 200 "database")+ :data+ (filter #(= (mt/id) (:id %)))+ first+ :can_upload)))))))))diff --git a/frontend/src/metabase/collections/components/CollectionContent/CollectionContentUpload.unit.spec.tsx b/frontend/src/metabase/collections/components/CollectionContent/CollectionContentUpload.unit.spec.tsxindex f4ef7b819f3..22105804914 100644--- a/frontend/src/metabase/collections/components/CollectionContent/CollectionContentUpload.unit.spec.tsx+++ b/frontend/src/metabase/collections/components/CollectionContent/CollectionContentUpload.unit.spec.tsx@@ -20,6 +20,7 @@ import {} from "__support__/ui";import { Route } from "metabase/router";import { FileUploadStatus } from "metabase/status/components/FileUploadStatus/FileUploadStatus";+import type { CollectionId } from "metabase-types/api";import {createMockCollection,createMockCollectionItem,@@ -61,9 +62,12 @@ const uploadedModel2 = createMockCollectionItem({based_on_upload: 124,});-async function setupCollectionContent(overrides = {}) {+async function setupCollectionContent({+ canUpload = true,+ ...overrides+}: { canUpload?: boolean; collectionId?: CollectionId } = {}) {setupUserMetabotPermissionsEndpoint();- setupDatabasesEndpoints([createMockDatabase({ can_upload: true })]);+ setupDatabasesEndpoints([createMockDatabase({ can_upload: canUpload })]);setupBookmarksEndpoints([]);setupNullGetUserKeyValueEndpoints();@@ -95,7 +99,14 @@ async function setupCollectionContent(overrides = {}) {);// wait for loading to complete- await screen.findByTestId("upload-input");+ if (canUpload) {+ await screen.findByTestId("upload-input");+ } else {+ await screen.findByTestId("collection-menu");+ await waitFor(() =>+ expect(fetchMock.callHistory.called("path:/api/database")).toBe(true),+ );+ }}describe("CollectionContent file uploads", () => {@@ -131,6 +142,18 @@ describe("CollectionContent file uploads", () => {jest.useRealTimers();});+ it("should show the upload button when the upload database allows uploads", async () => {+ await setupCollectionContent();++ expect(screen.getByLabelText("Upload data")).toBeInTheDocument();+ });++ it("should not show the upload button when the upload database does not allow uploads", async () => {+ await setupCollectionContent({ canUpload: false });++ expect(screen.queryByLabelText("Upload data")).not.toBeInTheDocument();+ });+it("Should show a start exploring link on completion", async () => {jest.useFakeTimers({ advanceTimers: true });fetchMock.post("path:/api/upload/csv", "3", { delay: 1000 });diff --git a/frontend/src/metabase/collections/components/CollectionHeader/tests/common.unit.spec.tsx b/frontend/src/metabase/collections/components/CollectionHeader/tests/common.unit.spec.tsxindex 0849e93bed8..8b44fdb48da 100644--- a/frontend/src/metabase/collections/components/CollectionHeader/tests/common.unit.spec.tsx+++ b/frontend/src/metabase/collections/components/CollectionHeader/tests/common.unit.spec.tsx@@ -295,6 +295,17 @@ describe("CollectionHeader", () => {expect(screen.queryByLabelText("Upload data")).not.toBeInTheDocument();});+ it("should not show the upload button if uploads are enabled but the user cannot upload to the database", () => {+ setup({+ collection: { can_write: true },+ uploadsEnabled: true,+ canUpload: false,+ isAdmin: false,+ });++ expect(screen.queryByLabelText("Upload data")).not.toBeInTheDocument();+ });+it("should show an informational modal when clicking the upload button when uploads are disabled", async () => {setup({collection: { can_write: true },