Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

UXW-2091 user without collection access to Our Analytics can't save documents (#65159)

Denis Berezin9f0f6eb78c7b
diff --git a/e2e/test/scenarios/documents/document-permissions.cy.spec.ts b/e2e/test/scenarios/documents/document-permissions.cy.spec.ts
new file mode 100644
index 00000000000..7a55363d9f3
--- /dev/null
+++ b/e2e/test/scenarios/documents/document-permissions.cy.spec.ts
@@ -0,0 +1,110 @@
+const { H } = cy;
+import { USER_GROUPS } from "e2e/support/cypress_data";
+
+const { ALL_USERS_GROUP } = USER_GROUPS;
+
+H.describeWithSnowplowEE("document permissions", () => {
+ beforeEach(() => {
+ H.restore();
+ cy.signInAsAdmin();
+ H.activateToken("bleeding-edge");
+ H.resetSnowplow();
+ cy.signOut();
+ });
+
+ it("should allow a non-admin user to create a new document and save it", () => {
+ cy.signInAsAdmin();
+
+ cy.updateCollectionGraph({
+ [ALL_USERS_GROUP]: { root: "none" },
+ });
+
+ cy.signOut();
+
+ cy.signIn("none");
+
+ cy.visit("/");
+
+ H.newButton("Document").click();
+ cy.title().should("eq", "New document · Metabase");
+
+ cy.findByRole("textbox", { name: "Document Title" })
+ .should("be.focused")
+ .type("User Document");
+
+ H.documentContent().type("This is a document created by a non-admin user");
+
+ cy.findByRole("button", { name: "Save" }).click();
+
+ cy.findByTestId("item-picker-level-0")
+ .findByText("Our analytics")
+ .should("not.exist");
+ H.entityPickerModalItem(0, "Collections").should("exist");
+
+ H.entityPickerModalItem(0, /Personal Collection/).click();
+ H.entityPickerModal().findByRole("button", { name: "Select" }).click();
+
+ cy.location("pathname").should("match", /^\/document\/\d+/);
+ cy.title().should("eq", "User Document · Metabase");
+
+ H.expectUnstructuredSnowplowEvent({ event: "document_created" });
+
+ H.appBar()
+ .findByRole("link", { name: /Personal Collection/ })
+ .click();
+
+ H.collectionTable()
+ .findByRole("link", { name: "User Document" })
+ .should("exist");
+ });
+
+ it("should allow a non-admin user to edit their own document", () => {
+ cy.signInAsNormalUser();
+
+ H.createDocument({
+ name: "User Document",
+ document: {
+ content: [
+ {
+ type: "paragraph",
+ content: [
+ {
+ type: "text",
+ text: "Original content",
+ },
+ ],
+ attrs: {
+ _id: "1",
+ },
+ },
+ ],
+ type: "doc",
+ },
+ collection_id: null,
+ alias: "document",
+ idAlias: "documentId",
+ });
+
+ H.visitDocument("@documentId");
+
+ H.documentContent().should("contain.text", "Original content");
+
+ H.documentContent()
+ .findByRole("textbox")
+ .should("have.attr", "contenteditable", "true");
+
+ H.documentContent().click();
+ H.addToDocument(" and some new content");
+
+ H.documentSaveButton().click();
+
+ cy.findByTestId("toast-undo")
+ .findByText("Document saved")
+ .should("be.visible");
+
+ H.documentContent().should(
+ "contain.text",
+ "Original content and some new content",
+ );
+ });
+});
diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx b/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx
index 82fff427f7b..91e028bd56f 100644
--- a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx
@@ -455,7 +455,6 @@ export const DocumentPage = ({
<CollectionPickerModal
title={t`Where should we save this document?`}
onClose={() => setCollectionPickerMode(null)}
- value={{ id: "root", model: "collection" }}
options={{
showPersonalCollections: true,
showRootCollection: true,
diff --git a/frontend/src/metabase/common/components/Pickers/CollectionPicker/components/CollectionPickerModal.tsx b/frontend/src/metabase/common/components/Pickers/CollectionPicker/components/CollectionPickerModal.tsx
index f6ff3ca71bf..ef020b24846 100644
--- a/frontend/src/metabase/common/components/Pickers/CollectionPicker/components/CollectionPickerModal.tsx
+++ b/frontend/src/metabase/common/components/Pickers/CollectionPicker/components/CollectionPickerModal.tsx
@@ -29,7 +29,7 @@ export interface CollectionPickerModalProps {
onChange: (item: CollectionPickerValueItem) => void;
onClose: () => void;
options?: CollectionPickerOptions;
- value: Pick<CollectionPickerValueItem, "id" | "model" | "collection_id">;
+ value?: Pick<CollectionPickerValueItem, "id" | "model" | "collection_id">;
shouldDisableItem?: (item: CollectionPickerItem) => boolean;
searchResultFilter?: (searchResults: SearchResult[]) => SearchResult[];
recentFilter?: (recentItems: RecentItem[]) => RecentItem[];
@@ -38,7 +38,7 @@ export interface CollectionPickerModalProps {
}
const baseCanSelectItem = (
- item: Pick<CollectionPickerItem, "can_write" | "model"> | null,
+ item: Pick<CollectionPickerItem, "can_write" | "model"> | null | undefined,
): item is CollectionPickerValueItem => {
return (
!!item &&
@@ -62,17 +62,22 @@ export const CollectionPickerModal = ({
shouldDisableItem,
searchResultFilter,
recentFilter,
- models = ["collection"],
+ models: modelsProp,
canSelectItem: _canSelectItem,
}: CollectionPickerModalProps) => {
options = { ...defaultOptions, ...options };
+ const models = modelsProp || ["collection"];
+
const [selectedItem, setSelectedItem] = useState<CollectionPickerItem | null>(
null,
);
const canSelectItem = useCallback(
(
- item: Pick<CollectionPickerItem, "id" | "can_write" | "model"> | null,
+ item:
+ | Pick<CollectionPickerItem, "id" | "can_write" | "model">
+ | null
+ | undefined,
): item is CollectionPickerValueItem => {
return baseCanSelectItem(item) && (_canSelectItem?.(item) ?? true);
},
@@ -166,8 +171,8 @@ export const CollectionPickerModal = ({
displayName: models.some((model) => model !== "collection")
? t`Browse`
: t`Collections`,
- models,
- folderModels: ["collection" as const],
+ models: models,
+ folderModels: ["collection"],
icon: "folder",
render: ({ onItemSelect }) => (
<CollectionPicker