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
Move documents feature to OSS (#66223)
Denis Berezin19e4e35d00d4
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex 33c38ea8c62..e7b085f20be 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -93,7 +93,6 @@configeventsmodels- premium-featuresutil}}analytics@@ -238,8 +237,6 @@:uses #{apiapp-dbcollections- config- premium-featuresqueriesutil}}@@ -387,6 +384,20 @@uploadutil}}+ comments+ {:team "UX West"+ :api #{metabase.comments.api+ metabase.comments.init}+ :uses #{analytics+ api+ channel+ events+ models+ request+ users+ users-rest+ util}}+;; technically this 'uses' `enterprise/core` and `test` since it tries to load them to see if they exists so we know;; if EE/test code is available; however we can ignore them since they're not real usages.config@@ -481,6 +492,28 @@:api #{metabase.database-routing.core}:uses #{premium-features}}+ documents+ {:team "UX West"+ :api #{metabase.documents.api+ metabase.documents.core+ metabase.documents.init+ metabase.documents.prose-mirror}+ :uses #{activity-feed+ api+ app-db+ batch-processing+ collections+ events+ models+ public-sharing+ queries+ query-permissions+ query-processor+ revisions+ search+ util+ view-log}}+driver{:team "Drivers":api #{metabase.driver@@ -1779,11 +1812,6 @@store-apiutil}}- enterprise/bookmarks- {:team "UX West"- :api #{}- :uses #{}}-enterprise/cache{:team "UX West":api #{metabase-enterprise.cache.init}@@ -1803,20 +1831,6 @@utilenterprise/harbormaster}}- enterprise/comments- {:team "UX West"- :api #{metabase-enterprise.comments.api- metabase-enterprise.comments.init}- :uses #{analytics- api- channel- events- models- request- users- users-rest- util}}-enterprise/content-translation{:team "UX West":api #{metabase-enterprise.content-translation.routes}@@ -1897,6 +1911,7 @@:uses #{analyzeapicollections+ documentsdrivereventsgraph@@ -1911,31 +1926,7 @@revisionssettingstask- util- enterprise/documents}}-- enterprise/documents- {:team "UX West"- :api #{metabase-enterprise.documents.api- metabase-enterprise.documents.core- metabase-enterprise.documents.init- metabase-enterprise.documents.prose-mirror}- :uses #{activity-feed- api- app-db- batch-processing- collections- events- models- premium-features- public-sharing- queries- query-permissions- query-processor- revisions- search- util- view-log}}+ util}}enterprise/email{:team "UX West"@@ -2028,6 +2019,7 @@audit-appcollectionsconfig+ documentsdriverlegacy-mbqllib@@ -2051,7 +2043,6 @@warehouse-schemawarehouses-restenterprise/dependencies- enterprise/documentsenterprise/transformsenterprise/transforms-python}}@@ -2071,17 +2062,6 @@:uses #{premium-featuresutil}}- enterprise/public-sharing- {:team "UX West"- :api #{metabase-enterprise.public-sharing.api}- :uses #{api- events- premium-features- public-sharing- public-sharing-rest- query-processor- util}}-enterprise/remote-sync{:team "UX West":api #{metabase-enterprise.remote-sync.apidiff --git a/bb.edn b/bb.ednindex 752b5c217d4..33416d7d7be 100644--- a/bb.edn+++ b/bb.edn@@ -190,8 +190,8 @@;; note: no quoting -> expect it to be intcode (format "(notify-comment-id! %d)" (parse-long (:comment-id opts)))](if (:port opts)- (nrepl-eval "metabase-enterprise.comments.core" code (:port opts))- (nrepl-eval "metabase-enterprise.comments.core" code)))}+ (nrepl-eval "metabase.comments.core" code (:port opts))+ (nrepl-eval "metabase.comments.core" code)))}run-tests{:doc "Quickly run tests locally. Pass dirs/files as arguments to run them."diff --git a/deps.edn b/deps.ednindex ec2004ebd3c..340e49f89cc 100644--- a/deps.edn+++ b/deps.edn@@ -671,7 +671,7 @@"test/metabase/channel/render/png_test.clj""#.+#$""\\.transit\\.json$"- "enterprise/frontend/src/metabase-enterprise/documents/components/Editor/data/data\\.json$"]}}+ "frontend/src/metabase/documents/components/Editor/data/data\\.json$"]}};; clojure -X:dev:ee:ee-dev:test:cloverage:cloveragediff --git a/docs/api.json b/docs/api.jsonindex 44bcad9e230..343da13842f 100644--- a/docs/api.json+++ b/docs/api.json@@ -16586,9 +16586,9 @@"tags" : [ "/api/ee/cloud-add-ons" ]}},- "/api/ee/comment/" : {+ "/api/comment/" : {"get" : {- "summary" : "GET /api/ee/comment/",+ "summary" : "GET /api/comment/","description" : "Get comments for an entity","parameters" : [ {"in" : "query",@@ -16619,10 +16619,10 @@"description" : "Server error response"}},- "tags" : [ "/api/ee/comment" ]+ "tags" : [ "/api/comment" ]},"post" : {- "summary" : "POST /api/ee/comment/",+ "summary" : "POST /api/comment/","description" : "Create a new comment","parameters" : [ ],"responses" : {@@ -16671,12 +16671,12 @@}}},- "tags" : [ "/api/ee/comment" ]+ "tags" : [ "/api/comment" ]}},- "/api/ee/comment/mentions" : {+ "/api/comment/mentions" : {"get" : {- "summary" : "GET /api/ee/comment/mentions",+ "summary" : "GET /api/comment/mentions","description" : "Get a list of entities suitable for mentions. NOTE: only users for now.","parameters" : [ ],"responses" : {@@ -16690,12 +16690,12 @@"description" : "Server error response"}},- "tags" : [ "/api/ee/comment" ]+ "tags" : [ "/api/comment" ]}},- "/api/ee/comment/{comment-id}" : {+ "/api/comment/{comment-id}" : {"put" : {- "summary" : "PUT /api/ee/comment/{comment-id}",+ "summary" : "PUT /api/comment/{comment-id}","description" : "Update a comment","parameters" : [ {"in" : "path",@@ -16738,10 +16738,10 @@}}},- "tags" : [ "/api/ee/comment" ]+ "tags" : [ "/api/comment" ]},"delete" : {- "summary" : "DELETE /api/ee/comment/{comment-id}",+ "summary" : "DELETE /api/comment/{comment-id}","description" : "Soft delete a comment","parameters" : [ {"in" : "path",@@ -16764,12 +16764,12 @@"description" : "Server error response"}},- "tags" : [ "/api/ee/comment" ]+ "tags" : [ "/api/comment" ]}},- "/api/ee/comment/{comment-id}/reaction" : {+ "/api/comment/{comment-id}/reaction" : {"post" : {- "summary" : "POST /api/ee/comment/{comment-id}/reaction",+ "summary" : "POST /api/comment/{comment-id}/reaction","description" : "Toggle a reaction on a comment","parameters" : [ {"in" : "path",@@ -16809,7 +16809,7 @@}}},- "tags" : [ "/api/ee/comment" ]+ "tags" : [ "/api/comment" ]}},"/api/ee/content-translation/csv" : {@@ -17548,9 +17548,9 @@"tags" : [ "/api/ee/dependencies" ]}},- "/api/ee/document/" : {+ "/api/document/" : {"get" : {- "summary" : "GET /api/ee/document/",+ "summary" : "GET /api/document/","description" : "Gets existing `Documents`.","parameters" : [ ],"responses" : {@@ -17564,10 +17564,10 @@"description" : "Server error response"}},- "tags" : [ "/api/ee/document" ]+ "tags" : [ "/api/document" ]},"post" : {- "summary" : "POST /api/ee/document/",+ "summary" : "POST /api/document/","description" : "Create a new `Document`.","parameters" : [ ],"responses" : {@@ -17673,12 +17673,12 @@}}},- "tags" : [ "/api/ee/document" ]+ "tags" : [ "/api/document" ]}},- "/api/ee/document/public" : {+ "/api/document/public" : {"get" : {- "summary" : "GET /api/ee/document/public",+ "summary" : "GET /api/document/public","description" : "List all Documents that have public links.\n\n Returns a sequence of Documents that have been publicly shared. Each Document includes its `:id`, `:name`,\n and `:public_uuid`. Documents are only actually accessible via the public endpoint if public sharing is\n currently enabled. Archived Documents are excluded from the results.\n\n This endpoint is used to populate the public links listing in the Admin settings UI.\n\n Requires superuser permissions. Public sharing must be enabled via the `enable-public-sharing` setting.","parameters" : [ ],"responses" : {@@ -17718,12 +17718,12 @@"description" : "Server error response"}},- "tags" : [ "/api/ee/document" ]+ "tags" : [ "/api/document" ]}},- "/api/ee/document/{document-id}" : {+ "/api/document/{document-id}" : {"get" : {- "summary" : "GET /api/ee/document/{document-id}",+ "summary" : "GET /api/document/{document-id}","description" : "Returns an existing Document by ID.","parameters" : [ {"in" : "path",@@ -17746,10 +17746,10 @@"description" : "Server error response"}},- "tags" : [ "/api/ee/document" ]+ "tags" : [ "/api/document" ]},"put" : {- "summary" : "PUT /api/ee/document/{document-id}",+ "summary" : "PUT /api/document/{document-id}","description" : "Updates an existing `Document`.","parameters" : [ {"in" : "path",@@ -17866,10 +17866,10 @@}}},- "tags" : [ "/api/ee/document" ]+ "tags" : [ "/api/document" ]},"delete" : {- "summary" : "DELETE /api/ee/document/{document-id}",+ "summary" : "DELETE /api/document/{document-id}","description" : "Permanently deletes an archived Document.","parameters" : [ {"in" : "path",@@ -17892,12 +17892,12 @@"description" : "Server error response"}},- "tags" : [ "/api/ee/document" ]+ "tags" : [ "/api/document" ]}},- "/api/ee/document/{document-id}/card/{card-id}/query/{export-format}" : {+ "/api/document/{document-id}/card/{card-id}/query/{export-format}" : {"post" : {- "summary" : "POST /api/ee/document/{document-id}/card/{card-id}/query/{export-format}",+ "summary" : "POST /api/document/{document-id}/card/{card-id}/query/{export-format}","description" : "Download query results for a Card embedded in a Document.\n\n Returns query results in the requested format. The user must have read access to the document\n to download results. If the card's query fails, standard query error responses are returned.\n\n Route parameters:\n - document-id: ID of the document containing the card\n - card-id: ID of the card to download results from\n - export-format: Output format (csv, xlsx, json)\n\n Body parameters (snake_case):\n - parameters: Optional query parameters (array of maps or JSON string)\n - format_rows: Whether to apply formatting to results (boolean, default false)\n - pivot_results: Whether to pivot results (boolean, default false)","parameters" : [ {"in" : "path",@@ -17969,12 +17969,12 @@}}},- "tags" : [ "/api/ee/document" ]+ "tags" : [ "/api/document" ]}},- "/api/ee/document/{document-id}/public-link" : {+ "/api/document/{document-id}/public-link" : {"post" : {- "summary" : "POST /api/ee/document/{document-id}/public-link",+ "summary" : "POST /api/document/{document-id}/public-link","description" : "Generate a publicly-accessible UUID for a Document.\n\n Creates a public link that allows viewing the Document without authentication. If the Document already has\n a public UUID, returns the existing one rather than generating a new one. This enables sharing the Document\n via `GET /api/ee/public/document/:uuid`.\n\n Returns a map containing `:uuid` (the public UUID string).\n\n Requires superuser permissions. Public sharing must be enabled via the `enable-public-sharing` setting.","parameters" : [ {"in" : "path",@@ -18012,10 +18012,10 @@"description" : "Server error response"}},- "tags" : [ "/api/ee/document" ]+ "tags" : [ "/api/document" ]},"delete" : {- "summary" : "DELETE /api/ee/document/{document-id}/public-link",+ "summary" : "DELETE /api/document/{document-id}/public-link","description" : "Remove the public link for a Document.\n\n Deletes the public UUID from the Document, making it no longer accessible via the public sharing endpoint.\n This revokes public access to the Document - the existing public link will no longer work.\n\n Returns a 204 No Content response on success.\n\n Requires superuser permissions. Public sharing must be enabled via the `enable-public-sharing` setting.\n Throws a 404 if the Document doesn't exist, is archived, or doesn't have a public link.","parameters" : [ {"in" : "path",@@ -18038,7 +18038,7 @@"description" : "Server error response"}},- "tags" : [ "/api/ee/document" ]+ "tags" : [ "/api/document" ]}},"/api/ee/email/override" : {@@ -31662,4 +31662,4 @@"url" : "http://localhost:3000","description" : "Localhost"} ]-}\ No newline at end of file+}diff --git a/e2e/support/helpers/api/createComment.ts b/e2e/support/helpers/api/createComment.tsindex 9e70969abad..47e905590ab 100644--- a/e2e/support/helpers/api/createComment.ts+++ b/e2e/support/helpers/api/createComment.ts@@ -10,7 +10,7 @@ export const createComment = ({}: Partial<CreateCommentRequest>): Cypress.Chainable<Cypress.Response<Comment>> => {- return cy.request<Comment>("POST", "/api/ee/comment", {+ return cy.request<Comment>("POST", "/api/comment", {target_id,target_type,child_target_id,diff --git a/e2e/support/helpers/api/createDocument.ts b/e2e/support/helpers/api/createDocument.tsindex 0bc4d1ec504..fee398f3618 100644--- a/e2e/support/helpers/api/createDocument.ts+++ b/e2e/support/helpers/api/createDocument.ts@@ -20,7 +20,7 @@ export const createDocument = ({cy.log(`Create a document: ${name}`);return cy- .request("POST", "/api/ee/document", {+ .request("POST", "/api/document", {name,collection_id,document,diff --git a/e2e/support/helpers/api/createReaction.ts b/e2e/support/helpers/api/createReaction.tsindex 4062e864c83..7218ff5cd0c 100644--- a/e2e/support/helpers/api/createReaction.ts+++ b/e2e/support/helpers/api/createReaction.ts@@ -7,7 +7,7 @@ export const createReaction = ({comment_id: CommentId;emoji: string;}): Cypress.Chainable<Cypress.Response<Comment>> => {- return cy.request<Comment>("POST", `/api/ee/comment/${comment_id}/reaction`, {+ return cy.request<Comment>("POST", `/api/comment/${comment_id}/reaction`, {emoji,});};diff --git a/e2e/support/helpers/api/deleteComment.ts b/e2e/support/helpers/api/deleteComment.tsindex 281f0be9ee3..65d01bd4df9 100644--- a/e2e/support/helpers/api/deleteComment.ts+++ b/e2e/support/helpers/api/deleteComment.ts@@ -3,5 +3,5 @@ import type { CommentId } from "metabase-types/api";export const deleteComment = (commentId: CommentId,): Cypress.Chainable<Cypress.Response<void>> => {- return cy.request<void>("DELETE", `/api/ee/comment/${commentId}`);+ return cy.request<void>("DELETE", `/api/comment/${commentId}`);};diff --git a/e2e/support/helpers/api/updateComment.ts b/e2e/support/helpers/api/updateComment.tsindex f08ea5022b2..e385e7c2913 100644--- a/e2e/support/helpers/api/updateComment.ts+++ b/e2e/support/helpers/api/updateComment.ts@@ -7,7 +7,7 @@ export const updateComment = ({}: Partial<UpdateCommentRequest>): Cypress.Chainable<Cypress.Response<Comment>> => {- return cy.request<Comment>("PUT", `/api/ee/comment/${id}`, {+ return cy.request<Comment>("PUT", `/api/comment/${id}`, {content,is_resolved,});diff --git a/e2e/support/helpers/e2e-document-helpers.ts b/e2e/support/helpers/e2e-document-helpers.tsindex 17d234fd52d..8bf42e0d615 100644--- a/e2e/support/helpers/e2e-document-helpers.ts+++ b/e2e/support/helpers/e2e-document-helpers.ts@@ -92,7 +92,7 @@ function visitDocumentCommentById(commentId?: CommentId,) {const alias = `documentQuery-${documentId}`;- cy.intercept("GET", `/api/ee/document/${documentId}`).as(alias);+ cy.intercept("GET", `/api/document/${documentId}`).as(alias);const hash = commentId == null ? "" : `#comment-${commentId}`;cy.visit(`/document/${documentId}/comments/${nodeId}${hash}`);@@ -102,7 +102,7 @@ function visitDocumentCommentById(const visitDocumentById = (id: DocumentId) => {const alias = `documentQuery-${id}`;- cy.intercept("GET", `/api/ee/document/${id}`).as(alias);+ cy.intercept("GET", `/api/document/${id}`).as(alias);cy.visit(`/document/${id}`);diff --git a/e2e/support/helpers/e2e-embedding-helpers.js b/e2e/support/helpers/e2e-embedding-helpers.jsindex 912c28b4bb7..b8d518e7967 100644--- a/e2e/support/helpers/e2e-embedding-helpers.js+++ b/e2e/support/helpers/e2e-embedding-helpers.js@@ -353,7 +353,7 @@ export function createPublicDashboardLink(dashboardId) {}export function createPublicDocumentLink(documentId) {- return cy.request("POST", `/api/ee/document/${documentId}/public-link`, {});+ return cy.request("POST", `/api/document/${documentId}/public-link`, {});}/**diff --git a/e2e/test/scenarios/documents/card-embed-node.cy.spec.ts b/e2e/test/scenarios/documents/card-embed-node.cy.spec.tsindex 51b20e6976e..0a74ab948e2 100644--- a/e2e/test/scenarios/documents/card-embed-node.cy.spec.ts+++ b/e2e/test/scenarios/documents/card-embed-node.cy.spec.ts@@ -9,7 +9,6 @@ describe("documents card embed node custom logic", () => {beforeEach(() => {H.restore();cy.signInAsAdmin();- H.activateToken("bleeding-edge");});describe("cardEmbed drag and drop", () => {diff --git a/e2e/test/scenarios/documents/comments.cy.spec.ts b/e2e/test/scenarios/documents/comments.cy.spec.tsindex 74014cc9e80..ab7f881baa2 100644--- a/e2e/test/scenarios/documents/comments.cy.spec.ts+++ b/e2e/test/scenarios/documents/comments.cy.spec.ts@@ -28,7 +28,6 @@ describe("document comments", () => {beforeEach(() => {H.restore();cy.signInAsAdmin();- H.activateToken("bleeding-edge");H.resetSnowplow();});@@ -737,7 +736,6 @@ describe("document comments", () => {cy.findByText("Lorem ipsum").should("not.exist");cy.findByText("Bobby Tables").should("be.visible");cy.findByText("No Collection Tableton").should("be.visible");- cy.findByText("Most viewed content").should("be.visible");});cy.realType("s");@@ -1054,7 +1052,7 @@ describe("document comments", () => {it("opens a link to a resolved comment correctly", () => {cy.get<number>("@headingCommentId").then((commentId) => {- cy.request("PUT", `/api/ee/comment/${commentId}`, {+ cy.request("PUT", `/api/comment/${commentId}`, {is_resolved: true,});H.visitDocumentComment("@documentId", HEADING_1_ID, commentId);diff --git a/e2e/test/scenarios/documents/document-downloads.cy.spec.ts b/e2e/test/scenarios/documents/document-downloads.cy.spec.tsindex 4aaef0fdfc4..618816de873 100644--- a/e2e/test/scenarios/documents/document-downloads.cy.spec.ts+++ b/e2e/test/scenarios/documents/document-downloads.cy.spec.ts@@ -8,7 +8,6 @@ describe("scenarios > documents > downloads", () => {beforeEach(() => {H.restore();cy.signInAsAdmin();- H.activateToken("bleeding-edge");});it("shows Download results for read-only document access", () => {@@ -145,6 +144,8 @@ describe("scenarios > documents > downloads", () => {});it("hides Download results when the person lacks download permission but can view the collection", () => {+ H.activateToken("bleeding-edge");+H.createDocument({name: "No Download Permission Document",document: DOCUMENT_WITH_TWO_CARDS,diff --git a/e2e/test/scenarios/documents/document-links.cy.spec.ts b/e2e/test/scenarios/documents/document-links.cy.spec.tsindex 10d6f6c76d1..7b5e7686a66 100644--- a/e2e/test/scenarios/documents/document-links.cy.spec.ts+++ b/e2e/test/scenarios/documents/document-links.cy.spec.ts@@ -8,7 +8,6 @@ describe("Links in documents", () => {beforeEach(() => {H.restore();cy.signInAsAdmin();- H.activateToken("bleeding-edge");});describe("plain links", () => {diff --git a/e2e/test/scenarios/documents/document-permissions.cy.spec.ts b/e2e/test/scenarios/documents/document-permissions.cy.spec.tsindex 7692e97f47e..74f7d6ee76a 100644--- a/e2e/test/scenarios/documents/document-permissions.cy.spec.ts+++ b/e2e/test/scenarios/documents/document-permissions.cy.spec.ts@@ -7,7 +7,6 @@ describe("document permissions", () => {beforeEach(() => {H.restore();cy.signInAsAdmin();- H.activateToken("bleeding-edge");H.resetSnowplow();cy.signOut();});diff --git a/e2e/test/scenarios/documents/documents.cy.spec.ts b/e2e/test/scenarios/documents/documents.cy.spec.tsindex e88c006e2ef..a994e10d191 100644--- a/e2e/test/scenarios/documents/documents.cy.spec.ts+++ b/e2e/test/scenarios/documents/documents.cy.spec.ts@@ -18,14 +18,13 @@ describe("documents", () => {beforeEach(() => {H.restore();cy.signInAsAdmin();- H.activateToken("bleeding-edge");H.resetSnowplow();});it("should allow you to create a new document from the new button and save", () => {const getDocumentStub = cy.stub();- cy.intercept("GET", "/api/ee/document/1", getDocumentStub);+ cy.intercept("GET", "/api/document/1", getDocumentStub);cy.visit("/");@@ -553,6 +552,9 @@ describe("documents", () => {});it("should support keyboard and mouse selection in suggestions without double highlight", () => {+ H.activateToken("bleeding-edge");+ H.visitDocument("@documentId");+H.documentContent().click();H.addToDocument("/", false);@@ -799,11 +801,11 @@ describe("documents", () => {it("should copy an added card on save", () => {cy.intercept({method: "PUT",- path: "/api/ee/document/*",+ path: "/api/document/*",}).as("documentUpdate");cy.intercept({method: "GET",- path: "/api/ee/document/*",+ path: "/api/document/*",}).as("documentGet");cy.intercept("POST", "/api/card/*/query").as("cardQuery");@@ -1019,7 +1021,6 @@ describe("documents", () => {cy.log("Trigger command menu and navigate to 'Chart' item");H.addToDocument("/", false);- cy.realPress("{downarrow}");H.commandSuggestionItem("Chart").should("have.attr","aria-selected",@@ -1226,7 +1227,7 @@ describe("documents", () => {describe("error handling", () => {it("should display an error toast when creating a new document fails", () => {// setup- cy.intercept("POST", "/api/ee/document", { statusCode: 500 });+ cy.intercept("POST", "/api/document", { statusCode: 500 });cy.visit("/document/new");// make changes and attempt to save@@ -1247,7 +1248,7 @@ describe("documents", () => {it("should display an error toast when updating a document fails", () => {// setup- cy.intercept("PUT", "/api/ee/document/*", { statusCode: 500 });+ cy.intercept("PUT", "/api/document/*", { statusCode: 500 });H.createDocument({name: "Test Document",document: { type: "doc", content: [] },diff --git a/e2e/test/scenarios/documents/public-documents.cy.spec.ts b/e2e/test/scenarios/documents/public-documents.cy.spec.tsindex c71472859a0..1e084a238cf 100644--- a/e2e/test/scenarios/documents/public-documents.cy.spec.ts+++ b/e2e/test/scenarios/documents/public-documents.cy.spec.ts@@ -94,7 +94,6 @@ describe("scenarios > documents > public", () => {beforeEach(() => {H.restore();cy.signInAsAdmin();- H.activateToken("bleeding-edge");H.updateSetting("enable-public-sharing", true);});@@ -226,6 +225,36 @@ describe("scenarios > documents > public", () => {verifyDocumentIsReadOnly();});+ it("should display metabot blocks in a read-only state", () => {+ const text = "Some metabot prompt";+ H.createDocument({+ name: "Document with metabot block",+ document: {+ content: [+ {+ type: "metabot",+ content: [{ type: "text", text }],+ },+ ],+ type: "doc",+ },+ collection_id: null,+ idAlias: "documentId",+ });+ visitPublicDocument();++ cy.log("Click the metabot block and enter text");+ H.documentContent().findByText(text).click();+ cy.realType("a");++ cy.log("Verify the text wasn't updated");+ H.documentContent().findByText(text).should("exist");++ cy.log("Verify that run/close buttons don't exist but a metabot icon does");+ H.documentContent().find("button").should("not.exist");+ H.documentContent().icon("metabot").should("exist");+ });+it("should allow downloading results from embedded cards", () => {// Create a document with an embedded cardcreateTestDocumentWithCard("Download Test Document");@@ -342,4 +371,43 @@ describe("scenarios > documents > public", () => {verifyErrorMessage("Not found");});});++ it("should display 'Powered by Metabase' link in footer", () => {+ // Create a document+ createTestDocument(+ "Test Document with Footer",+ "Testing footer branding link",+ );++ cy.log("Create public link and visit public document");+ visitPublicDocument("@documentId", { signOut: true });++ cy.log("Verify document content is visible");+ H.documentContent().should("contain", "Testing footer branding link");++ cy.log("Verify 'Powered by Metabase' link exists in footer");+ cy.findByRole("link", { name: "Powered by Metabase" })+ .should("exist")+ .should("be.visible")+ .should("have.attr", "href")+ .and("contain", "https://www.metabase.com/powered-by-metabase");+ });++ it("should not display footer for premium", () => {+ H.activateToken("bleeding-edge");++ // Create a document+ createTestDocument(+ "Test Document with Footer",+ "Testing footer branding link",+ );++ cy.log("Create public link and visit public document");+ visitPublicDocument("@documentId", { signOut: true });++ cy.log("Verify document content is visible");+ H.documentContent().should("contain", "Testing footer branding link");++ cy.findByTestId("embed-frame-footer").should("not.exist");+ });});diff --git a/e2e/test/scenarios/documents/supporting-text.cy.spec.ts b/e2e/test/scenarios/documents/supporting-text.cy.spec.tsindex be14b242615..5ffa853f048 100644--- a/e2e/test/scenarios/documents/supporting-text.cy.spec.ts+++ b/e2e/test/scenarios/documents/supporting-text.cy.spec.ts@@ -10,7 +10,6 @@ describe("documents supporting text", () => {beforeEach(() => {H.restore();cy.signInAsAdmin();- H.activateToken("bleeding-edge");});it("should add supporting text to a standalone cardEmbed", () => {@@ -291,7 +290,7 @@ describe("documents supporting text", () => {it("should allow resizing supporting text and persist width after save", () => {cy.intercept({method: "GET",- path: "/api/ee/document/*",+ path: "/api/document/*",}).as("documentGet");H.createDocument({diff --git a/e2e/test/scenarios/embedding/interactive-embedding.cy.spec.js b/e2e/test/scenarios/embedding/interactive-embedding.cy.spec.jsindex 699da39a7ec..7bd5f7acc71 100644--- a/e2e/test/scenarios/embedding/interactive-embedding.cy.spec.js+++ b/e2e/test/scenarios/embedding/interactive-embedding.cy.spec.js@@ -1839,12 +1839,12 @@ describe("scenarios > embedding > full app", () => {cy.intercept({method: "GET",- path: "/api/ee/document/*",+ path: "/api/document/*",}).as("documentGet");cy.intercept({method: "GET",- path: "/api/ee/comment/*",+ path: "/api/comment/*",}).as("commentGet");H.visitFullAppEmbeddingUrl({diff --git a/e2e/test/scenarios/onboarding/command-palette.cy.spec.js b/e2e/test/scenarios/onboarding/command-palette.cy.spec.jsindex a887d0c0ab2..b6f048dc5f9 100644--- a/e2e/test/scenarios/onboarding/command-palette.cy.spec.js+++ b/e2e/test/scenarios/onboarding/command-palette.cy.spec.js@@ -167,7 +167,7 @@ describe("command palette", () => {cy.wait(100); // pressing page down too fast does nothingH.pressPageDown();H.commandPalette()- .findByRole("option", { name: "New metric" })+ .findByRole("option", { name: "New model" }).should("have.attr", "aria-selected", "true");H.pressPageDown();@@ -177,7 +177,7 @@ describe("command palette", () => {H.pressPageUp();H.commandPalette()- .findByRole("option", { name: "New metric" })+ .findByRole("option", { name: "New model" }).should("have.attr", "aria-selected", "true");H.pressPageUp();@@ -225,12 +225,10 @@ describe("command palette", () => {// Enables a bunch of other stuff and messes up the "Renders a searchable command palette"// test. In the future, this can be integrated into the test above, or moved to a BE testit("should display collection names for documents in recents", () => {- H.activateToken("bleeding-edge");-//Create a document so that it appears in the recents listcy.request("POST",- "/api/ee/document",+ "/api/document",createMockDocument({ collection_id: ADMIN_PERSONAL_COLLECTION_ID }),);diff --git a/enterprise/backend/src/metabase_enterprise/api_routes/routes.clj b/enterprise/backend/src/metabase_enterprise/api_routes/routes.cljindex c0a8b676a79..1f888d33cd8 100644--- a/enterprise/backend/src/metabase_enterprise/api_routes/routes.clj+++ b/enterprise/backend/src/metabase_enterprise/api_routes/routes.clj@@ -15,14 +15,12 @@[metabase-enterprise.audit-app.api.routes][metabase-enterprise.billing.api.routes][metabase-enterprise.cloud-add-ons.api]- [metabase-enterprise.comments.api][metabase-enterprise.content-translation.routes][metabase-enterprise.content-verification.api.routes][metabase-enterprise.data-studio.api][metabase-enterprise.database-replication.api :as database-replication.api][metabase-enterprise.database-routing.api][metabase-enterprise.dependencies.api]- [metabase-enterprise.documents.api][metabase-enterprise.email.api][metabase-enterprise.embedding-hub.api][metabase-enterprise.gsheets.api :as gsheets.api]@@ -31,7 +29,6 @@[metabase-enterprise.metabot-v3.api][metabase-enterprise.metabot-v3.tools.api][metabase-enterprise.permission-debug.api]- [metabase-enterprise.public-sharing.api][metabase-enterprise.remote-sync.api][metabase-enterprise.sandbox.api.routes][metabase-enterprise.scim.routes]@@ -43,7 +40,6 @@[metabase-enterprise.transforms.api][metabase-enterprise.upload-management.api][metabase.api.macros :as api.macros]- [metabase.api.routes.common :as api.routes.common][metabase.api.util.handlers :as handlers][metabase.util.i18n :refer [deferred-tru]]))@@ -61,7 +57,6 @@:content-translation (deferred-tru "Content translation"):data-studio (deferred-tru "Data Studio"):dependencies (deferred-tru "Dependency Tracking")- :documents (deferred-tru "Documents"):embedding (deferred-tru "Embedding"):remote-sync (deferred-tru "Remote Sync"):etl-connections (deferred-tru "ETL Connections")@@ -109,7 +104,6 @@"/billing" metabase-enterprise.billing.api.routes/routes"/content-translation" (premium-handler metabase-enterprise.content-translation.routes/routes :content-translation)"/cloud-add-ons" metabase-enterprise.cloud-add-ons.api/routes- "/comment" (premium-handler metabase-enterprise.comments.api/routes :documents)"/data-studio" (premium-handler metabase-enterprise.data-studio.api/routes :data-studio)"/database-replication" (-> database-replication.api/routes ;; database-replication requires all these features.(premium-handler :attached-dwh)@@ -117,7 +111,6 @@(premium-handler :etl-connections-pg))"/database-routing" (premium-handler metabase-enterprise.database-routing.api/routes :database-routing)"/dependencies" (premium-handler metabase-enterprise.dependencies.api/routes :dependencies)- "/document" (premium-handler metabase-enterprise.documents.api/routes :documents)"/email" (premium-handler metabase-enterprise.email.api/routes :cloud-custom-smtp)"/remote-sync" (premium-handler metabase-enterprise.remote-sync.api/routes :remote-sync)"/embedding-hub" (premium-handler metabase-enterprise.embedding-hub.api/routes :embedding)@@ -129,7 +122,6 @@"/metabot-tools" metabase-enterprise.metabot-v3.tools.api/routes"/metabot-v3" (premium-handler metabase-enterprise.metabot-v3.api/routes :metabot-v3)"/permission_debug" (premium-handler metabase-enterprise.permission-debug.api/routes :advanced-permissions)- "/public" (api.routes.common/+public-exceptions metabase-enterprise.public-sharing.api/routes)"/transforms-python" (premium-handler metabase-enterprise.transforms-python.api/routes :transforms-python)"/scim" (premium-handler metabase-enterprise.scim.routes/routes :scim)"/semantic-search" (premium-handler metabase-enterprise.semantic-search.api/routes :semantic-search)diff --git a/enterprise/backend/src/metabase_enterprise/bookmarks/models/bookmark.clj b/enterprise/backend/src/metabase_enterprise/bookmarks/models/bookmark.cljdeleted file mode 100644index e8e3994d711..00000000000--- a/enterprise/backend/src/metabase_enterprise/bookmarks/models/bookmark.clj+++ /dev/null@@ -1,10 +0,0 @@-(ns metabase-enterprise.bookmarks.models.bookmark- "Enterprise DocumentBookmark model. Provides bookmarking functionality for documents."- (:require- [methodical.core :as methodical]- [toucan2.core :as t2]))--(methodical/defmethod t2/table-name :model/DocumentBookmark [_model] :document_bookmark)--(doto :model/DocumentBookmark- (derive :metabase/model))diff --git a/enterprise/backend/src/metabase_enterprise/comments/core.clj b/enterprise/backend/src/metabase_enterprise/comments/core.cljdeleted file mode 100644index a9e26b9d627..00000000000--- a/enterprise/backend/src/metabase_enterprise/comments/core.clj+++ /dev/null@@ -1,8 +0,0 @@-(ns metabase-enterprise.comments.core- (:require- [metabase-enterprise.comments.api :as api.comments]- [potemkin :as p]))--(p/import-vars- [api.comments- notify-comment-id!])diff --git a/enterprise/backend/src/metabase_enterprise/comments/init.clj b/enterprise/backend/src/metabase_enterprise/comments/init.cljdeleted file mode 100644index 004dc3bd04c..00000000000--- a/enterprise/backend/src/metabase_enterprise/comments/init.clj+++ /dev/null@@ -1,4 +0,0 @@-(ns metabase-enterprise.comments.init- (:require- [metabase-enterprise.comments.models.comment]- [metabase-enterprise.comments.models.comment-reaction]))diff --git a/enterprise/backend/src/metabase_enterprise/core/init.clj b/enterprise/backend/src/metabase_enterprise/core/init.cljindex 394902e55ec..7fd6a17bec4 100644--- a/enterprise/backend/src/metabase_enterprise/core/init.clj+++ b/enterprise/backend/src/metabase_enterprise/core/init.clj@@ -10,10 +10,8 @@[metabase-enterprise.advanced-config.init][metabase-enterprise.audit-app.init][metabase-enterprise.cache.init]- [metabase-enterprise.comments.init][metabase-enterprise.database-replication.init][metabase-enterprise.dependencies.init]- [metabase-enterprise.documents.init][metabase-enterprise.gsheets.init][metabase-enterprise.llm.init][metabase-enterprise.metabot-v3.init]diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/calculation.clj b/enterprise/backend/src/metabase_enterprise/dependencies/calculation.cljindex 8f4f4594dfe..61dc5f1bf7c 100644--- a/enterprise/backend/src/metabase_enterprise/dependencies/calculation.clj+++ b/enterprise/backend/src/metabase_enterprise/dependencies/calculation.clj@@ -2,7 +2,7 @@(:require[metabase-enterprise.dependencies.native-validation :as deps.native][metabase-enterprise.dependencies.schema :as deps.schema]- [metabase-enterprise.documents.prose-mirror :as prose-mirror]+ [metabase.documents.prose-mirror :as prose-mirror][metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata][metabase.lib.schema :as lib.schema]diff --git a/enterprise/backend/src/metabase_enterprise/documents/api.clj b/enterprise/backend/src/metabase_enterprise/documents/api.cljdeleted file mode 100644index aa5e46b3d78..00000000000--- a/enterprise/backend/src/metabase_enterprise/documents/api.clj+++ /dev/null@@ -1,10 +0,0 @@-(ns metabase-enterprise.documents.api- "`/api/ee/document/` routes"- (:require- [metabase-enterprise.documents.api.document]- [metabase.api.util.handlers :as handlers]))--(def ^{:arglists '([request respond raise])} routes- "`/api/ee/document/` routes."- (handlers/routes- metabase-enterprise.documents.api.document/routes))diff --git a/enterprise/backend/src/metabase_enterprise/documents/core.clj b/enterprise/backend/src/metabase_enterprise/documents/core.cljdeleted file mode 100644index a8a252a41ce..00000000000--- a/enterprise/backend/src/metabase_enterprise/documents/core.clj+++ /dev/null@@ -1,15 +0,0 @@-(ns metabase-enterprise.documents.core- (:require- [metabase-enterprise.documents.api.document]- [metabase-enterprise.documents.recent-views]- [potemkin :as p]))--(comment- metabase-enterprise.documents.api.document/keep-me- metabase-enterprise.documents.recent-views/keep-me)--(p/import-vars- [metabase-enterprise.documents.api.document- get-document]- [metabase-enterprise.documents.recent-views- select-documents-for-recents])diff --git a/enterprise/backend/src/metabase_enterprise/documents/init.clj b/enterprise/backend/src/metabase_enterprise/documents/init.cljdeleted file mode 100644index 5dad6cb10c3..00000000000--- a/enterprise/backend/src/metabase_enterprise/documents/init.clj+++ /dev/null@@ -1,5 +0,0 @@-(ns metabase-enterprise.documents.init- (:require- [metabase-enterprise.documents.recent-views]- [metabase-enterprise.documents.revisions.impl]- [metabase-enterprise.documents.view-log]))diff --git a/enterprise/backend/src/metabase_enterprise/metabot_v3/dummy_tools.clj b/enterprise/backend/src/metabase_enterprise/metabot_v3/dummy_tools.cljindex f3350118939..1f8b3605f03 100644--- a/enterprise/backend/src/metabase_enterprise/metabot_v3/dummy_tools.clj+++ b/enterprise/backend/src/metabase_enterprise/metabot_v3/dummy_tools.clj@@ -1,9 +1,9 @@(ns metabase-enterprise.metabot-v3.dummy-tools(:require[medley.core :as m]- [metabase-enterprise.documents.core :as documents][metabase-enterprise.metabot-v3.tools.util :as metabot-v3.tools.u][metabase.api.common :as api]+ [metabase.documents.core :as documents][metabase.lib-be.core :as lib-be][metabase.lib.core :as lib][metabase.lib.metadata :as lib.metadata]diff --git a/enterprise/backend/src/metabase_enterprise/public_sharing/api.clj b/enterprise/backend/src/metabase_enterprise/public_sharing/api.cljdeleted file mode 100644index 3a32d1e9e4b..00000000000--- a/enterprise/backend/src/metabase_enterprise/public_sharing/api.clj+++ /dev/null@@ -1,137 +0,0 @@-(ns metabase-enterprise.public-sharing.api- "`/api/ee/public/*` routes for Enterprise Edition entities (Documents, etc.).-- These routes handle public sharing of EE-only features. They require premium features but do not require- authentication, allowing public access to shared documents."- (:require- [metabase.api.common :as api]- [metabase.api.macros :as api.macros]- [metabase.events.core :as events]- [metabase.premium-features.core :as premium-features]- [metabase.public-sharing-rest.api :as public-sharing.api]- [metabase.public-sharing.validation :as public-sharing.validation]- [metabase.query-processor.middleware.constraints :as qp.constraints]- [metabase.query-processor.schema :as qp.schema]- [metabase.util :as u]- [metabase.util.i18n :refer [tru]]- [metabase.util.json :as json]- [metabase.util.malli.schema :as ms]- [toucan2.core :as t2]))--(set! *warn-on-reflection* true)--;;; ----------------------------------------------- Public Documents ---------------------------------------------------(defn- remove-document-non-public-columns- "Remove sensitive fields from a document before exposing it publicly.-- We filter out collection_id, creator_id, public_uuid, and other sensitive fields to prevent unauthenticated users- from discovering internal organizational structure, permissions boundaries, or who created the document. Only the- document content itself, basic metadata, and embedded cards are safe to expose publicly."- [document]- (select-keys document [:id :name :document :created_at :updated_at :cards]))--(defn- public-document- "Fetch a public document with all embedded cards hydrated upfront.-- We hydrate cards eagerly (rather than requiring separate requests per card) to avoid N+1 queries and provide a- consistent experience with public dashboards. This also allows us to filter sensitive fields from all cards at- once before exposing them to unauthenticated users. The document and all cards must not be archived to be- accessible publicly."- [& conditions]- (let [document (-> (api/check-404 (apply t2/select-one [:model/Document :id :name :document :content_type :created_at :updated_at]- :archived false, conditions))- ;; Hydrate cards via Toucan batched hydration to avoid N+1 queries- (t2/hydrate :cards))]- (-> document- ;; Filter sensitive fields from all cards before exposing publicly- (update :cards #(update-vals % public-sharing.api/remove-card-non-public-columns))- (dissoc :content_type)- remove-document-non-public-columns)))--(defn- validate-card-in-public-document- "Ensure a card is actually embedded in the specified public document before running queries.-- We validate the document-card association to prevent users from querying arbitrary cards by guessing IDs. Only- cards explicitly embedded in the public document (via document_id FK) are accessible through public document- endpoints. This prevents bypassing collection permissions by accessing cards through public document routes."- [uuid card-id]- (let [document-id (api/check-404 (t2/select-one-pk :model/Document :public_uuid uuid :archived false))]- (api/check-404 (t2/select-one-pk :model/Card :id card-id :document_id document-id :archived false))))--;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to-;; use our API + we will need it when we make auto-TypeScript-signature generation happen-;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}-(api.macros/defendpoint :get "/document/:uuid"- "Fetch a publicly-accessible Document. Does not require auth credentials. Public sharing must be enabled.-- Returns a Document with sensitive fields removed (excludes collection_id, permissions, creator details, etc.).- Includes all embedded Cards with their metadata hydrated so the frontend doesn't need to make separate- requests for each card — just like public Dashboards do."- [{:keys [uuid]} :- [:map- [:uuid ms/UUIDString]]]- (premium-features/assert-has-feature :documents (tru "Documents"))- (public-sharing.validation/check-public-sharing-enabled)- (let [document (public-document :public_uuid uuid)]- (events/publish-event! :event/document-read {:object-id (:id document), :user-id api/*current-user-id*})- document))--;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to-;; use our API + we will need it when we make auto-TypeScript-signature generation happen-;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}-(api.macros/defendpoint :get "/document/:uuid/card/:card-id"- "Run a query for a Card that's embedded in a public Document. Doesn't require auth credentials. Public sharing must- be enabled."- [{:keys [uuid card-id]} :- [:map- [:uuid ms/UUIDString]- [:card-id ms/PositiveInt]]- {:keys [parameters]} :- [:map- [:parameters {:optional true} [:maybe ms/JSONString]]]]- (premium-features/assert-has-feature :documents (tru "Documents"))- (public-sharing.validation/check-public-sharing-enabled)- (validate-card-in-public-document uuid card-id)- ;; Run the query as admin since public documents are available to everyone anyway- (u/prog1 (public-sharing.api/process-query-for-card-with-id- card-id- :api- (json/decode+kw parameters)- :constraints (qp.constraints/default-query-constraints))- (events/publish-event! :event/card-read {:object-id card-id :user-id api/*current-user-id* :context :question})))--;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to-;; use our API + we will need it when we make auto-TypeScript-signature generation happen-;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}-(api.macros/defendpoint :post "/document/:uuid/card/:card-id/:export-format"- "Fetch a Card embedded in a public Document and return query results in the specified format.- Does not require auth credentials. Public sharing must be enabled."- [{:keys [uuid card-id export-format]} :- [:map- [:uuid ms/UUIDString]- [:card-id ms/PositiveInt]- [:export-format ::qp.schema/export-format]]- _query-params- {:keys [parameters format_rows pivot_results]} :- [:map- [:parameters {:optional true} [:maybe [:or- [:sequential ms/Map]- ms/JSONString]]]- [:format_rows {:default false} ms/BooleanValue]- [:pivot_results {:default false} ms/BooleanValue]]]- (premium-features/assert-has-feature :documents (tru "Documents"))- (public-sharing.validation/check-public-sharing-enabled)- (validate-card-in-public-document uuid card-id)- (public-sharing.api/process-query-for-card-with-id- card-id- export-format- (cond-> parameters- (string? parameters) json/decode+kw)- :constraints nil- :middleware {:process-viz-settings? true- :js-int-to-string? false- :format-rows? format_rows- :pivot? pivot_results}))--(def ^{:arglists '([request respond raise])} routes- "`/api/ee/public/*` routes for Enterprise Edition entities."- (api.macros/ns-handler *ns*))diff --git a/enterprise/backend/test/metabase_enterprise/api/session_test.clj b/enterprise/backend/test/metabase_enterprise/api/session_test.cljindex f68ccf39653..cec332f9732 100644--- a/enterprise/backend/test/metabase_enterprise/api/session_test.clj+++ b/enterprise/backend/test/metabase_enterprise/api/session_test.clj@@ -21,7 +21,6 @@:database-auth-providers:data-studio:development-mode- :documents:email-allow-list:email-restrict-recipients:embedding@@ -71,7 +70,6 @@:database_auth_providers true:data_studio true:development_mode true- :documents true:email_allow_list true:email_restrict_recipients true:embedding truediff --git a/enterprise/backend/test/metabase_enterprise/bookmarks/api_test.clj b/enterprise/backend/test/metabase_enterprise/bookmarks/api_test.cljdeleted file mode 100644index 8e6b55f1c59..00000000000--- a/enterprise/backend/test/metabase_enterprise/bookmarks/api_test.clj+++ /dev/null@@ -1,79 +0,0 @@-(ns metabase-enterprise.bookmarks.api-test- (:require- [clojure.test :refer :all]- [metabase.models.interface :as mi]- [metabase.test :as mt]- [metabase.util :as u]- [toucan2.core :as t2]))--(defn bookmark-models [user-id & models]- (doseq [model models]- (cond- (mi/instance-of? :model/Card model)- (t2/insert! :model/CardBookmark- {:user_id user-id- :card_id (u/the-id model)})-- (mi/instance-of? :model/Document model)- (t2/insert! :model/DocumentBookmark- {:user_id user-id- :document_id (u/the-id model)})-- :else- (throw (ex-info "Unknown type" {:user-id user-id :model model})))))--(deftest document-bookmarks-test- (testing "Document bookmarks with enterprise features"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Collection {coll-id :id} {:name "Test Collection"}- :model/Document document {:name "Test Document" :collection_id coll-id}]- (testing "can bookmark a document when enterprise enabled"- (is (= (u/the-id document)- (->> (mt/user-http-request :rasta :post 200 (str "bookmark/document/" (u/the-id document)))- :document_id))))-- (testing "document appears in bookmark list"- (let [result (mt/user-http-request :rasta :get 200 "bookmark")- document-bookmark (first (filter #(= (:type %) "document") result))]- (is (some? document-bookmark))- (is (= "Test Document" (:name document-bookmark)))- (is (= (u/the-id document) (:item_id document-bookmark)))))-- (testing "can delete document bookmark"- (mt/user-http-request :rasta :delete 204 (str "bookmark/document/" (u/the-id document)))- (is (empty? (filter #(= (:type %) "document")- (mt/user-http-request :rasta :get 200 "bookmark")))))-- (testing "document bookmarks are included in ordering"- (mt/with-temp [:model/Card card {:name "Test Card"}]- (mt/with-model-cleanup [:model/BookmarkOrdering]- (bookmark-models (mt/user->id :rasta) document card)- (mt/user-http-request :rasta :put 204 "bookmark/ordering"- {:orderings [{:type "document" :item_id (u/the-id document)}- {:type "card" :item_id (u/the-id card)}]})- (is (= ["document" "card"]- (map :type (mt/user-http-request :rasta :get 200 "bookmark"))))))))))-- (testing "Document bookmarks without enterprise features"- (mt/with-premium-features #{}- (mt/with-temp [:model/Collection {coll-id :id} {:name "Test Collection"}- :model/Document document {:name "Test Document" :collection_id coll-id}]- (testing "cannot bookmark documents when enterprise disabled"- (mt/user-http-request :rasta :post 402 (str "bookmark/document/" (u/the-id document))))-- (testing "document model not included in allowed models"- (let [response (mt/user-http-request :rasta :post 402 (str "bookmark/document/" (u/the-id document)))]- (is (=? {:message #"Documents is a paid feature.*"}- response))))))))--(deftest document-bookmarks-archived-test- (testing "Document bookmarks on archived documents"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Collection {coll-id :id} {:name "Test Collection"}- :model/Document archived-document {:name "Archived Document"- :collection_id coll-id- :archived true}]- (bookmark-models (mt/user->id :rasta) archived-document)- (testing "archived documents don't appear in bookmark list"- (is (empty? (filter #(= (:type %) "document")- (mt/user-http-request :rasta :get 200 "bookmark")))))))))diff --git a/enterprise/backend/test/metabase_enterprise/comments/api_test.clj b/enterprise/backend/test/metabase_enterprise/comments/api_test.cljdeleted file mode 100644index 0c516ca3347..00000000000--- a/enterprise/backend/test/metabase_enterprise/comments/api_test.clj+++ /dev/null@@ -1,336 +0,0 @@-(ns metabase-enterprise.comments.api-test- "Tests for /api/ee/comment/ endpoints."- (:require- [clojure.set :as set]- [clojure.string :as str]- [clojure.test :refer :all]- [metabase-enterprise.test :as met]- [metabase.analytics.sdk :as sdk]- [metabase.notification.seed :as notification.seed]- [metabase.test :as mt]- [metabase.util :as u]- [toucan2.core :as t2]))--(use-fixtures :each (fn [f] (mt/with-premium-features #{:documents} (f))))--(defn- relaxed-re [& s]- (re-pattern (str "(?s).*" (str/join ".*" s) ".*")))--;;; tiptap helpers--(defn- render-tiptap [node]- (if (string? node)- {:type "text" :text node}- (let [tag (case (first node)- :p "paragraph"- (name (first node)))- block? #{"paragraph"}- attrs (when (map? (second node)) (second node))- content (if attrs (drop 2 node) (drop 1 node))]- (u/remove-nils- {:type tag- :attrs (cond-> attrs- (block? tag) (assoc :_id (str (random-uuid)))- true not-empty)- :content (when (seq content)- (mapv render-tiptap content))}))))--(defn tiptap- "Little helpers to generate tiptap docs"- [& content]- {:type "doc"- :content (mapv render-tiptap content)})--(deftest tiptap-helpers-test- (testing "can generate some content but less verbose"- (is (=? {:type "doc"- :content- [{:type "paragraph"- :attrs {:_id string?},- :content- [{:type "text" :text "omg is that you? "}- {:type "smartLink"- :attrs {:entityId 6 :model "user"}}]}]}- (tiptap [:p- "omg is that you? "- [:smartLink {:entityId 6 :model "user"}]])))))--(deftest comments-require-documents-feature- (testing "GET /api/ee/comment/"- (mt/with-premium-features #{}- (mt/with-temp [:model/Document {doc-id :id} {}]- (testing "should not return the comments"- (mt/user-http-request :crowberto :get 402 "ee/comment/"- :target_type "document"- :target_id doc-id))))))--(deftest basic-comments-test- (testing "GET /api/ee/comment/"- (mt/with-temp [:model/Document {doc-id :id doc :document} {:name "New Document"- :creator_id (mt/user->id :lucky)}]- (mt/with-model-cleanup [:model/CommentReaction- :model/Comment- :model/Notification]- (mt/with-fake-inbox- (notification.seed/seed-notification!)- (is (set/subset? #{:event/comment-created}- (t2/select-fn-set :event_name :model/NotificationSubscription)))- (testing "returns empty comments list for entity with no comments"- (is (= {:comments []}- (mt/user-http-request :rasta :get 200 "ee/comment/"- :target_type "document"- :target_id doc-id))))- (testing "creates and returns comments for entity"- (let [content (tiptap [:p "New comment"])- created (mt/user-http-request :rasta :post 200 "ee/comment/"- {:target_type "document"- :target_id doc-id- :content content- :html "<p>New comment</p>"})- expected1 {:id int?- :content content- :target_type "document"- :target_id doc-id- :creator {:id (mt/user->id :rasta)}- :reactions []}]- (is (=? expected1 created))- (is (=? {:comments [expected1]}- (mt/user-http-request :rasta :get 200 "ee/comment/"- :target_type "document"- :target_id doc-id)))- (testing "document creator receives notifications for top-level comments"- (is (=? {(:email (mt/fetch-user :lucky))- [{:subject "Comment on New Document"- :body [{:content (relaxed-re- (str (:common_name (mt/fetch-user :rasta)) " left a comment")- (format "http://localhost:\\d+/document/%s#comment-%s"- doc-id- (:id created)))}]}]}- (first (swap-vals! mt/inbox empty)))))-- (testing "creates a reply to an existing comment"- (let [content2 (tiptap [:p "Other comment"])- child (mt/user-http-request :crowberto :post 200 "ee/comment/"- {:target_type "document"- :target_id doc-id- :parent_comment_id (:id created)- :content content2- :html "<p>Other comment</p>"})- expected2 {:id int?- :content content2- :target_type "document"- :target_id doc-id- :creator {:id (mt/user->id :crowberto)}- :parent_comment_id (:id created)- :reactions []}]- (is (=? expected2 child))- (is (=? {:comments [expected1 expected2]}- (mt/user-http-request :rasta :get 200 "ee/comment/"- :target_type "document"- :target_id doc-id)))- (testing "participants in the thread receive notifications for new replies"- (is (=? {(:email (mt/fetch-user :rasta))- [{:subject "Comment on New Document"- :body [{:content (relaxed-re- (str (:common_name (mt/fetch-user :crowberto)) " replied to a thread"))}]}]}- (first (swap-vals! mt/inbox empty)))))))-- (testing "comment in a thread should send emails to all participants of the thread"- (let [_another (mt/user-http-request :lucky :post 200 "ee/comment/"- {:target_type "document"- :target_id doc-id- :parent_comment_id (:id created)- :content (tiptap [:p "Third comment in a thread"])- :html "<p>Third comment in a thread</p>"})]- (is (=? {(:email (mt/fetch-user :rasta))- [{:subject "Comment on New Document"- :body [{:content (relaxed-re- (str (:common_name (mt/fetch-user :lucky)) " replied to a thread"))}]}]- (:email (mt/fetch-user :crowberto))- [{:subject "Comment on New Document"- :body [{:content (relaxed-re- (str (:common_name (mt/fetch-user :lucky)) " replied to a thread"))}]}]}- (first (swap-vals! mt/inbox empty))))))))-- (testing "creates a comment for part of an entity"- (let [part-id (-> doc :content first :attrs :_id)- created (mt/user-http-request :rasta :post 200 "ee/comment/"- {:target_type "document"- :target_id doc-id- :child_target_id part-id- :content (tiptap [:p "Part comment"])- :html "<p>Part comment</p>"})]- (is (=? {:id int?- :content {:type "doc"}- :target_type "document"- :target_id doc-id- :child_target_id part-id- :creator {:id (mt/user->id :rasta)}- :reactions []}- created))- (testing "Comments on concrete paragraphs are also sent as notifications"- (is (=? {(:email (mt/fetch-user :lucky))- [{:subject "Comment on New Document"- :body [{:content (relaxed-re (format "http://localhost:\\d+/document/%s/comments/%s#comment-%s"- doc-id- part-id- (:id created)))}]}]}- (first (swap-vals! mt/inbox empty)))))))-- (testing "Comments with mentions send notification emails"- (let [_created (mt/user-http-request :rasta :post 200 "ee/comment/"- {:target_type "document"- :target_id doc-id- :content (tiptap- [:smartLink {:model "user"- :entityId (mt/user->id :crowberto)}])- :html "<p>Mention of @crowberto :)</p>"})]- (is (=? {(:email (mt/fetch-user :lucky)) [{:subject "Comment on New Document"}]- (:email (mt/fetch-user :crowberto)) [{:subject "Comment on New Document"}]}- (first (swap-vals! mt/inbox empty)))))))))))--(deftest update-comment-test- (testing "PUT /api/ee/comment/:comment-id"- (mt/with-temp [:model/Document {doc-id :id} {}- :model/Comment {comment-id :id} {:target_id doc-id}]- (testing "updates comment content"- (is (=? {:content {:text "Updated content"}}- (mt/user-http-request :rasta :put 200 (str "ee/comment/" comment-id)- {:content {"text" "Updated content"}}))))-- (testing "updates comment resolution status"- (is (=? {:is_resolved true}- (mt/user-http-request :rasta :put 200 (str "ee/comment/" comment-id)- {:is_resolved true})))))))--(deftest delete-comment-test- (testing "DELETE /api/ee/comment/:comment-id"- (mt/with-temp [:model/Document {doc-id :id} {}- :model/Comment {c1 :id} {:target_id doc-id}- :model/Comment {c2 :id} {:target_id doc-id}- :model/Comment {c3 :id} {:target_id doc-id- :parent_comment_id c2}]- (testing "soft deletes a comment"- (is (= nil- (mt/user-http-request :rasta :delete 204 (str "ee/comment/" c1))))- (testing "comment is marked as deleted in database"- (let [comment (t2/select-one :model/Comment :id c1)]- (is (some? (:deleted_at comment)))))- (testing "deleting a comment twice leaves sour taste in the mouth"- ;; NOTE: maybe it's fine and we should just noop here rather than return an error?- (is (= "Comment is already deleted"- (mt/user-http-request :rasta :delete 400 (str "ee/comment/" c1))))))-- (testing "deleting parent comment still leaves it in a response"- (is (= nil- (mt/user-http-request :rasta :delete 204 (str "ee/comment/" c2))))- (is (=? {:comments [{:id c2- :deleted_at some?}- {:id c3- :deleted_at nil}]}- (mt/user-http-request :rasta :get 200 "ee/comment/"- :target_type "document"- :target_id doc-id)))))))--(deftest toggle-reaction-test- (testing "POST /api/ee/comment/:comment-id/reaction"- (mt/with-temp [:model/Document {doc-id :id} {}- :model/Comment {comment-id :id} {:target_id doc-id}]- (testing "adds a reaction to a comment"- (is (=? {:reacted true}- (mt/user-http-request :rasta :post 200 (str "ee/comment/" comment-id "/reaction")- {:emoji "👍"})))-- (is (=? {:comments [{:id comment-id- :reactions [{:emoji "👍"- :count 1- :users [{:id (mt/user->id :rasta)}]}]}]}- (mt/user-http-request :rasta :get 200 "ee/comment/"- :target_type "document"- :target_id doc-id))))-- (testing "removes an existing reaction when toggled again"- (is (=? {:reacted false}- (mt/user-http-request :rasta :post 200 (str "ee/comment/" comment-id "/reaction")- {:emoji "👍"})))-- (is (=? {:comments [{:id comment-id- :reactions []}]}- (mt/user-http-request :rasta :get 200 "ee/comment/"- :target_type "document"- :target_id doc-id)))))))--(deftest comments-permissions-test- (testing "Comment permissions - users without document access cannot read or write comments"- (mt/with-non-admin-groups-no-root-collection-perms- (mt/with-temp [:model/Collection {restricted-col :id} {:name "Restricted Collection"}- :model/Document {restricted-doc-id :id} {:collection_id restricted-col- :name "Restricted Document"}- :model/Comment {restricted-comment-id :id} {:target_id restricted-doc-id}]-- (mt/with-model-cleanup [:model/Comment]- (testing "GET /api/ee/comment/ - users without document read permissions cannot see comments"- (is (= "You don't have permissions to do that."- (mt/user-http-request :lucky :get 403 "ee/comment/"- :target_type "document"- :target_id restricted-doc-id))))-- (testing "POST /api/ee/comment/ - users without document read permissions cannot create comments"- (is (= "You don't have permissions to do that."- (mt/user-http-request :lucky :post 403 "ee/comment/"- {:target_type "document"- :target_id restricted-doc-id- :content (tiptap "Comment by lucky")- :html "You shall not pass"}))))-- (testing "PUT /api/ee/comment/:id - users without document access cannot update comments"- (is (= "You don't have permissions to do that."- (mt/user-http-request :lucky :put 403 (str "ee/comment/" restricted-comment-id)- {:content {:text "Updated by lucky"}}))))-- (testing "DELETE /api/ee/comment/:id - users without document access cannot delete comments"- (is (= "You don't have permissions to do that."- (mt/user-http-request :lucky :delete 403 (str "ee/comment/" restricted-comment-id)))))-- (testing "POST /api/ee/comment/:id/reaction - users without document access cannot react to comments"- (is (= "You don't have permissions to do that."- (mt/user-http-request :lucky :post 403 (str "ee/comment/" restricted-comment-id "/reaction")- {:emoji "👍"})))))))))--(deftest mention-entities-test- (testing "We can get users to mention"- (is (=? {:data [{:id int? :common_name "Crowberto Corv" :model "user"}- {:id int? :common_name "Lucky Pigeon" :model "user"}- {:id int? :common_name "Rasta Toucan" :model "user"}]- :total int?- :limit 50- :offset 0}- (-> (mt/user-http-request :rasta :get 200 "ee/comment/mentions" :limit 50)- (update :data #(filter mt/test-user? %))))))- (testing "Sandboxed users don't get to see other users"- (met/with-gtaps-for-user! :rasta {:gtaps {:venues {}}}- (is (=? {:data [{:id int? :common_name "Rasta Toucan" :model "user"}]- :total 1- :limit 50- :offset 0}- (mt/user-http-request :rasta :get 200 "ee/comment/mentions" :limit 50))))))--(deftest iframe-comments-test- (testing "comments are disabled inside of an iframe"- (mt/with-temp [:model/Document {doc-id :id} {}- :model/Comment {comment-id :id} {:target_id doc-id}]- (testing "Comments are not shown if in iframe"- (is (=? {:comments [{:id comment-id}]}- (mt/user-http-request :rasta :get 200 "ee/comment/"- :target_type "document"- :target_id doc-id)))- (is (=? {:comments []- :disabled true}- (mt/user-http-request :rasta :get 200 "ee/comment/"- {:request-options {:headers {"x-metabase-client" @#'sdk/embedding-iframe-client}}}- :target_type "document"- :target_id doc-id))))- (testing "Users mentions are not available either"- (is (= "Not found."- (mt/user-http-request :rasta :get 404 "ee/comment/mentions"- {:request-options {:headers {"x-metabase-client" @#'sdk/embedding-iframe-client}}})))))))diff --git a/enterprise/backend/test/metabase_enterprise/documents/api/collection_test.clj b/enterprise/backend/test/metabase_enterprise/documents/api/collection_test.cljdeleted file mode 100644index 88bd147283b..00000000000--- a/enterprise/backend/test/metabase_enterprise/documents/api/collection_test.clj+++ /dev/null@@ -1,294 +0,0 @@-(ns metabase-enterprise.documents.api.collection-test- (:require- [clojure.test :refer :all]- [metabase.collections.models.collection :as collection]- [metabase.test :as mt]))--(deftest document-cards-do-not-appear-in-collection-items- (testing "GET /api/collection/:id/items excludes cards with document_id"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Collection {coll-id :id} {}- :model/Document {doc-id :id} {}- :model/Card {normal-card-id :id} {:collection_id coll-id}- :model/Card _ {:collection_id coll-id- :document_id doc-id}- :model/Dashboard {dash-id :id} {:collection_id coll-id}]- (testing "Normal cards and dashboards appear, but in_document cards do not"- (is (= #{[normal-card-id "card"]- [dash-id "dashboard"]}- (set (map (juxt :id :model)- (:data (mt/user-http-request :rasta :get 200- (str "collection/" coll-id "/items"))))))))- (testing "Even with show_dashboard_questions=true, in_document cards do not appear"- (is (= #{[normal-card-id "card"]- [dash-id "dashboard"]}- (set (map (juxt :id :model)- (:data (mt/user-http-request :rasta :get 200- (str "collection/" coll-id "/items?show_dashboard_questions=true"))))))))))))--(deftest document-cards-do-not-appear-in-root-items- (testing "GET /api/collection/root/items excludes cards with document_id"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Document {doc-id :id} {}- :model/Card {normal-card-id :id} {:collection_id nil- :name "Normal Root Card"}- :model/Card {in-document-card-id :id} {:collection_id nil- :document_id doc-id- :name "In Document Root Card"}- :model/Dashboard {dash-id :id} {:collection_id nil- :name "Root Dashboard"}]- (testing "Normal cards and dashboards in root appear, but in_document cards do not"- (let [items (mt/user-http-request :rasta :get 200 "collection/root/items")- root-test-items (filter #(#{normal-card-id dash-id in-document-card-id} (:id %))- (:data items))]- (is (= #{[normal-card-id "card"]- [dash-id "dashboard"]}- (set (map (juxt :id :model) root-test-items))))))- (testing "Even with show_dashboard_questions=true, in_document cards do not appear"- (let [items (mt/user-http-request :rasta :get 200 "collection/root/items?show_dashboard_questions=true")- root-test-items (filter #(#{normal-card-id dash-id in-document-card-id} (:id %))- (:data items))]- (is (= #{[normal-card-id "card"]- [dash-id "dashboard"]}- (set (map (juxt :id :model) root-test-items))))))))))--(deftest document-cards-do-not-appear-in-root-items-without-premium- (testing "GET /api/collection/root/items excludes cards with document_id when documents feature is disabled"- (mt/with-premium-features #{}- (mt/with-temp [:model/Card {normal-card-id :id} {:collection_id nil- :name "Normal Root Card"}- :model/Dashboard {dash-id :id} {:collection_id nil- :name "Root Dashboard"}]- (testing "Normal cards and dashboards in root appear, no documents"- (let [items (mt/user-http-request :rasta :get 200 "collection/root/items")- root-test-items (filter #(#{normal-card-id dash-id} (:id %))- (:data items))]- (is (= #{[normal-card-id "card"]- [dash-id "dashboard"]}- (set (map (juxt :id :model) root-test-items))))))))))--(deftest documents-appear-in-collection-items- (testing "GET /api/collection/:id/items includes documents"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Collection {coll-id :id} {}- :model/Document {doc-id :id} {:collection_id coll-id- :name "Test Document"}- :model/Card {card-id :id} {:collection_id coll-id}- :model/Dashboard {dash-id :id} {:collection_id coll-id}]- (testing "Documents appear alongside cards and dashboards"- (is (= #{[doc-id "document"]- [card-id "card"]- [dash-id "dashboard"]}- (set (map (juxt :id :model)- (:data (mt/user-http-request :rasta :get 200- (str "collection/" coll-id "/items"))))))))))))--(deftest documents-do-not-appear-in-collection-items-without-premium- (testing "GET /api/collection/:id/items excludes documents when documents feature is disabled"- (mt/with-premium-features #{}- (mt/with-temp [:model/Collection {coll-id :id} {}- :model/Card {card-id :id} {:collection_id coll-id}- :model/Document _ {:collection_id coll-id- :name "Test Document"}- :model/Dashboard {dash-id :id} {:collection_id coll-id}]- (testing "Only cards and dashboards appear, no documents"- (is (= #{[card-id "card"]- [dash-id "dashboard"]}- (set (map (juxt :id :model)- (:data (mt/user-http-request :rasta :get 200- (str "collection/" coll-id "/items"))))))))))))--(deftest documents-appear-in-root-items- (testing "GET /api/collection/root/items includes documents"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Document {doc-id :id} {:collection_id nil- :name "Root Document"}- :model/Card {card-id :id} {:collection_id nil- :name "Root Card"}- :model/Dashboard {dash-id :id} {:collection_id nil- :name "Root Dashboard"}]- (testing "Documents appear alongside cards and dashboards in root"- (let [items (mt/user-http-request :rasta :get 200 "collection/root/items")- root-test-items (filter #(#{doc-id card-id dash-id} (:id %))- (:data items))]- (is (= #{[doc-id "document"]- [card-id "card"]- [dash-id "dashboard"]}- (set (map (juxt :id :model) root-test-items))))))))))--(deftest documents-do-not-appear-in-root-items-without-premium- (testing "GET /api/collection/root/items excludes documents when documents feature is disabled"- (mt/with-premium-features #{}- (mt/with-temp [:model/Card {card-id :id} {:collection_id nil- :name "Root Card"}- :model/Document _ {:collection_id nil- :name "Test Document"}- :model/Dashboard {dash-id :id} {:collection_id nil- :name "Root Dashboard"}]- (testing "Only cards and dashboards appear in root, no documents"- (let [items (mt/user-http-request :rasta :get 200 "collection/root/items")- root-test-items (filter #(#{card-id dash-id} (:id %))- (:data items))]- (is (= #{[card-id "card"]- [dash-id "dashboard"]}- (set (map (juxt :id :model) root-test-items))))))))))--(deftest archived-documents-appear-in-trash-items- (testing "GET /api/collection/trash/items includes documents with archived_directly true"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Document {archived-doc-id :id} {:collection_id nil- :name "Archived Document"- :archived true- :archived_directly true}- :model/Document {normal-doc-id :id} {:collection_id nil- :name "Normal Document"- :archived_directly false}- :model/Card {archived-card-id :id} {:collection_id nil- :name "Archived Card"- :archived true- :archived_directly true}- :model/Dashboard {archived-dash-id :id} {:collection_id nil- :name "Archived Dashboard"- :archived true- :archived_directly true}]- (testing "Archived documents appear alongside other archived items in trash"- (let [items (mt/user-http-request :rasta :get 200 (format "collection/%d/items" (collection/trash-collection-id)))- trash-test-items (filter #(#{archived-doc-id normal-doc-id archived-card-id archived-dash-id} (:id %))- (:data items))]- (is (= #{[archived-doc-id "document" true true]- [archived-card-id "card" true true]- [archived-dash-id "dashboard" true true]}- (set (map (juxt :id :model :can_delete :can_restore) trash-test-items))))- (testing "Non-archived documents do not appear in trash"- (is (not (some #(= normal-doc-id (:id %)) trash-test-items))))))))))--(deftest archived-documents-do-not-appear-in-trash-items-without-premium- (testing "GET /api/collection/trash/items excludes documents when documents feature is disabled"- (mt/with-premium-features #{}- (mt/with-temp [:model/Document _ {:collection_id nil- :name "Archived Document"- :archived true- :archived_directly true}- :model/Card {archived-card-id :id} {:collection_id nil- :name "Archived Card"- :archived true- :archived_directly true}- :model/Dashboard {archived-dash-id :id} {:collection_id nil- :name "Archived Dashboard"- :archived true- :archived_directly true}]- (testing "Only archived cards and dashboards appear in trash, no documents"- (let [items (mt/user-http-request :rasta :get 200 (format "collection/%d/items" (collection/trash-collection-id)))- trash-test-items (:data items)]- (is (= #{[archived-card-id "card"]- [archived-dash-id "dashboard"]}- (set (map (juxt :id :model) trash-test-items))))))))))--(deftest document-pinning-collection-items- (testing "GET /api/collection/:id/items supports pinned_state parameter for documents"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Collection {coll-id :id} {}- :model/Document {pinned-doc-id :id} {:collection_id coll-id- :name "Pinned Document"- :collection_position 1}- :model/Document {unpinned-doc-id :id} {:collection_id coll-id- :name "Unpinned Document"- :collection_position nil}- :model/Card {pinned-card-id :id} {:collection_id coll-id- :name "Pinned Card"- :collection_position 2}- :model/Card {unpinned-card-id :id} {:collection_id coll-id- :name "Unpinned Card"- :collection_position nil}]- (testing "pinned_state=is_pinned returns only pinned documents and cards"- (let [items (:data (mt/user-http-request :rasta :get 200- (str "collection/" coll-id "/items?pinned_state=is_pinned")))- item-ids (set (map :id items))]- (is (contains? item-ids pinned-doc-id))- (is (contains? item-ids pinned-card-id))- (is (not (contains? item-ids unpinned-doc-id)))- (is (not (contains? item-ids unpinned-card-id)))))-- (testing "pinned_state=is_not_pinned returns only unpinned documents and cards"- (let [items (:data (mt/user-http-request :rasta :get 200- (str "collection/" coll-id "/items?pinned_state=is_not_pinned")))- item-ids (set (map :id items))]- (is (not (contains? item-ids pinned-doc-id)))- (is (not (contains? item-ids pinned-card-id)))- (is (contains? item-ids unpinned-doc-id))- (is (contains? item-ids unpinned-card-id))))-- (testing "pinned_state=all returns all documents and cards"- (let [items (:data (mt/user-http-request :rasta :get 200- (str "collection/" coll-id "/items?pinned_state=all")))- item-ids (set (map :id items))]- (is (contains? item-ids pinned-doc-id))- (is (contains? item-ids pinned-card-id))- (is (contains? item-ids unpinned-doc-id))- (is (contains? item-ids unpinned-card-id))))))))--(deftest document-pinning-root-items- (testing "GET /api/collection/root/items supports pinned_state parameter for documents"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Document {pinned-doc-id :id} {:collection_id nil- :name "Pinned Root Document"- :collection_position 1}- :model/Document {unpinned-doc-id :id} {:collection_id nil- :name "Unpinned Root Document"- :collection_position nil}- :model/Card {pinned-card-id :id} {:collection_id nil- :name "Pinned Root Card"- :collection_position 2}- :model/Card {unpinned-card-id :id} {:collection_id nil- :name "Unpinned Root Card"- :collection_position nil}]- (testing "pinned_state=is_pinned returns only pinned root documents and cards"- (let [items (:data (mt/user-http-request :rasta :get 200 "collection/root/items?pinned_state=is_pinned"))- test-item-ids (set (filter #{pinned-doc-id unpinned-doc-id pinned-card-id unpinned-card-id}- (map :id items)))]- (is (contains? test-item-ids pinned-doc-id))- (is (contains? test-item-ids pinned-card-id))- (is (not (contains? test-item-ids unpinned-doc-id)))- (is (not (contains? test-item-ids unpinned-card-id)))))-- (testing "pinned_state=is_not_pinned returns only unpinned root documents and cards"- (let [items (:data (mt/user-http-request :rasta :get 200 "collection/root/items?pinned_state=is_not_pinned"))- test-item-ids (set (filter #{pinned-doc-id unpinned-doc-id pinned-card-id unpinned-card-id}- (map :id items)))]- (is (not (contains? test-item-ids pinned-doc-id)))- (is (not (contains? test-item-ids pinned-card-id)))- (is (contains? test-item-ids unpinned-doc-id))- (is (contains? test-item-ids unpinned-card-id))))))))--(deftest mixed-pinned-unpinned-documents-collection-view- (testing "Integration test for mixed pinned/unpinned documents in collection view"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Collection {coll-id :id} {}- :model/Document {doc1-id :id} {:collection_id coll-id- :name "Document A"- :collection_position 1}- :model/Document _ {:collection_id coll-id- :name "Document B"- :collection_position nil}- :model/Document {doc3-id :id} {:collection_id coll-id- :name "Document C"- :collection_position 3}]- (testing "Default view includes all documents with collection_position field"- (let [items (:data (mt/user-http-request :rasta :get 200- (str "collection/" coll-id "/items")))- docs (filter #(= "document" (:model %)) items)- doc-positions (map :collection_position docs)]- (is (= 3 (count docs)))- ;; Verify collection_position is included in the response- (is (some #(= 1 %) doc-positions))- (is (some nil? doc-positions))- (is (some #(= 3 %) doc-positions))))-- (testing "Pinned documents have higher collection_position values and appear before unpinned"- (let [items (:data (mt/user-http-request :rasta :get 200- (str "collection/" coll-id "/items?pinned_state=is_pinned")))- pinned-docs (filter #(= "document" (:model %)) items)]- (is (= 2 (count pinned-docs)))- ;; Verify all pinned docs have non-nil collection_position- (is (every? #(some? (:collection_position %)) pinned-docs))- (is (= #{doc1-id doc3-id} (set (map :id pinned-docs))))))))))diff --git a/enterprise/backend/test/metabase_enterprise/documents/recent_views_test.clj b/enterprise/backend/test/metabase_enterprise/documents/recent_views_test.cljdeleted file mode 100644index 4acd2670a46..00000000000--- a/enterprise/backend/test/metabase_enterprise/documents/recent_views_test.clj+++ /dev/null@@ -1,204 +0,0 @@-(ns metabase-enterprise.documents.recent-views-test- (:require- [clojure.test :refer :all]- [metabase-enterprise.documents.recent-views :as recent-views]- [metabase.activity-feed.core :as activity-feed]- [metabase.events.core :as events]- [metabase.test :as mt]- [toucan2.core :as t2]))--(defn- most-recent-view- [user-id model-id model-type]- (t2/select-one [:model/RecentViews :user_id :model :model_id]- :user_id user-id- :model_id model-id- :model model-type- {:order-by [[:id :desc]]}))--(deftest card-query-test- (mt/with-test-user :rasta- (testing "document cards should not be counted"- (mt/with-temp [:model/Document {doc-id :id} {}- :model/Card card-3 {:creator_id (mt/user->id :rasta)- :document_id doc-id}]- (events/publish-event! :event/card-query {:card-id (:id card-3)- :user-id (mt/user->id :rasta)- :context :question})- (is (nil? (most-recent-view (mt/user->id :rasta) (:id card-3) "card")))))))--(deftest legacy-card-read-test- (testing "in_document cards should not be counted even with context :question"- (mt/with-temp [:model/Document {doc-id :id} {}- :model/Card card {:creator_id (mt/user->id :rasta)- :document_id doc-id}]- (mt/with-test-user :rasta- (events/publish-event! :event/card-read {:object-id (:id card)- :user-id (mt/user->id :rasta)- :context :question})- (is (nil? (most-recent-view (mt/user->id :rasta) (:id card) "card")))))))--(deftest select-documents-for-recents-empty-input-test- (mt/with-premium-features #{:documents}- (testing "returns empty vector when given empty document-ids"- (is (= [] (recent-views/select-documents-for-recents [])))- (is (= [] (recent-views/select-documents-for-recents nil))))))--(deftest select-documents-for-recents-with-collection-test- (mt/with-premium-features #{:documents}- (testing "returns documents with collection information"- (mt/with-temp [:model/Collection {coll-id :id} {:name "Test Collection"- :authority_level "official"- :archived false}- :model/Document {doc1-id :id} {:name "Document 1"- :collection_id coll-id- :archived false}- :model/Document {doc2-id :id} {:name "Document 2"- :collection_id coll-id- :archived false}]- (let [results (recent-views/select-documents-for-recents [doc1-id doc2-id])]- (is (= 2 (count results)))-- ;; Check first document- (let [doc1 (first (filter #(= (:id %) doc1-id) results))]- (is (= "Document 1" (:name doc1)))- (is (= false (:archived doc1)))- (is (= coll-id (:entity-coll-id doc1)))- (is (= coll-id (:collection_id doc1)))- (is (= "Test Collection" (:collection_name doc1)))- (is (= "official" (:collection_authority_level doc1))))-- ;; Check second document- (let [doc2 (first (filter #(= (:id %) doc2-id) results))]- (is (= "Document 2" (:name doc2)))- (is (= false (:archived doc2)))))))))--(deftest select-documents-for-recents-without-collection-test- (mt/with-premium-features #{:documents}- (testing "returns documents without collection when collection_id is nil"- (mt/with-temp [:model/Document {doc-id :id} {:name "Orphan Document"- :collection_id nil- :archived false}]- (let [results (recent-views/select-documents-for-recents [doc-id])]- (is (= 1 (count results)))- (let [doc (first results)]- (is (= "Orphan Document" (:name doc)))- (is (= false (:archived doc)))- (is (nil? (:entity-coll-id doc)))- (is (nil? (:collection_id doc)))- (is (nil? (:collection_name doc)))- (is (nil? (:collection_authority_level doc)))))))))--(deftest select-documents-for-recents-archived-collections-test- (mt/with-premium-features #{:documents}- (testing "excludes documents from archived collections via left join"- (mt/with-temp [:model/Collection {archived-coll-id :id} {:name "Archived Collection"- :authority_level "official"- :archived true}- :model/Collection {active-coll-id :id} {:name "Active Collection"- :authority_level "official"- :archived false}- :model/Document {doc1-id :id} {:name "Document in Archived Collection"- :collection_id archived-coll-id- :archived false}- :model/Document {doc2-id :id} {:name "Document in Active Collection"- :collection_id active-coll-id- :archived false}]- (let [results (recent-views/select-documents-for-recents [doc1-id doc2-id])]- (is (= 2 (count results)))-- ;; Document from archived collection should have nil collection info- (let [doc1 (first (filter #(= (:id %) doc1-id) results))]- (is (= "Document in Archived Collection" (:name doc1)))- (is (= archived-coll-id (:entity-coll-id doc1)))- (is (nil? (:collection_id doc1)))- (is (nil? (:collection_name doc1)))- (is (nil? (:collection_authority_level doc1))))-- ;; Document from active collection should have collection info- (let [doc2 (first (filter #(= (:id %) doc2-id) results))]- (is (= "Document in Active Collection" (:name doc2)))- (is (= active-coll-id (:entity-coll-id doc2)))- (is (= active-coll-id (:collection_id doc2)))- (is (= "Active Collection" (:collection_name doc2)))- (is (= "official" (:collection_authority_level doc2)))))))))--(deftest select-documents-for-recents-archived-documents-test- (mt/with-premium-features #{:documents}- (testing "includes archived documents in results"- (mt/with-temp [:model/Collection {coll-id :id} {:name "Test Collection"- :archived false}- :model/Document {doc-id :id} {:name "Archived Document"- :collection_id coll-id- :archived true}]- (let [results (recent-views/select-documents-for-recents [doc-id])]- (is (= 1 (count results)))- (let [doc (first results)]- (is (= "Archived Document" (:name doc)))- (is (true? (:archived doc)))))))))--(deftest select-documents-for-recents-nonexistent-ids-test- (mt/with-premium-features #{:documents}- (testing "handles non-existent document IDs gracefully"- (let [results (recent-views/select-documents-for-recents [999999 888888])]- (is (= [] results))))))--(deftest select-documents-for-recents-mixed-ids-test- (mt/with-premium-features #{:documents}- (testing "handles mixed existing and non-existing document IDs"- (mt/with-temp [:model/Document {doc-id :id} {:name "Existing Document"- :archived false}]- (let [results (recent-views/select-documents-for-recents [doc-id 999999])]- (is (= 1 (count results)))- (is (= "Existing Document" (:name (first results)))))))))--(deftest select-documents-for-recents-duplicates-test- (mt/with-premium-features #{:documents}- (testing "preserves order and handles duplicates in document-ids"- (mt/with-temp [:model/Document {doc1-id :id} {:name "Document 1" :archived false}- :model/Document {doc2-id :id} {:name "Document 2" :archived false}]- (let [results (recent-views/select-documents-for-recents [doc1-id doc2-id doc1-id])]- ;; Should return unique documents even if IDs are duplicated- (is (= 2 (count results)))- (is (= #{doc1-id doc2-id} (set (map :id results)))))))))--(deftest recents-api-with-documents-premium-feature-test- (testing "/recents API returns documents when :document premium feature is enabled"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Collection {coll-id :id} {:name "Test Collection"}- :model/Document {doc-id :id} {:name "Test Document"- :collection_id coll-id- :archived false}]- ;; Add document to recent views- (activity-feed/update-users-recent-views! (mt/user->id :rasta) :model/Document doc-id :view)-- ;; Call the API- (let [response (mt/user-http-request :rasta :get 200 "activity/recents" :context [:views])]- (is (some #(and (= (:model %) "document")- (= (:id %) doc-id)- (= (:name %) "Test Document"))- (:recents response))- "Document should be present in recents when premium feature is enabled"))))))--(deftest select-documents-for-recents-without-premium-feature-test- (testing "returns empty vector when :documents premium feature is disabled"- (mt/with-premium-features #{}- (mt/with-temp [:model/Document {doc-id :id} {:name "Test Document"- :archived false}]- (let [results (recent-views/select-documents-for-recents [doc-id])]- (is (= [] results)- "Should return empty vector when premium feature is disabled"))))))--(deftest recents-api-without-documents-premium-feature-test- (testing "/recents API does not return documents when :document premium feature is disabled"- (mt/with-premium-features #{}- (mt/with-temp [:model/Collection {coll-id :id} {:name "Test Collection"}- :model/Document {doc-id :id} {:name "Test Document"- :collection_id coll-id- :archived false}]- ;; Add document to recent views- (activity-feed/update-users-recent-views! (mt/user->id :rasta) :model/Document doc-id :view)-- ;; Call the API- (let [response (mt/user-http-request :rasta :get 200 "activity/recents" :context [:views])]- (is (not-any? #(= (:model %) :document) (:recents response))- "No documents should be present in recents when premium feature is disabled"))))))diff --git a/enterprise/backend/test/metabase_enterprise/documents/revisions/integration_test.clj b/enterprise/backend/test/metabase_enterprise/documents/revisions/integration_test.cljdeleted file mode 100644index 5d7c9c3ade7..00000000000--- a/enterprise/backend/test/metabase_enterprise/documents/revisions/integration_test.clj+++ /dev/null@@ -1,270 +0,0 @@-(ns metabase-enterprise.documents.revisions.integration-test- "Integration tests for Document revision history including API endpoints, events, and permissions."- (:require- [clojure.string :as str]- [clojure.test :refer :all]- [metabase-enterprise.documents.revisions.impl]- [metabase.config.core :as config]- [metabase.events.core :as events]- [metabase.revisions.models.revision :as revision]- [metabase.test :as mt]- [metabase.util :as u]- [toucan2.core :as t2]))--(def ^:private rasta-revision-info- (delay {:id (mt/user->id :rasta)- :first_name "Rasta"- :last_name "Toucan"- :common_name "Rasta Toucan"}))--(defn- create-document-revision!- "Helper function to create a Document revision manually for testing."- [document-id is-creation? user]- (revision/push-revision!- {:object (t2/select-one :model/Document :id document-id)- :entity :model/Document- :id document-id- :user-id (mt/user->id user)- :is-creation? is-creation?}))--(defn- get-document-revisions- "Helper function to get revisions for a Document via API."- [document-id]- (mt/user-http-request :rasta :get 200 (format "revision/document/%d" document-id)))--(deftest document-create-event-triggers-revision-test- (testing "Document creation triggers revision creation via events"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Document {doc-id :id, :as document} {:name "Test Document"- :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Hello World"}]}]}- :creator_id (mt/user->id :crowberto)}]- (events/publish-event! :event/document-create {:object document :user-id (mt/user->id :crowberto)})- (let [revision (t2/select-one :model/Revision :model "Document" :model_id doc-id)]- (is revision "Revision should be created")- (is (= "Document" (:model revision)))- (is (= doc-id (:model_id revision)))- (is (= (mt/user->id :crowberto) (:user_id revision)))- (is (:is_creation revision))- (is (not (:is_reversion revision)))- (testing "serialized object excludes metadata fields"- (let [object (:object revision)]- (is (= "Test Document" (:name object)))- (is (= {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Hello World"}]}]} (:document object)))- (is (not (contains? object :id)))- (is (not (contains? object :creator_id)))- (is (not (contains? object :created_at)))- (is (not (contains? object :updated_at)))- (is (not (contains? object :collection_id))))))))))--(deftest document-update-event-triggers-revision-test- (testing "Document update triggers revision creation via events"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Document {doc-id :id, :as document} {:name "Original Document"- :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Original content"}]}]}- :creator_id (mt/user->id :crowberto)}]- (let [updated-document (assoc document- :name "Updated Document"- :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Updated content"}]}]})]- (events/publish-event! :event/document-update {:object updated-document :user-id (mt/user->id :rasta)})- (let [revision (t2/select-one :model/Revision :model "Document" :model_id doc-id :user_id (mt/user->id :rasta))]- (is revision "Revision should be created for update")- (is (= "Document" (:model revision)))- (is (= doc-id (:model_id revision)))- (is (= (mt/user->id :rasta) (:user_id revision)))- (is (not (:is_creation revision)))- (is (not (:is_reversion revision)))- (testing "serialized object contains updated data"- (let [object (:object revision)]- (is (= "Updated Document" (:name object)))- (is (= {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Updated content"}]}]} (:document object)))))))))))--(deftest document-revision-api-endpoints-test- (testing "Document revision API endpoints work correctly"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Document {doc-id :id} {:name "Test Document"- :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Initial content"}]}]}- :creator_id (mt/user->id :rasta)}]- (create-document-revision! doc-id true :rasta)-- (testing "GET /api/revision/document/:id returns Document revisions"- (let [revisions (get-document-revisions doc-id)]- (is (= 1 (count revisions)))- (let [revision (first revisions)]- (is (:is_creation revision))- (is (not (:is_reversion revision)))- (is (= "created this." (:description revision)))- (is (=? @rasta-revision-info (:user revision)))- (is (= config/mb-version-string (:metabase_version revision))))))-- (testing "Multiple revisions are returned in correct order"- (t2/update! :model/Document doc-id {:name "Updated Document"})- (create-document-revision! doc-id false :rasta)-- (let [revisions (get-document-revisions doc-id)]- (is (= 2 (count revisions)))- (let [[latest-revision creation-revision] revisions]- (is (not (:is_creation latest-revision)))- (is (:is_creation creation-revision))- (is (= "created this." (:description creation-revision)))- (is (not= "created this." (:description latest-revision))))))))))--(deftest document-reversion-api-test- (testing "Document reversion via API works correctly"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Document {doc-id :id} {:name "Original Document"- :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Original content"}]}]}- :creator_id (mt/user->id :rasta)}]- (create-document-revision! doc-id true :rasta)-- (testing "Document can be updated and reverted"- (t2/update! :model/Document doc-id {:name "Updated Document"- :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Updated content"}]}]}})- (create-document-revision! doc-id false :rasta)-- (let [revisions (revision/revisions :model/Document doc-id)- [_ {original-revision-id :id}] revisions]-- (testing "Revert via API endpoint"- (let [revert-response (mt/user-http-request :rasta :post "revision/revert"- {:entity :document- :id doc-id- :revision_id original-revision-id})]- (is (:is_reversion revert-response))- (is (= "reverted to an earlier version." (:description revert-response)))- (is (=? @rasta-revision-info (:user revert-response)))))-- (testing "Document state is restored"- (let [reverted-document (t2/select-one :model/Document :id doc-id)]- (is (= "Original Document" (:name reverted-document)))- (is (= {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Original content"}]}]}- (:document reverted-document)))))-- (testing "Reversion creates new revision entry"- (let [final-revisions (get-document-revisions doc-id)]- (is (= 3 (count final-revisions)))- (let [latest-revision (first final-revisions)]- (is (:is_reversion latest-revision))- (is (= "reverted to an earlier version." (:description latest-revision))))))))))))--(deftest document-revision-permission-checks-test- (testing "Document revision API respects permissions"- (mt/with-premium-features #{:documents}- (mt/with-non-admin-groups-no-root-collection-perms- (mt/with-temp [:model/Collection collection {:name "Private collection"}- :model/Document document {:collection_id (u/the-id collection)- :name "Private document"- :document {:type "doc" :content []}- :creator_id (mt/user->id :crowberto)}]- (create-document-revision! (:id document) true :crowberto)- (t2/update! :model/Document (:id document) {:name "Updated Private Document"})- (create-document-revision! (:id document) false :crowberto)-- (let [document-id (u/the-id document)- [_ {prev-rev-id :id}] (revision/revisions :model/Document document-id)]-- (testing "User without permissions cannot access revisions"- (is (= "You don't have permissions to do that."- (mt/user-http-request :rasta :get 403 (format "revision/document/%d" document-id)))))-- (testing "User without permissions cannot revert"- (is (= "You don't have permissions to do that."- (mt/user-http-request :rasta :post 403 "revision/revert"- {:entity :document- :id document-id- :revision_id prev-rev-id}))))))))))--(deftest document-revision-cross-boundary-integration-test- (testing "Document revisions integrate properly with OSS revision system"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Document {doc-id :id} {:name "Cross-boundary Document"- :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Enterprise content"}]}]}- :creator_id (mt/user->id :rasta)}]-- (testing "Document revisions work with OSS revision/revisions function"- (create-document-revision! doc-id true :rasta)- (let [revisions (revision/revisions :model/Document doc-id)]- (is (seq revisions))- (is (= 1 (count revisions)))- (let [revision (first revisions)]- (is (= doc-id (:model_id revision)))- (is (= "Document" (:model revision))))))-- (testing "Document revisions work with OSS revision API routes"- (let [revisions-response (mt/user-http-request :rasta :get (format "revision/document/%d" doc-id))]- (is (seq revisions-response))- (is (every? #(contains? % :is_creation) revisions-response))- (is (every? #(contains? % :description) revisions-response))))-- (testing "Document reversion integrates with OSS revert endpoint"- (t2/update! :model/Document doc-id {:name "Modified Document"})- (create-document-revision! doc-id false :rasta)-- (let [[_ {original-rev-id :id}] (revision/revisions :model/Document doc-id)- revert-response (mt/user-http-request :rasta :post "revision/revert"- {:entity :document- :id doc-id- :revision_id original-rev-id})]- (is (:is_reversion revert-response))- (let [reverted-doc (t2/select-one :model/Document :id doc-id)]- (is (= "Cross-boundary Document" (:name reverted-doc))))))))))--(deftest document-revision-event-handler-integration-test- (testing "Document revision events are published and handled correctly"- (mt/with-premium-features #{:documents}- (let [original-event events/publish-event!- events-received (atom [])]- (with-redefs [events/publish-event! (fn [topic event]- (swap! events-received conj [topic event])- (original-event topic event))]- (mt/with-temp [:model/Document {doc-id :id, :as document} {:name "Event Test Document"- :document {:type "doc" :content []}- :creator_id (mt/user->id :rasta)}]-- (testing "Create event triggers revision creation"- (events/publish-event! :event/document-create {:object document :user-id (mt/user->id :rasta)})- (let [revision (t2/select-one :model/Revision :model "Document" :model_id doc-id)]- (is revision)- (is (:is_creation revision))))-- (testing "Update event triggers revision creation"- (let [updated-document (assoc document :name "Updated Event Document")]- (events/publish-event! :event/document-update {:object updated-document :user-id (mt/user->id :rasta)})- (let [revisions (t2/select :model/Revision :model "Document" :model_id doc-id {:order-by [[:id :desc]]})]- (is (= 2 (count revisions)))- (let [latest-revision (first revisions)]- (is (not (:is_creation latest-revision)))- (is (= "Updated Event Document" (get-in latest-revision [:object :name])))))))-- (testing "Events were published correctly"- (is (>= (count @events-received) 2))- (is (some #(= :event/document-create (first %)) @events-received))- (is (some #(= :event/document-update (first %)) @events-received)))))))))--(deftest document-revision-diff-and-descriptions-test- (testing "Document revision diffs and descriptions work correctly"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Document {doc-id :id} {:name "Original Title"- :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Original content"}]}]}- :creator_id (mt/user->id :rasta)}]- (create-document-revision! doc-id true :rasta)-- (testing "Name change produces correct diff and description"- (t2/update! :model/Document doc-id {:name "Updated Title"})- (create-document-revision! doc-id false :rasta)-- (let [revisions (get-document-revisions doc-id)- update-revision (first revisions)]- (is (= "Original Title" (get-in update-revision [:diff :before :name])))- (is (= "Updated Title" (get-in update-revision [:diff :after :name])))- (is (str/includes? (:description update-revision) "renamed"))))-- (testing "Content change produces diff"- (t2/update! :model/Document doc-id {:document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "New content"}]}]}})- (create-document-revision! doc-id false :rasta)-- (let [revisions (get-document-revisions doc-id)- content-revision (first revisions)]- (is (= {:content [{:content [{:text "Original content"}]}]}- (get-in content-revision [:diff :before :document])))- (is (= {:content [{:content [{:text "New content"}]}]}- (get-in content-revision [:diff :after :document])))))))))diff --git a/enterprise/backend/test/metabase_enterprise/documents/search_test.clj b/enterprise/backend/test/metabase_enterprise/documents/search_test.cljdeleted file mode 100644index 2d5d02336ed..00000000000--- a/enterprise/backend/test/metabase_enterprise/documents/search_test.clj+++ /dev/null@@ -1,176 +0,0 @@-(ns metabase-enterprise.documents.search-test- (:require- [clojure.test :refer :all]- [java-time.api :as t]- [metabase.events.core :as events]- [metabase.permissions.core :as perms]- [metabase.permissions.models.permissions-group :as perms-group]- [metabase.search.test-util :as search.tu]- [metabase.test :as mt]- [metabase.test.fixtures :as fixtures]- [metabase.util :as u]- [toucan2.core :as t2]))--(defn- text->prose-mirror-ast- "Convert plain text to a ProseMirror AST structure."- [text]- (if (empty? text)- {:type "doc" :content []}- {:type "doc"- :content [{:type "paragraph"- :content [{:type "text"- :text text}]}]}))--(use-fixtures :once (fixtures/initialize :db :test-users))--(defn card-with-name-and-query- ([]- (card-with-name-and-query (mt/random-name)))- ([card-name]- {:name card-name- :display "scalar"- :dataset_query (mt/mbql-query venues)- :visualization_settings {:global {:title nil}}}))--(deftest card-search-exclusion-test- (testing "Cards with document_id are excluded from search indexing"- (let [card-name (mt/random-name)- regular-card-name (str card-name "-regular")]- (search.tu/with-temp-index-table- (mt/with-temp [:model/Document document {:name "Test Document"- :document (text->prose-mirror-ast "")}- :model/Card document-card (-> (card-with-name-and-query card-name)- (assoc :document_id (u/the-id document)))- :model/Card regular-card (card-with-name-and-query regular-card-name)]-- (testing "Search API excludes document cards"- (let [results (mt/user-http-request :crowberto :get 200 "search" :q card-name :models "card")]- (is (not (some #(= (:id %) (u/the-id document-card)) (:data results)))- "Document card should not appear in search results"))- (let [regular-results (mt/user-http-request :crowberto :get 200 "search" :q regular-card-name :models "card")]- (is (some #(= (:id %) (u/the-id regular-card)) (:data regular-results))- "Regular card should appear in search results"))))))))--(deftest document-permission-filtering-test- (testing "Document search respects collection-based permissions"- (mt/with-premium-features #{:documents}- (mt/with-non-admin-groups-no-root-collection-perms- (search.tu/with-temp-index-table- (mt/with-temp [:model/Collection {coll-id :id} {}- :model/Collection {private-coll-id :id} {}- :model/Document {doc-in-public-coll :id} {:name "Public Document"- :collection_id coll-id- :document (text->prose-mirror-ast "content")}- :model/Document {doc-in-private-coll :id} {:name "Private Document"- :collection_id private-coll-id- :document (text->prose-mirror-ast "content")}- :model/Document {doc-archived :id} {:name "Archived Document"- :collection_id coll-id- :archived true- :document (text->prose-mirror-ast "content")}]- ;; Give user read access to first collection only- (perms/grant-collection-read-permissions! (perms-group/all-users) coll-id)-- (testing "Regular user sees only documents in accessible collections"- (let [results (mt/user-http-request :rasta :get 200 "search" :q "Document" :models "document")]- (is (= #{doc-in-public-coll}- (set (map :id (:data results))))- "Should only see document in accessible collection")))-- (testing "Regular user cannot see archived documents (no write perms)"- (let [results (mt/user-http-request :rasta :get 200 "search" :q "Archived" :archived true :models "document")]- (is (empty? (:data results))- "Should not see archived document without write permissions")))-- (testing "Admin can see all documents including archived"- (let [regular-results (mt/user-http-request :crowberto :get 200 "search" :q "Document" :models "document")- archived-results (mt/user-http-request :crowberto :get 200 "search" :q "Archived" :archived true :models "document")]- (is (= #{doc-in-public-coll doc-in-private-coll}- (set (map :id (:data regular-results))))- "Admin should see all non-archived documents")- (is (= #{doc-archived}- (set (map :id (:data archived-results))))- "Admin should see archived documents")))-- (testing "User with write permissions can see archived documents"- ;; Give user write access to first collection- (perms/grant-collection-readwrite-permissions! (perms-group/all-users) coll-id)- (let [archived-results (mt/user-http-request :rasta :get 200 "search" :q "Archived" :archived true :models "document")]- (is (= #{doc-archived}- (set (map :id (:data archived-results))))- "User with write permissions should see archived documents in accessible collections")))))))))--(deftest document-search-without-premium-feature-test- (testing "Documents are not returned from search when documents premium feature is disabled"- (mt/with-premium-features #{}- (search.tu/with-temp-index-table- (mt/with-temp [:model/Collection {coll-id :id} {}- :model/Document {doc-id :id} {:name "Test Document"- :collection_id coll-id- :document (text->prose-mirror-ast "searchable content")}- :model/Card {card-id :id} (-> (card-with-name-and-query "Test Card")- (assoc :collection_id coll-id))]-- (testing "Search for documents returns empty results"- (let [results (mt/user-http-request :crowberto :get 200 "search" :q "Test Document" :models "document")]- (is (empty? (:data results))- "Should not return any documents when premium feature is disabled")))-- (testing "Search for cards still works normally"- (let [results (mt/user-http-request :crowberto :get 200 "search" :q "Test Card" :models "card")]- (is (= #{card-id}- (set (map :id (:data results))))- "Should still return cards when documents feature is disabled")))-- (testing "General search excludes documents but includes other models"- (let [results (mt/user-http-request :crowberto :get 200 "search" :q "Test")]- (is (some #(= (:id %) card-id) (:data results))- "Should include cards in general search")- (is (not (some #(= (:id %) doc-id) (:data results)))- "Should not include documents in general search when feature is disabled"))))))))--(deftest document-view-tracking-integration-test- (testing "Document view tracking integrates with search"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Document {doc-id :id} {:name "Viewed Document"- :document (text->prose-mirror-ast "content")- :view_count 0}]-- (testing "Document has initial state"- (let [doc (t2/select-one :model/Document :id doc-id)]- (is (= 0 (:view_count doc)))- ;; last_viewed_at has a default timestamp from migration, not nil- (is (some? (:last_viewed_at doc)))))-- (testing "Publishing document-read event works without errors"- ;; The actual view count increment is batched and asynchronous- ;; So we test that the event publishes successfully- (is (some? (events/publish-event! :event/document-read- {:object-id doc-id- :user-id (mt/user->id :crowberto)}))- "Document read event should publish successfully"))-- (testing "Document with higher view count appears in search"- ;; Manually set view count to test search integration- (t2/update! :model/Document doc-id {:view_count 5- :last_viewed_at (t/offset-date-time)})- (search.tu/with-temp-index-table- (let [results (mt/user-http-request :crowberto :get 200 "search" {:q "Viewed" :models "document"})- doc-results (filter #(= "document" (:model %)) (:data results))]- (when (seq doc-results)- (let [doc-result (first doc-results)]- (is (= doc-id (:id doc-result)))- ;; View count affects scoring but isn't directly in result- (is (some #(= "view-count" (:name %)) (:scores doc-result))))))))-- (testing "Document with recent view appears in search results"- (let [recent-time (t/minus (t/offset-date-time) (t/minutes 5))]- (t2/update! :model/Document doc-id {:last_viewed_at recent-time})- (search.tu/with-temp-index-table- (let [results (mt/user-http-request :crowberto :get 200 "search" {:q "Viewed" :models "document"})- doc-results (filter #(= "document" (:model %)) (:data results))]- (when (seq doc-results)- (let [doc-result (first doc-results)]- (is (= doc-id (:id doc-result)))- ;; User recency affects scoring- (is (some #(= "user-recency" (:name %)) (:scores doc-result)))))))))))))diff --git a/enterprise/backend/test/metabase_enterprise/documents/view_log_test.clj b/enterprise/backend/test/metabase_enterprise/documents/view_log_test.cljdeleted file mode 100644index 20321c50293..00000000000--- a/enterprise/backend/test/metabase_enterprise/documents/view_log_test.clj+++ /dev/null@@ -1,149 +0,0 @@-(ns metabase-enterprise.documents.view-log-test- (:require- [clojure.test :refer :all]- [java-time.api :as t]- [metabase-enterprise.documents.view-log :as documents.view-log]- [metabase.events.core :as events]- [metabase.test :as mt]- [toucan2.core :as t2]))--(set! *warn-on-reflection* true)--(defn latest-view- "Returns the most recent view for a given user and document ID"- [user-id document-id]- (t2/select-one :model/ViewLog- :user_id user-id- :model "document"- :model_id document-id- {:order-by [[:id :desc]]}))--(deftest document-read-ee-test- (mt/with-premium-features #{:audit-app :documents}- (mt/with-temp [:model/Collection collection {}- :model/User user {}- :model/Document document {:collection_id (:id collection)- :name "Test Document"- :document "{\"type\":\"doc\",\"content\":[]}"- :creator_id (:id user)}]- (testing "A basic document read event is recorded in EE"- (events/publish-event! :event/document-read {:object-id (:id document) :user-id (:id user)})- (is (partial=- {:user_id (:id user)- :model "document"- :model_id (:id document)- :has_access true- :context nil}- (latest-view (:id user) (:id document))))))))--(deftest document-read-oss-no-view-logging-test- (mt/with-premium-features #{:documents} ; documents feature but not audit-app- (mt/with-temp [:model/Collection collection {}- :model/User user {}- :model/Document document {:collection_id (:id collection)- :name "Test Document"- :document "{\"type\":\"doc\",\"content\":[]}"- :creator_id (:id user)}]- (testing "A basic document read event is not recorded without audit-app"- (events/publish-event! :event/document-read {:object-id (:id document) :user-id (:id user)})- (is (nil? (latest-view (:id user) (:id document)))- "view log entries should not be made without audit-app feature")))))--(deftest document-read-view-count-test- (mt/test-helpers-set-global-values!- (mt/with-temporary-setting-values [synchronous-batch-updates true]- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Collection collection {}- :model/User user {}- :model/Document document {:collection_id (:id collection)- :name "Test Document"- :document "{\"type\":\"doc\",\"content\":[]}"- :creator_id (:id user)- :view_count 0}]- (testing "Document read events are recorded by a document's view_count"- (is (= 0 (:view_count document))- "view_count should be 0 before the event is published")- (events/publish-event! :event/document-read {:object-id (:id document) :user-id (:id user)})- (is (= 1 (t2/select-one-fn :view_count :model/Document (:id document))))- (events/publish-event! :event/document-read {:object-id (:id document) :user-id (:id user)})- (is (= 2 (t2/select-one-fn :view_count :model/Document (:id document))))))))))--(deftest update-document-last-viewed-at-test- (let [now (-> (t/offset-date-time)- (.withNano 0))- one-hour-ago (t/minus now (t/hours 1))- two-hours-ago (t/minus now (t/hours 2))]- (testing "update with multiple documents of the same IDs will set timestamp to the latest"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Collection collection {}- :model/User user {}- :model/Document document {:collection_id (:id collection)- :name "Test Document"- :document "{\"type\":\"doc\",\"content\":[]}"- :creator_id (:id user)- :last_viewed_at two-hours-ago}]- (#'documents.view-log/update-document-last-viewed-at!* [{:id (:id document) :timestamp one-hour-ago}- {:id (:id document) :timestamp two-hours-ago}])- (is (= one-hour-ago- (-> (t2/select-one-fn :last_viewed_at :model/Document (:id document))- t/offset-date-time- (.withNano 0)))))))-- (testing "if the existing last_viewed_at is greater than the updating values, do not override it"- (mt/with-premium-features #{:documents}- (mt/with-temp [:model/Collection collection {}- :model/User user {}- :model/Document document {:collection_id (:id collection)- :name "Test Document"- :document "{\"type\":\"doc\",\"content\":[]}"- :creator_id (:id user)- :last_viewed_at now}]- (#'documents.view-log/update-document-last-viewed-at!* [{:id (:id document) :timestamp one-hour-ago}])- (is (= now- (-> (t2/select-one-fn :last_viewed_at :model/Document (:id document))- t/offset-date-time- (.withNano 0)))))))))--(deftest document-event-derivation-test- (testing "Document events are properly derived from base events"- (is (isa? :metabase-enterprise.documents.view-log/document-read :metabase/event))- (is (isa? :event/document-read :metabase-enterprise.documents.view-log/document-read))))--(deftest document-read-error-handling-test- (mt/with-premium-features #{:documents}- (testing "Document read event handles missing document gracefully"- ;; This should not throw an exception- (is (some? (events/publish-event! :event/document-read {:object-id 999999 :user-id (mt/user->id :rasta)}))))))--(deftest document-statistics-lock-test- (testing "Document statistics lock is properly defined"- (is (= :metabase-enterprise.documents.view-log/document-statistics-lock- @#'documents.view-log/document-statistics-lock))))--(deftest document-read-updates-recent-views-test- (mt/with-premium-features #{:audit-app :documents}- (mt/with-temp [:model/Collection collection {}- :model/User user {}- :model/Document document {:collection_id (:id collection)- :name "Test Document"- :document "{\"type\":\"doc\",\"content\":[]}"- :creator_id (:id user)}]- (testing "Document read event updates user's recent views"- ;; Verify no recent views initially- (is (empty? (t2/select :model/RecentViews- :user_id (:id user)- :model "document"- :model_id (:id document))))-- ;; Publish document read event- (events/publish-event! :event/document-read {:object-id (:id document) :user-id (:id user)})-- ;; Verify recent view was created- (let [recent-view (t2/select-one :model/RecentViews- :user_id (:id user)- :model "document"- :model_id (:id document))]- (is (some? recent-view) "Recent view should be created")- (is (= (:id user) (:user_id recent-view)))- (is (= "document" (:model recent-view)))- (is (= (:id document) (:model_id recent-view))))))))diff --git a/enterprise/backend/test/metabase_enterprise/public_sharing/api_test.clj b/enterprise/backend/test/metabase_enterprise/public_sharing/api_test.cljdeleted file mode 100644index 634cccc09e6..00000000000--- a/enterprise/backend/test/metabase_enterprise/public_sharing/api_test.clj+++ /dev/null@@ -1,211 +0,0 @@-(ns metabase-enterprise.public-sharing.api-test- "Tests for public sharing endpoints for EE-only entities (Documents).-- These tests verify that public document endpoints work correctly when routed through the EE module."- (:require- [clojure.test :refer :all]- [metabase-enterprise.documents.test-util :as documents.test-util]- [metabase.test :as mt]- [toucan2.core :as t2]))--(defn- document-with-public-link- "Create test Document data including a public UUID and made_public_by_id."- [overrides]- (merge {:name "Test Document"- :document (documents.test-util/text->prose-mirror-ast "Test content")- :public_uuid (str (random-uuid))- :made_public_by_id (mt/user->id :crowberto)}- overrides))--;;; ---------------------------------------- Unauthenticated Access ---------------------------------------------------------(deftest unauthenticated-public-document-access-test- (testing "EE public document endpoints should work without authentication when feature is enabled"- (mt/with-premium-features #{:documents}- (mt/with-temporary-setting-values [enable-public-sharing true]- (mt/with-temp [:model/Document document (document-with-public-link {:name "Unauthenticated Test Document"- :document (documents.test-util/text->prose-mirror-ast "Public content")})]- (testing "Can access public document without authentication at /api/ee/public/document"- (let [response (mt/client-full-response :get (str "ee/public/document/" (:public_uuid document)))]- (is (= 200 (:status response))- "Should return 200 OK for public document without auth")- (is (contains? (:body response) :name)- "Should return document data in response body"))))))))--;;; ---------------------------------------- Premium Feature Requirement ---------------------------------------------------(deftest public-document-requires-documents-feature-test- (testing "Public document endpoints should require :documents premium feature"- (mt/with-premium-features #{}- (mt/with-temporary-setting-values [enable-public-sharing true]- (mt/with-temp [:model/Document document (document-with-public-link {:name "Feature Test Document"- :document (documents.test-util/text->prose-mirror-ast "Test content")})]- (testing "Should return generic error when :documents feature is not enabled"- (let [response (mt/client-full-response :get (str "ee/public/document/" (:public_uuid document)))]- (is (= 400 (:status response))- "Should return 400 when feature is not enabled to avoid leaking premium feature information")- (is (= "An error occurred." (:body response))))))))))--;;; ---------------------------------------- GET /api/ee/public/document/:uuid ------------------------------------------------(deftest public-document-card-requires-documents-feature-test- (testing "Card query and export endpoints should require :documents premium feature"- (mt/with-premium-features #{}- (mt/with-temporary-setting-values [enable-public-sharing true]- (mt/with-temp [:model/Document document (document-with-public-link {})- :model/Card card {:name "Feature Test Card"- :dataset_query (mt/mbql-query venues {:limit 5})- :document_id (:id document)}]- (testing "Card query endpoint returns error without feature"- (let [response (mt/client-full-response :get (format "ee/public/document/%s/card/%d"- (:public_uuid document)- (:id card)))]- (is (= 400 (:status response))- "Should return 400 when feature is not enabled to avoid leaking premium feature information")))- (testing "Card export endpoint returns error without feature"- (let [response (mt/client-full-response :post (format "ee/public/document/%s/card/%d/csv"- (:public_uuid document)- (:id card))- {})]- (is (= 400 (:status response))- "Should return 400 when feature is not enabled to avoid leaking premium feature information"))))))))--(deftest fetch-public-document-test- (testing "GET /api/ee/public/document/:uuid"- (testing "Can fetch a public Document via EE public sharing routes"- (mt/with-premium-features #{:documents}- (mt/with-temporary-setting-values [enable-public-sharing true]- (mt/with-temp [:model/Document document (document-with-public-link {:name "Public Test Document"- :document (documents.test-util/text->prose-mirror-ast "Public test content")})]- (is (partial= {:name "Public Test Document"- :document (documents.test-util/text->prose-mirror-ast "Public test content")- :id (:id document)}- (mt/client :get 200 (str "ee/public/document/" (:public_uuid document)))))))))))--(deftest public-document-returns-only-safe-fields-test- (testing "GET /api/ee/public/document/:uuid should only return safe fields"- (mt/with-premium-features #{:documents}- (mt/with-temporary-setting-values [enable-public-sharing true]- (mt/with-temp [:model/Document document (document-with-public-link {:name "Public Test Document"- :document (documents.test-util/text->prose-mirror-ast "Public test content")})]- (let [result (mt/client :get 200 (str "ee/public/document/" (:public_uuid document)))]- (testing "Should include safe fields"- (is (contains? result :id))- (is (contains? result :name))- (is (contains? result :document))- (is (contains? result :created_at))- (is (contains? result :updated_at)))- (testing "Should not include sensitive fields"- (is (not (contains? result :public_uuid)))- (is (not (contains? result :made_public_by_id)))- (is (not (contains? result :collection_id))))))))))--(deftest public-document-hydrates-cards-test- (testing "GET /api/ee/public/document/:uuid hydrates cards for public access"- (mt/with-premium-features #{:documents}- (mt/with-temporary-setting-values [enable-public-sharing true]- (mt/with-temp [:model/Document document (document-with-public-link {:name "Document with Cards"})- :model/Card {card1-id :id} {:name "Card 1"- :dataset_query (mt/mbql-query venues {:limit 5})- :document_id (:id document)}- :model/Card {card2-id :id} {:name "Card 2"- :dataset_query (mt/mbql-query venues {:limit 10})- :document_id (:id document)}]- (let [result (mt/client :get 200 (str "ee/public/document/" (:public_uuid document)))]- (testing "response includes cards field"- (is (contains? result :cards)))-- (testing "cards are returned as a map keyed by card ID"- (is (map? (:cards result)))- (is (= 2 (count (:cards result))))- (is (contains? (:cards result) card1-id))- (is (contains? (:cards result) card2-id)))-- (testing "cards contain expected metadata"- (is (= "Card 1" (get-in result [:cards card1-id :name])))- (is (= "Card 2" (get-in result [:cards card2-id :name])))- (is (= card1-id (get-in result [:cards card1-id :id])))- (is (= card2-id (get-in result [:cards card2-id :id]))))-- (testing "cards do not include sensitive fields"- (is (not (contains? (get-in result [:cards card1-id]) :collection_id)))- (is (not (contains? (get-in result [:cards card1-id]) :creator_id))))))))))--(deftest get-public-document-errors-test- (testing "GET /api/ee/public/document/:uuid"- (testing "Cannot fetch a public Document if public sharing is disabled"- (mt/with-premium-features #{:documents}- (mt/with-temporary-setting-values [enable-public-sharing false]- (mt/with-temp [:model/Document document (document-with-public-link {})]- (is (= "API endpoint does not exist."- (mt/client :get 404 (str "ee/public/document/" (:public_uuid document)))))))))-- (testing "Returns 404 if the Document doesn't exist"- (mt/with-premium-features #{:documents}- (mt/with-temporary-setting-values [enable-public-sharing true]- (is (= "Not found."- (mt/client :get 404 (str "ee/public/document/" (random-uuid))))))))))--(deftest public-document-not-accessible-when-archived-test- (testing "GET /api/ee/public/document/:uuid should not work for archived documents"- (mt/with-premium-features #{:documents}- (mt/with-temporary-setting-values [enable-public-sharing true]- (mt/with-temp [:model/Document document (document-with-public-link {})]- (let [uuid (:public_uuid document)]- (testing "Document is accessible when not archived"- (is (= 200- (:status (mt/client-full-response :get (str "ee/public/document/" uuid))))))- (testing "Document is not accessible after archiving"- (t2/update! :model/Document (:id document) {:archived true})- (is (= "Not found."- (mt/client :get 404 (str "ee/public/document/" uuid)))))))))))--;;; ------------------------------ GET /api/ee/public/document/:uuid/card/:card-id -----------------------------------------(deftest fetch-public-document-card-test- (testing "GET /api/ee/public/document/:uuid/card/:card-id"- (testing "Can run query for card embedded in public document"- (mt/with-premium-features #{:documents}- (mt/with-temporary-setting-values [enable-public-sharing true]- (mt/with-temp [:model/Document document (document-with-public-link {})- :model/Card card {:name "Test Card"- :dataset_query (mt/mbql-query venues {:limit 5})- :document_id (:id document)}]- (let [result (mt/client :get 202 (format "ee/public/document/%s/card/%d" (:public_uuid document) (:id card)))]- (is (some? result))- (is (= "completed" (:status result))))))))))--(deftest public-document-card-validates-association-test- (testing "GET /api/ee/public/document/:uuid/card/:card-id validates card is associated with document"- (mt/with-premium-features #{:documents}- (mt/with-temporary-setting-values [enable-public-sharing true]- (mt/with-temp [:model/Document document (document-with-public-link {})- :model/Card card {:name "Unassociated Card"- :dataset_query (mt/mbql-query venues {:limit 5})}]- (is (= "Not found."- (mt/client :get 404 (format "ee/public/document/%s/card/%d" (:public_uuid document) (:id card))))))))))--;;; ----------------------- POST /api/ee/public/document/:uuid/card/:card-id/:export-format ---------------------------------(deftest export-public-document-card-test- (testing "POST /api/ee/public/document/:uuid/card/:card-id/:export-format"- (mt/with-premium-features #{:documents}- (mt/with-temporary-setting-values [enable-public-sharing true]- (mt/with-temp [:model/Document document (document-with-public-link {})- :model/Card card {:name "Export Test Card"- :dataset_query (mt/mbql-query venues {:limit 5})- :document_id (:id document)}]- (testing "Can export card results as CSV"- (let [response (mt/client-full-response :post (format "ee/public/document/%s/card/%d/csv"- (:public_uuid document)- (:id card))- {})]- (is (= 200 (:status response)))- (is (= "text/csv" (get-in response [:headers "Content-Type"])))))-- (testing "Can export card results as JSON"- (let [response (mt/client-full-response :post (format "ee/public/document/%s/card/%d/json"- (:public_uuid document)- (:id card))- {})]- (is (= 200 (:status response))))))))))diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/api/comments_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/api/comments_test.cljnew file mode 100644index 00000000000..9ed34acc03b--- /dev/null+++ b/enterprise/backend/test/metabase_enterprise/sandbox/api/comments_test.clj@@ -0,0 +1,15 @@+(ns metabase-enterprise.sandbox.api.comments-test+ "Tests for special behavior of `/api/metabase/comment` endpoints in the Metabase Enterprise Edition."+ (:require+ [clojure.test :refer :all]+ [metabase-enterprise.test :as met]+ [metabase.test :as mt]))++(deftest mention-entities-test+ (testing "Sandboxed users don't get to see other users"+ (met/with-gtaps-for-user! :rasta {:gtaps {:venues {}}}+ (is (=? {:data [{:id int? :common_name "Rasta Toucan" :model "user"}]+ :total 1+ :limit 50+ :offset 0}+ (mt/user-http-request :rasta :get 200 "comment/mentions" :limit 50))))))diff --git a/enterprise/frontend/src/metabase-enterprise/api/index.ts b/enterprise/frontend/src/metabase-enterprise/api/index.tsindex bad4aa11fb0..8edd9e2e5e6 100644--- a/enterprise/frontend/src/metabase-enterprise/api/index.ts+++ b/enterprise/frontend/src/metabase-enterprise/api/index.ts@@ -3,11 +3,9 @@ export * from "./api";export * from "./audit-info";export * from "./billing-info";export * from "./cloud-add-ons";-export * from "./comment";export * from "./content-translation";export * from "./db-routing";export * from "./dependencies";-export * from "./document";export * from "./gdrive";export * from "./library";export * from "./metabot";diff --git a/enterprise/frontend/src/metabase-enterprise/api/tags.ts b/enterprise/frontend/src/metabase-enterprise/api/tags.tsindex 7d86357713f..8eddd5500f5 100644--- a/enterprise/frontend/src/metabase-enterprise/api/tags.ts+++ b/enterprise/frontend/src/metabase-enterprise/api/tags.ts@@ -12,7 +12,6 @@ import type {BulkTableInfo,BulkTableSelectionInfo,CardDependencyNode,- Comment,DashboardDependencyNode,DependencyGraph,DependencyNode,@@ -37,9 +36,6 @@ export const ENTERPRISE_TAG_TYPES = ["metabot-entities-list","metabot-prompt-suggestions","gsheets-status",- "document",- "public-document",- "comment","sandbox","transform-tag","transform-job",@@ -143,22 +139,6 @@ export function provideTransformJobListTags(return [listTag("transform-job"), ...jobs.flatMap(provideTransformJobTags)];}-export function provideCommentListTags(- comments: Comment[],-): TagDescription<EnterpriseTagType>[] {- return [listTag("comment"), ...comments.flatMap(provideCommentTags)];-}--export function provideCommentTags(- comment: Comment,-): TagDescription<EnterpriseTagType>[] {- if (comment.creator) {- return [idTag("comment", comment.id), ...provideUserTags(comment.creator)];- }-- return [idTag("comment", comment.id)];-}-export function providePythonLibraryTags(library: PythonLibrary,): TagDescription<EnterpriseTagType>[] {diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/types.ts b/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/types.tsdeleted file mode 100644index 9e8b73887a3..00000000000--- a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/types.ts+++ /dev/null@@ -1,4 +0,0 @@-export interface CardEmbedRef {- id: number;- name?: string;-}diff --git a/enterprise/frontend/src/metabase-enterprise/documents/index.ts b/enterprise/frontend/src/metabase-enterprise/documents/index.tsdeleted file mode 100644index 6fb7e1eea0c..00000000000--- a/enterprise/frontend/src/metabase-enterprise/documents/index.ts+++ /dev/null@@ -1,34 +0,0 @@-import {- PLUGIN_DOCUMENTS,- PLUGIN_ENTITIES,- PLUGIN_REDUCERS,-} from "metabase/plugins";-import Documents from "metabase-enterprise/entities/documents";-import { hasPremiumFeature } from "metabase-enterprise/settings";--import { DocumentCopyForm } from "./components/DocumentCopyForm/DocumentCopyForm";-import { documentsReducer } from "./documents.slice";-import { getRoutes } from "./routes";-import {- getCommentSidebarOpen,- getCurrentDocument,- getSidebarOpen,-} from "./selectors";--/**- * Initialize documents plugin features that depend on hasPremiumFeature.- */-export function initializePlugin() {- if (hasPremiumFeature("documents")) {- PLUGIN_DOCUMENTS.getRoutes = getRoutes;- PLUGIN_DOCUMENTS.shouldShowDocumentInNewItemMenu = () => true;- PLUGIN_DOCUMENTS.getCurrentDocument = getCurrentDocument;- PLUGIN_DOCUMENTS.getSidebarOpen = getSidebarOpen;- PLUGIN_DOCUMENTS.getCommentSidebarOpen = getCommentSidebarOpen;- PLUGIN_DOCUMENTS.DocumentCopyForm = DocumentCopyForm;-- PLUGIN_REDUCERS.documents = documentsReducer;-- PLUGIN_ENTITIES.entities["documents"] = Documents;- }-}diff --git a/enterprise/frontend/src/metabase-enterprise/documents/routes.tsx b/enterprise/frontend/src/metabase-enterprise/documents/routes.tsxdeleted file mode 100644index 5ce790c7c55..00000000000--- a/enterprise/frontend/src/metabase-enterprise/documents/routes.tsx+++ /dev/null@@ -1,31 +0,0 @@-import type { ComponentProps } from "react";-import { Route } from "react-router";--import { ModalRoute } from "metabase/hoc/ModalRoute";-import { extractEntityId } from "metabase/lib/urls";--import { CommentsSidesheet } from "./components/CommentsSidesheet";-import { DocumentPage } from "./components/DocumentPage";--const DocumentPageOuter = (props: ComponentProps<typeof DocumentPage>) => {- const { entityId } = props.params;- const documentId = entityId === "new" ? "new" : extractEntityId(entityId);-- // Remounts DocumentPage when navigating to a different document.- // Prevents data, state, undo history, etc from bleeding between documents.- return <DocumentPage key={documentId} {...props} />;-};--export const getRoutes = () => (- <Route path="document/:entityId" component={DocumentPageOuter}>- <ModalRoute- path="comments/:childTargetId"- modal={CommentsSidesheet}- noWrap- modalProps={{- enableTransition: false,- closeOnClickOutside: false,- }}- />- </Route>-);diff --git a/enterprise/frontend/src/metabase-enterprise/documents/types.ts b/enterprise/frontend/src/metabase-enterprise/documents/types.tsdeleted file mode 100644index 5dbe8856563..00000000000--- a/enterprise/frontend/src/metabase-enterprise/documents/types.ts+++ /dev/null@@ -1,9 +0,0 @@-import type { State } from "metabase-types/store";--import type { DocumentsState } from "./documents.slice";--export interface DocumentsStoreState extends State {- plugins?: {- documents?: DocumentsState;- };-}diff --git a/enterprise/frontend/src/metabase-enterprise/embedding/components/PublicLinkPopover/index.ts b/enterprise/frontend/src/metabase-enterprise/embedding/components/PublicLinkPopover/index.tsdeleted file mode 100644index 419298278d6..00000000000--- a/enterprise/frontend/src/metabase-enterprise/embedding/components/PublicLinkPopover/index.ts+++ /dev/null@@ -1 +0,0 @@-export { DocumentPublicLinkPopover } from "./DocumentPublicLinkPopover";diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/AIMarkdown/AIMarkdown.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/AIMarkdown/AIMarkdown.tsxindex 4cec2ef8590..b7c6847a13a 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/AIMarkdown/AIMarkdown.tsx+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/AIMarkdown/AIMarkdown.tsx@@ -6,7 +6,7 @@ import { memo, useMemo } from "react";import Markdown, {type MarkdownProps,} from "metabase/common/components/Markdown";-import { parseMetabaseProtocolLink } from "metabase-enterprise/metabot/utils/links";+import { parseMetabaseProtocolLink } from "metabase/metabot/utils/links";import S from "./AIMarkdown.module.css";import { InternalLink } from "./components/InternalLink";diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/AIMarkdown/components/MarkdownSmartLink.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/AIMarkdown/components/MarkdownSmartLink.tsxindex 1c4d9f39825..713cde08da3 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/AIMarkdown/components/MarkdownSmartLink.tsx+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/AIMarkdown/components/MarkdownSmartLink.tsx@@ -2,10 +2,10 @@ import { match } from "ts-pattern";import { getIcon } from "metabase/lib/icon";import { modelToUrl } from "metabase/lib/urls";+import type { MetabaseProtocolEntityModel } from "metabase/metabot/utils/links";+import { useEntityData } from "metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode";+import { entityToUrlableModel } from "metabase/rich_text_editing/tiptap/extensions/shared/suggestionUtils";import { Icon } from "metabase/ui";-import type { MetabaseProtocolEntityModel } from "metabase-enterprise/metabot/utils/links";-import { useEntityData } from "metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode";-import { entityToUrlableModel } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/suggestionUtils";import S from "../AIMarkdown.module.css";diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/Metabot.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/Metabot.tsxindex c11510e56b4..cfe6431c948 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/Metabot.tsx+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/Metabot.tsx@@ -3,8 +3,8 @@ import { tinykeys } from "tinykeys";import ErrorBoundary from "metabase/ErrorBoundary";import { useSelector } from "metabase/lib/redux";+import type { SuggestionModel } from "metabase/rich_text_editing/tiptap/extensions/shared/types";import { getUser } from "metabase/selectors/user";-import type { SuggestionModel } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/types";import { trackMetabotChatOpened } from "../analytics";import { useMetabotAgent } from "../hooks";diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotChat/MetabotChatEditor/MetabotChatEditor.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotChat/MetabotChatEditor/MetabotChatEditor.tsxindex 7b607ee5627..3b0501417ff 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotChat/MetabotChatEditor/MetabotChatEditor.tsx+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotChat/MetabotChatEditor/MetabotChatEditor.tsx@@ -12,16 +12,16 @@ import { t } from "ttag";import { useSelector } from "metabase/lib/redux";import type { MetabotChatInputRef } from "metabase/metabot";-import { getSetting } from "metabase/selectors/settings";-import { Box, Icon, UnstyledButton } from "metabase/ui";-import { createMentionSuggestion } from "metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion";+import { createMentionSuggestion } from "metabase/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion";import {MetabotMentionExtension,MetabotMentionPluginKey,-} from "metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotMention/MetabotMentionExtension";-import { SmartLink } from "metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode";-import type { SuggestionModel } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/types";-import { createSuggestionRenderer } from "metabase-enterprise/rich_text_editing/tiptap/extensions/suggestionRenderer";+} from "metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotMentionExtension";+import { SmartLink } from "metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode";+import type { SuggestionModel } from "metabase/rich_text_editing/tiptap/extensions/shared/types";+import { createSuggestionRenderer } from "metabase/rich_text_editing/tiptap/extensions/suggestionRenderer";+import { getSetting } from "metabase/selectors/settings";+import { Box, Icon, UnstyledButton } from "metabase/ui";import S from "./MetabotChatEditor.module.css";import {diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotChat/MetabotChatEditor/MetabotChatEditor.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotChat/MetabotChatEditor/MetabotChatEditor.unit.spec.tsxindex fabd344d567..6be1ef34a87 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotChat/MetabotChatEditor/MetabotChatEditor.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotChat/MetabotChatEditor/MetabotChatEditor.unit.spec.tsx@@ -9,7 +9,7 @@ import {import { setupSearchEndpoints } from "__support__/server-mocks/search";import { mockSettings } from "__support__/settings";import { renderWithProviders } from "__support__/ui";-import type { SuggestionModel } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/types";+import type { SuggestionModel } from "metabase/rich_text_editing/tiptap/extensions/shared/types";import { createMockCard, createMockUser } from "metabase-types/api/mocks";import { createSampleDatabase } from "metabase-types/api/mocks/presets";import { createMockSearchResult } from "metabase-types/api/mocks/search";diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotChat/MetabotChatEditor/utils.ts b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotChat/MetabotChatEditor/utils.tsindex 228bab44707..4cd3814566f 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotChat/MetabotChatEditor/utils.ts+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotChat/MetabotChatEditor/utils.ts@@ -4,8 +4,8 @@ import { match } from "ts-pattern";import {METABSE_PROTOCOL_MD_LINK,createMetabaseProtocolLink,-} from "metabase-enterprise/metabot/utils/links";-import { mbProtocolModelToSuggestionModel } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/suggestionUtils";+} from "metabase/metabot/utils/links";+import { mbProtocolModelToSuggestionModel } from "metabase/rich_text_editing/tiptap/extensions/shared/suggestionUtils";function serializeNodes(nodes: JSONContent[]): string {return nodes.map((node) => serializeNode(node)).join("");diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/index.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/index.tsxindex 2cd31a46ff0..00298752fa5 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/index.tsx+++ b/enterprise/frontend/src/metabase-enterprise/metabot/index.tsx@@ -4,6 +4,7 @@ import { t } from "ttag";import { createAdminRouteGuard } from "metabase/admin/utils";import { AdminSettingsLayout } from "metabase/common/components/AdminLayout/AdminSettingsLayout";import { PLUGIN_METABOT, PLUGIN_REDUCERS } from "metabase/plugins";+import { useLazyMetabotGenerateContentQuery } from "metabase-enterprise/api";import { MetabotPurchasePage } from "metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage";import { MetabotDataStudioSidebar } from "metabase-enterprise/metabot/components/MetabotDataStudioSidebar";import { hasPremiumFeature } from "metabase-enterprise/settings";@@ -12,6 +13,7 @@ import { Metabot } from "./components/Metabot";import { MetabotAdminPage } from "./components/MetabotAdmin/MetabotAdminPage";import { MetabotTrialPage } from "./components/MetabotAdmin/MetabotTrialPage";import { MetabotAppBarButton } from "./components/MetabotAppBarButton";+import MetabotThinkingStyles from "./components/MetabotChat/MetabotThinking.module.css";import { MetabotDataStudioButton } from "./components/MetabotDataStudioButton";import { getMetabotQuickLinks } from "./components/MetabotQuickLinks";import { MetabotToggleButton } from "./components/MetabotToggleButton";@@ -66,6 +68,9 @@ export function initializePlugin() {PLUGIN_METABOT.MetabotAppBarButton = MetabotAppBarButton;PLUGIN_METABOT.MetabotDataStudioButton = MetabotDataStudioButton;PLUGIN_METABOT.MetabotDataStudioSidebar = MetabotDataStudioSidebar;+ PLUGIN_METABOT.useLazyMetabotGenerateContentQuery =+ useLazyMetabotGenerateContentQuery;+ PLUGIN_METABOT.MetabotThinkingStyles = MetabotThinkingStyles;} else if (hasPremiumFeature("offer_metabase_ai_tiered")) {PLUGIN_METABOT.getAdminPaths = () => [{@@ -96,5 +101,8 @@ export function initializePlugin() {</Route></Route>);+ PLUGIN_METABOT.useLazyMetabotGenerateContentQuery =+ useLazyMetabotGenerateContentQuery;+ PLUGIN_METABOT.MetabotThinkingStyles = MetabotThinkingStyles;}}diff --git a/enterprise/frontend/src/metabase-enterprise/plugins.js b/enterprise/frontend/src/metabase-enterprise/plugins.jsindex a3b54afe513..9db99e40043 100644--- a/enterprise/frontend/src/metabase-enterprise/plugins.js+++ b/enterprise/frontend/src/metabase-enterprise/plugins.js@@ -24,7 +24,6 @@ import { initializePlugin as initializeDataStudio } from "./data-studio";import { initializePlugin as initializeDatabaseReplication } from "./database_replication";import { initializePlugin as initializeDatabaseRouting } from "./database_routing";import { initializePlugin as initializeDependencies } from "./dependencies";-import { initializePlugin as initializeDocuments } from "./documents";import { initializePlugin as initializeEmbedding } from "./embedding";import { initializePlugin as initializeEmbeddingSdk } from "./embedding-sdk";import { initializePlugin as initializeEmbeddingIframeSdk } from "./embedding_iframe_sdk";@@ -34,7 +33,6 @@ import { initializePlugin as initializeGroupManagers } from "./group_managers";import { initializePlugin as initializeMetabot } from "./metabot";import { initializePlugin as initializeModelPersistence } from "./model_persistence";import { initializePlugin as initializeModeration } from "./moderation";-import { initializePlugin as initializePublicSharing } from "./public-sharing";import { initializePlugin as initializeRemoteSync } from "./remote_sync";import { initializePlugin as initializeResourceDownloads } from "./resource_downloads";import { initializePlugin as initializeSandboxes } from "./sandboxes";@@ -91,10 +89,8 @@ export function initializePlugins() {initializeDatabaseReplication();initializeTableEditing();initializeDependencies();- initializeDocuments();initializeSemanticSearch();initializeTransforms();initializeTransformsPython();- initializePublicSharing();initializeSupport();}diff --git a/enterprise/frontend/src/metabase-enterprise/public-sharing/index.ts b/enterprise/frontend/src/metabase-enterprise/public-sharing/index.tsdeleted file mode 100644index 9559ca2b56a..00000000000--- a/enterprise/frontend/src/metabase-enterprise/public-sharing/index.ts+++ /dev/null@@ -1,12 +0,0 @@-import { PLUGIN_PUBLIC_SHARING } from "metabase/plugins";--import { PublicLinksDocumentListing } from "../admin/settings/components/widgets/PublicLinksListing/PublicDocumentResources";-import { PublicDocument } from "../public/containers/PublicDocument";--/**- * Initialize sharing plugin features that depend on hasPremiumFeature.- */-export function initializePlugin() {- PLUGIN_PUBLIC_SHARING.PublicDocumentRoute = PublicDocument;- PLUGIN_PUBLIC_SHARING.PublicLinksDocumentListing = PublicLinksDocumentListing;-}diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.tsindex 6c61f7099cf..17320ee8782 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.ts+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.ts@@ -5,11 +5,11 @@ import { Api } from "metabase/api";import { cardApi } from "metabase/api/card";import { collectionApi } from "metabase/api/collection";import { dashboardApi } from "metabase/api/dashboard";+import { documentApi } from "metabase/api/document";import { tag } from "metabase/api/tags";import { timelineApi } from "metabase/api/timeline";import { timelineEventApi } from "metabase/api/timeline-event";import { getCollectionFromCollectionsTree } from "metabase/selectors/collection";-import { documentApi } from "metabase-enterprise/api/document";import { remoteSyncApi } from "metabase-enterprise/api/remote-sync";import type {Card,diff --git a/enterprise/frontend/src/metabase-enterprise/transforms/index.tsx b/enterprise/frontend/src/metabase-enterprise/transforms/index.tsxindex b5e2418bad4..843eba53c03 100644--- a/enterprise/frontend/src/metabase-enterprise/transforms/index.tsx+++ b/enterprise/frontend/src/metabase-enterprise/transforms/index.tsx@@ -1,5 +1,6 @@import { PLUGIN_ENTITIES, PLUGIN_TRANSFORMS } from "metabase/plugins";import { getUserIsAdmin } from "metabase/selectors/user";+import { useGetTransformQuery } from "metabase-enterprise/api";import { Transforms } from "metabase-enterprise/entities/transforms";import { hasPremiumFeature } from "metabase-enterprise/settings";@@ -17,5 +18,6 @@ export function initializePlugin() {PLUGIN_TRANSFORMS.getDataStudioTransformRoutes =getDataStudioTransformRoutes;PLUGIN_TRANSFORMS.TransformPicker = TransformPicker;+ PLUGIN_TRANSFORMS.useGetTransformQuery = useGetTransformQuery;}}diff --git a/frontend/src/metabase-types/api/document.ts b/frontend/src/metabase-types/api/document.tsindex 03a8880cc18..031157a5068 100644--- a/frontend/src/metabase-types/api/document.ts+++ b/frontend/src/metabase-types/api/document.ts@@ -40,3 +40,5 @@ export type UpdateDocumentRequest = Pick<Document, "id"> &Partial<Omit<Document, "id">>;export type DeleteDocumentRequest = Pick<Document, "id">;++export type GetPublicDocument = Pick<Document, "id" | "name" | "public_uuid">;diff --git a/frontend/src/metabase-types/api/mocks/settings.ts b/frontend/src/metabase-types/api/mocks/settings.tsindex 950eecc976e..4687c248c2a 100644--- a/frontend/src/metabase-types/api/mocks/settings.ts+++ b/frontend/src/metabase-types/api/mocks/settings.ts@@ -138,7 +138,6 @@ export const createMockTokenFeatures = (database_routing: false,development_mode: false,table_data_editing: false,- documents: false,semantic_search: false,transforms: false,remote_sync: false,diff --git a/frontend/src/metabase-types/api/settings.ts b/frontend/src/metabase-types/api/settings.tsindex 9ba40ce3f9c..cd10ebd89b9 100644--- a/frontend/src/metabase-types/api/settings.ts+++ b/frontend/src/metabase-types/api/settings.ts@@ -326,7 +326,6 @@ export const tokenFeatures = ["table_data_editing","remote_sync","dependencies",- "documents","semantic_search","transforms","transforms-python",diff --git a/frontend/src/metabase-types/store/documents.ts b/frontend/src/metabase-types/store/documents.tsnew file mode 100644index 00000000000..4dc20f797ab--- /dev/null+++ b/frontend/src/metabase-types/store/documents.ts@@ -0,0 +1,24 @@+import type { Card, Document } from "metabase-types/api";++export interface CardEmbedRef {+ id: number;+ name?: string;+}++export interface MentionCacheItem {+ entityId: string;+ model: string;+ name: string;+}++export interface DocumentsState {+ selectedEmbedIndex: number | null;+ cardEmbeds: CardEmbedRef[];+ currentDocument: Document | null;+ draftCards: Record<number, Card>;+ mentionsCache: Record<string, MentionCacheItem>;+ isCommentSidebarOpen: boolean;+ childTargetId: string | undefined;+ hoveredChildTargetId: string | undefined;+ hasUnsavedChanges: boolean;+}diff --git a/frontend/src/metabase-types/store/state.ts b/frontend/src/metabase-types/store/state.tsindex 3def458ed3a..bc4f597a7a6 100644--- a/frontend/src/metabase-types/store/state.ts+++ b/frontend/src/metabase-types/store/state.ts@@ -2,6 +2,7 @@ import type { RouterState } from "react-router-redux";import type { Api } from "metabase/api/api";import type { User } from "metabase-types/api";+import type { DocumentsState } from "metabase-types/store/documents";import type { AdminState } from "./admin";import type { AppState } from "./app";@@ -48,6 +49,7 @@ export interface State {future: VisualizerState[];};"metabase-api": MetabaseApiState;+ documents: DocumentsState;}export type Dispatch<T = any> = (action: T) => unknown | Promise<unknown>;diff --git a/frontend/src/metabase/admin/settings/components/SettingsPages/PublicSharingSettingsPage.tsx b/frontend/src/metabase/admin/settings/components/SettingsPages/PublicSharingSettingsPage.tsxindex 4ca2f20af7e..fe3849f687d 100644--- a/frontend/src/metabase/admin/settings/components/SettingsPages/PublicSharingSettingsPage.tsx+++ b/frontend/src/metabase/admin/settings/components/SettingsPages/PublicSharingSettingsPage.tsx@@ -4,19 +4,18 @@ import {SettingsPageWrapper,SettingsSection,} from "metabase/admin/components/SettingsSection";-import { useHasTokenFeature, useSetting } from "metabase/common/hooks";-import { PLUGIN_PUBLIC_SHARING } from "metabase/plugins";+import { useSetting } from "metabase/common/hooks";import { AdminSettingInput } from "../widgets/AdminSettingInput";import {PublicLinksActionListing,PublicLinksDashboardListing,+ PublicLinksDocumentListing,PublicLinksQuestionListing,} from "../widgets/PublicLinksListing";export function PublicSharingSettingsPage() {const publicSharingEnabled = useSetting("enable-public-sharing");- const hasDocumentsFeature = useHasTokenFeature("documents");return (<SettingsPageWrapper title={t`Public sharing`}><SettingsSection>@@ -34,12 +33,9 @@ export function PublicSharingSettingsPage() {<SettingsSection title={t`Shared questions`}><PublicLinksQuestionListing /></SettingsSection>- {hasDocumentsFeature &&- PLUGIN_PUBLIC_SHARING.PublicLinksDocumentListing && (- <SettingsSection title={t`Shared documents`}>- <PLUGIN_PUBLIC_SHARING.PublicLinksDocumentListing />- </SettingsSection>- )}+ <SettingsSection title={t`Shared documents`}>+ <PublicLinksDocumentListing />+ </SettingsSection><SettingsSection title={t`Shared action forms`}><PublicLinksActionListing /></SettingsSection>diff --git a/frontend/src/metabase/admin/settings/components/SettingsPages/PublicSharingSettingsPage.unit.spec.tsx b/frontend/src/metabase/admin/settings/components/SettingsPages/PublicSharingSettingsPage.unit.spec.tsxindex 61e776247d4..a2922921a6f 100644--- a/frontend/src/metabase/admin/settings/components/SettingsPages/PublicSharingSettingsPage.unit.spec.tsx+++ b/frontend/src/metabase/admin/settings/components/SettingsPages/PublicSharingSettingsPage.unit.spec.tsx@@ -6,6 +6,7 @@ import {setupListPublicActionsEndpoint,setupListPublicCardsEndpoint,setupListPublicDashboardsEndpoint,+ setupListPublicDocumentsEndpoint,setupPropertiesEndpoints,setupSettingsEndpoints,setupUpdateSettingEndpoint,@@ -56,6 +57,13 @@ const setup = async (enablePublicSharing = false) => {public_uuid: "16a4568d-c328-4306-9c4b-ec8fbd6e4c8e",},]);+ setupListPublicDocumentsEndpoint([+ {+ name: "Test Document",+ id: 4,+ public_uuid: "3a9a7c46-ff19-4935-bfbe-4932d315732a",+ },+ ]);renderWithProviders(<div>@@ -80,9 +88,11 @@ describe("PublicSharingSettingsPage", () => {"Shared dashboards","Shared questions","Shared action forms",+ "Shared documents","Test Action","Test Dashboard","Test Question",+ "Test Document",].forEach((text) => {expect(screen.queryByText(text)).not.toBeInTheDocument();});@@ -95,9 +105,11 @@ describe("PublicSharingSettingsPage", () => {"Shared dashboards","Shared questions","Shared action forms",+ "Shared documents","Test Action","Test Dashboard","Test Question",+ "Test Document",].forEach((text) => {expect(screen.getByText(text)).toBeInTheDocument();});@@ -108,6 +120,7 @@ describe("PublicSharingSettingsPage", () => {expect(screen.queryByText("Shared Dashboards")).not.toBeInTheDocument();expect(screen.queryByText("Shared Questions")).not.toBeInTheDocument();expect(screen.queryByText("Shared Action Forms")).not.toBeInTheDocument();+ expect(screen.queryByText("Shared Documents")).not.toBeInTheDocument();// Toggle public sharing onconst toggle = await screen.findByRole("switch");diff --git a/enterprise/frontend/src/metabase-enterprise/admin/settings/components/widgets/PublicLinksListing/PublicDocumentResources.tsx b/frontend/src/metabase/admin/settings/components/widgets/PublicLinksListing/PublicDocumentResources.tsxsimilarity index 92%rename from enterprise/frontend/src/metabase-enterprise/admin/settings/components/widgets/PublicLinksListing/PublicDocumentResources.tsxrename to frontend/src/metabase/admin/settings/components/widgets/PublicLinksListing/PublicDocumentResources.tsxindex 8f6e27c00cd..232775312c5 100644--- a/enterprise/frontend/src/metabase-enterprise/admin/settings/components/widgets/PublicLinksListing/PublicDocumentResources.tsx+++ b/frontend/src/metabase/admin/settings/components/widgets/PublicLinksListing/PublicDocumentResources.tsx@@ -1,11 +1,11 @@import { t } from "ttag";-import { PublicLinksListing } from "metabase/admin/settings/components/widgets/PublicLinksListing";-import * as Urls from "metabase/lib/urls";+import { PublicLinksListing } from "metabase/admin/settings/components/widgets/PublicLinksListing/index";import {useDeleteDocumentPublicLinkMutation,useListPublicDocumentsQuery,-} from "metabase-enterprise/api";+} from "metabase/api";+import * as Urls from "metabase/lib/urls";import type { Document } from "metabase-types/api";export const PublicLinksDocumentListing = () => {diff --git a/frontend/src/metabase/admin/settings/components/widgets/PublicLinksListing/index.ts b/frontend/src/metabase/admin/settings/components/widgets/PublicLinksListing/index.tsindex b1c96261518..ce6b5be8f54 100644--- a/frontend/src/metabase/admin/settings/components/widgets/PublicLinksListing/index.ts+++ b/frontend/src/metabase/admin/settings/components/widgets/PublicLinksListing/index.ts@@ -1,3 +1,4 @@export * from "./PublicLinksListing";export * from "./EmbeddedResources";export * from "./PublicResources";+export * from "./PublicDocumentResources";diff --git a/enterprise/frontend/src/metabase-enterprise/api/comment.ts b/frontend/src/metabase/api/comment.tssimilarity index 81%rename from enterprise/frontend/src/metabase-enterprise/api/comment.tsrename to frontend/src/metabase/api/comment.tsindex 6afdaa8a73b..8a28207d685 100644--- a/enterprise/frontend/src/metabase-enterprise/api/comment.ts+++ b/frontend/src/metabase/api/comment.ts@@ -1,4 +1,11 @@-import { provideUserListTags } from "metabase/api/tags";+import { Api } from "metabase/api/api";+import {+ idTag,+ invalidateTags,+ listTag,+ provideCommentListTags,+ provideUserListTags,+} from "metabase/api/tags";import type {Comment,CommentId,@@ -10,10 +17,7 @@ import type {UpdateCommentRequest,} from "metabase-types/api";-import { EnterpriseApi } from "./api";-import { idTag, invalidateTags, listTag, provideCommentListTags } from "./tags";--export const commentApi = EnterpriseApi.injectEndpoints({+export const commentApi = Api.injectEndpoints({endpoints: (builder) => ({listComments: builder.query<{ comments: Comment[] },@@ -21,7 +25,7 @@ export const commentApi = EnterpriseApi.injectEndpoints({>({query: (params) => ({method: "GET",- url: "/api/ee/comment",+ url: "/api/comment",params,}),providesTags: (response) =>@@ -31,7 +35,7 @@ export const commentApi = EnterpriseApi.injectEndpoints({createComment: builder.mutation<Comment, CreateCommentRequest>({query: (body) => ({method: "POST",- url: `/api/ee/comment`,+ url: `/api/comment`,body,}),invalidatesTags: (_, error) =>@@ -41,7 +45,7 @@ export const commentApi = EnterpriseApi.injectEndpoints({updateComment: builder.mutation<Comment, UpdateCommentRequest>({query: ({ id, ...body }) => ({method: "PUT",- url: `/api/ee/comment/${id}`,+ url: `/api/comment/${id}`,body,}),invalidatesTags: (_, error, { id }) =>@@ -51,7 +55,7 @@ export const commentApi = EnterpriseApi.injectEndpoints({deleteComment: builder.mutation<void, CommentId>({query: (id) => ({method: "DELETE",- url: `/api/ee/comment/${id}`,+ url: `/api/comment/${id}`,}),invalidatesTags: (_, error, id) =>invalidateTags(error, [idTag("comment", id), listTag("comment")]),@@ -63,7 +67,7 @@ export const commentApi = EnterpriseApi.injectEndpoints({>({query: ({ id, emoji }) => ({method: "POST",- url: `/api/ee/comment/${id}/reaction`,+ url: `/api/comment/${id}/reaction`,body: { emoji },}),invalidatesTags: (_, error, { id }) =>@@ -76,7 +80,7 @@ export const commentApi = EnterpriseApi.injectEndpoints({>({query: (params) => ({method: "GET",- url: "/api/ee/comment/mentions",+ url: "/api/comment/mentions",params,}),providesTags: (response) =>diff --git a/enterprise/frontend/src/metabase-enterprise/api/document.ts b/frontend/src/metabase/api/document.tssimilarity index 83%rename from enterprise/frontend/src/metabase-enterprise/api/document.tsrename to frontend/src/metabase/api/document.tsindex a4d457a8438..593fd7e1c03 100644--- a/enterprise/frontend/src/metabase-enterprise/api/document.ts+++ b/frontend/src/metabase/api/document.ts@@ -1,20 +1,20 @@+import { Api } from "metabase/api/api";+import { idTag, listTag } from "metabase/api/tags";import type {CreateDocumentRequest,DeleteDocumentRequest,Document,GetDocumentRequest,+ GetPublicDocument,UpdateDocumentRequest,} from "metabase-types/api";-import { EnterpriseApi } from "./api";-import { idTag, listTag } from "./tags";--export const documentApi = EnterpriseApi.injectEndpoints({+export const documentApi = Api.injectEndpoints({endpoints: (builder) => ({getDocument: builder.query<Document, GetDocumentRequest>({query: ({ id }) => ({method: "GET",- url: `/api/ee/document/${id}`,+ url: `/api/document/${id}`,}),providesTags: (result, error, { id }) =>!error ? [idTag("document", id)] : [],@@ -22,7 +22,7 @@ export const documentApi = EnterpriseApi.injectEndpoints({createDocument: builder.mutation<Document, CreateDocumentRequest>({query: (body) => ({method: "POST",- url: "/api/ee/document",+ url: "/api/document",body,}),invalidatesTags: (_, error) => (error ? [] : [listTag("document")]),@@ -40,7 +40,7 @@ export const documentApi = EnterpriseApi.injectEndpoints({updateDocument: builder.mutation<Document, UpdateDocumentRequest>({query: (document) => ({method: "PUT",- url: `/api/ee/document/${document.id}`,+ url: `/api/document/${document.id}`,body: document,}),invalidatesTags: (_, error, { id }) =>@@ -49,18 +49,15 @@ export const documentApi = EnterpriseApi.injectEndpoints({deleteDocument: builder.mutation<void, DeleteDocumentRequest>({query: (document) => ({method: "DELETE",- url: `/api/ee/document/${document.id}`,+ url: `/api/document/${document.id}`,}),invalidatesTags: (_, error, { id }) =>!error ? [listTag("document"), idTag("document", id)] : [],}),- listPublicDocuments: builder.query<- Array<Pick<Document, "id" | "name" | "public_uuid">>,- void- >({+ listPublicDocuments: builder.query<GetPublicDocument[], void>({query: () => ({method: "GET",- url: "/api/ee/document/public",+ url: "/api/document/public",}),providesTags: (result = []) => [...result.map((res) => idTag("public-document", res.id)),@@ -73,7 +70,7 @@ export const documentApi = EnterpriseApi.injectEndpoints({>({query: ({ id }) => ({method: "POST",- url: `/api/ee/document/${id}/public-link`,+ url: `/api/document/${id}/public-link`,}),invalidatesTags: (_, error, { id }) =>!error ? [listTag("public-document"), idTag("document", id)] : [],@@ -88,7 +85,7 @@ export const documentApi = EnterpriseApi.injectEndpoints({>({query: ({ id }) => ({method: "DELETE",- url: `/api/ee/document/${id}/public-link`,+ url: `/api/document/${id}/public-link`,}),transformResponse: (_baseQueryReturnValue, _meta, { id }) => ({ id }),invalidatesTags: (_, error, { id }) =>diff --git a/frontend/src/metabase/api/index.ts b/frontend/src/metabase/api/index.tsindex d93f667c22e..61c3f5a61ae 100644--- a/frontend/src/metabase/api/index.ts+++ b/frontend/src/metabase/api/index.ts@@ -9,9 +9,11 @@ export * from "./card";export * from "./channel";export * from "./cloud-migration";export * from "./collection";+export * from "./comment";export * from "./dashboard";export * from "./database";export * from "./dataset";+export * from "./document";export * from "./glossary";export * from "./entity-id";export * from "./field";diff --git a/frontend/src/metabase/api/tags/constants.ts b/frontend/src/metabase/api/tags/constants.tsindex 7f6be88a44b..b70b6f06499 100644--- a/frontend/src/metabase/api/tags/constants.ts+++ b/frontend/src/metabase/api/tags/constants.ts@@ -16,6 +16,8 @@ export const TAG_TYPES = ["database","dataset","document",+ "public-document",+ "comment","embedding-hub-checklist","field","field-values",diff --git a/frontend/src/metabase/api/tags/utils.ts b/frontend/src/metabase/api/tags/utils.tsindex ef74a034ad4..617f7b3ec30 100644--- a/frontend/src/metabase/api/tags/utils.ts+++ b/frontend/src/metabase/api/tags/utils.ts@@ -11,6 +11,7 @@ import type {Collection,CollectionItem,CollectionItemModel,+ Comment,Dashboard,DashboardQueryMetadata,DashboardSubscription,@@ -655,3 +656,19 @@ export function provideUserKeyValueTags({}: GetUserKeyValueRequest) {return [{ type: "user-key-value" as const, id: `${namespace}#${key}` }];}++export function provideCommentListTags(+ comments: Comment[],+): TagDescription<TagType>[] {+ return [listTag("comment"), ...comments.flatMap(provideCommentTags)];+}++export function provideCommentTags(+ comment: Comment,+): TagDescription<TagType>[] {+ if (comment.creator) {+ return [idTag("comment", comment.id), ...provideUserTags(comment.creator)];+ }++ return [idTag("comment", comment.id)];+}diff --git a/enterprise/frontend/src/metabase-enterprise/comments/components/CommentEditor/CommentEditor.module.css b/frontend/src/metabase/comments/components/CommentEditor/CommentEditor.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/comments/components/CommentEditor/CommentEditor.module.cssrename to frontend/src/metabase/comments/components/CommentEditor/CommentEditor.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/comments/components/CommentEditor/CommentEditor.tsx b/frontend/src/metabase/comments/components/CommentEditor/CommentEditor.tsxsimilarity index 84%rename from enterprise/frontend/src/metabase-enterprise/comments/components/CommentEditor/CommentEditor.tsxrename to frontend/src/metabase/comments/components/CommentEditor/CommentEditor.tsxindex 546d96e1f88..b426331cd9d 100644--- a/enterprise/frontend/src/metabase-enterprise/comments/components/CommentEditor/CommentEditor.tsx+++ b/frontend/src/metabase/comments/components/CommentEditor/CommentEditor.tsx@@ -9,18 +9,18 @@ import { t } from "ttag";import CS from "metabase/css/core/index.css";import { METAKEY } from "metabase/lib/browser";import { useSelector } from "metabase/lib/redux";+import { EditorBubbleMenu } from "metabase/rich_text_editing/tiptap/components/EditorBubbleMenu/EditorBubbleMenu";+import type { FormattingOptions } from "metabase/rich_text_editing/tiptap/components/EditorBubbleMenu/types";+import { CustomStarterKit } from "metabase/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit";+import { DisableMetabotSidebar } from "metabase/rich_text_editing/tiptap/extensions/DisableMetabotSidebar";+import { EmojiSuggestionExtension } from "metabase/rich_text_editing/tiptap/extensions/Emoji/EmojiSuggestionExtension";+import { MentionExtension } from "metabase/rich_text_editing/tiptap/extensions/Mention/MentionExtension";+import { createMentionSuggestion } from "metabase/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion";+import { SmartLink } from "metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode";+import { LINK_SEARCH_MODELS } from "metabase/rich_text_editing/tiptap/extensions/shared/constants";+import { createSuggestionRenderer } from "metabase/rich_text_editing/tiptap/extensions/suggestionRenderer";import { getSetting } from "metabase/selectors/settings";import { ActionIcon, Box, Flex, Icon, Tooltip } from "metabase/ui";-import { EditorBubbleMenu } from "metabase-enterprise/rich_text_editing/tiptap/components/EditorBubbleMenu/EditorBubbleMenu";-import type { FormattingOptions } from "metabase-enterprise/rich_text_editing/tiptap/components/EditorBubbleMenu/types";-import { CustomStarterKit } from "metabase-enterprise/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit";-import { DisableMetabotSidebar } from "metabase-enterprise/rich_text_editing/tiptap/extensions/DisableMetabotSidebar";-import { EmojiSuggestionExtension } from "metabase-enterprise/rich_text_editing/tiptap/extensions/Emoji/EmojiSuggestionExtension";-import { MentionExtension } from "metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionExtension";-import { createMentionSuggestion } from "metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion";-import { SmartLink } from "metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode";-import { LINK_SEARCH_MODELS } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/constants";-import { createSuggestionRenderer } from "metabase-enterprise/rich_text_editing/tiptap/extensions/suggestionRenderer";import type { DocumentContent } from "metabase-types/api";import S from "./CommentEditor.module.css";diff --git a/enterprise/frontend/src/metabase-enterprise/comments/components/CommentEditor/index.ts b/frontend/src/metabase/comments/components/CommentEditor/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/comments/components/CommentEditor/index.tsrename to frontend/src/metabase/comments/components/CommentEditor/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/Discussion.module.css b/frontend/src/metabase/comments/components/Discussion/Discussion.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/Discussion.module.cssrename to frontend/src/metabase/comments/components/Discussion/Discussion.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/Discussion.tsx b/frontend/src/metabase/comments/components/Discussion/Discussion.tsxsimilarity index 96%rename from enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/Discussion.tsxrename to frontend/src/metabase/comments/components/Discussion/Discussion.tsxindex 7213d576083..5d5959c3579 100644--- a/enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/Discussion.tsx+++ b/frontend/src/metabase/comments/components/Discussion/Discussion.tsx@@ -2,17 +2,17 @@ import { useState } from "react";import { t } from "ttag";import { getCurrentUser } from "metabase/admin/datamodel/selectors";-import { useToast } from "metabase/common/hooks";-import { useDispatch, useSelector } from "metabase/lib/redux";-import { Avatar, Stack, Timeline, rem } from "metabase/ui";import {useCreateCommentMutation,useDeleteCommentMutation,useToggleReactionMutation,useUpdateCommentMutation,-} from "metabase-enterprise/api";-import { getCommentsUrl } from "metabase-enterprise/comments/utils";-import { setHoveredChildTargetId } from "metabase-enterprise/documents/documents.slice";+} from "metabase/api";+import { getCommentsUrl } from "metabase/comments/utils";+import { useToast } from "metabase/common/hooks";+import { setHoveredChildTargetId } from "metabase/documents/documents.slice";+import { useDispatch, useSelector } from "metabase/lib/redux";+import { Avatar, Stack, Timeline, rem } from "metabase/ui";import type {Comment,CommentEntityType,diff --git a/enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/DiscussionActionPanel.tsx b/frontend/src/metabase/comments/components/Discussion/DiscussionActionPanel.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/DiscussionActionPanel.tsxrename to frontend/src/metabase/comments/components/Discussion/DiscussionActionPanel.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/DiscussionComment.tsx b/frontend/src/metabase/comments/components/Discussion/DiscussionComment.tsxsimilarity index 97%rename from enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/DiscussionComment.tsxrename to frontend/src/metabase/comments/components/Discussion/DiscussionComment.tsxindex 690fc5727f0..89bc06eb93f 100644--- a/enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/DiscussionComment.tsx+++ b/frontend/src/metabase/comments/components/Discussion/DiscussionComment.tsx@@ -5,12 +5,9 @@ import { useLocation } from "react-use";import { t } from "ttag";import { getCurrentUser } from "metabase/admin/datamodel/selectors";+import { formatCommentDate, getCommentNodeId } from "metabase/comments/utils";import { useSelector } from "metabase/lib/redux";import { Avatar, Box, Group, Icon, Text, Timeline, Tooltip } from "metabase/ui";-import {- formatCommentDate,- getCommentNodeId,-} from "metabase-enterprise/comments/utils";import type { Comment, DocumentContent } from "metabase-types/api";import { CommentEditor } from "../CommentEditor";diff --git a/enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/DiscussionReactions.tsx b/frontend/src/metabase/comments/components/Discussion/DiscussionReactions.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/DiscussionReactions.tsxrename to frontend/src/metabase/comments/components/Discussion/DiscussionReactions.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/Reaction.tsx b/frontend/src/metabase/comments/components/Discussion/Reaction.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/Reaction.tsxrename to frontend/src/metabase/comments/components/Discussion/Reaction.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/index.ts b/frontend/src/metabase/comments/components/Discussion/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/comments/components/Discussion/index.tsrename to frontend/src/metabase/comments/components/Discussion/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/comments/components/Discussions/Discussions.tsx b/frontend/src/metabase/comments/components/Discussions/Discussions.tsxsimilarity index 93%rename from enterprise/frontend/src/metabase-enterprise/comments/components/Discussions/Discussions.tsxrename to frontend/src/metabase/comments/components/Discussions/Discussions.tsxindex 98c2fb2f658..d2f17c524a5 100644--- a/enterprise/frontend/src/metabase-enterprise/comments/components/Discussions/Discussions.tsx+++ b/frontend/src/metabase/comments/components/Discussions/Discussions.tsx@@ -1,7 +1,7 @@import { Fragment, useMemo } from "react";+import { getCommentThreads } from "metabase/comments/utils";import { Box, Stack } from "metabase/ui";-import { getCommentThreads } from "metabase-enterprise/comments/utils";import type { Comment } from "metabase-types/api/comments";import { Discussion } from "../Discussion";diff --git a/enterprise/frontend/src/metabase-enterprise/comments/components/Discussions/index.ts b/frontend/src/metabase/comments/components/Discussions/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/comments/components/Discussions/index.tsrename to frontend/src/metabase/comments/components/Discussions/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/comments/components/index.ts b/frontend/src/metabase/comments/components/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/comments/components/index.tsrename to frontend/src/metabase/comments/components/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/comments/types.ts b/frontend/src/metabase/comments/types.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/comments/types.tsrename to frontend/src/metabase/comments/types.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/comments/utils.ts b/frontend/src/metabase/comments/utils.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/comments/utils.tsrename to frontend/src/metabase/comments/utils.tsdiff --git a/frontend/src/metabase/common/components/NewItemMenu/NewItemMenuView.tsx b/frontend/src/metabase/common/components/NewItemMenu/NewItemMenuView.tsxindex 2275a3f71b6..c8e294011de 100644--- a/frontend/src/metabase/common/components/NewItemMenu/NewItemMenuView.tsx+++ b/frontend/src/metabase/common/components/NewItemMenu/NewItemMenuView.tsx@@ -5,7 +5,6 @@ import { t } from "ttag";import { ForwardRefLink } from "metabase/common/components/Link";import { useDispatch, useSelector } from "metabase/lib/redux";import * as Urls from "metabase/lib/urls";-import { PLUGIN_DOCUMENTS } from "metabase/plugins";import { setOpenModal } from "metabase/redux/ui";import { getSetting } from "metabase/selectors/settings";import { Box, Icon, Menu } from "metabase/ui";@@ -90,18 +89,16 @@ const NewItemMenuView = ({</Menu.Item>,);- if (PLUGIN_DOCUMENTS.shouldShowDocumentInNewItemMenu()) {- items.push(- <Menu.Item- key="document"- component={ForwardRefLink}- to="/document/new"- leftSection={<Icon name="document" />}- >- {t`Document`}- </Menu.Item>,- );- }+ items.push(+ <Menu.Item+ key="document"+ component={ForwardRefLink}+ to="/document/new"+ leftSection={<Icon name="document" />}+ >+ {t`Document`}+ </Menu.Item>,+ );return items;}, [diff --git a/frontend/src/metabase/dashboard/actions/tabs.ts b/frontend/src/metabase/dashboard/actions/tabs.tsindex 8433246cb72..52bac18e843 100644--- a/frontend/src/metabase/dashboard/actions/tabs.ts+++ b/frontend/src/metabase/dashboard/actions/tabs.ts@@ -219,9 +219,7 @@ export function getPrevDashAndTabs({filterRemovedTabs?: boolean;}) {const dashId = state.dashboardId;- const prevDash =- // @ts-expect-error - possibly infinite type error- dashId ? state.dashboards[dashId] : null;+ const prevDash = dashId ? state.dashboards[dashId] : null;const prevTabs =prevDash?.tabs?.filter((t) => !filterRemovedTabs || !t.isRemoved) ?? [];diff --git a/enterprise/frontend/src/metabase-enterprise/documents/CLAUDE.md b/frontend/src/metabase/documents/CLAUDE.mdsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/CLAUDE.mdrename to frontend/src/metabase/documents/CLAUDE.mddiff --git a/enterprise/frontend/src/metabase-enterprise/documents/actions.ts b/frontend/src/metabase/documents/actions.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/actions.tsrename to frontend/src/metabase/documents/actions.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/analytics.ts b/frontend/src/metabase/documents/analytics.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/analytics.tsrename to frontend/src/metabase/documents/analytics.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.module.css b/frontend/src/metabase/documents/components/CommentsSidesheet/CommentsSidesheet.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.module.cssrename to frontend/src/metabase/documents/components/CommentsSidesheet/CommentsSidesheet.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.tsx b/frontend/src/metabase/documents/components/CommentsSidesheet/CommentsSidesheet.tsxsimilarity index 93%rename from enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.tsxrename to frontend/src/metabase/documents/components/CommentsSidesheet/CommentsSidesheet.tsxindex 5afbae28a58..f19cd952247 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/CommentsSidesheet.tsx+++ b/frontend/src/metabase/documents/components/CommentsSidesheet/CommentsSidesheet.tsx@@ -4,8 +4,19 @@ import { useLatest, useLocation } from "react-use";import { t } from "ttag";import noResultsSource from "assets/img/no_results.svg";+import { useCreateCommentMutation, useListCommentsQuery } from "metabase/api";+import { CommentEditor } from "metabase/comments/components";+import { Discussions } from "metabase/comments/components/Discussions";+import {+ deleteNewParamFromURLIfNeeded,+ getCommentNodeId,+ getCommentsCount,+} from "metabase/comments/utils";import { useToast } from "metabase/common/hooks";import Animation from "metabase/css/core/animation.module.css";+import { useDocumentState } from "metabase/documents/hooks/use-document-state";+import { getCurrentDocument } from "metabase/documents/selectors";+import { getListCommentsQuery } from "metabase/documents/utils/api";import { useDispatch, useSelector } from "metabase/lib/redux";import {ActionIcon,@@ -17,20 +28,6 @@ import {Text,Title,} from "metabase/ui";-import {- useCreateCommentMutation,- useListCommentsQuery,-} from "metabase-enterprise/api";-import { CommentEditor } from "metabase-enterprise/comments/components";-import { Discussions } from "metabase-enterprise/comments/components/Discussions";-import {- deleteNewParamFromURLIfNeeded,- getCommentNodeId,- getCommentsCount,-} from "metabase-enterprise/comments/utils";-import { useDocumentState } from "metabase-enterprise/documents/hooks/use-document-state";-import { getCurrentDocument } from "metabase-enterprise/documents/selectors";-import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";import type { Comment, DocumentContent } from "metabase-types/api";import S from "./CommentsSidesheet.module.css";diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/index.ts b/frontend/src/metabase/documents/components/CommentsSidesheet/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/CommentsSidesheet/index.tsrename to frontend/src/metabase/documents/components/CommentsSidesheet/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentArchivedEntityBanner.tsx b/frontend/src/metabase/documents/components/DocumentArchivedEntityBanner.tsxsimilarity index 95%rename from enterprise/frontend/src/metabase-enterprise/documents/components/DocumentArchivedEntityBanner.tsxrename to frontend/src/metabase/documents/components/DocumentArchivedEntityBanner.tsxindex 53f37b46e8c..505c3d06ec1 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentArchivedEntityBanner.tsx+++ b/frontend/src/metabase/documents/components/DocumentArchivedEntityBanner.tsx@@ -3,8 +3,8 @@ import { t } from "ttag";import { deletePermanently } from "metabase/archive/actions";import { ArchivedEntityBanner } from "metabase/archive/components/ArchivedEntityBanner/ArchivedEntityBanner";import Bookmarks from "metabase/entities/bookmarks";+import Documents from "metabase/entities/documents";import { useDispatch, useSelector } from "metabase/lib/redux";-import Documents from "metabase-enterprise/entities/documents";import { getCurrentDocument } from "../selectors";diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentCopyForm/DocumentCopyForm.tsx b/frontend/src/metabase/documents/components/DocumentCopyForm/DocumentCopyForm.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/DocumentCopyForm/DocumentCopyForm.tsxrename to frontend/src/metabase/documents/components/DocumentCopyForm/DocumentCopyForm.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentHeader.module.css b/frontend/src/metabase/documents/components/DocumentHeader.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/DocumentHeader.module.cssrename to frontend/src/metabase/documents/components/DocumentHeader.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentHeader.tsx b/frontend/src/metabase/documents/components/DocumentHeader.tsxsimilarity index 95%rename from enterprise/frontend/src/metabase-enterprise/documents/components/DocumentHeader.tsxrename to frontend/src/metabase/documents/components/DocumentHeader.tsxindex 9f88e982ed6..6e95181b976 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentHeader.tsx+++ b/frontend/src/metabase/documents/components/DocumentHeader.tsx@@ -5,7 +5,7 @@ import { t } from "ttag";import DateTime, {getFormattedTime,} from "metabase/common/components/DateTime";-import { useHasTokenFeature, useSetting } from "metabase/common/hooks";+import { useSetting } from "metabase/common/hooks";import CS from "metabase/css/core/index.css";import { isWithinIframe } from "metabase/lib/dom";import { useSelector } from "metabase/lib/redux";@@ -23,9 +23,9 @@ import {Transition,type TransitionProps,} from "metabase/ui";-import { DocumentPublicLinkPopover } from "metabase-enterprise/embedding/components/PublicLinkPopover";import type { Document } from "metabase-types/api";+import { DocumentPublicLinkPopover } from "../../embedding/components/PublicLinkPopover";import { trackDocumentPrint } from "../analytics";import { DOCUMENT_TITLE_MAX_LENGTH } from "../constants";@@ -69,12 +69,10 @@ export const DocumentHeader = ({hasComments = false,}: DocumentHeaderProps) => {const isPublicSharingEnabled = useSetting("enable-public-sharing");- const hasDocumentsFeature = useHasTokenFeature("documents");const isAdmin = useSelector(getUserIsAdmin);const [isPublicLinkPopoverOpen, setIsPublicLinkPopoverOpen] = useState(false);const hasPublicLink = !!document?.public_uuid;- const canUsePublicSharing = isPublicSharingEnabled && hasDocumentsFeature;const handlePrint = useCallback(() => {window.print();@@ -199,13 +197,13 @@ export const DocumentHeader = ({<Menu.ItemleftSection={<Icon name="link" />}onClick={() => setIsPublicLinkPopoverOpen(true)}- {...(!canUsePublicSharing && {+ {...(!isPublicSharingEnabled && {onClick: undefined,component: "div",disabled: true,})}>- {canUsePublicSharing ? (+ {isPublicSharingEnabled ? (hasPublicLink ? (t`Public link`) : (diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentHeader.unit.spec.tsx b/frontend/src/metabase/documents/components/DocumentHeader.unit.spec.tsxsimilarity index 97%rename from enterprise/frontend/src/metabase-enterprise/documents/components/DocumentHeader.unit.spec.tsxrename to frontend/src/metabase/documents/components/DocumentHeader.unit.spec.tsxindex 59e91a6fa55..e61c1a68b52 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentHeader.unit.spec.tsx+++ b/frontend/src/metabase/documents/components/DocumentHeader.unit.spec.tsx@@ -1,11 +1,7 @@import userEvent from "@testing-library/user-event";import { renderWithProviders, screen } from "__support__/ui";-import {- createMockDocument,- createMockTokenFeatures,- createMockUser,-} from "metabase-types/api/mocks";+import { createMockDocument, createMockUser } from "metabase-types/api/mocks";import { DOCUMENT_TITLE_MAX_LENGTH } from "../constants";@@ -53,7 +49,6 @@ const setup = ({settings: {values: {"enable-public-sharing": isPublicSharingEnabled,- "token-features": createMockTokenFeatures({ documents: true }),} as any,loading: false,},diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.module.css b/frontend/src/metabase/documents/components/DocumentPage.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.module.cssrename to frontend/src/metabase/documents/components/DocumentPage.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx b/frontend/src/metabase/documents/components/DocumentPage.tsxsimilarity index 99%rename from enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsxrename to frontend/src/metabase/documents/components/DocumentPage.tsxindex 66155eec534..4fb9dad49d9 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx+++ b/frontend/src/metabase/documents/components/DocumentPage.tsx@@ -14,8 +14,12 @@ import _ from "underscore";import {skipToken,useCreateBookmarkMutation,+ useCreateDocumentMutation,useDeleteBookmarkMutation,+ useGetDocumentQuery,useListBookmarksQuery,+ useListCommentsQuery,+ useUpdateDocumentMutation,} from "metabase/api";import { canonicalCollectionId } from "metabase/collections/utils";import {@@ -30,12 +34,6 @@ import { useDispatch, useSelector } from "metabase/lib/redux";import { extractEntityId } from "metabase/lib/urls";import { setErrorPage } from "metabase/redux/app";import { Box } from "metabase/ui";-import {- useCreateDocumentMutation,- useGetDocumentQuery,- useListCommentsQuery,- useUpdateDocumentMutation,-} from "metabase-enterprise/api";import type {Card,CollectionId,diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.unit.spec.tsx b/frontend/src/metabase/documents/components/DocumentPage.unit.spec.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.unit.spec.tsxrename to frontend/src/metabase/documents/components/DocumentPage.unit.spec.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/CommentsMenu/CommentsMenu.module.css b/frontend/src/metabase/documents/components/Editor/CommentsMenu/CommentsMenu.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/CommentsMenu/CommentsMenu.module.cssrename to frontend/src/metabase/documents/components/Editor/CommentsMenu/CommentsMenu.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/CommentsMenu/CommentsMenu.tsx b/frontend/src/metabase/documents/components/Editor/CommentsMenu/CommentsMenu.tsxsimilarity index 90%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/CommentsMenu/CommentsMenu.tsxrename to frontend/src/metabase/documents/components/Editor/CommentsMenu/CommentsMenu.tsxindex 2a089670289..ffea5a0d27e 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/CommentsMenu/CommentsMenu.tsx+++ b/frontend/src/metabase/documents/components/Editor/CommentsMenu/CommentsMenu.tsx@@ -2,10 +2,10 @@ import cx from "classnames";import { type CSSProperties, forwardRef, useMemo } from "react";import { createPortal } from "react-dom";+import type { CommentThread } from "metabase/comments/types";import { ForwardRefLink } from "metabase/common/components/Link";+import { CommentsButton } from "metabase/rich_text_editing/tiptap/components/CommentsButton";import { Box, rem } from "metabase/ui";-import type { CommentThread } from "metabase-enterprise/comments/types";-import { CommentsButton } from "metabase-enterprise/rich_text_editing/tiptap/components/CommentsButton";import S from "./CommentsMenu.module.css";diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/CommentsMenu/index.ts b/frontend/src/metabase/documents/components/Editor/CommentsMenu/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/CommentsMenu/index.tsrename to frontend/src/metabase/documents/components/Editor/CommentsMenu/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/Editor.module.css b/frontend/src/metabase/documents/components/Editor/Editor.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/Editor.module.cssrename to frontend/src/metabase/documents/components/Editor/Editor.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/Editor.stories.tsx b/frontend/src/metabase/documents/components/Editor/Editor.stories.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/Editor.stories.tsxrename to frontend/src/metabase/documents/components/Editor/Editor.stories.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/Editor.tsx b/frontend/src/metabase/documents/components/Editor/Editor.tsxsimilarity index 71%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/Editor.tsxrename to frontend/src/metabase/documents/components/Editor/Editor.tsxindex c96e82363a0..f6fcccb9c58 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/Editor.tsx+++ b/frontend/src/metabase/documents/components/Editor/Editor.tsx@@ -9,41 +9,41 @@ import { useLatest, usePrevious } from "react-use";import { t } from "ttag";import { DND_IGNORE_CLASS_NAME } from "metabase/common/components/dnd";+import { getMentionsCache } from "metabase/documents/selectors";+import { isMetabotBlock } from "metabase/documents/utils/editorNodeUtils";+import { getMentionsCacheKey } from "metabase/documents/utils/mentionsUtils";import { useSelector, useStore } from "metabase/lib/redux";-import { getSetting } from "metabase/selectors/settings";-import { Box, Loader } from "metabase/ui";-import { getMentionsCache } from "metabase-enterprise/documents/selectors";-import type { DocumentsStoreState } from "metabase-enterprise/documents/types";-import { isMetabotBlock } from "metabase-enterprise/documents/utils/editorNodeUtils";-import { getMentionsCacheKey } from "metabase-enterprise/documents/utils/mentionsUtils";-import { EditorBubbleMenu } from "metabase-enterprise/rich_text_editing/tiptap/components/EditorBubbleMenu/EditorBubbleMenu";-import { CardEmbed } from "metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode";-import { CommandExtension } from "metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandExtension";-import { CommandSuggestion } from "metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandSuggestion";-import { CustomStarterKit } from "metabase-enterprise/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit";-import { DisableMetabotSidebar } from "metabase-enterprise/rich_text_editing/tiptap/extensions/DisableMetabotSidebar";-import DropCursorS from "metabase-enterprise/rich_text_editing/tiptap/extensions/DropCursor/DropCursor.module.css";-import { FlexContainer } from "metabase-enterprise/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer";-import { HandleEditorDrop } from "metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/HandleEditorDrop";-import { LinkHoverMenu } from "metabase-enterprise/rich_text_editing/tiptap/extensions/LinkHoverMenu/LinkHoverMenu";-import { MentionExtension } from "metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionExtension";-import { MentionSuggestion } from "metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion";+import { EditorBubbleMenu } from "metabase/rich_text_editing/tiptap/components/EditorBubbleMenu/EditorBubbleMenu";+import { CardEmbed } from "metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode";+import { CommandExtension } from "metabase/rich_text_editing/tiptap/extensions/Command/CommandExtension";+import { CommandSuggestion } from "metabase/rich_text_editing/tiptap/extensions/Command/CommandSuggestion";+import { CustomStarterKit } from "metabase/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit";+import { DisableMetabotSidebar } from "metabase/rich_text_editing/tiptap/extensions/DisableMetabotSidebar";+import DropCursorS from "metabase/rich_text_editing/tiptap/extensions/DropCursor/DropCursor.module.css";+import { FlexContainer } from "metabase/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer";+import { HandleEditorDrop } from "metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/HandleEditorDrop";+import { LinkHoverMenu } from "metabase/rich_text_editing/tiptap/extensions/LinkHoverMenu/LinkHoverMenu";+import { MentionExtension } from "metabase/rich_text_editing/tiptap/extensions/Mention/MentionExtension";+import { MentionSuggestion } from "metabase/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion";import {MetabotNode,type PromptSerializer,-} from "metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotEmbed";-import { MetabotMentionExtension } from "metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotMention/MetabotMentionExtension";-import { MetabotMentionSuggestion } from "metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion";-import { PlainLink } from "metabase-enterprise/rich_text_editing/tiptap/extensions/PlainLink/PlainLink";-import { ResizeNode } from "metabase-enterprise/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode";-import { SmartLink } from "metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode";-import { SupportingText } from "metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText";-import { DROP_ZONE_COLOR } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/constants";-import { createSuggestionRenderer } from "metabase-enterprise/rich_text_editing/tiptap/extensions/suggestionRenderer";+} from "metabase/rich_text_editing/tiptap/extensions/MetabotEmbed";+import { MetabotMentionExtension } from "metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotMentionExtension";+import { MetabotMentionSuggestion } from "metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion";+import { PlainLink } from "metabase/rich_text_editing/tiptap/extensions/PlainLink/PlainLink";+import { ResizeNode } from "metabase/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode";+import { SmartLink } from "metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode";+import { SupportingText } from "metabase/rich_text_editing/tiptap/extensions/SupportingText/SupportingText";+import { DROP_ZONE_COLOR } from "metabase/rich_text_editing/tiptap/extensions/shared/constants";+import { createSuggestionRenderer } from "metabase/rich_text_editing/tiptap/extensions/suggestionRenderer";+import { getSetting } from "metabase/selectors/settings";+import { Box, Loader } from "metabase/ui";+import type { State } from "metabase-types/store";+import type { CardEmbedRef } from "metabase-types/store/documents";import S from "./Editor.module.css";import { useCardEmbedsTracking, useQuestionSelection } from "./hooks";-import type { CardEmbedRef } from "./types";const BUBBLE_MENU_DISALLOWED_NODES: string[] = [CardEmbed.name,@@ -58,7 +58,7 @@ const BUBBLE_MENU_DISALLOWED_FULLY_SELECTED_NODES: string[] = [];const getMetabotPromptSerializer =- (getState: () => DocumentsStoreState): PromptSerializer =>+ (getState: () => State): PromptSerializer =>(node) => {const payload: ReturnType<PromptSerializer> = { instructions: "" };return node.content.content.reduce((acc, child) => {diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/constants.ts b/frontend/src/metabase/documents/components/Editor/constants.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/constants.tsrename to frontend/src/metabase/documents/components/Editor/constants.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/data/data.json b/frontend/src/metabase/documents/components/Editor/data/data.jsonsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/data/data.jsonrename to frontend/src/metabase/documents/components/Editor/data/data.jsondiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/hooks/index.ts b/frontend/src/metabase/documents/components/Editor/hooks/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/hooks/index.tsrename to frontend/src/metabase/documents/components/Editor/hooks/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/hooks/useCardEmbedSelection.ts b/frontend/src/metabase/documents/components/Editor/hooks/useCardEmbedSelection.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/hooks/useCardEmbedSelection.tsrename to frontend/src/metabase/documents/components/Editor/hooks/useCardEmbedSelection.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/hooks/useCardEmbedsTracking.ts b/frontend/src/metabase/documents/components/Editor/hooks/useCardEmbedsTracking.tssimilarity index 96%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/hooks/useCardEmbedsTracking.tsrename to frontend/src/metabase/documents/components/Editor/hooks/useCardEmbedsTracking.tsindex 0dce42631d1..6162a9fb002 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/hooks/useCardEmbedsTracking.ts+++ b/frontend/src/metabase/documents/components/Editor/hooks/useCardEmbedsTracking.ts@@ -1,7 +1,7 @@import type { Editor as TiptapEditor } from "@tiptap/react";import { useEffect } from "react";-import type { CardEmbedRef } from "../types";+import type { CardEmbedRef } from "metabase-types/store/documents";/*** Extracts all question references from the editor document.diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/index.ts b/frontend/src/metabase/documents/components/Editor/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/index.tsrename to frontend/src/metabase/documents/components/Editor/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/shared/MenuComponents.tsx b/frontend/src/metabase/documents/components/Editor/shared/MenuComponents.tsxsimilarity index 96%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/shared/MenuComponents.tsxrename to frontend/src/metabase/documents/components/Editor/shared/MenuComponents.tsxindex 69fbac8c418..2f09fcf51fa 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/shared/MenuComponents.tsx+++ b/frontend/src/metabase/documents/components/Editor/shared/MenuComponents.tsx@@ -1,6 +1,7 @@import type { DOMAttributes, MouseEvent } from "react";import { t } from "ttag";+import type { SuggestionModel } from "metabase/rich_text_editing/tiptap/extensions/shared/types";import {Avatar,Group,@@ -10,7 +11,6 @@ import {Text,UnstyledButton,} from "metabase/ui";-import type { SuggestionModel } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/types";import S from "./MenuItems.module.css";diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/shared/MenuItems.module.css b/frontend/src/metabase/documents/components/Editor/shared/MenuItems.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/shared/MenuItems.module.cssrename to frontend/src/metabase/documents/components/Editor/shared/MenuItems.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/shared/SuggestionPaper.module.css b/frontend/src/metabase/documents/components/Editor/shared/SuggestionPaper.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/shared/SuggestionPaper.module.cssrename to frontend/src/metabase/documents/components/Editor/shared/SuggestionPaper.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/shared/SuggestionPaper.tsx b/frontend/src/metabase/documents/components/Editor/shared/SuggestionPaper.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/shared/SuggestionPaper.tsxrename to frontend/src/metabase/documents/components/Editor/shared/SuggestionPaper.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/tiptap.types.d.ts b/frontend/src/metabase/documents/components/Editor/tiptap.types.d.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/Editor/tiptap.types.d.tsrename to frontend/src/metabase/documents/components/Editor/tiptap.types.d.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/EmbedQuestionSettingsSidebar.module.css b/frontend/src/metabase/documents/components/EmbedQuestionSettingsSidebar.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/EmbedQuestionSettingsSidebar.module.cssrename to frontend/src/metabase/documents/components/EmbedQuestionSettingsSidebar.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/EmbedQuestionSettingsSidebar.tsx b/frontend/src/metabase/documents/components/EmbedQuestionSettingsSidebar.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/components/EmbedQuestionSettingsSidebar.tsxrename to frontend/src/metabase/documents/components/EmbedQuestionSettingsSidebar.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/constants.ts b/frontend/src/metabase/documents/constants.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/constants.tsrename to frontend/src/metabase/documents/constants.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/documents.slice.ts b/frontend/src/metabase/documents/documents.slice.tssimilarity index 88%rename from enterprise/frontend/src/metabase-enterprise/documents/documents.slice.tsrename to frontend/src/metabase/documents/documents.slice.tsindex 8435b87ddd5..ee44e47eea4 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/documents.slice.ts+++ b/frontend/src/metabase/documents/documents.slice.ts@@ -12,8 +12,12 @@ import type {Document,VisualizationSettings,} from "metabase-types/api";+import type {+ CardEmbedRef,+ DocumentsState,+ MentionCacheItem,+} from "metabase-types/store/documents";-import type { CardEmbedRef } from "./components/Editor/types";import { getMentionsCacheKey } from "./utils/mentionsUtils";let nextDraftCardId = -1;@@ -26,24 +30,6 @@ export const loadMetadataForDocumentCard = createAsyncThunk(},);-interface MentionCacheItem {- entityId: string;- model: string;- name: string;-}--export interface DocumentsState {- selectedEmbedIndex: number | null;- cardEmbeds: CardEmbedRef[];- currentDocument: Document | null;- draftCards: Record<number, Card>;- mentionsCache: Record<string, MentionCacheItem>;- isCommentSidebarOpen: boolean;- childTargetId: string | undefined;- hoveredChildTargetId: string | undefined;- hasUnsavedChanges: boolean;-}-export const initialState: DocumentsState = {selectedEmbedIndex: null,cardEmbeds: [],@@ -97,6 +83,7 @@ const documentsSlice = createSlice({state.cardEmbeds = action.payload;},setCurrentDocument: (state, action: PayloadAction<Document | null>) => {+ // @ts-expect-error - possibly infinite type errorstate.currentDocument = action.payload;},resetDocuments: () => {diff --git a/enterprise/frontend/src/metabase-enterprise/documents/hooks/use-card-data.ts b/frontend/src/metabase/documents/hooks/use-card-data.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/hooks/use-card-data.tsrename to frontend/src/metabase/documents/hooks/use-card-data.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/hooks/use-document-state.ts b/frontend/src/metabase/documents/hooks/use-document-state.tssimilarity index 96%rename from enterprise/frontend/src/metabase-enterprise/documents/hooks/use-document-state.tsrename to frontend/src/metabase/documents/hooks/use-document-state.tsindex c684e630bf5..5094ba4897d 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/hooks/use-document-state.ts+++ b/frontend/src/metabase/documents/hooks/use-document-state.ts@@ -3,8 +3,8 @@ import { useCallback, useEffect, useRef, useState } from "react";import { useDispatch } from "metabase/lib/redux";import type { DocumentContent } from "metabase-types/api";+import type { CardEmbedRef } from "metabase-types/store/documents";-import type { CardEmbedRef } from "../components/Editor/types";import { setCardEmbeds, setIsCommentSidebarOpen } from "../documents.slice";export function useDocumentState(documentData?: {diff --git a/enterprise/frontend/src/metabase-enterprise/documents/hooks/use-draft-card-operations.ts b/frontend/src/metabase/documents/hooks/use-draft-card-operations.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/hooks/use-draft-card-operations.tsrename to frontend/src/metabase/documents/hooks/use-draft-card-operations.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/hooks/use-register-document-metabot-context.ts b/frontend/src/metabase/documents/hooks/use-register-document-metabot-context.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/hooks/use-register-document-metabot-context.tsrename to frontend/src/metabase/documents/hooks/use-register-document-metabot-context.tsdiff --git a/frontend/src/metabase/documents/routes.tsx b/frontend/src/metabase/documents/routes.tsxnew file mode 100644index 00000000000..080c7d41321--- /dev/null+++ b/frontend/src/metabase/documents/routes.tsx@@ -0,0 +1,16 @@+import type { ComponentProps } from "react";++import { extractEntityId } from "metabase/lib/urls";++import { DocumentPage } from "./components/DocumentPage";++export const DocumentPageOuter = (+ props: ComponentProps<typeof DocumentPage>,+) => {+ const { entityId } = props.params;+ const documentId = entityId === "new" ? "new" : extractEntityId(entityId);++ // Remounts DocumentPage when navigating to a different document.+ // Prevents data, state, undo history, etc from bleeding between documents.+ return <DocumentPage key={documentId} {...props} />;+};diff --git a/enterprise/frontend/src/metabase-enterprise/documents/selectors.ts b/frontend/src/metabase/documents/selectors.tssimilarity index 84%rename from enterprise/frontend/src/metabase-enterprise/documents/selectors.tsrename to frontend/src/metabase/documents/selectors.tsindex 7b506c158e5..9e38a09e83f 100644--- a/enterprise/frontend/src/metabase-enterprise/documents/selectors.ts+++ b/frontend/src/metabase/documents/selectors.ts@@ -1,12 +1,12 @@import { createSelector } from "@reduxjs/toolkit";import type { Card, CardId } from "metabase-types/api";+import type { State } from "metabase-types/store";import { initialState } from "./documents.slice";-import type { DocumentsStoreState } from "./types";-export const getDocumentsState = (state: DocumentsStoreState) =>- state.plugins?.documents || initialState;+export const getDocumentsState = (state: State) =>+ state.documents || initialState;export const getSelectedQuestionId = createSelector(getDocumentsState,@@ -52,15 +52,15 @@ export const getDraftCards = createSelector(// Get a specific draft card by IDexport const getDraftCardById = createSelector(- [getDraftCards, (_state: DocumentsStoreState, cardId: number) => cardId],+ [getDraftCards, (_state, cardId: number) => cardId],(draftCards, cardId) => draftCards[cardId],);export const getCardWithDraft = createSelector([getDraftCards,- (_state: DocumentsStoreState, cardId: CardId) => cardId,- (_state: DocumentsStoreState, _cardId: CardId, card?: Card) => card,+ (_state, cardId: CardId) => cardId,+ (_state, _cardId: CardId, card?: Card) => card,],(draftCards, cardId, card) => {const draftCard = draftCards[cardId];diff --git a/enterprise/frontend/src/metabase-enterprise/documents/utils/api.ts b/frontend/src/metabase/documents/utils/api.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/utils/api.tsrename to frontend/src/metabase/documents/utils/api.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/utils/editorNodeUtils.ts b/frontend/src/metabase/documents/utils/editorNodeUtils.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/utils/editorNodeUtils.tsrename to frontend/src/metabase/documents/utils/editorNodeUtils.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/utils/mentionsUtils.ts b/frontend/src/metabase/documents/utils/mentionsUtils.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/utils/mentionsUtils.tsrename to frontend/src/metabase/documents/utils/mentionsUtils.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/utils/processUrl.ts b/frontend/src/metabase/documents/utils/processUrl.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/utils/processUrl.tsrename to frontend/src/metabase/documents/utils/processUrl.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/utils/processUrl.unit.spec.ts b/frontend/src/metabase/documents/utils/processUrl.unit.spec.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/utils/processUrl.unit.spec.tsrename to frontend/src/metabase/documents/utils/processUrl.unit.spec.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/documents/utils/visualizationUtils.ts b/frontend/src/metabase/documents/utils/visualizationUtils.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/documents/utils/visualizationUtils.tsrename to frontend/src/metabase/documents/utils/visualizationUtils.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/embedding/components/PublicLinkPopover/DocumentPublicLinkPopover.tsx b/frontend/src/metabase/embedding/components/PublicLinkPopover/DocumentPublicLinkPopover.tsxsimilarity index 98%rename from enterprise/frontend/src/metabase-enterprise/embedding/components/PublicLinkPopover/DocumentPublicLinkPopover.tsxrename to frontend/src/metabase/embedding/components/PublicLinkPopover/DocumentPublicLinkPopover.tsxindex 5851aada398..f13ffa7e34a 100644--- a/enterprise/frontend/src/metabase-enterprise/embedding/components/PublicLinkPopover/DocumentPublicLinkPopover.tsx+++ b/frontend/src/metabase/embedding/components/PublicLinkPopover/DocumentPublicLinkPopover.tsx@@ -1,6 +1,10 @@import { useAsync } from "react-use";import { t } from "ttag";+import {+ useCreateDocumentPublicLinkMutation,+ useDeleteDocumentPublicLinkMutation,+} from "metabase/api";import { publicDocument as getPublicDocumentUrl } from "metabase/lib/urls/documents";import {trackPublicEmbedCodeCopied,@@ -8,10 +12,6 @@ import {trackPublicLinkRemoved,} from "metabase/public/lib/analytics";import { Box, Popover, Title } from "metabase/ui";-import {- useCreateDocumentPublicLinkMutation,- useDeleteDocumentPublicLinkMutation,-} from "metabase-enterprise/api";import type { Document } from "metabase-types/api";import { DocumentPublicLinkPopoverContent } from "./DocumentPublicLinkPopoverContent";diff --git a/enterprise/frontend/src/metabase-enterprise/embedding/components/PublicLinkPopover/DocumentPublicLinkPopoverContent.module.css b/frontend/src/metabase/embedding/components/PublicLinkPopover/DocumentPublicLinkPopoverContent.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/embedding/components/PublicLinkPopover/DocumentPublicLinkPopoverContent.module.cssrename to frontend/src/metabase/embedding/components/PublicLinkPopover/DocumentPublicLinkPopoverContent.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/embedding/components/PublicLinkPopover/DocumentPublicLinkPopoverContent.tsx b/frontend/src/metabase/embedding/components/PublicLinkPopover/DocumentPublicLinkPopoverContent.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/embedding/components/PublicLinkPopover/DocumentPublicLinkPopoverContent.tsxrename to frontend/src/metabase/embedding/components/PublicLinkPopover/DocumentPublicLinkPopoverContent.tsxdiff --git a/frontend/src/metabase/embedding/components/PublicLinkPopover/index.ts b/frontend/src/metabase/embedding/components/PublicLinkPopover/index.tsindex 4d7a49d6357..02bd171acba 100644--- a/frontend/src/metabase/embedding/components/PublicLinkPopover/index.ts+++ b/frontend/src/metabase/embedding/components/PublicLinkPopover/index.ts@@ -1,2 +1,3 @@export { QuestionPublicLinkPopover } from "./QuestionPublicLinkPopover";export { DashboardPublicLinkPopover } from "./DashboardPublicLinkPopover";+export { DocumentPublicLinkPopover } from "./DocumentPublicLinkPopover";diff --git a/frontend/src/metabase/entities/bookmarks.js b/frontend/src/metabase/entities/bookmarks.jsindex 70a895d30bf..4e2bde5d8fc 100644--- a/frontend/src/metabase/entities/bookmarks.js+++ b/frontend/src/metabase/entities/bookmarks.js@@ -6,6 +6,7 @@ import _ from "underscore";import { bookmarkApi, useListBookmarksQuery } from "metabase/api";import Collections from "metabase/entities/collections";import Dashboards from "metabase/entities/dashboards";+import Documents from "metabase/entities/documents";import Questions from "metabase/entities/questions";import { createEntity, entityCompatibleQuery } from "metabase/lib/entities";import { addUndo } from "metabase/redux/undo";@@ -126,6 +127,20 @@ const Bookmarks = createEntity({}}+ if (type === Documents.actionTypes.UPDATE && payload?.object) {+ const { id, archived, name } = payload.object;+ const key = `document-${id}`;++ if (!getIn(state, [key])) {+ return state;+ }+ if (archived) {+ return dissoc(state, key);+ } else {+ return updateIn(state, [key], (item) => ({ ...item, name }));+ }+ }+if (type === Bookmarks.actionTypes.REORDER) {const indexes = payload.reduce((indexes, bookmark, index) => {indexes[bookmark.id] = index;diff --git a/frontend/src/metabase/entities/containers/EntityCopyModal.tsx b/frontend/src/metabase/entities/containers/EntityCopyModal.tsxindex acc8b22051e..559247771bc 100644--- a/frontend/src/metabase/entities/containers/EntityCopyModal.tsx+++ b/frontend/src/metabase/entities/containers/EntityCopyModal.tsx@@ -7,7 +7,7 @@ import {CopyDashboardFormConnected,type CopyDashboardFormProperties,} from "metabase/dashboard/containers/CopyDashboardForm";-import { PLUGIN_DOCUMENTS } from "metabase/plugins";+import { DocumentCopyForm } from "metabase/documents/components/DocumentCopyForm/DocumentCopyForm";import { CopyCardForm } from "metabase/questions/components/CopyCardForm/CopyCardForm";import { Modal } from "metabase/ui";@@ -79,12 +79,11 @@ const EntityCopyModal = ({/>)}{entityType === "documents" && (- <PLUGIN_DOCUMENTS.DocumentCopyForm+ <DocumentCopyFormonSubmit={copy}onCancel={onClose}onSaved={onSaved}initialValues={initialValues}- model={entityObject?.type}{...props}/>)}diff --git a/frontend/src/metabase/entities/containers/rtk-query/types/entities.ts b/frontend/src/metabase/entities/containers/rtk-query/types/entities.tsindex 6717dc2e64c..a0dca7d5b0d 100644--- a/frontend/src/metabase/entities/containers/rtk-query/types/entities.ts+++ b/frontend/src/metabase/entities/containers/rtk-query/types/entities.ts@@ -42,6 +42,7 @@ export type EntityType =| "collections"| "dashboards"| "databases"+ | "documents"| "fields"| "groups"| "indexedEntities"diff --git a/enterprise/frontend/src/metabase-enterprise/entities/documents.ts b/frontend/src/metabase/entities/documents.tssimilarity index 97%rename from enterprise/frontend/src/metabase-enterprise/entities/documents.tsrename to frontend/src/metabase/entities/documents.tsindex e1b0c66539e..e52d5135486 100644--- a/enterprise/frontend/src/metabase-enterprise/entities/documents.ts+++ b/frontend/src/metabase/entities/documents.ts@@ -1,5 +1,6 @@import { t } from "ttag";+import { documentApi, useGetDocumentQuery } from "metabase/api";import {canonicalCollectionId,isRootTrashCollection,@@ -12,7 +13,6 @@ import {import * as Urls from "metabase/lib/urls";import { DocumentSchema } from "metabase/schema";import { color } from "metabase/ui/utils/colors";-import { documentApi, useGetDocumentQuery } from "metabase-enterprise/api";import type {Collection,CollectionId,@@ -30,7 +30,7 @@ import type { Dispatch } from "metabase-types/store";const Documents = createEntity({name: "documents",nameOne: "document",- path: "/api/ee/document",+ path: "/api/document",schema: DocumentSchema,// eslint-disable-next-line ttag/no-module-declaration -- see metabase#55045diff --git a/frontend/src/metabase/entities/index.ts b/frontend/src/metabase/entities/index.tsindex ebb26acea02..91e6f05e3f0 100644--- a/frontend/src/metabase/entities/index.ts+++ b/frontend/src/metabase/entities/index.ts@@ -21,3 +21,4 @@ export { default as groups } from "./groups";export { default as search } from "./search";export { default as persistedModels } from "./persisted-models";export { default as snippets } from "./snippets";+export { default as documents } from "./documents";diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/utils/links.ts b/frontend/src/metabase/metabot/utils/links.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/metabot/utils/links.tsrename to frontend/src/metabase/metabot/utils/links.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/metabot/utils/links.unit.spec.ts b/frontend/src/metabase/metabot/utils/links.unit.spec.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/metabot/utils/links.unit.spec.tsrename to frontend/src/metabase/metabot/utils/links.unit.spec.tsdiff --git a/frontend/src/metabase/nav/containers/AppBar/AppBar.tsx b/frontend/src/metabase/nav/containers/AppBar/AppBar.tsxindex 291277f32ba..6706064282a 100644--- a/frontend/src/metabase/nav/containers/AppBar/AppBar.tsx+++ b/frontend/src/metabase/nav/containers/AppBar/AppBar.tsx@@ -1,9 +1,13 @@import { withRouter } from "react-router";import _ from "underscore";+import {+ getCommentSidebarOpen,+ getSidebarOpen,+} from "metabase/documents/selectors";import Collections from "metabase/entities/collections";import { connect } from "metabase/lib/redux";-import { PLUGIN_DOCUMENTS, PLUGIN_METABOT } from "metabase/plugins";+import { PLUGIN_METABOT } from "metabase/plugins";import { closeNavbar, toggleNavbar } from "metabase/redux/app";import type { RouterProps } from "metabase/selectors/app";import {@@ -29,8 +33,8 @@ const mapStateToProps = (state: State, props: RouterProps) => ({isNavBarOpen: getIsNavbarOpen(state),isNavBarEnabled: getIsNavBarEnabled(state, props),isMetabotVisible: PLUGIN_METABOT.getMetabotVisible(state),- isDocumentSidebarOpen: PLUGIN_DOCUMENTS.getSidebarOpen(state),- isCommentSidebarOpen: PLUGIN_DOCUMENTS.getCommentSidebarOpen(state),+ isDocumentSidebarOpen: getSidebarOpen(state),+ isCommentSidebarOpen: getCommentSidebarOpen(state),isLogoVisible: getIsLogoVisible(state),isSearchVisible: getIsSearchVisible(state),isEmbeddingIframe: getIsEmbeddingIframe(state),diff --git a/frontend/src/metabase/palette/hooks/useCommandPaletteBasicActions.tsx b/frontend/src/metabase/palette/hooks/useCommandPaletteBasicActions.tsxindex cb6409e5873..757375ab05c 100644--- a/frontend/src/metabase/palette/hooks/useCommandPaletteBasicActions.tsx+++ b/frontend/src/metabase/palette/hooks/useCommandPaletteBasicActions.tsx@@ -13,10 +13,7 @@ import {import Collections from "metabase/entities/collections/collections";import { useDispatch, useSelector } from "metabase/lib/redux";import * as Urls from "metabase/lib/urls";-import {- PLUGIN_DOCUMENTS,- type SdkIframeEmbedSetupModalProps,-} from "metabase/plugins";+import type { SdkIframeEmbedSetupModalProps } from "metabase/plugins";import { openDiagnostics } from "metabase/redux/app";import {closeModal,@@ -138,17 +135,17 @@ export const useCommandPaletteBasicActions = ({openNewModal("dashboard");},});- if (PLUGIN_DOCUMENTS.shouldShowDocumentInNewItemMenu()) {- actions.push({- id: "create-new-document",- name: t`New document`,- section: "basic",- icon: "document",- perform: () => {- dispatch(push(Urls.newDocument()));- },- });- }++ actions.push({+ id: "create-new-document",+ name: t`New document`,+ section: "basic",+ icon: "document",+ perform: () => {+ dispatch(push(Urls.newDocument()));+ },+ });+actions.push({id: "create-new-collection",name: t`New collection`,diff --git a/frontend/src/metabase/plugins/index.ts b/frontend/src/metabase/plugins/index.tsindex 29a580c673d..32ac3d926fe 100644--- a/frontend/src/metabase/plugins/index.ts+++ b/frontend/src/metabase/plugins/index.ts@@ -71,7 +71,6 @@ export {PLUGIN_DATABASE_REPLICATION,PLUGIN_TABLE_EDITING,} from "./oss/database";-export { PLUGIN_DOCUMENTS } from "./oss/documents";export { PLUGIN_EMBEDDING, type SimpleDataPickerProps } from "./oss/embedding";export { PLUGIN_EMBEDDING_IFRAME_SDK } from "./oss/embedding-iframe-sdk";export {@@ -106,7 +105,6 @@ export {PLUGIN_APPLICATION_PERMISSIONS,PLUGIN_GROUP_MANAGERS,} from "./oss/permissions";-export { PLUGIN_PUBLIC_SHARING } from "./oss/public-sharing";export { PLUGIN_REMOTE_SYNC } from "./oss/remote-sync";export { PLUGIN_RESOURCE_DOWNLOADS } from "./oss/resource-downloads";export { PLUGIN_SEMANTIC_SEARCH } from "./oss/semantic-search";@@ -163,7 +161,6 @@ import { reinitialize as reinitializeCore } from "./oss/core";import { reinitialize as reinitializeDashcardMenu } from "./oss/dashcard-menu";import { reinitialize as reinitializeDatastudio } from "./oss/data-studio";import { reinitialize as reinitializeDatabase } from "./oss/database";-import { reinitialize as reinitializeDocuments } from "./oss/documents";import { reinitialize as reinitializeEmbedding } from "./oss/embedding";import { reinitialize as reinitializeEmbeddingIframeSdk } from "./oss/embedding-iframe-sdk";import { reinitialize as reinitializeEmbeddingIframeSdkSetup } from "./oss/embedding-iframe-sdk-setup";@@ -172,7 +169,6 @@ import { reinitialize as reinitializeEntities } from "./oss/entities";import { reinitialize as reinitializeModelPersistence } from "./oss/model-persistence";import { reinitialize as reinitializeModeration } from "./oss/moderation";import { reinitialize as reinitializePermissions } from "./oss/permissions";-import { reinitialize as reinitializePublicSharing } from "./oss/public-sharing";import { reinitialize as reinitializeRemoteSync } from "./oss/remote-sync";import { reinitialize as reinitializeResourceDownloads } from "./oss/resource-downloads";import { reinitialize as reinitializeSemanticSearch } from "./oss/semantic-search";@@ -204,7 +200,6 @@ export function reinitialize() {reinitializeDashcardMenu();reinitializeDatabase();reinitializeDatastudio();- reinitializeDocuments();reinitializeEmbedding();reinitializeEmbeddingIframeSdk();reinitializeEmbeddingIframeSdkSetup();@@ -213,7 +208,6 @@ export function reinitialize() {reinitializeModelPersistence();reinitializeModeration();reinitializePermissions();- reinitializePublicSharing();reinitializeRemoteSync();reinitializeResourceDownloads();reinitializeSemanticSearch();diff --git a/frontend/src/metabase/plugins/oss/ai.ts b/frontend/src/metabase/plugins/oss/ai.tsindex 98a2070dcb5..b41b8c62db4 100644--- a/frontend/src/metabase/plugins/oss/ai.ts+++ b/frontend/src/metabase/plugins/oss/ai.ts@@ -1,3 +1,5 @@+import type { BaseQueryFn } from "@reduxjs/toolkit/query";+import type { TypedUseLazyQuery } from "@reduxjs/toolkit/src/query/react/buildHooks";import type { ComponentType } from "react";import React from "react";@@ -6,6 +8,8 @@ import { PluginPlaceholder } from "metabase/plugins/components/PluginPlaceholderimport type Question from "metabase-lib/v1/Question";import type {DashCardId,+ MetabotGenerateContentRequest,+ MetabotGenerateContentResponse,SearchModel,Timeline,TimelineEvent,@@ -67,6 +71,12 @@ type PluginMetabotType = {MetabotAdminAppBarButton: ComponentType;MetabotDataStudioButton: ComponentType;MetabotDataStudioSidebar: ComponentType;+ useLazyMetabotGenerateContentQuery: TypedUseLazyQuery<+ MetabotGenerateContentResponse,+ MetabotGenerateContentRequest,+ BaseQueryFn+ >;+ MetabotThinkingStyles: { [key: string]: string };};const getDefaultMetabotContextValue = (): MetabotContext => ({@@ -120,6 +130,9 @@ const getDefaultPluginMetabot = (): PluginMetabotType => ({MetabotAdminAppBarButton: PluginPlaceholder,MetabotDataStudioButton: PluginPlaceholder,MetabotDataStudioSidebar: PluginPlaceholder,+ useLazyMetabotGenerateContentQuery:+ (() => []) as unknown as PluginMetabotType["useLazyMetabotGenerateContentQuery"],+ MetabotThinkingStyles: {},});export const PLUGIN_METABOT: PluginMetabotType = getDefaultPluginMetabot();diff --git a/frontend/src/metabase/plugins/oss/documents.ts b/frontend/src/metabase/plugins/oss/documents.tsdeleted file mode 100644index 0cbe3d0c3ae..00000000000--- a/frontend/src/metabase/plugins/oss/documents.ts+++ /dev/null@@ -1,21 +0,0 @@-import type React from "react";--import type { Document } from "metabase-types/api";--const getDefaultPluginDocuments = () => ({- getRoutes: () => null as React.ReactElement | null,- shouldShowDocumentInNewItemMenu: () => false,- getCurrentDocument: (_state: any) => null as Document | null,- getSidebarOpen: (_state: any) => false,- getCommentSidebarOpen: (_state: any) => false,- DocumentCopyForm: (_props: any) => null as React.ReactElement | null,-});--export const PLUGIN_DOCUMENTS = getDefaultPluginDocuments();--/**- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.- */-export function reinitialize() {- Object.assign(PLUGIN_DOCUMENTS, getDefaultPluginDocuments());-}diff --git a/frontend/src/metabase/plugins/oss/public-sharing.ts b/frontend/src/metabase/plugins/oss/public-sharing.tsdeleted file mode 100644index fc68e83bd8a..00000000000--- a/frontend/src/metabase/plugins/oss/public-sharing.ts+++ /dev/null@@ -1,15 +0,0 @@-import type React from "react";--const getDefaultPluginPublicSharing = () => ({- PublicDocumentRoute: (_props: any) => null as React.ReactElement | null,- PublicLinksDocumentListing: () => null as React.ReactElement | null,-});--export const PLUGIN_PUBLIC_SHARING = getDefaultPluginPublicSharing();--/**- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.- */-export function reinitialize() {- Object.assign(PLUGIN_PUBLIC_SHARING, getDefaultPluginPublicSharing());-}diff --git a/frontend/src/metabase/plugins/oss/transforms.ts b/frontend/src/metabase/plugins/oss/transforms.tsindex 467398406c4..5feedb421dc 100644--- a/frontend/src/metabase/plugins/oss/transforms.ts+++ b/frontend/src/metabase/plugins/oss/transforms.ts@@ -1,6 +1,9 @@+import type { BaseQueryFn, QueryDefinition } from "@reduxjs/toolkit/query";import type { ComponentType, Context, ReactNode } from "react";import { createContext } from "react";+import type { TagType } from "metabase/api/tags";+import type { UseQuery } from "metabase/entities/containers/rtk-query/types/rtk";import {NotFoundPlaceholder,PluginPlaceholder,@@ -34,6 +37,9 @@ export type TransformsPlugin = {canAccessTransforms: (state: State) => boolean;getDataStudioTransformRoutes(): ReactNode;TransformPicker: ComponentType<TransformPickerProps>;+ useGetTransformQuery: UseQuery<+ QueryDefinition<TransformId, BaseQueryFn, TagType, Transform>+ >;};export type PythonTransformEditorProps = {@@ -138,6 +144,8 @@ const getDefaultPluginTransforms = (): TransformsPlugin => ({canAccessTransforms: () => false,getDataStudioTransformRoutes: () => null,TransformPicker: PluginPlaceholder,+ useGetTransformQuery:+ (() => []) as unknown as TransformsPlugin["useGetTransformQuery"],});export const PLUGIN_TRANSFORMS = getDefaultPluginTransforms();diff --git a/frontend/src/metabase/public/components/EmbedFrame/EmbedFrame.tsx b/frontend/src/metabase/public/components/EmbedFrame/EmbedFrame.tsxindex 6c314c2c821..d95b0c3569a 100644--- a/frontend/src/metabase/public/components/EmbedFrame/EmbedFrame.tsx+++ b/frontend/src/metabase/public/components/EmbedFrame/EmbedFrame.tsx@@ -58,7 +58,7 @@ export type EmbedFrameBaseProps = Partial<{className: string;name: string | null;description: string | null;- question: Question;+ question: Question | null;dashboard: Dashboard | null;headerButtons: ReactNode;actionButtons: ReactNode;@@ -74,6 +74,7 @@ export type EmbedFrameBaseProps = Partial<{dashboardTabs: ReactNode;pdfDownloadsEnabled: boolean;withFooter: boolean;+ contentClassName?: string;}>;type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;@@ -105,6 +106,7 @@ export const EmbedFrame = ({hide_parameters,pdfDownloadsEnabled = true,withFooter = true,+ contentClassName,}: EmbedFrameProps) => {useGlobalTheme(theme);const hasEmbedBranding = useSelector(@@ -188,7 +190,7 @@ export const EmbedFrame = ({><ContentContainerid={DASHBOARD_PDF_EXPORT_ROOT_ID}- className={cx({+ className={cx(contentClassName, {[EmbedFrameS.ContentContainer]: true,[EmbedFrameS.WithThemeBackground]: true,diff --git a/enterprise/frontend/src/metabase-enterprise/public/containers/PublicDocument/PublicDocument.module.css b/frontend/src/metabase/public/containers/PublicDocument/PublicDocument.module.csssimilarity index 93%rename from enterprise/frontend/src/metabase-enterprise/public/containers/PublicDocument/PublicDocument.module.cssrename to frontend/src/metabase/public/containers/PublicDocument/PublicDocument.module.cssindex bacab086b7b..336330f3378 100644--- a/enterprise/frontend/src/metabase-enterprise/public/containers/PublicDocument/PublicDocument.module.css+++ b/frontend/src/metabase/public/containers/PublicDocument/PublicDocument.module.css@@ -1,3 +1,16 @@+.container:not([data-css-specificity-hack="🤷♀️"]) {+ height: 100vh;+ display: flex;+ flex-direction: column;+ justify-content: stretch;+ overflow: hidden;+}++.documentArea:not([data-css-specificity-hack="🤷♀️"]) {+ flex-shrink: 1;+ overflow: auto;+}+.editorContent :global(.ProseMirror) {padding: 1.5rem 0 2rem 0;outline: none;diff --git a/enterprise/frontend/src/metabase-enterprise/public/containers/PublicDocument/PublicDocument.tsx b/frontend/src/metabase/public/containers/PublicDocument/PublicDocument.tsxsimilarity index 52%rename from enterprise/frontend/src/metabase-enterprise/public/containers/PublicDocument/PublicDocument.tsxrename to frontend/src/metabase/public/containers/PublicDocument/PublicDocument.tsxindex 181723b9f3c..47b8e08ea69 100644--- a/enterprise/frontend/src/metabase-enterprise/public/containers/PublicDocument/PublicDocument.tsx+++ b/frontend/src/metabase/public/containers/PublicDocument/PublicDocument.tsx@@ -2,6 +2,7 @@ import Image from "@tiptap/extension-image";import Link from "@tiptap/extension-link";import type { JSONContent } from "@tiptap/react";import { EditorContent, useEditor } from "@tiptap/react";+import type { Location } from "history";import { useEffect, useMemo } from "react";import { useAsync, useMount } from "react-use";@@ -9,33 +10,42 @@ import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrimport CS from "metabase/css/core/index.css";import { initializeIframeResizer } from "metabase/lib/dom";import { useDispatch, useSelector } from "metabase/lib/redux";+import { EmbedFrame } from "metabase/public/components/EmbedFrame";+import { PublicDocumentProvider } from "metabase/public/contexts/PublicDocumentContext";+import { useEmbedFrameOptions } from "metabase/public/hooks";import { setErrorPage } from "metabase/redux/app";+import { CardEmbed } from "metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode";+import { CustomStarterKit } from "metabase/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit";+import { FlexContainer } from "metabase/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer";+import { MetabotNode } from "metabase/rich_text_editing/tiptap/extensions/MetabotEmbed";+import { ResizeNode } from "metabase/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode";+import { SmartLink } from "metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode";+import { SupportingText } from "metabase/rich_text_editing/tiptap/extensions/SupportingText/SupportingText";+import { DROP_ZONE_COLOR } from "metabase/rich_text_editing/tiptap/extensions/shared/constants";import { getSetting } from "metabase/selectors/settings";import { PublicApi } from "metabase/services";import { Box } from "metabase/ui";-import { PublicDocumentProvider } from "metabase-enterprise/public/contexts/PublicDocumentContext";-import { CardEmbed } from "metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode";-import { CustomStarterKit } from "metabase-enterprise/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit";-import { FlexContainer } from "metabase-enterprise/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer";-import { ResizeNode } from "metabase-enterprise/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode";-import { SmartLink } from "metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode";-import { SupportingText } from "metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText";-import { DROP_ZONE_COLOR } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/constants";import type { Document } from "metabase-types/api";import S from "./PublicDocument.module.css";interface PublicDocumentProps {+ location: Location;params: {uuid: string;};}-export const PublicDocument = ({ params }: PublicDocumentProps) => {+export const PublicDocument = ({ location, params }: PublicDocumentProps) => {const { uuid } = params;const dispatch = useDispatch();const siteUrl = useSelector((state) => getSetting(state, "site-url"));+ const { theme } = useEmbedFrameOptions({ location });+ const hasEmbedBranding = useSelector(+ (state) => !getSetting(state, "hide-embed-branding?"),+ );+const {value: document,loading,@@ -77,6 +87,7 @@ export const PublicDocument = ({ params }: PublicDocumentProps) => {FlexContainer,ResizeNode,SupportingText,+ MetabotNode,],[siteUrl],);@@ -110,31 +121,40 @@ export const PublicDocument = ({ params }: PublicDocumentProps) => {});return (- <LoadingAndErrorWrapper- loading={loading}- noBackground- style={{- display: "flex",- flex: 1,- flexDirection: "column",- }}+ <EmbedFrame+ theme={theme}+ titled={false}+ className={S.container}+ contentClassName={S.documentArea}+ background={false}+ withFooter={hasEmbedBranding}>- {document && editor && (- <PublicDocumentProvider- value={{- publicDocumentUuid: uuid,- publicDocument: document,- publicDocumentCards: document.cards,- }}- >- <Box maw={900} mx="auto" p="xl" w="100%">- <h1 style={{ marginBottom: "1rem" }}>{document.name}</h1>- <div className={S.editorContent}>- <EditorContent data-testid="document-content" editor={editor} />- </div>- </Box>- </PublicDocumentProvider>- )}- </LoadingAndErrorWrapper>+ <LoadingAndErrorWrapper+ loading={loading}+ noBackground+ style={{+ display: "flex",+ flex: 1,+ flexDirection: "column",+ }}+ >+ {document && editor && (+ <PublicDocumentProvider+ value={{+ publicDocumentUuid: uuid,+ publicDocument: document,+ publicDocumentCards: document.cards,+ }}+ >+ <Box maw={900} mx="auto" p="xl" w="100%">+ <h1 style={{ marginBottom: "1rem" }}>{document.name}</h1>+ <div className={S.editorContent}>+ <EditorContent data-testid="document-content" editor={editor} />+ </div>+ </Box>+ </PublicDocumentProvider>+ )}+ </LoadingAndErrorWrapper>+ </EmbedFrame>);};diff --git a/enterprise/frontend/src/metabase-enterprise/public/containers/PublicDocument/index.ts b/frontend/src/metabase/public/containers/PublicDocument/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/public/containers/PublicDocument/index.tsrename to frontend/src/metabase/public/containers/PublicDocument/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/public/contexts/PublicDocumentContext.tsx b/frontend/src/metabase/public/contexts/PublicDocumentContext.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/public/contexts/PublicDocumentContext.tsxrename to frontend/src/metabase/public/contexts/PublicDocumentContext.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/public/hooks/use-public-document-card-data.ts b/frontend/src/metabase/public/hooks/use-public-document-card-data.tssimilarity index 95%rename from enterprise/frontend/src/metabase-enterprise/public/hooks/use-public-document-card-data.tsrename to frontend/src/metabase/public/hooks/use-public-document-card-data.tsindex a2ab46498b0..e9138716ed1 100644--- a/enterprise/frontend/src/metabase-enterprise/public/hooks/use-public-document-card-data.ts+++ b/frontend/src/metabase/public/hooks/use-public-document-card-data.ts@@ -2,9 +2,9 @@ import { useMemo } from "react";import { useAsync } from "react-use";import { useSelector } from "metabase/lib/redux";+import { usePublicDocumentContext } from "metabase/public/contexts/PublicDocumentContext";import { getMetadata } from "metabase/selectors/metadata";import { PublicApi } from "metabase/services";-import { usePublicDocumentContext } from "metabase-enterprise/public/contexts/PublicDocumentContext";import Question from "metabase-lib/v1/Question";import type { Card, Dataset, RawSeries } from "metabase-types/api";diff --git a/frontend/src/metabase/reducers-common.ts b/frontend/src/metabase/reducers-common.tsindex 9f514085916..d10e1f5eef9 100644--- a/frontend/src/metabase/reducers-common.ts+++ b/frontend/src/metabase/reducers-common.ts@@ -4,6 +4,7 @@ import { combineReducers } from "@reduxjs/toolkit";import { Api } from "metabase/api";import { dashboardReducers as dashboard } from "metabase/dashboard/reducers";+import { documentsReducer as documents } from "metabase/documents/documents.slice";import * as parameters from "metabase/parameters/reducers";import app from "metabase/redux/app";import { reducer as auth } from "metabase/redux/auth";@@ -29,6 +30,7 @@ export const commonReducers = {settings,undo,entities,+ documents,upload,auth,[Api.reducerPath]: Api.reducer,diff --git a/frontend/src/metabase/redux/downloads.ts b/frontend/src/metabase/redux/downloads.tsindex 13d32498c98..c69fef3876d 100644--- a/frontend/src/metabase/redux/downloads.ts+++ b/frontend/src/metabase/redux/downloads.ts@@ -228,7 +228,7 @@ const getPublicDocumentCardParams = (exportParams: ExportParams,): DownloadQueryResultsParams => ({method: "POST",- url: `/api/ee/public/document/${documentUuid}/card/${cardId}/${type}`,+ url: `/api/public/document/${documentUuid}/card/${cardId}/${type}`,body: {parameters: result?.json_query?.parameters ?? [],...exportParams,@@ -327,7 +327,7 @@ const getInternalDocumentCardParams = (exportParams: ExportParams,): DownloadQueryResultsParams => ({method: "POST",- url: `/api/ee/document/${documentId}/card/${cardId}/query/${type}`,+ url: `/api/document/${documentId}/card/${cardId}/query/${type}`,body: {parameters: result?.json_query?.parameters ?? [],...exportParams,diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/CommentsButton.tsx b/frontend/src/metabase/rich_text_editing/tiptap/components/CommentsButton.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/CommentsButton.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/components/CommentsButton.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/EditorBubbleMenu/EditorBubbleMenu.module.css b/frontend/src/metabase/rich_text_editing/tiptap/components/EditorBubbleMenu/EditorBubbleMenu.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/EditorBubbleMenu/EditorBubbleMenu.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/components/EditorBubbleMenu/EditorBubbleMenu.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/EditorBubbleMenu/EditorBubbleMenu.tsx b/frontend/src/metabase/rich_text_editing/tiptap/components/EditorBubbleMenu/EditorBubbleMenu.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/EditorBubbleMenu/EditorBubbleMenu.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/components/EditorBubbleMenu/EditorBubbleMenu.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/EditorBubbleMenu/LinkEditor.tsx b/frontend/src/metabase/rich_text_editing/tiptap/components/EditorBubbleMenu/LinkEditor.tsxsimilarity index 96%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/EditorBubbleMenu/LinkEditor.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/components/EditorBubbleMenu/LinkEditor.tsxindex b0c0dda4674..ddfbf4a4f18 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/EditorBubbleMenu/LinkEditor.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/components/EditorBubbleMenu/LinkEditor.tsx@@ -1,6 +1,7 @@import { useEffect, useRef, useState } from "react";import { t } from "ttag";+import { processUrl } from "metabase/documents/utils/processUrl";import {ActionIcon,Box,@@ -9,7 +10,6 @@ import {TextInput,Tooltip,} from "metabase/ui";-import { processUrl } from "metabase-enterprise/documents/utils/processUrl";interface LinkPopupProps {initialUrl: string;diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/EditorBubbleMenu/types.ts b/frontend/src/metabase/rich_text_editing/tiptap/components/EditorBubbleMenu/types.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/EditorBubbleMenu/types.tsrename to frontend/src/metabase/rich_text_editing/tiptap/components/EditorBubbleMenu/types.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/FormatButton/FormatButton.module.css b/frontend/src/metabase/rich_text_editing/tiptap/components/FormatButton/FormatButton.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/FormatButton/FormatButton.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/components/FormatButton/FormatButton.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/FormatButton/FormatButton.tsx b/frontend/src/metabase/rich_text_editing/tiptap/components/FormatButton/FormatButton.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/components/FormatButton/FormatButton.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/components/FormatButton/FormatButton.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Blockquote/Blockquote.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Blockquote/Blockquote.tsxsimilarity index 86%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Blockquote/Blockquote.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Blockquote/Blockquote.tsxindex 666bbc136cf..aaed593dc03 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Blockquote/Blockquote.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Blockquote/Blockquote.tsx@@ -9,18 +9,18 @@ import {import cx from "classnames";import { useEffect, useMemo, useState } from "react";-import { isWithinIframe } from "metabase/lib/dom";-import { useSelector } from "metabase/lib/redux";-import { useListCommentsQuery } from "metabase-enterprise/api";-import { getTargetChildCommentThreads } from "metabase-enterprise/comments/utils";-import { CommentsMenu } from "metabase-enterprise/documents/components/Editor/CommentsMenu";+import { useListCommentsQuery } from "metabase/api";+import { getTargetChildCommentThreads } from "metabase/comments/utils";+import { CommentsMenu } from "metabase/documents/components/Editor/CommentsMenu";import {getChildTargetId,getCurrentDocument,getHoveredChildTargetId,-} from "metabase-enterprise/documents/selectors";-import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";-import { isTopLevel } from "metabase-enterprise/documents/utils/editorNodeUtils";+} from "metabase/documents/selectors";+import { getListCommentsQuery } from "metabase/documents/utils/api";+import { isTopLevel } from "metabase/documents/utils/editorNodeUtils";+import { isWithinIframe } from "metabase/lib/dom";+import { useSelector } from "metabase/lib/redux";import { createIdAttribute, createProseMirrorPlugin } from "../NodeIds";import S from "../extensions.module.css";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Blockquote/index.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Blockquote/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Blockquote/index.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Blockquote/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/BulletList/BulletList.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/BulletList/BulletList.tsxsimilarity index 86%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/BulletList/BulletList.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/BulletList/BulletList.tsxindex 99c9ca8fa2b..395d17f9f43 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/BulletList/BulletList.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/BulletList/BulletList.tsx@@ -9,18 +9,18 @@ import {import cx from "classnames";import { useEffect, useMemo, useState } from "react";-import { isWithinIframe } from "metabase/lib/dom";-import { useSelector } from "metabase/lib/redux";-import { useListCommentsQuery } from "metabase-enterprise/api";-import { getTargetChildCommentThreads } from "metabase-enterprise/comments/utils";-import { CommentsMenu } from "metabase-enterprise/documents/components/Editor/CommentsMenu";+import { useListCommentsQuery } from "metabase/api";+import { getTargetChildCommentThreads } from "metabase/comments/utils";+import { CommentsMenu } from "metabase/documents/components/Editor/CommentsMenu";import {getChildTargetId,getCurrentDocument,getHoveredChildTargetId,-} from "metabase-enterprise/documents/selectors";-import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";-import { isTopLevel } from "metabase-enterprise/documents/utils/editorNodeUtils";+} from "metabase/documents/selectors";+import { getListCommentsQuery } from "metabase/documents/utils/api";+import { isTopLevel } from "metabase/documents/utils/editorNodeUtils";+import { isWithinIframe } from "metabase/lib/dom";+import { useSelector } from "metabase/lib/redux";import { createIdAttribute, createProseMirrorPlugin } from "../NodeIds";import S from "../extensions.module.css";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/BulletList/index.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/BulletList/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/BulletList/index.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/BulletList/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedMenuDropdown.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedMenuDropdown.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedMenuDropdown.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedMenuDropdown.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.module.css b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsxsimilarity index 95%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsxindex 304fba88f02..85f07f9ba37 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsx@@ -13,43 +13,43 @@ import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";import { push } from "react-router-redux";import { t } from "ttag";+import { useListCommentsQuery } from "metabase/api";+import { getTargetChildCommentThreads } from "metabase/comments/utils";import { Ellipsified } from "metabase/common/components/Ellipsified";import { QuestionPickerModal } from "metabase/common/components/Pickers/QuestionPicker/components/QuestionPickerModal";import type { QuestionPickerValueItem } from "metabase/common/components/Pickers/QuestionPicker/types";-import { useDispatch, useSelector } from "metabase/lib/redux";-import { useDownloadData } from "metabase/query_builder/components/QuestionDownloadWidget/use-download-data";-import { getMetadata } from "metabase/selectors/metadata";-import { Box, Flex, Icon, Loader, Menu, Text, TextInput } from "metabase/ui";-import { DocumentMode } from "metabase/visualizations/click-actions/modes/DocumentMode";-import Visualization from "metabase/visualizations/components/Visualization";-import { ErrorView } from "metabase/visualizations/components/Visualization/ErrorView/ErrorView";-import ChartSkeleton from "metabase/visualizations/components/skeletons/ChartSkeleton";-import { getGenericErrorMessage } from "metabase/visualizations/lib/errors";-import { useListCommentsQuery } from "metabase-enterprise/api";-import { getTargetChildCommentThreads } from "metabase-enterprise/comments/utils";-import { navigateToCardFromDocument } from "metabase-enterprise/documents/actions";+import { navigateToCardFromDocument } from "metabase/documents/actions";import {trackDocumentAddSupportingText,trackDocumentReplaceCard,-} from "metabase-enterprise/documents/analytics";-import { getUnresolvedComments } from "metabase-enterprise/documents/components/Editor/CommentsMenu";-import { EDITOR_STYLE_BOUNDARY_CLASS } from "metabase-enterprise/documents/components/Editor/constants";-import { MAX_GROUP_SIZE } from "metabase-enterprise/documents/constants";+} from "metabase/documents/analytics";+import { getUnresolvedComments } from "metabase/documents/components/Editor/CommentsMenu";+import { EDITOR_STYLE_BOUNDARY_CLASS } from "metabase/documents/components/Editor/constants";+import { MAX_GROUP_SIZE } from "metabase/documents/constants";import {loadMetadataForDocumentCard,openVizSettingsSidebar,-} from "metabase-enterprise/documents/documents.slice";-import { useCardData } from "metabase-enterprise/documents/hooks/use-card-data";+} from "metabase/documents/documents.slice";+import { useCardData } from "metabase/documents/hooks/use-card-data";import {getChildTargetId,getCurrentDocument,getHasUnsavedChanges,getHoveredChildTargetId,-} from "metabase-enterprise/documents/selectors";-import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";-import { usePublicDocumentContext } from "metabase-enterprise/public/contexts/PublicDocumentContext";-import { usePublicDocumentCardData } from "metabase-enterprise/public/hooks/use-public-document-card-data";-import { DropZone } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/dnd/DropZone";+} from "metabase/documents/selectors";+import { getListCommentsQuery } from "metabase/documents/utils/api";+import { useDispatch, useSelector } from "metabase/lib/redux";+import { usePublicDocumentContext } from "metabase/public/contexts/PublicDocumentContext";+import { usePublicDocumentCardData } from "metabase/public/hooks/use-public-document-card-data";+import { useDownloadData } from "metabase/query_builder/components/QuestionDownloadWidget/use-download-data";+import { DropZone } from "metabase/rich_text_editing/tiptap/extensions/shared/dnd/DropZone";+import { getMetadata } from "metabase/selectors/metadata";+import { Box, Flex, Icon, Loader, Menu, Text, TextInput } from "metabase/ui";+import { DocumentMode } from "metabase/visualizations/click-actions/modes/DocumentMode";+import Visualization from "metabase/visualizations/components/Visualization";+import { ErrorView } from "metabase/visualizations/components/Visualization/ErrorView/ErrorView";+import ChartSkeleton from "metabase/visualizations/components/skeletons/ChartSkeleton";+import { getGenericErrorMessage } from "metabase/visualizations/lib/errors";import Question from "metabase-lib/v1/Question";import { getUrl } from "metabase-lib/v1/urls";import type { CardDisplayType, Dataset } from "metabase-types/api";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/PublicDocumentCardMenu.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/PublicDocumentCardMenu.tsxsimilarity index 96%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/PublicDocumentCardMenu.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/PublicDocumentCardMenu.tsxindex 29460c385a2..540eec76a28 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/PublicDocumentCardMenu.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/PublicDocumentCardMenu.tsx@@ -5,12 +5,12 @@ import { t } from "ttag";import { useSelector } from "metabase/lib/redux";import { checkNotNull } from "metabase/lib/types";+import { usePublicDocumentContext } from "metabase/public/contexts/PublicDocumentContext";import { QuestionDownloadWidget } from "metabase/query_builder/components/QuestionDownloadWidget";import { useDownloadData } from "metabase/query_builder/components/QuestionDownloadWidget/use-download-data";import { getMetadata } from "metabase/selectors/metadata";import { ActionIcon, Icon, Menu } from "metabase/ui";import { SAVING_DOM_IMAGE_HIDDEN_CLASS } from "metabase/visualizations/lib/save-chart-image";-import { usePublicDocumentContext } from "metabase-enterprise/public/contexts/PublicDocumentContext";import Question from "metabase-lib/v1/Question";import type { Card, Dataset } from "metabase-types/api";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/modals/ModifyQuestionModal.module.css b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/modals/ModifyQuestionModal.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/modals/ModifyQuestionModal.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/modals/ModifyQuestionModal.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/modals/ModifyQuestionModal.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/modals/ModifyQuestionModal.tsxsimilarity index 98%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/modals/ModifyQuestionModal.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/modals/ModifyQuestionModal.tsxindex f03c7bd2d64..4637576d86e 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/modals/ModifyQuestionModal.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/modals/ModifyQuestionModal.tsx@@ -2,16 +2,16 @@ import { useEffect, useMemo, useState } from "react";import { t } from "ttag";import _ from "underscore";+import {+ createDraftCard,+ generateDraftCardId,+ loadMetadataForDocumentCard,+} from "metabase/documents/documents.slice";import { useDispatch, useSelector, useStore } from "metabase/lib/redux";import { Notebook } from "metabase/querying/notebook/components/Notebook";import { getMetadata } from "metabase/selectors/metadata";import { getSetting } from "metabase/selectors/settings";import { Box, Button, Flex, Modal, Text } from "metabase/ui";-import {- createDraftCard,- generateDraftCardId,- loadMetadataForDocumentCard,-} from "metabase-enterprise/documents/documents.slice";import * as Lib from "metabase-lib";import Question from "metabase-lib/v1/Question";import type { Card } from "metabase-types/api";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/use-update-card-operations.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/use-update-card-operations.tssimilarity index 90%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/use-update-card-operations.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/use-update-card-operations.tsindex 04dc9342717..039b83b2c79 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/use-update-card-operations.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/use-update-card-operations.ts@@ -1,12 +1,12 @@import type { NodeViewProps } from "@tiptap/core";import { useCallback } from "react";+import { navigateToCardFromDocument } from "metabase/documents/actions";+import { updateVizSettings } from "metabase/documents/documents.slice";+import type { UseCardDataResult } from "metabase/documents/hooks/use-card-data";+import { useDraftCardOperations } from "metabase/documents/hooks/use-draft-card-operations";import { useDispatch, useSelector } from "metabase/lib/redux";import { getMetadata } from "metabase/selectors/metadata";-import { navigateToCardFromDocument } from "metabase-enterprise/documents/actions";-import { updateVizSettings } from "metabase-enterprise/documents/documents.slice";-import type { UseCardDataResult } from "metabase-enterprise/documents/hooks/use-card-data";-import { useDraftCardOperations } from "metabase-enterprise/documents/hooks/use-draft-card-operations";import Question from "metabase-lib/v1/Question";import { getUrl } from "metabase-lib/v1/urls";import type { Card, Document, VisualizationSettings } from "metabase-types/api";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/utils.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/utils.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CardEmbed/utils.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/utils.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CodeBlock/CodeBlock.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CodeBlock/CodeBlock.tsxsimilarity index 92%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CodeBlock/CodeBlock.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/CodeBlock/CodeBlock.tsxindex 25792b42757..0753668ec54 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CodeBlock/CodeBlock.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CodeBlock/CodeBlock.tsx@@ -10,18 +10,18 @@ import {import cx from "classnames";import { useEffect, useMemo, useState } from "react";-import { isWithinIframe } from "metabase/lib/dom";-import { useSelector } from "metabase/lib/redux";-import { useListCommentsQuery } from "metabase-enterprise/api";-import { getTargetChildCommentThreads } from "metabase-enterprise/comments/utils";-import { CommentsMenu } from "metabase-enterprise/documents/components/Editor/CommentsMenu";+import { useListCommentsQuery } from "metabase/api";+import { getTargetChildCommentThreads } from "metabase/comments/utils";+import { CommentsMenu } from "metabase/documents/components/Editor/CommentsMenu";import {getChildTargetId,getCurrentDocument,getHoveredChildTargetId,-} from "metabase-enterprise/documents/selectors";-import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";-import { isTopLevel } from "metabase-enterprise/documents/utils/editorNodeUtils";+} from "metabase/documents/selectors";+import { getListCommentsQuery } from "metabase/documents/utils/api";+import { isTopLevel } from "metabase/documents/utils/editorNodeUtils";+import { isWithinIframe } from "metabase/lib/dom";+import { useSelector } from "metabase/lib/redux";import { createIdAttribute, createProseMirrorPlugin } from "../NodeIds";import S from "../extensions.module.css";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CodeBlock/index.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CodeBlock/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CodeBlock/index.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/CodeBlock/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandExtension.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandExtension.tssimilarity index 99%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandExtension.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandExtension.tsindex 538737de533..dc6cdb004b7 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandExtension.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandExtension.ts@@ -6,7 +6,7 @@ import {trackDocumentAddCard,trackDocumentAddSmartLink,trackDocumentAskMetabot,-} from "metabase-enterprise/documents/analytics";+} from "metabase/documents/analytics";import type { Document } from "metabase-types/api";import { wrapCardEmbed } from "../shared/layout";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.module.css b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.tsxsimilarity index 97%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.tsxindex 398e09d7865..c53fbda1a79 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.tsx@@ -11,7 +11,18 @@ import {} from "react";import { t } from "ttag";+import {+ CreateNewQuestionFooter,+ MenuItemComponent,+ SearchResultsFooter,+} from "metabase/documents/components/Editor/shared/MenuComponents";+import {+ LoadingSuggestionPaper,+ SuggestionPaper,+} from "metabase/documents/components/Editor/shared/SuggestionPaper";+import { getCurrentDocument } from "metabase/documents/selectors";import { useSelector } from "metabase/lib/redux";+import { getBrowseAllItemIndex } from "metabase/rich_text_editing/tiptap/extensions/shared/suggestionUtils";import {Box,Divider,@@ -21,17 +32,6 @@ import {Text,UnstyledButton,} from "metabase/ui";-import {- CreateNewQuestionFooter,- MenuItemComponent,- SearchResultsFooter,-} from "metabase-enterprise/documents/components/Editor/shared/MenuComponents";-import {- LoadingSuggestionPaper,- SuggestionPaper,-} from "metabase-enterprise/documents/components/Editor/shared/SuggestionPaper";-import { getCurrentDocument } from "metabase-enterprise/documents/selectors";-import { getBrowseAllItemIndex } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/suggestionUtils";import type { SearchResult } from "metabase-types/api";import { EntitySearchSection } from "../shared/EntitySearchSection";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.unit.spec.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.unit.spec.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.unit.spec.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CommandSuggestion.unit.spec.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CreateNativeQuestionModal.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CreateNativeQuestionModal.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CreateNativeQuestionModal.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CreateNativeQuestionModal.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CreateStructuredQuestionModal.module.css b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CreateStructuredQuestionModal.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CreateStructuredQuestionModal.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CreateStructuredQuestionModal.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CreateStructuredQuestionModal.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CreateStructuredQuestionModal.tsxsimilarity index 98%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CreateStructuredQuestionModal.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CreateStructuredQuestionModal.tsxindex a327ffb46d3..4498b7cc9ef 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/CreateStructuredQuestionModal.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/CreateStructuredQuestionModal.tsx@@ -2,16 +2,16 @@ import { useMemo, useState } from "react";import { t } from "ttag";import _ from "underscore";+import {+ createDraftCard,+ generateDraftCardId,+ loadMetadataForDocumentCard,+} from "metabase/documents/documents.slice";import { useDispatch, useSelector, useStore } from "metabase/lib/redux";import { Notebook } from "metabase/querying/notebook/components/Notebook";import { getMetadata } from "metabase/selectors/metadata";import { getSetting } from "metabase/selectors/settings";import { Box, Button, Flex, Modal } from "metabase/ui";-import {- createDraftCard,- generateDraftCardId,- loadMetadataForDocumentCard,-} from "metabase-enterprise/documents/documents.slice";import * as Lib from "metabase-lib";import Question from "metabase-lib/v1/Question";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/NewQuestionTypeMenuView.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/NewQuestionTypeMenuView.tsxsimilarity index 94%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/NewQuestionTypeMenuView.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/NewQuestionTypeMenuView.tsxindex f1f0d36995b..7498ad4749e 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/NewQuestionTypeMenuView.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/NewQuestionTypeMenuView.tsx@@ -1,6 +1,6 @@import { useCallback, useLayoutEffect } from "react";-import { MenuItemComponent } from "metabase-enterprise/documents/components/Editor/shared/MenuComponents";+import { MenuItemComponent } from "metabase/documents/components/Editor/shared/MenuComponents";import { CreateNativeQuestionModal } from "./CreateNativeQuestionModal";import { CreateStructuredQuestionModal } from "./CreateStructuredQuestionModal";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/types.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/types.tssimilarity index 80%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/types.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/types.tsindex 05991a275b1..ba94bd5c2fe 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/types.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/types.ts@@ -1,7 +1,7 @@import type { Editor } from "@tiptap/core";+import type { MenuItem } from "metabase/documents/components/Editor/shared/MenuComponents";import type { IconName } from "metabase/ui";-import type { MenuItem } from "metabase-enterprise/documents/components/Editor/shared/MenuComponents";export interface CommandOption {icon?: IconName;diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/use-create-questions-menu-items.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/use-create-questions-menu-items.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/use-create-questions-menu-items.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/use-create-questions-menu-items.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/utils.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/utils.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Command/utils.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Command/utils.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/CustomStarterKit/CustomStarterKit.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/DisableMetabotSidebar.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/DisableMetabotSidebar.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/DisableMetabotSidebar.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/DisableMetabotSidebar.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/DropCursor/DropCursor.module.css b/frontend/src/metabase/rich_text_editing/tiptap/extensions/DropCursor/DropCursor.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/DropCursor/DropCursor.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/DropCursor/DropCursor.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Emoji/EmojiSuggestionExtension.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Emoji/EmojiSuggestionExtension.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Emoji/EmojiSuggestionExtension.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Emoji/EmojiSuggestionExtension.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.module.css b/frontend/src/metabase/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/FlexContainer/FlexContainer.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToCard.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToCard.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToCard.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToCard.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToDocument.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToDocument.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToDocument.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToDocument.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToFlexContainer.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToFlexContainer.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToFlexContainer.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/cardToFlexContainer.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/index.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/index.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/DropHandlers/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/HandleEditorDrop.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/HandleEditorDrop.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/HandleEditorDrop.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/HandleEditorDrop.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/utils.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/utils.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/HandleEditorDrop/utils.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/HandleEditorDrop/utils.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Heading/Heading.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Heading/Heading.tsxsimilarity index 87%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Heading/Heading.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Heading/Heading.tsxindex 0260fcc34e0..201e1e8f551 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Heading/Heading.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Heading/Heading.tsx@@ -9,18 +9,18 @@ import {import cx from "classnames";import { useEffect, useMemo, useState } from "react";-import { isWithinIframe } from "metabase/lib/dom";-import { useSelector } from "metabase/lib/redux";-import { useListCommentsQuery } from "metabase-enterprise/api";-import { getTargetChildCommentThreads } from "metabase-enterprise/comments/utils";-import { CommentsMenu } from "metabase-enterprise/documents/components/Editor/CommentsMenu";+import { useListCommentsQuery } from "metabase/api";+import { getTargetChildCommentThreads } from "metabase/comments/utils";+import { CommentsMenu } from "metabase/documents/components/Editor/CommentsMenu";import {getChildTargetId,getCurrentDocument,getHoveredChildTargetId,-} from "metabase-enterprise/documents/selectors";-import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";-import { isTopLevel } from "metabase-enterprise/documents/utils/editorNodeUtils";+} from "metabase/documents/selectors";+import { getListCommentsQuery } from "metabase/documents/utils/api";+import { isTopLevel } from "metabase/documents/utils/editorNodeUtils";+import { isWithinIframe } from "metabase/lib/dom";+import { useSelector } from "metabase/lib/redux";import { createIdAttribute, createProseMirrorPlugin } from "../NodeIds";import S from "../extensions.module.css";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Heading/index.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Heading/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Heading/index.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Heading/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/LinkHoverMenu/LinkHoverMenu.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/LinkHoverMenu/LinkHoverMenu.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/LinkHoverMenu/LinkHoverMenu.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/LinkHoverMenu/LinkHoverMenu.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionExtension.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Mention/MentionExtension.tssimilarity index 96%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionExtension.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Mention/MentionExtension.tsindex ec893eb5162..468713d2ec1 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionExtension.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Mention/MentionExtension.ts@@ -3,7 +3,7 @@ import type { Node as ProseMirrorNode } from "@tiptap/pm/model";import { PluginKey } from "@tiptap/pm/state";import Suggestion, { type SuggestionOptions } from "@tiptap/suggestion";-import { trackDocumentAddSmartLink } from "metabase-enterprise/documents/analytics";+import { trackDocumentAddSmartLink } from "metabase/documents/analytics";import type { Document } from "metabase-types/api";export interface MentionOptions {diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.tsxsimilarity index 95%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.tsxindex 53ee2d2909d..983d8dc66a8 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.tsx@@ -2,12 +2,12 @@ import type { Editor, Range } from "@tiptap/core";import { forwardRef, useCallback, useImperativeHandle } from "react";import { t } from "ttag";-import { useSelector } from "metabase/lib/redux";import {LoadingSuggestionPaper,SuggestionPaper,-} from "metabase-enterprise/documents/components/Editor/shared/SuggestionPaper";-import { getCurrentDocument } from "metabase-enterprise/documents/selectors";+} from "metabase/documents/components/Editor/shared/SuggestionPaper";+import { getCurrentDocument } from "metabase/documents/selectors";+import { useSelector } from "metabase/lib/redux";import type { SearchResult } from "metabase-types/api";import { EntitySearchSection } from "../shared/EntitySearchSection";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.unit.spec.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.unit.spec.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.unit.spec.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Mention/MentionSuggestion.unit.spec.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.module.css b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.tsxsimilarity index 84%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.tsxindex 67e8d8f0038..36e478fd9a5 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.tsx@@ -12,18 +12,16 @@ import { useLatest } from "react-use";import { t } from "ttag";import CS from "metabase/css/core/index.css";-import { useDispatch, useSelector } from "metabase/lib/redux";-import { PLUGIN_METABOT } from "metabase/plugins";-import { Box, Button, Flex, Icon, Text, Tooltip } from "metabase/ui";-import { useLazyMetabotGenerateContentQuery } from "metabase-enterprise/api/metabot";-import { trackDocumentAskMetabot } from "metabase-enterprise/documents/analytics";+import { trackDocumentAskMetabot } from "metabase/documents/analytics";import {createDraftCard,generateDraftCardId,loadMetadataForDocumentCard,-} from "metabase-enterprise/documents/documents.slice";-import { getCurrentDocument } from "metabase-enterprise/documents/selectors";-import MetabotThinkingStyles from "metabase-enterprise/metabot/components/MetabotChat/MetabotThinking.module.css";+} from "metabase/documents/documents.slice";+import { getCurrentDocument } from "metabase/documents/selectors";+import { useDispatch, useSelector } from "metabase/lib/redux";+import { PLUGIN_METABOT } from "metabase/plugins";+import { Box, Button, Flex, Icon, Text, Tooltip } from "metabase/ui";import type { Card, MetabotGenerateContentRequest } from "metabase-types/api";import { wrapCardEmbed } from "../shared/layout";@@ -153,7 +151,7 @@ export const MetabotComponent = memo(const controllerRef = useRef<AbortController | null>(null);const [isLoading, setIsLoading] = useState(false);const [errorText, setErrorText] = useState("");- const [queryMetabot] = useLazyMetabotGenerateContentQuery();+ const [queryMetabot] = PLUGIN_METABOT.useLazyMetabotGenerateContentQuery();const isMetabotEnabled = PLUGIN_METABOT.isEnabled();const handleRunMetabot = async () => {@@ -297,21 +295,30 @@ export const MetabotComponent = memo(direction="column"mb="md">- <Button- variant="subtle"+ <Boxpos="absolute"top={0}right={0}- p="sm"- m="sm"- size="sm"opacity="0.5"className={S.closeButton}- onClick={() => deleteNode()}>- <Icon name="close" data-hide-on-print />- <Icon name="metabot" data-show-on-print />- </Button>+ {editor.options.editable ? (+ <Button+ variant="subtle"+ p="sm"+ m="sm"+ size="sm"+ onClick={() => deleteNode()}+ >+ <Icon name="close" data-hide-on-print />+ <Icon name="metabot" data-show-on-print />+ </Button>+ ) : (+ <Box p="md">+ <Icon name="metabot" />+ </Box>+ )}+ </Box><Flex flex={1} direction="column" className={S.contentWrapper}><BoxclassName={S.placeholder}@@ -321,7 +328,7 @@ export const MetabotComponent = memo({t`Ask Metabot to generate a chart for you, and use @ to select a specific Database to use`}</Box><NodeViewContent- contentEditable={!isLoading}+ contentEditable={isLoading ? false : undefined}className={S.codeBlockTextArea}/></Flex>@@ -330,7 +337,9 @@ export const MetabotComponent = memo({isLoading ? (<Textflex={1}- className={MetabotThinkingStyles.toolCallStarted}+ className={+ PLUGIN_METABOT.MetabotThinkingStyles.toolCallStarted+ }>{t`Working on it...`}</Text>@@ -343,25 +352,27 @@ export const MetabotComponent = memo(</Flex>) : null}</Flex>- <Tooltip- label={tooltip}- disabled={tooltip == null}- position="bottom"- >- <Button- size="sm"- disabled={!isMetabotEnabled}- onClick={() =>- isLoading ? handleStopMetabot() : handleRunMetabot()- }- classNames={{- label: CS.flex, // ensures icon is vertically centered- }}- data-hide-on-print+ {editor.options.editable && (+ <Tooltip+ label={tooltip}+ disabled={tooltip == null}+ position="bottom">- {isLoading ? <Icon name="close" /> : t`Run`}- </Button>- </Tooltip>+ <Button+ size="sm"+ disabled={!isMetabotEnabled}+ onClick={() =>+ isLoading ? handleStopMetabot() : handleRunMetabot()+ }+ classNames={{+ label: CS.flex, // ensures icon is vertically centered+ }}+ data-hide-on-print+ >+ {isLoading ? <Icon name="close" /> : t`Run`}+ </Button>+ </Tooltip>+ )}</Flex></Flex></NodeViewWrapper>diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.unit.spec.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.unit.spec.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.unit.spec.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/MetabotEmbed.unit.spec.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotEmbed/__support__/editor-mocks.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/__support__/editor-mocks.tssimilarity index 73%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotEmbed/__support__/editor-mocks.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/__support__/editor-mocks.tsindex bcf176af1a1..0b1de28ca2d 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotEmbed/__support__/editor-mocks.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/__support__/editor-mocks.ts@@ -1,6 +1,6 @@import type { Editor } from "@tiptap/react";-export const createMockEditor = (overrides = {}): Editor =>+export const createMockEditor = (overrides: Partial<Editor> = {}): Editor =>({on: jest.fn(),off: jest.fn(),@@ -15,5 +15,9 @@ export const createMockEditor = (overrides = {}): Editor =>selection: { $from: {}, empty: true },doc: { nodeAt: jest.fn(), resolve: jest.fn() },},+ options: {+ editable: true,+ ...overrides.options,+ },...overrides,}) as unknown as Editor;diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotEmbed/__support__/node-view-mocks.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/__support__/node-view-mocks.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotEmbed/__support__/node-view-mocks.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/__support__/node-view-mocks.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotEmbed/index.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotEmbed/index.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotEmbed/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotMention/MetabotMentionExtension.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotMentionExtension.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotMention/MetabotMentionExtension.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotMentionExtension.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.tsxsimilarity index 92%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.tsxindex c6682699afd..57059fa9223 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/MetabotMention/MetabotSuggestion.tsx@@ -15,10 +15,10 @@ import type {Section,} from "metabase/common/components/AccordionList/types";import { searchFilter } from "metabase/common/components/AccordionList/utils";+import type { MenuItem } from "metabase/documents/components/Editor/shared/MenuComponents";+import { MenuItemComponent } from "metabase/documents/components/Editor/shared/MenuComponents";+import { SuggestionPaper } from "metabase/documents/components/Editor/shared/SuggestionPaper";import { Box, Group, Loader, Text } from "metabase/ui";-import type { MenuItem } from "metabase-enterprise/documents/components/Editor/shared/MenuComponents";-import { MenuItemComponent } from "metabase-enterprise/documents/components/Editor/shared/MenuComponents";-import { SuggestionPaper } from "metabase-enterprise/documents/components/Editor/shared/SuggestionPaper";import type { Database, SearchResult } from "metabase-types/api";import { buildDbMenuItems } from "../shared/suggestionUtils";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/NodeIds/constants.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/NodeIds/constants.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/NodeIds/constants.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/NodeIds/constants.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/NodeIds/index.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/NodeIds/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/NodeIds/index.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/NodeIds/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/NodeIds/utils.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/NodeIds/utils.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/NodeIds/utils.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/NodeIds/utils.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/OrderedList/OrderedList.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/OrderedList/OrderedList.tsxsimilarity index 87%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/OrderedList/OrderedList.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/OrderedList/OrderedList.tsxindex 97861b8e6cc..469cf3521e8 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/OrderedList/OrderedList.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/OrderedList/OrderedList.tsx@@ -9,18 +9,18 @@ import {import cx from "classnames";import { useEffect, useMemo, useState } from "react";-import { isWithinIframe } from "metabase/lib/dom";-import { useSelector } from "metabase/lib/redux";-import { useListCommentsQuery } from "metabase-enterprise/api";-import { getTargetChildCommentThreads } from "metabase-enterprise/comments/utils";-import { CommentsMenu } from "metabase-enterprise/documents/components/Editor/CommentsMenu";+import { useListCommentsQuery } from "metabase/api";+import { getTargetChildCommentThreads } from "metabase/comments/utils";+import { CommentsMenu } from "metabase/documents/components/Editor/CommentsMenu";import {getChildTargetId,getCurrentDocument,getHoveredChildTargetId,-} from "metabase-enterprise/documents/selectors";-import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";-import { isTopLevel } from "metabase-enterprise/documents/utils/editorNodeUtils";+} from "metabase/documents/selectors";+import { getListCommentsQuery } from "metabase/documents/utils/api";+import { isTopLevel } from "metabase/documents/utils/editorNodeUtils";+import { isWithinIframe } from "metabase/lib/dom";+import { useSelector } from "metabase/lib/redux";import { createIdAttribute, createProseMirrorPlugin } from "../NodeIds";import S from "../extensions.module.css";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/OrderedList/index.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/OrderedList/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/OrderedList/index.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/OrderedList/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Paragraph/Paragraph.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Paragraph/Paragraph.tsxsimilarity index 86%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Paragraph/Paragraph.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Paragraph/Paragraph.tsxindex 3b2dfdf81d3..2f373194838 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Paragraph/Paragraph.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Paragraph/Paragraph.tsx@@ -9,18 +9,18 @@ import {import cx from "classnames";import { useEffect, useMemo, useState } from "react";-import { isWithinIframe } from "metabase/lib/dom";-import { useSelector } from "metabase/lib/redux";-import { useListCommentsQuery } from "metabase-enterprise/api";-import { getTargetChildCommentThreads } from "metabase-enterprise/comments/utils";-import { CommentsMenu } from "metabase-enterprise/documents/components/Editor/CommentsMenu";+import { useListCommentsQuery } from "metabase/api";+import { getTargetChildCommentThreads } from "metabase/comments/utils";+import { CommentsMenu } from "metabase/documents/components/Editor/CommentsMenu";import {getChildTargetId,getCurrentDocument,getHoveredChildTargetId,-} from "metabase-enterprise/documents/selectors";-import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";-import { isTopLevel } from "metabase-enterprise/documents/utils/editorNodeUtils";+} from "metabase/documents/selectors";+import { getListCommentsQuery } from "metabase/documents/utils/api";+import { isTopLevel } from "metabase/documents/utils/editorNodeUtils";+import { isWithinIframe } from "metabase/lib/dom";+import { useSelector } from "metabase/lib/redux";import { createIdAttribute, createProseMirrorPlugin } from "../NodeIds";import S from "../extensions.module.css";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Paragraph/index.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/Paragraph/index.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/Paragraph/index.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/Paragraph/index.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/PlainLink/PlainLink.module.css b/frontend/src/metabase/rich_text_editing/tiptap/extensions/PlainLink/PlainLink.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/PlainLink/PlainLink.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/PlainLink/PlainLink.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/PlainLink/PlainLink.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/PlainLink/PlainLink.tssimilarity index 98%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/PlainLink/PlainLink.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/PlainLink/PlainLink.tsindex ea99889ad4c..74a84d0acb0 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/PlainLink/PlainLink.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/PlainLink/PlainLink.ts@@ -8,7 +8,7 @@ import { Link } from "@tiptap/extension-link";import cx from "classnames";import CS from "metabase/css/core/index.css";-import { processUrl } from "metabase-enterprise/documents/utils/processUrl";+import { processUrl } from "metabase/documents/utils/processUrl";import S from "./PlainLink.module.css";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode.module.css b/frontend/src/metabase/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/ResizeNode/ResizeNode.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.module.css b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsxsimilarity index 97%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsxindex 92130b45f53..f81ebf6732a 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.tsx@@ -14,9 +14,12 @@ import {useGetCollectionQuery,useGetDashboardQuery,useGetDatabaseQuery,+ useGetDocumentQuery,useGetSegmentQuery,useGetTableQuery,+ useListMentionsQuery,} from "metabase/api";+import { updateMentionsCache } from "metabase/documents/documents.slice";import {type IconModel,type ObjectWithModel,@@ -25,17 +28,12 @@ import {import { useDispatch } from "metabase/lib/redux";import { modelToUrl } from "metabase/lib/urls/modelToUrl";import { extractEntityId } from "metabase/lib/urls/utils";-import { Icon } from "metabase/ui";-import {- useGetDocumentQuery,- useGetTransformQuery,- useListMentionsQuery,-} from "metabase-enterprise/api";-import { updateMentionsCache } from "metabase-enterprise/documents/documents.slice";import {METABSE_PROTOCOL_MD_LINK,parseMetabaseProtocolMarkdownLink,-} from "metabase-enterprise/metabot/utils/links";+} from "metabase/metabot/utils/links";+import { PLUGIN_TRANSFORMS } from "metabase/plugins";+import { Icon } from "metabase/ui";import type {Card,CardDisplayType,@@ -319,8 +317,8 @@ export const useEntityData = (},);- const transformQuery = useGetTransformQuery(entityId!, {- skip: !entityId || model !== "transform",+ const transformQuery = PLUGIN_TRANSFORMS.useGetTransformQuery(entityId!, {+ skip: !PLUGIN_TRANSFORMS.isEnabled || !entityId || model !== "transform",});const actionQuery = useGetActionQuery(@@ -472,7 +470,7 @@ export const SmartLinkComponent = memo(if (model === "user" && isMentionableUser(entity)) {return (<NodeViewWrapper as="span">- <span className={styles.userMention}>@{entity.name}</span>+ <span className={styles.userMention}>@{entity.common_name}</span></NodeViewWrapper>);}diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.unit.spec.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.unit.spec.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.unit.spec.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/SmartLink/SmartLinkNode.unit.spec.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.module.css b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.tsxsimilarity index 84%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.tsxindex 59d3b3027f0..4ead0db96eb 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/SupportingText/SupportingText.tsx@@ -15,19 +15,19 @@ import { useMemo } from "react";import { push } from "react-router-redux";import { t } from "ttag";-import { isWithinIframe } from "metabase/lib/dom";-import { useDispatch, useSelector } from "metabase/lib/redux/hooks";-import { Box } from "metabase/ui";-import { useListCommentsQuery } from "metabase-enterprise/api/comment";-import { getTargetChildCommentThreads } from "metabase-enterprise/comments/utils";-import { getUnresolvedComments } from "metabase-enterprise/documents/components/Editor/CommentsMenu";+import { useListCommentsQuery } from "metabase/api/comment";+import { getTargetChildCommentThreads } from "metabase/comments/utils";+import { getUnresolvedComments } from "metabase/documents/components/Editor/CommentsMenu";import {getChildTargetId,getCurrentDocument,-} from "metabase-enterprise/documents/selectors";-import { getListCommentsQuery } from "metabase-enterprise/documents/utils/api";-import { DropZone } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/dnd/DropZone";-import { useDndHelpers } from "metabase-enterprise/rich_text_editing/tiptap/extensions/shared/dnd/use-dnd-helpers";+} from "metabase/documents/selectors";+import { getListCommentsQuery } from "metabase/documents/utils/api";+import { isWithinIframe } from "metabase/lib/dom";+import { useDispatch, useSelector } from "metabase/lib/redux/hooks";+import { DropZone } from "metabase/rich_text_editing/tiptap/extensions/shared/dnd/DropZone";+import { useDndHelpers } from "metabase/rich_text_editing/tiptap/extensions/shared/dnd/use-dnd-helpers";+import { Box } from "metabase/ui";import { CommentsButton } from "../../components/CommentsButton";import { cleanupFlexContainerNodes } from "../HandleEditorDrop/utils";@@ -204,29 +204,31 @@ const SupportingTextComponent = ({</div>{/* Would be nice to use a real `button` here, but that prevents ProseMirror plugin dragstart events from firing */}- <div- role="button"- tabIndex={0}- data-drag-handle- ref={dragElRef}- contentEditable={false}- aria-label={t`Supporting text`}- className={S.handle}- onClick={() => {- const pos = getPos();- pos && editor.commands.setNodeSelection(pos);- }}- onKeyDown={(e) => {- if (e.key === "Backspace" || e.key === "Delete") {+ {canWrite && (+ <div+ role="button"+ tabIndex={0}+ data-drag-handle+ ref={dragElRef}+ contentEditable={false}+ aria-label={t`Supporting text`}+ className={S.handle}+ onClick={() => {const pos = getPos();- deleteNode();- cleanupFlexContainerNodes(editor.view);- if (pos != null) {- editor.commands.focus(pos);+ pos && editor.commands.setNodeSelection(pos);+ }}+ onKeyDown={(e) => {+ if (e.key === "Backspace" || e.key === "Delete") {+ const pos = getPos();+ deleteNode();+ cleanupFlexContainerNodes(editor.view);+ if (pos != null) {+ editor.commands.focus(pos);+ }}- }- }}- />+ }}+ />+ )}{document && !isWithinIframe() && (<Boxpos="absolute"diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/extensions.module.css b/frontend/src/metabase/rich_text_editing/tiptap/extensions/extensions.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/extensions.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/extensions.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/EntitySearchSection.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/EntitySearchSection.tsxsimilarity index 94%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/EntitySearchSection.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/EntitySearchSection.tsxindex 21b1b4f6d02..7bfbca0c4ab 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/EntitySearchSection.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/EntitySearchSection.tsx@@ -2,13 +2,13 @@ import { t } from "ttag";import { QuestionPickerModal } from "metabase/common/components/Pickers/QuestionPicker/components/QuestionPickerModal";import type { QuestionPickerValueItem } from "metabase/common/components/Pickers/QuestionPicker/types";-import { Box, Divider, Text } from "metabase/ui";-import type { MenuItem } from "metabase-enterprise/documents/components/Editor/shared/MenuComponents";+import type { MenuItem } from "metabase/documents/components/Editor/shared/MenuComponents";import {CreateNewQuestionFooter,MenuItemComponent,SearchResultsFooter,-} from "metabase-enterprise/documents/components/Editor/shared/MenuComponents";+} from "metabase/documents/components/Editor/shared/MenuComponents";+import { Box, Divider, Text } from "metabase/ui";import type { SearchResult } from "metabase-types/api";import { getBrowseAllItemIndex } from "./suggestionUtils";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/NativeQueryModal.module.css b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/NativeQueryModal.module.csssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/NativeQueryModal.module.cssrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/NativeQueryModal.module.cssdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/NativeQueryModal.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/NativeQueryModal.tsxsimilarity index 99%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/NativeQueryModal.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/NativeQueryModal.tsxindex 390cfa074a5..2b66b48dd39 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/NativeQueryModal.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/NativeQueryModal.tsx@@ -4,6 +4,11 @@ import { c, t } from "ttag";import EmptyCodeResult from "assets/img/empty-states/code.svg";import { datasetApi } from "metabase/api/dataset";import { ErrorMessage } from "metabase/common/components/ErrorMessage";+import {+ createDraftCard,+ generateDraftCardId,+ loadMetadataForDocumentCard,+} from "metabase/documents/documents.slice";import { isMac } from "metabase/lib/browser";import { useDispatch, useSelector } from "metabase/lib/redux";import NativeQueryEditor from "metabase/query_builder/components/NativeQueryEditor";@@ -13,11 +18,6 @@ import { getMetadata } from "metabase/selectors/metadata";import { Box, Button, Flex, Loader, Modal, Stack, Text } from "metabase/ui";import Visualization from "metabase/visualizations/components/Visualization";import NoResultsView from "metabase/visualizations/components/Visualization/NoResultsView/NoResultsView";-import {- createDraftCard,- generateDraftCardId,- loadMetadataForDocumentCard,-} from "metabase-enterprise/documents/documents.slice";import * as Lib from "metabase-lib";import Question from "metabase-lib/v1/Question";import type NativeQuery from "metabase-lib/v1/queries/NativeQuery";diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/constants.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/constants.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/constants.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/constants.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/dnd/DropZone.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/dnd/DropZone.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/dnd/DropZone.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/dnd/DropZone.tsxdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/dnd/use-dnd-helpers.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/dnd/use-dnd-helpers.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/dnd/use-dnd-helpers.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/dnd/use-dnd-helpers.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/layout.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/layout.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/layout.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/layout.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/suggestionUtils.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/suggestionUtils.tssimilarity index 95%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/suggestionUtils.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/suggestionUtils.tsindex 6646492fcf8..3e031440ac9 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/suggestionUtils.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/suggestionUtils.ts@@ -1,11 +1,11 @@import { match } from "ts-pattern";import { getTranslatedEntityName } from "metabase/common/utils/model-names";+import type { MenuItem } from "metabase/documents/components/Editor/shared/MenuComponents";import { getIcon } from "metabase/lib/icon";import { getName } from "metabase/lib/name";import { type UrlableModel, modelToUrl } from "metabase/lib/urls/modelToUrl";-import type { MenuItem } from "metabase-enterprise/documents/components/Editor/shared/MenuComponents";-import type { MetabaseProtocolEntityModel } from "metabase-enterprise/metabot/utils/links";+import type { MetabaseProtocolEntityModel } from "metabase/metabot/utils/links";import type {Database,MentionableUser,diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/types.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/types.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/types.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/types.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/useEntitySearch.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/useEntitySearch.tssimilarity index 93%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/useEntitySearch.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/useEntitySearch.tsindex 4f013bc3211..e32be281ccd 100644--- a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/useEntitySearch.ts+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/useEntitySearch.ts@@ -1,8 +1,11 @@import { useMemo } from "react";-import { useListRecentsQuery, useSearchQuery } from "metabase/api";-import { useListMentionsQuery } from "metabase-enterprise/api";-import type { MenuItem } from "metabase-enterprise/documents/components/Editor/shared/MenuComponents";+import {+ useListMentionsQuery,+ useListRecentsQuery,+ useSearchQuery,+} from "metabase/api";+import type { MenuItem } from "metabase/documents/components/Editor/shared/MenuComponents";import type {MentionableUser,RecentItem,diff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/useEntitySuggestions.ts b/frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/useEntitySuggestions.tssimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/shared/useEntitySuggestions.tsrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/shared/useEntitySuggestions.tsdiff --git a/enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/suggestionRenderer.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/suggestionRenderer.tsxsimilarity index 100%rename from enterprise/frontend/src/metabase-enterprise/rich_text_editing/tiptap/extensions/suggestionRenderer.tsxrename to frontend/src/metabase/rich_text_editing/tiptap/extensions/suggestionRenderer.tsxdiff --git a/frontend/src/metabase/routes-public.jsx b/frontend/src/metabase/routes-public.jsxindex 8cbfa1c62bb..7d24f21182d 100644--- a/frontend/src/metabase/routes-public.jsx+++ b/frontend/src/metabase/routes-public.jsx@@ -1,13 +1,12 @@import { Route } from "react-router";-import { PLUGIN_PUBLIC_SHARING } from "metabase/plugins";import { PublicNotFound } from "metabase/public/components/PublicNotFound";import PublicAction from "metabase/public/containers/PublicAction";import PublicApp from "metabase/public/containers/PublicApp";+import { PublicDocument } from "metabase/public/containers/PublicDocument";+import { PublicOrEmbeddedDashboardPage } from "metabase/public/containers/PublicOrEmbeddedDashboard";import { PublicOrEmbeddedQuestion } from "metabase/public/containers/PublicOrEmbeddedQuestion";-import { PublicOrEmbeddedDashboardPage } from "./public/containers/PublicOrEmbeddedDashboard";-export const getRoutes = (store) => {return (<Route>@@ -18,10 +17,7 @@ export const getRoutes = (store) => {path="dashboard/:uuid(/:tabSlug)"component={PublicOrEmbeddedDashboardPage}/>- <Route- path="document/:uuid"- component={PLUGIN_PUBLIC_SHARING.PublicDocumentRoute}- />+ <Route path="document/:uuid" component={PublicDocument} /><Route path="*" component={PublicNotFound} /></Route><Route path="*" component={PublicNotFound} />diff --git a/frontend/src/metabase/routes.jsx b/frontend/src/metabase/routes.jsxindex 391baec7e7c..5f20104f7c3 100644--- a/frontend/src/metabase/routes.jsx+++ b/frontend/src/metabase/routes.jsx@@ -30,6 +30,8 @@ import { ArchiveDashboardModalConnected } from "metabase/dashboard/containers/Arimport { AutomaticDashboardApp } from "metabase/dashboard/containers/AutomaticDashboardApp";import { DashboardApp } from "metabase/dashboard/containers/DashboardApp/DashboardApp";import { TableDetailPage } from "metabase/detail-view/pages/TableDetailPage";+import { CommentsSidesheet } from "metabase/documents/components/CommentsSidesheet";+import { DocumentPageOuter } from "metabase/documents/routes";import { ModalRoute } from "metabase/hoc/ModalRoute";import { HomePage } from "metabase/home/components/HomePage";import { Onboarding } from "metabase/home/components/Onboarding";@@ -39,7 +41,6 @@ import { getRoutes as getModelRoutes } from "metabase/models/routes";import {PLUGIN_COLLECTIONS,PLUGIN_DATA_STUDIO,- PLUGIN_DOCUMENTS,PLUGIN_LANDING_PAGE,PLUGIN_METABOT,PLUGIN_TABLE_EDITING,@@ -154,7 +155,17 @@ export const getRoutes = (store) => {<Redirect from="archive" to="trash" replace /><Route path="trash" component={TrashCollectionLanding} />- {PLUGIN_DOCUMENTS.getRoutes()}+ <Route path="document/:entityId" component={DocumentPageOuter}>+ <ModalRoute+ path="comments/:childTargetId"+ modal={CommentsSidesheet}+ noWrap+ modalProps={{+ enableTransition: false,+ closeOnClickOutside: false,+ }}+ />+ </Route><Routepath="collection/entity/:entity_id(**)"diff --git a/frontend/src/metabase/selectors/app.ts b/frontend/src/metabase/selectors/app.tsindex a9e79b20662..9406c7261c5 100644--- a/frontend/src/metabase/selectors/app.ts+++ b/frontend/src/metabase/selectors/app.ts@@ -7,7 +7,7 @@ import {getDashboardId,getIsEditing as getIsEditingDashboard,} from "metabase/dashboard/selectors";-import { PLUGIN_DOCUMENTS } from "metabase/plugins";+import { getCurrentDocument } from "metabase/documents/selectors";import {getIsSavedQuestionChanged,getQuestion,@@ -71,7 +71,7 @@ export const getIsCollectionPathVisible = createSelector([getQuestion,getDashboard,- (state) => PLUGIN_DOCUMENTS.getCurrentDocument(state),+ getCurrentDocument,getRouterPath,getIsEmbeddingIframe,getEmbedOptions,@@ -227,7 +227,7 @@ export const getCollectionId = createSelector(getQuestion,getDashboard,getDashboardId,- (state) => PLUGIN_DOCUMENTS.getCurrentDocument(state),+ getCurrentDocument,getDetailViewState,],(question, dashboard, dashboardId, document, detailView) => {diff --git a/frontend/src/metabase/services.js b/frontend/src/metabase/services.jsindex ac19da301e4..c246c2ae1e8 100644--- a/frontend/src/metabase/services.js+++ b/frontend/src/metabase/services.js@@ -203,8 +203,8 @@ export const PublicApi = {prefetchDashcardValues: GET(`${publicBase}/dashboard/:dashboardId/dashcard/:dashcardId/execute`,),- document: GET(`/api/ee/public/document/:uuid`),- documentCardQuery: GET(`/api/ee/public/document/:uuid/card/:cardId`),+ document: GET(`/api/public/document/:uuid`),+ documentCardQuery: GET(`/api/public/document/:uuid/card/:cardId`),};export const EmbedApi = {diff --git a/frontend/test/__support__/server-mocks/comment.ts b/frontend/test/__support__/server-mocks/comment.tsindex 82797ad7a4d..2e9914859da 100644--- a/frontend/test/__support__/server-mocks/comment.ts+++ b/frontend/test/__support__/server-mocks/comment.ts@@ -6,7 +6,7 @@ export const setupCommentEndpoints = (comments: Comment[],{ target_type, target_id }: { target_type: "document"; target_id: number },) => {- const url = new URL("api/ee/comment", "http://localhost");+ const url = new URL("api/comment", "http://localhost");url.searchParams.append("target_type", target_type);url.searchParams.append("target_id", target_id.toString());diff --git a/frontend/test/__support__/server-mocks/document.ts b/frontend/test/__support__/server-mocks/document.tsindex 2f917218f9e..20079dd8da3 100644--- a/frontend/test/__support__/server-mocks/document.ts+++ b/frontend/test/__support__/server-mocks/document.ts@@ -1,13 +1,19 @@import fetchMock from "fetch-mock";-import type { Document } from "metabase-types/api";+import type { Document, GetPublicDocument } from "metabase-types/api";export function setupDocumentEndpoints(doc: Document) {- fetchMock.get(`path:/api/ee/document/${doc.id}`, doc);- fetchMock.post(`path:/api/ee/document/${doc.id}`, {});- fetchMock.put(`path:/api/ee/document/${doc.id}`, async (call) => {+ fetchMock.get(`path:/api/document/${doc.id}`, doc);+ fetchMock.post(`path:/api/document/${doc.id}`, {});+ fetchMock.put(`path:/api/document/${doc.id}`, async (call) => {const body = await call?.request?.json();return { ...doc, ...body };});- fetchMock.delete(`path:/api/ee/document/${doc.id}`, {});+ fetchMock.delete(`path:/api/document/${doc.id}`, {});+}++export function setupListPublicDocumentsEndpoint(+ publicDocuments: GetPublicDocument[],+) {+ fetchMock.get("path:/api/document/public", publicDocuments);}diff --git a/src/metabase/activity_feed/models/recent_views.clj b/src/metabase/activity_feed/models/recent_views.cljindex fb8b64cc188..6f57e5ae795 100644--- a/src/metabase/activity_feed/models/recent_views.clj+++ b/src/metabase/activity_feed/models/recent_views.clj@@ -38,7 +38,6 @@[metabase.collections.models.collection.root :as root][metabase.config.core :as config][metabase.models.interface :as mi]- [metabase.premium-features.core :refer [defenterprise]][metabase.util :as u][metabase.util.honey-sql-2 :as h2x][metabase.util.log :as log]@@ -82,21 +81,18 @@"Keywords representing entity types that can be returned as recent views.";; n.b.: `:card`, `metric` and `:dataset` are stored in recent_views as "card", and a join with report_card is;; needed to distinguish between them. `:dataset` is an alias for `:model/Card` with type "model".- (cond-> [:card :dataset :metric- :dashboard :table :collection]- config/ee-available? (conj :document)))+ [:card :dataset :metric :dashboard :table :collection :document])(mu/defn rv-model->model"Given a rv-model, returns the toucan model identifier for it."[rvm :- (into [:enum] rv-models)]- (let [base-mapping {:dataset :model/Card- :card :model/Card- :dashboard :model/Dashboard- :table :model/Table- :collection :model/Collection}- document-mapping (when config/ee-available?- {:document :model/Document})]- (get (merge base-mapping document-mapping) rvm)))+ (get {:dataset :model/Card+ :card :model/Card+ :dashboard :model/Dashboard+ :table :model/Table+ :collection :model/Collection+ :document :model/Document}+ rvm))(defn- ids-to-prune-for-user+model [user-id model context](t2/select-fn-set :id@@ -460,14 +456,6 @@:left-join [[:metabase_database :db][:= :db.id :t.db_id]]}))- ;; ================== Recent Documents ==================--(defenterprise select-documents-for-recents- "Returns empty when not running in enterprise mode."- metabase-enterprise.documents.recent-views- [_document-ids]- [])-(defmethod fill-recent-view-info :table [{:keys [_model model_id timestamp model_object]}](let [table model_object](when (and (not= "hidden" (:visibility_type table))@@ -560,6 +548,30 @@(cond-> processed-item(not (:include-metadata? options)) (dissoc :result_metadata)))))))+;; ================== Recent Documents ==================++(defn- document-recents+ "Query to select recent document data. Returns documents with their collection information+ for use in recent views display."+ [document-ids]+ (if-not (seq document-ids)+ []+ (let [documents (t2/select :model/Document+ {:select [:d.id+ :d.name+ :d.archived+ [:d.collection_id :entity-coll-id]+ [:c.id :collection_id]+ [:c.name :collection_name]+ [:c.authority_level :collection_authority_level]]+ :from [[:document :d]]+ :where [:in :d.id document-ids]+ :left-join [[:collection :c]+ [:and+ [:= :c.id :d.collection_id]+ [:= :c.archived false]]]})]+ documents)))+(defn- get-entity->id->data [views](let [{card-ids :carddashboard-ids :dashboard@@ -572,7 +584,7 @@:dashboard (m/index-by :id (dashboard-recents dashboard-ids)):collection (m/index-by :id (collection-recents collection-ids)):table (m/index-by :id (table-recents table-ids))- :document (m/index-by :id (select-documents-for-recents document-ids))}))+ :document (m/index-by :id (document-recents document-ids))}))(def ^:private ItemValidator (mr/validator Item))diff --git a/src/metabase/analytics/stats.clj b/src/metabase/analytics/stats.cljindex b98fed53e81..5282a5a98c3 100644--- a/src/metabase/analytics/stats.clj+++ b/src/metabase/analytics/stats.clj@@ -829,9 +829,6 @@:enabled (if (premium-features/enable-database-routing?)(t2/exists? :model/DatabaseRouter)false)}- {:name :documents- :available (premium-features/enable-documents?)- :enabled (premium-features/enable-documents?)}{:name :config-text-file:available (premium-features/enable-config-text-file?):enabled (some? (get env/env :mb-config-file-path))}diff --git a/src/metabase/api/common.clj b/src/metabase/api/common.cljindex 385fa58fe1d..6c65d3714f1 100644--- a/src/metabase/api/common.clj+++ b/src/metabase/api/common.clj@@ -80,7 +80,6 @@"Dynamic variables and utility functions/macros for writing API functions."(:require[metabase.api.open-api :as open-api]- [metabase.config.core :as config][metabase.events.core :as events][metabase.models.interface :as mi][metabase.util :as u]@@ -422,8 +421,7 @@old-position :- [:maybe ms/PositiveInt]new-position :- [:maybe ms/PositiveInt]](let [update-fn! (fn [plus-or-minus position-update-clause]- (doseq [model (cond-> '[Card Dashboard Pulse]- config/ee-available? (conj 'Document))]+ (doseq [model '[Card Dashboard Pulse Document]](t2/update! model {:collection_id collection-id:collection_position position-update-clause}{:collection_position [plus-or-minus :collection_position 1]})))]@@ -575,6 +573,7 @@"dashboard" {:db-model :model/Dashboard :alias :dashboard}"database" {:db-model :model/Database :alias :database}"dataset" {:db-model :model/Card :alias :card}+ "document" {:db-model :model/Document :alias :document}"indexed-entity" {:db-model :model/ModelIndexValue :alias :model-index-value}"metric" {:db-model :model/Card :alias :card}"segment" {:db-model :model/Segment :alias :segment}diff --git a/src/metabase/api_routes/routes.clj b/src/metabase/api_routes/routes.cljindex fce2465fd17..efaf505a7f5 100644--- a/src/metabase/api_routes/routes.clj+++ b/src/metabase/api_routes/routes.clj@@ -17,8 +17,10 @@[metabase.channel.api][metabase.cloud-migration.api][metabase.collections-rest.api]+ [metabase.comments.api][metabase.config.core :as config][metabase.dashboards-rest.api]+ [metabase.documents.api][metabase.eid-translation.api][metabase.embedding-rest.api][metabase.geojson.api]@@ -66,8 +68,10 @@metabase.bug-reporting.api/keep-memetabase.cache.api/keep-memetabase.cloud-migration.api/keep-me+ metabase.comments.api/keep-memetabase.collections-rest.api/keep-memetabase.dashboards-rest.api/keep-me+ metabase.documents.api/keep-memetabase.eid-translation.api/keep-memetabase.geojson.api/keep-memetabase.glossary.api/keep-me@@ -142,10 +146,12 @@"/channel" (+auth metabase.channel.api/channel-routes)"/cloud-migration" (+auth 'metabase.cloud-migration.api)"/collection" (+auth 'metabase.collections-rest.api)+ "/comment" (+auth metabase.comments.api/routes)"/dashboard" (+auth 'metabase.dashboards-rest.api)"/database" (+auth 'metabase.warehouses-rest.api)"/dataset" (+auth 'metabase.query-processor.api)"/docs" (metabase.api.docs/make-routes #'routes)+ "/document" (+auth metabase.documents.api/routes)"/eid-translation" 'metabase.eid-translation.api"/email" metabase.channel.api/email-routes"/embed" (+message-only-exceptions metabase.embedding-rest.api/embedding-routes)diff --git a/src/metabase/bookmarks/api.clj b/src/metabase/bookmarks/api.cljindex 89059e24945..8af1912c7c3 100644--- a/src/metabase/bookmarks/api.clj+++ b/src/metabase/bookmarks/api.clj@@ -8,8 +8,6 @@[metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.bookmarks.models.bookmark :as bookmark]- [metabase.premium-features.core :as premium-features]- [metabase.util.i18n :refer [tru]][metabase.util.malli.schema :as ms][toucan2.core :as t2]))@@ -51,8 +49,6 @@[{:keys [model id]} :- [:map[:model Models][:id ms/PositiveInt]]]- (when (= model "document")- (premium-features/assert-has-feature :documents (tru "Documents")))(let [[item-model bookmark-model item-key] (lookup model)](api/read-check item-model id)(api/check (not (t2/exists? bookmark-model item-key id@@ -69,8 +65,6 @@[{:keys [model id]} :- [:map[:model Models][:id ms/PositiveInt]]]- (when (= model "document")- (premium-features/assert-has-feature :documents (tru "Documents")));; todo: allow admins to include an optional user id to delete for so they can delete other's bookmarks.(let [[_ bookmark-model item-key] (lookup model)](t2/delete! bookmark-modeldiff --git a/src/metabase/bookmarks/models/bookmark.clj b/src/metabase/bookmarks/models/bookmark.cljindex 390ce9f8ad5..c9aa258342c 100644--- a/src/metabase/bookmarks/models/bookmark.clj+++ b/src/metabase/bookmarks/models/bookmark.clj@@ -3,8 +3,6 @@[clojure.string :as str][metabase.app-db.core :as mdb][metabase.collections.models.collection :as collection]- [metabase.config.core :as config]- [metabase.premium-features.core :as premium-features][metabase.queries.schema :as queries.schema][metabase.util.honey-sql-2 :as h2x][metabase.util.malli :as mu]@@ -16,11 +14,13 @@(methodical/defmethod t2/table-name :model/DashboardBookmark [_model] :dashboard_bookmark)(methodical/defmethod t2/table-name :model/CollectionBookmark [_model] :collection_bookmark)(methodical/defmethod t2/table-name :model/BookmarkOrdering [_model] :bookmark_ordering)+(methodical/defmethod t2/table-name :model/DocumentBookmark [_model] :document_bookmark)(derive :model/CardBookmark :metabase/model)(derive :model/DashboardBookmark :metabase/model)(derive :model/CollectionBookmark :metabase/model)(derive :model/BookmarkOrdering :metabase/model)+(derive :model/DocumentBookmark :metabase/model)(defn- unqualify-key[k]@@ -62,11 +62,6 @@:authority_level])(assoc :id id-str))))-(defn- has-documents?- []- (and (premium-features/enable-documents?)- config/ee-available?))-(defn- bookmarks-union-query[user-id](let [as-null (when (= (mdb/db-type) :postgres) (h2x/->integer nil))@@ -97,56 +92,50 @@:created_at]:from [:collection_bookmark]:where [:= :user_id user-id]}]]- {:union-all (if (has-documents?)- (conj base-queries- {:select [[as-null :card_id]- [as-null :dashboard_id]- [as-null :collection_id]- :document_id- [:document_id :item_id]- [(h2x/literal "document") :type]- :created_at]- :from [:document_bookmark]- :where [:= :user_id user-id]})- base-queries)}))+ {:union-all (conj base-queries+ {:select [[as-null :card_id]+ [as-null :dashboard_id]+ [as-null :collection_id]+ :document_id+ [:document_id :item_id]+ [(h2x/literal "document") :type]+ :created_at]+ :from [:document_bookmark]+ :where [:= :user_id user-id]})}))(mu/defn bookmarks-for-user :- [:sequential BookmarkResult]"Get all bookmarks for a user. Each bookmark will have a string id made of the model and model-id, a type, anditem_id, name, and description from the underlying bookmarked item."[user-id]- (let [select-fields (cond-> [[:bookmark.created_at :created_at]- [:bookmark.type :type]- [:bookmark.item_id :item_id]- [:card.name (mdb/qualify :model/Card :name)]- [:card.type (mdb/qualify :model/Card :card_type)]- [:card.display (mdb/qualify :model/Card :display)]- [:card.description (mdb/qualify :model/Card :description)]- [:card.archived (mdb/qualify :model/Card :archived)]- [:dashboard.name (mdb/qualify :model/Dashboard :name)]- [:dashboard.description (mdb/qualify :model/Dashboard :description)]- [:dashboard.archived (mdb/qualify :model/Dashboard :archived)]- [:collection.name (mdb/qualify :model/Collection :name)]- [:collection.authority_level (mdb/qualify :model/Collection :authority_level)]- [:collection.description (mdb/qualify :model/Collection :description)]- [:collection.archived (mdb/qualify :model/Collection :archived)]]- (has-documents?)- (conj [:document.name (mdb/qualify :model/Document :name)]- [:document.archived (mdb/qualify :model/Document :archived)]))- left-joins (cond-> [[:report_card :card] [:= :bookmark.card_id :card.id]- [:report_dashboard :dashboard] [:= :bookmark.dashboard_id :dashboard.id]- ;; use of [[h2x/identifier]] here is a workaround for https://github.com/seancorfield/honeysql/issues/450- [:collection :collection] [:in :collection.id [(h2x/identifier :field :bookmark :collection_id)- (h2x/identifier :field :dashboard :collection_id)]]- [:bookmark_ordering :bookmark_ordering] [:and- [:= :bookmark_ordering.user_id user-id]- [:= :bookmark_ordering.type :bookmark.type]- [:= :bookmark_ordering.item_id :bookmark.item_id]]]- (has-documents?)- (conj [:document :document] [:= :bookmark.document_id :document.id]))+ (let [select-fields [[:bookmark.created_at :created_at]+ [:bookmark.type :type]+ [:bookmark.item_id :item_id]+ [:card.name (mdb/qualify :model/Card :name)]+ [:card.type (mdb/qualify :model/Card :card_type)]+ [:card.display (mdb/qualify :model/Card :display)]+ [:card.description (mdb/qualify :model/Card :description)]+ [:card.archived (mdb/qualify :model/Card :archived)]+ [:dashboard.name (mdb/qualify :model/Dashboard :name)]+ [:dashboard.description (mdb/qualify :model/Dashboard :description)]+ [:dashboard.archived (mdb/qualify :model/Dashboard :archived)]+ [:collection.name (mdb/qualify :model/Collection :name)]+ [:collection.authority_level (mdb/qualify :model/Collection :authority_level)]+ [:collection.description (mdb/qualify :model/Collection :description)]+ [:collection.archived (mdb/qualify :model/Collection :archived)]+ [:document.name (mdb/qualify :model/Document :name)]+ [:document.archived (mdb/qualify :model/Document :archived)]]+ left-joins [[:report_card :card] [:= :bookmark.card_id :card.id]+ [:report_dashboard :dashboard] [:= :bookmark.dashboard_id :dashboard.id]+ ;; use of [[h2x/identifier]] here is a workaround for https://github.com/seancorfield/honeysql/issues/450+ [:collection :collection] [:in :collection.id [(h2x/identifier :field :bookmark :collection_id)+ (h2x/identifier :field :dashboard :collection_id)]]+ [:bookmark_ordering :bookmark_ordering] [:and+ [:= :bookmark_ordering.user_id user-id]+ [:= :bookmark_ordering.type :bookmark.type]+ [:= :bookmark_ordering.item_id :bookmark.item_id]]+ [:document :document] [:= :bookmark.document_id :document.id]]where-conditions (into [:and]- (for [table (if (has-documents?)- [:card :dashboard :collection :document]- [:card :dashboard :collection])+ (for [table [:card :dashboard :collection :document]:let [field (keyword (str (name table) "." "archived"))]][:or [:= field false] [:= field nil]]))](->> (mdb/querydiff --git a/src/metabase/cmd/copy.clj b/src/metabase/cmd/copy.cljindex 393bbebc144..9ddc86b2542 100644--- a/src/metabase/cmd/copy.clj+++ b/src/metabase/cmd/copy.clj@@ -116,18 +116,18 @@;; 57+:model/Glossary;; 58+- :model/AuthIdentity]+ :model/AuthIdentity+ :model/Document+ :model/DocumentBookmark+ :model/Comment+ :model/CommentReaction](when config/ee-available?[:model/Sandbox:model/ConnectionImpersonation:model/Metabot:model/MetabotConversation:model/MetabotMessage- :model/MetabotPrompt- :model/Document- :model/DocumentBookmark- :model/Comment- :model/CommentReaction])))+ :model/MetabotPrompt])))(defn- objects->colums+values"Given a sequence of objects/rows fetched from the H2 DB, return a the `columns` that should be used in the `INSERT`diff --git a/src/metabase/collections/models/collection.clj b/src/metabase/collections/models/collection.cljindex 6fa8c5c41e8..c50bf30b27f 100644--- a/src/metabase/collections/models/collection.clj+++ b/src/metabase/collections/models/collection.clj@@ -48,8 +48,7 @@(defn- archived-directly-models[]- (cond-> #{:model/Card :model/Dashboard}- (premium-features/enable-documents?) (conj :model/Document)))+ #{:model/Card :model/Dashboard :model/Document})(defn- collectable-models[]@@ -1867,15 +1866,14 @@[:= :collection_id id](when skip-archived [:not :archived])]})]{["Card" card-id] {"Collection" id}}))- documents (when config/ee-available?- (into {} (for [doc-id (t2/select-pks-set :model/Document {:where- [:and [:= :collection_id id]- (when skip-archived [:not :archived])]})]- {["Document" doc-id] {"Collection" id}})))- timelines (into {} (for [timeline-id (t2/select-pks-set :model/Timeline {:where [:and- [:= :collection_id id]- (when skip-archived [:not :archived])]})]- {["Timeline" timeline-id] {"Collection" id}}))]+ documents (into {} (for [doc-id (t2/select-pks-set :model/Document {:where+ [:and [:= :collection_id id]+ (when skip-archived [:not :archived])]})]+ {["Document" doc-id] {"Collection" id}}))+ timelines (into {} (for [timeline-id (t2/select-pks-set :model/Timeline {:where [:and+ [:= :collection_id id]+ (when skip-archived [:not :archived])]})]+ {["Timeline" timeline-id] {"Collection" id}}))](merge child-colls dashboards cards documents timelines)))(defmethod serdes/storage-path "Collection" [coll {:keys [collections]}]diff --git a/src/metabase/collections_rest/api.clj b/src/metabase/collections_rest/api.cljindex 87a22eb63d6..ce472efdaa6 100644--- a/src/metabase/collections_rest/api.clj+++ b/src/metabase/collections_rest/api.clj@@ -1037,10 +1037,9 @@"Fetch a sequence of 'child' objects belonging to a Collection, filtered using `options`."[{collection-namespace :namespace, :as collection} :- collection/CollectionWithLocationAndIDOrRoot{:keys [models], :as options} :- CollectionChildrenOptions]- (let [valid-models (for [model-kw (cond-> [:collection :dataset :metric :card :dashboard :pulse :snippet :timeline]+ (let [valid-models (for [model-kw (cond-> [:collection :dataset :metric :card :dashboard :pulse :snippet :timeline :document];; Tables in collections are an EE feature (data-studio)- (premium-features/has-feature? :data-studio) (conj :table)- (premium-features/enable-documents?) (conj :document))+ (premium-features/has-feature? :data-studio) (conj :table));; only fetch models that are specified by the `model` param; or everything if it's empty:when (or (empty? models) (contains? models model-kw)):let [toucan-model (model-name->toucan-model model-kw)diff --git a/enterprise/backend/src/metabase_enterprise/comments/api.clj b/src/metabase/comments/api.cljsimilarity index 98%rename from enterprise/backend/src/metabase_enterprise/comments/api.cljrename to src/metabase/comments/api.cljindex dbe69d16921..c109904ad5a 100644--- a/enterprise/backend/src/metabase_enterprise/comments/api.clj+++ b/src/metabase/comments/api.clj@@ -1,14 +1,14 @@-(ns metabase-enterprise.comments.api- "`/api/ee/comment/` routes"+(ns metabase.comments.api+ "`/api/comment/` routes"(:require[honey.sql.helpers :as sql.helpers]- [metabase-enterprise.comments.models.comment :as comment]- [metabase-enterprise.comments.models.comment-reaction :as comment-reaction][metabase.analytics.core :as analytics][metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.api.routes.common :refer [+auth]][metabase.channel.render.core :as channel.render]+ [metabase.comments.models.comment :as comment]+ [metabase.comments.models.comment-reaction :as comment-reaction][metabase.events.core :as events][metabase.request.core :as request][metabase.users-rest.api :as api.user]@@ -309,5 +309,5 @@:offset (request/offset)}))(def ^{:arglists '([request respond raise])} routes- "`/api/ee/comment/` routes."+ "`/api/comment/` routes."(api.macros/ns-handler *ns* +auth))diff --git a/src/metabase/comments/core.clj b/src/metabase/comments/core.cljnew file mode 100644index 00000000000..9b0b7a79cf3--- /dev/null+++ b/src/metabase/comments/core.clj@@ -0,0 +1,8 @@+(ns metabase.comments.core+ (:require+ [metabase.comments.api :as api.comments]+ [potemkin :as p]))++(p/import-vars+ [api.comments+ notify-comment-id!])diff --git a/src/metabase/comments/init.clj b/src/metabase/comments/init.cljnew file mode 100644index 00000000000..48a9618c8cf--- /dev/null+++ b/src/metabase/comments/init.clj@@ -0,0 +1,4 @@+(ns metabase.comments.init+ (:require+ [metabase.comments.models.comment]+ [metabase.comments.models.comment-reaction]))diff --git a/enterprise/backend/src/metabase_enterprise/comments/models/comment.clj b/src/metabase/comments/models/comment.cljsimilarity index 94%rename from enterprise/backend/src/metabase_enterprise/comments/models/comment.cljrename to src/metabase/comments/models/comment.cljindex e17dec9936e..6f0c4bbd2b3 100644--- a/enterprise/backend/src/metabase_enterprise/comments/models/comment.clj+++ b/src/metabase/comments/models/comment.clj@@ -1,7 +1,7 @@-(ns metabase-enterprise.comments.models.comment+(ns metabase.comments.models.comment(:require- [metabase-enterprise.comments.models.comment-reaction :as comment-reaction][metabase.api.common :as api]+ [metabase.comments.models.comment-reaction :as comment-reaction][metabase.models.interface :as mi][methodical.core :as methodical][toucan2.core :as t2]))diff --git a/enterprise/backend/src/metabase_enterprise/comments/models/comment_reaction.clj b/src/metabase/comments/models/comment_reaction.cljsimilarity index 98%rename from enterprise/backend/src/metabase_enterprise/comments/models/comment_reaction.cljrename to src/metabase/comments/models/comment_reaction.cljindex 7456a673bf2..5837af7ffd1 100644--- a/enterprise/backend/src/metabase_enterprise/comments/models/comment_reaction.clj+++ b/src/metabase/comments/models/comment_reaction.clj@@ -1,4 +1,4 @@-(ns metabase-enterprise.comments.models.comment-reaction+(ns metabase.comments.models.comment-reaction"Model for comment reactions (emoji reactions on comments)"(:require[metabase.models.interface :as mi]diff --git a/src/metabase/core/init.clj b/src/metabase/core/init.cljindex 37f3cc84755..6b7ee780374 100644--- a/src/metabase/core/init.clj+++ b/src/metabase/core/init.clj@@ -20,9 +20,11 @@[metabase.channel.init][metabase.classloader.init][metabase.cloud-migration.init]+ [metabase.comments.init][metabase.config.core :as config][metabase.content-verification.init][metabase.dashboards.init]+ [metabase.documents.init][metabase.driver.init][metabase.eid-translation.init][metabase.embedding.init]diff --git a/src/metabase/documents/api.clj b/src/metabase/documents/api.cljnew file mode 100644index 00000000000..0b31c7d91f9--- /dev/null+++ b/src/metabase/documents/api.clj@@ -0,0 +1,10 @@+(ns metabase.documents.api+ "`/api/document/` routes"+ (:require+ [metabase.api.util.handlers :as handlers]+ [metabase.documents.api.document]))++(def ^{:arglists '([request respond raise])} routes+ "`/api/document/` routes."+ (handlers/routes+ metabase.documents.api.document/routes))diff --git a/enterprise/backend/src/metabase_enterprise/documents/api/document.clj b/src/metabase/documents/api/document.cljsimilarity index 98%rename from enterprise/backend/src/metabase_enterprise/documents/api/document.cljrename to src/metabase/documents/api/document.cljindex 01cc6171857..078ee945ff7 100644--- a/enterprise/backend/src/metabase_enterprise/documents/api/document.clj+++ b/src/metabase/documents/api/document.clj@@ -1,13 +1,13 @@-(ns metabase-enterprise.documents.api.document- "`/api/ee/document/` routes"+(ns metabase.documents.api.document+ "`/api/document/` routes"(:require- [metabase-enterprise.documents.models.document :as m.document]- [metabase-enterprise.documents.prose-mirror :as prose-mirror][metabase.api.common :as api][metabase.api.macros :as api.macros][metabase.api.routes.common :refer [+auth]][metabase.collections.core :as collections][metabase.collections.models.collection :as collection]+ [metabase.documents.models.document :as m.document]+ [metabase.documents.prose-mirror :as prose-mirror][metabase.events.core :as events][metabase.public-sharing.validation :as public-sharing.validation][metabase.queries.core :as card]@@ -399,5 +399,5 @@:js-int-to-string? false}))(def ^{:arglists '([request respond raise])} routes- "`/api/ee/document/` routes."+ "`/api/document/` routes."(api.macros/ns-handler *ns* +auth))diff --git a/src/metabase/documents/core.clj b/src/metabase/documents/core.cljnew file mode 100644index 00000000000..bd46bad06f9--- /dev/null+++ b/src/metabase/documents/core.clj@@ -0,0 +1,13 @@+(ns metabase.documents.core+ (:require+ [metabase.documents.api.document]+ [metabase.documents.recent-views]+ [potemkin :as p]))++(comment+ metabase.documents.api.document/keep-me+ metabase.documents.recent-views/keep-me)++(p/import-vars+ [metabase.documents.api.document+ get-document])diff --git a/src/metabase/documents/init.clj b/src/metabase/documents/init.cljnew file mode 100644index 00000000000..cfe8e761aa0--- /dev/null+++ b/src/metabase/documents/init.clj@@ -0,0 +1,5 @@+(ns metabase.documents.init+ (:require+ [metabase.documents.recent-views]+ [metabase.documents.revisions.impl]+ [metabase.documents.view-log]))diff --git a/enterprise/backend/src/metabase_enterprise/documents/models/document.clj b/src/metabase/documents/models/document.cljsimilarity index 98%rename from enterprise/backend/src/metabase_enterprise/documents/models/document.cljrename to src/metabase/documents/models/document.cljindex a3d8a9079ad..e12a002ebfb 100644--- a/enterprise/backend/src/metabase_enterprise/documents/models/document.clj+++ b/src/metabase/documents/models/document.clj@@ -1,9 +1,9 @@-(ns metabase-enterprise.documents.models.document+(ns metabase.documents.models.document(:require[clojure.string :as str]- [metabase-enterprise.documents.prose-mirror :as prose-mirror][metabase.api.common :as api][metabase.collections.models.collection :as collection]+ [metabase.documents.prose-mirror :as prose-mirror][metabase.models.interface :as mi][metabase.models.serialization :as serdes][metabase.public-sharing.core :as public-sharing]diff --git a/enterprise/backend/src/metabase_enterprise/documents/prose_mirror.clj b/src/metabase/documents/prose_mirror.cljsimilarity index 97%rename from enterprise/backend/src/metabase_enterprise/documents/prose_mirror.cljrename to src/metabase/documents/prose_mirror.cljindex 2706b188b63..4cbe34f880f 100644--- a/enterprise/backend/src/metabase_enterprise/documents/prose_mirror.clj+++ b/src/metabase/documents/prose_mirror.clj@@ -1,4 +1,4 @@-(ns metabase-enterprise.documents.prose-mirror+(ns metabase.documents.prose-mirror"Manipulate the prose mirror ast for documents"(:require[clojure.walk :as walk]))diff --git a/enterprise/backend/src/metabase_enterprise/documents/recent_views.clj b/src/metabase/documents/recent_views.cljsimilarity index 54%rename from enterprise/backend/src/metabase_enterprise/documents/recent_views.cljrename to src/metabase/documents/recent_views.cljindex 936ba5c72c5..814f6dca7e9 100644--- a/enterprise/backend/src/metabase_enterprise/documents/recent_views.clj+++ b/src/metabase/documents/recent_views.clj@@ -1,34 +1,9 @@-(ns metabase-enterprise.documents.recent-views- "Enterprise multimethod implementations for documents in recent views."+(ns metabase.documents.recent-views+ "Multimethod implementations for documents in recent views."(:require[metabase.activity-feed.core :as activity-feed][metabase.collections.models.collection.root :as root]- [metabase.models.interface :as mi]- [metabase.premium-features.core :refer [defenterprise]]- [toucan2.core :as t2]))--(defenterprise select-documents-for-recents- "Query to select recent document data. Returns documents with their collection information- for use in recent views display."- :feature :documents- [document-ids]- (if-not (seq document-ids)- []- (let [documents (t2/select :model/Document- {:select [:d.id- :d.name- :d.archived- [:d.collection_id :entity-coll-id]- [:c.id :collection_id]- [:c.name :collection_name]- [:c.authority_level :collection_authority_level]]- :from [[:document :d]]- :where [:in :d.id document-ids]- :left-join [[:collection :c]- [:and- [:= :c.id :d.collection_id]- [:= :c.archived false]]]})]- documents)))+ [metabase.models.interface :as mi]))(defn- fill-parent-coll"Fill in parent collection information for a document, following the same patterndiff --git a/enterprise/backend/src/metabase_enterprise/documents/revisions/impl.clj b/src/metabase/documents/revisions/impl.cljsimilarity index 94%rename from enterprise/backend/src/metabase_enterprise/documents/revisions/impl.cljrename to src/metabase/documents/revisions/impl.cljindex d5772da60cb..eab88da5b0e 100644--- a/enterprise/backend/src/metabase_enterprise/documents/revisions/impl.clj+++ b/src/metabase/documents/revisions/impl.clj@@ -1,4 +1,4 @@-(ns metabase-enterprise.documents.revisions.impl+(ns metabase.documents.revisions.impl"Document revision serialization implementation.Implements Document revision serialization following the Card exclusion pattern,diff --git a/enterprise/backend/src/metabase_enterprise/documents/view_log.clj b/src/metabase/documents/view_log.cljsimilarity index 98%rename from enterprise/backend/src/metabase_enterprise/documents/view_log.cljrename to src/metabase/documents/view_log.cljindex e717f51d53a..82ffd9b2a60 100644--- a/enterprise/backend/src/metabase_enterprise/documents/view_log.clj+++ b/src/metabase/documents/view_log.clj@@ -1,4 +1,4 @@-(ns metabase-enterprise.documents.view-log+(ns metabase.documents.view-log"Integrates view logging events for documents"(:require[java-time.api :as t]diff --git a/src/metabase/eid_translation/util.clj b/src/metabase/eid_translation/util.cljindex 4a0721b63b0..827515b575d 100644--- a/src/metabase/eid_translation/util.clj+++ b/src/metabase/eid_translation/util.clj@@ -27,6 +27,7 @@:dashboard-tab :model/DashboardTab:dataset :model/Card:dimension :model/Dimension+ :document :model/Document:metric :model/Card:permissions-group :model/PermissionsGroup:pulse :model/Pulsediff --git a/src/metabase/models/resolution.clj b/src/metabase/models/resolution.cljindex 7e504a238c9..07117957472 100644--- a/src/metabase/models/resolution.clj+++ b/src/metabase/models/resolution.clj@@ -27,8 +27,8 @@:model/Collection metabase.collections.models.collection:model/CollectionBookmark metabase.bookmarks.models.bookmark:model/CollectionPermissionGraphRevision metabase.permissions.models.collection-permission-graph-revision- :model/Comment metabase-enterprise.comments.models.comment- :model/CommentReaction metabase-enterprise.comments.models.comment-reaction+ :model/Comment metabase.comments.models.comment+ :model/CommentReaction metabase.comments.models.comment-reaction:model/ConnectionImpersonation metabase-enterprise.impersonation.model:model/ContentTranslation metabase.content-translation.models:model/Dashboard metabase.dashboards.models.dashboard@@ -41,8 +41,8 @@:model/DatabaseRouter metabase-enterprise.database-routing.model:model/Dependency metabase-enterprise.dependencies.models.dependency:model/Dimension metabase.warehouse-schema.models.dimension- :model/Document metabase-enterprise.documents.models.document- :model/DocumentBookmark metabase-enterprise.bookmarks.models.bookmark+ :model/Document metabase.documents.models.document+ :model/DocumentBookmark metabase.bookmarks.models.bookmark:model/Field metabase.warehouse-schema.models.field:model/FieldUserSettings metabase.warehouse-schema.models.field-user-settings:model/FieldValues metabase.warehouse-schema.models.field-valuesdiff --git a/src/metabase/premium_features/core.clj b/src/metabase/premium_features/core.cljindex 113d948df86..d4e3a8c64f1 100644--- a/src/metabase/premium_features/core.clj+++ b/src/metabase/premium_features/core.clj@@ -53,7 +53,6 @@enable-database-auth-providers?enable-database-routing?enable-dependencies?- enable-documents?enable-email-allow-list?enable-email-restrict-recipients?enable-embedding-sdk-origins?diff --git a/src/metabase/premium_features/settings.clj b/src/metabase/premium_features/settings.cljindex bf666299ad9..d201da055a1 100644--- a/src/metabase/premium_features/settings.clj+++ b/src/metabase/premium_features/settings.clj@@ -291,10 +291,6 @@"Should we allow users to edit the data within tables?":table-data-editing)-(define-premium-feature ^{:added "0.57.0"} enable-documents?- "Does this instance support the new document entity."- :documents)-(define-premium-feature ^{:added "0.57.0"} enable-remote-sync?"Does this instance support remote syncing collections.":remote-sync)@@ -340,7 +336,6 @@:dependencies (enable-dependencies?):development_mode (development-mode?):disable_password_login (can-disable-password-login?)- :documents (enable-documents?):email_allow_list (enable-email-allow-list?):email_restrict_recipients (enable-email-restrict-recipients?):embedding (hide-embed-branding?)diff --git a/src/metabase/public_sharing_rest/api.clj b/src/metabase/public_sharing_rest/api.cljindex 7d7512d8d15..b1655753d80 100644--- a/src/metabase/public_sharing_rest/api.clj+++ b/src/metabase/public_sharing_rest/api.clj@@ -712,6 +712,115 @@(request/as-admin(api.tiles/process-tiles-query-for-dashcard dashboard-id dashcard-id card-id parameters zoom x y lat-field lon-field))))+;;; ------------------------------------------------ Public Documents -------------------------------------------------++(defn- remove-document-non-public-columns+ "Remove sensitive fields from a document before exposing it publicly.++ We filter out collection_id, creator_id, public_uuid, and other sensitive fields to prevent unauthenticated users+ from discovering internal organizational structure, permissions boundaries, or who created the document. Only the+ document content itself, basic metadata, and embedded cards are safe to expose publicly."+ [document]+ (select-keys document [:id :name :document :created_at :updated_at :cards]))++(defn- public-document+ "Fetch a public document with all embedded cards hydrated upfront.++ We hydrate cards eagerly (rather than requiring separate requests per card) to avoid N+1 queries and provide a+ consistent experience with public dashboards. This also allows us to filter sensitive fields from all cards at+ once before exposing them to unauthenticated users. The document and all cards must not be archived to be+ accessible publicly."+ [& conditions]+ (let [document (-> (api/check-404 (apply t2/select-one [:model/Document :id :name :document :content_type :created_at :updated_at]+ :archived false, conditions))+ ;; Hydrate cards via Toucan batched hydration to avoid N+1 queries+ (t2/hydrate :cards))]+ (-> document+ ;; Filter sensitive fields from all cards before exposing publicly+ (update :cards #(update-vals % remove-card-non-public-columns))+ (dissoc :content_type)+ remove-document-non-public-columns)))++(defn- validate-card-in-public-document+ "Ensure a card is actually embedded in the specified public document before running queries.++ We validate the document-card association to prevent users from querying arbitrary cards by guessing IDs. Only+ cards explicitly embedded in the public document (via document_id FK) are accessible through public document+ endpoints. This prevents bypassing collection permissions by accessing cards through public document routes."+ [uuid card-id]+ (let [document-id (api/check-404 (t2/select-one-pk :model/Document :public_uuid uuid :archived false))]+ (api/check-404 (t2/select-one-pk :model/Card :id card-id :document_id document-id :archived false))))++;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to+;; use our API + we will need it when we make auto-TypeScript-signature generation happen+;;+#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}+(api.macros/defendpoint :get "/document/:uuid"+ "Fetch a publicly-accessible Document. Does not require auth credentials. Public sharing must be enabled.++ Returns a Document with sensitive fields removed (excludes collection_id, permissions, creator details, etc.).+ Includes all embedded Cards with their metadata hydrated so the frontend doesn't need to make separate+ requests for each card — just like public Dashboards do."+ [{:keys [uuid]} :- [:map+ [:uuid ms/UUIDString]]]+ (public-sharing.validation/check-public-sharing-enabled)+ (let [document (public-document :public_uuid uuid)]+ (events/publish-event! :event/document-read {:object-id (:id document), :user-id api/*current-user-id*})+ document))++;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to+;; use our API + we will need it when we make auto-TypeScript-signature generation happen+;;+#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}+(api.macros/defendpoint :get "/document/:uuid/card/:card-id"+ "Run a query for a Card that's embedded in a public Document. Doesn't require auth credentials. Public sharing must+ be enabled."+ [{:keys [uuid card-id]} :- [:map+ [:uuid ms/UUIDString]+ [:card-id ms/PositiveInt]]+ {:keys [parameters]} :- [:map+ [:parameters {:optional true} [:maybe ms/JSONString]]]]+ (public-sharing.validation/check-public-sharing-enabled)+ (validate-card-in-public-document uuid card-id)+ ;; Run the query as admin since public documents are available to everyone anyway+ (u/prog1 (process-query-for-card-with-id+ card-id+ :api+ (json/decode+kw parameters)+ :constraints (qp.constraints/default-query-constraints))+ (events/publish-event! :event/card-read {:object-id card-id :user-id api/*current-user-id* :context :question})))++;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to+;; use our API + we will need it when we make auto-TypeScript-signature generation happen+;;+#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}+(api.macros/defendpoint :post "/document/:uuid/card/:card-id/:export-format"+ "Fetch a Card embedded in a public Document and return query results in the specified format.+ Does not require auth credentials. Public sharing must be enabled."+ [{:keys [uuid card-id export-format]} :- [:map+ [:uuid ms/UUIDString]+ [:card-id ms/PositiveInt]+ [:export-format ::qp.schema/export-format]]+ _query-params+ {:keys [parameters format_rows pivot_results]} :- [:map+ [:parameters {:optional true} [:maybe [:or+ [:sequential ms/Map]+ ms/JSONString]]]+ [:format_rows {:default false} ms/BooleanValue]+ [:pivot_results {:default false} ms/BooleanValue]]]+ (public-sharing.validation/check-public-sharing-enabled)+ (validate-card-in-public-document uuid card-id)+ (process-query-for-card-with-id+ card-id+ export-format+ (cond-> parameters+ (string? parameters) json/decode+kw)+ :constraints nil+ :middleware {:process-viz-settings? true+ :js-int-to-string? false+ :format-rows? format_rows+ :pivot? pivot_results}))+;;; ----------------------------------------- Route Definitions & Complaints -----------------------------------------;; TODO - why don't we just make these routes have a bit of middleware that includes thediff --git a/src/metabase/search/config.clj b/src/metabase/search/config.cljindex 8193f8eeb94..74182529426 100644--- a/src/metabase/search/config.clj+++ b/src/metabase/search/config.clj@@ -43,8 +43,7 @@(def model->db-model"Mapping of model name to :db_model and :alias"(cond-> api/model->db-model- config/ee-available? (assoc "document" {:db-model :model/Document :alias :document}- "transform" {:db-model :model/Transform :alias :transform})))+ config/ee-available? (assoc "transform" {:db-model :model/Transform :alias :transform})));; We won't need this once fully migrated to specs, but kept for now in case legacy cod falls out of sync(def excluded-models@@ -74,8 +73,8 @@(def models-search-order"The order of this list influences the order of the results: items earlier in thelist will be ranked higher."- (cond-> ["dashboard" "metric" "segment" "indexed-entity" "card" "dataset" "collection" "table" "action"]- config/ee-available? (concat ["document" "transform"])+ (cond-> ["dashboard" "metric" "segment" "indexed-entity" "card" "dataset" "collection" "table" "action" "document"]+ config/ee-available? (concat ["transform"]):always (conj "database")))(assert (= all-models (set models-search-order)) "The models search order has to include all models")diff --git a/src/metabase/search/impl.clj b/src/metabase/search/impl.cljindex 808ca920fbe..a4b8038d7cc 100644--- a/src/metabase/search/impl.clj+++ b/src/metabase/search/impl.clj@@ -55,10 +55,9 @@(defmethod check-permissions-for-model :document[search-ctx instance]- (and (premium-features/enable-documents?)- (if (:archived? search-ctx)- (can-write? search-ctx instance)- true)))+ (if (:archived? search-ctx)+ (can-write? search-ctx instance)+ true))(defmethod check-permissions-for-model :transform[search-ctx instance]diff --git a/src/metabase/search/spec.clj b/src/metabase/search/spec.cljindex 01c3779d08b..38f42ebacc5 100644--- a/src/metabase/search/spec.clj+++ b/src/metabase/search/spec.clj@@ -13,8 +13,8 @@(def search-models"Set of search model string names. Sorted by order to index based on importance and amount of time to index"- (cond-> ["collection" "dashboard" "segment" "database" "action"]- config/ee-available? (conj "document" "transform")+ (cond-> ["collection" "dashboard" "segment" "database" "action" "document"]+ config/ee-available? (conj "transform");; metric/card/dataset moved to the end because they take a long time due to computing has_temporal_dim etc.;; table and indexed-entity moved to the end because there can be a large number of themtrue (conj "table" "indexed-entity" "metric" "card" "dataset")))diff --git a/test/metabase/bookmarks/api_test.clj b/test/metabase/bookmarks/api_test.cljindex 489d7d915b2..f44812a0a01 100644--- a/test/metabase/bookmarks/api_test.clj+++ b/test/metabase/bookmarks/api_test.clj@@ -67,6 +67,11 @@{:user_id user-id:dashboard_id (u/the-id model)})+ (mi/instance-of? :model/Document model)+ (t2/insert! :model/DocumentBookmark+ {:user_id user-id+ :document_id (u/the-id model)})+:else(throw (ex-info "Unknown type" {:user-id user-id :model model})))))@@ -108,3 +113,45 @@(is (= ["card" "collection" "dashboard"](map :type(mt/user-http-request :rasta :get 200 "bookmark")))))))))++(deftest document-bookmarks-test+ (testing "Document bookmarks"+ (mt/with-temp [:model/Collection {coll-id :id} {:name "Test Collection"}+ :model/Document document {:name "Test Document" :collection_id coll-id}]+ (testing "can bookmark a document"+ (is (= (u/the-id document)+ (->> (mt/user-http-request :rasta :post 200 (str "bookmark/document/" (u/the-id document)))+ :document_id))))++ (testing "document appears in bookmark list"+ (let [result (mt/user-http-request :rasta :get 200 "bookmark")+ document-bookmark (first (filter #(= (:type %) "document") result))]+ (is (some? document-bookmark))+ (is (= "Test Document" (:name document-bookmark)))+ (is (= (u/the-id document) (:item_id document-bookmark)))))++ (testing "can delete document bookmark"+ (mt/user-http-request :rasta :delete 204 (str "bookmark/document/" (u/the-id document)))+ (is (empty? (filter #(= (:type %) "document")+ (mt/user-http-request :rasta :get 200 "bookmark")))))++ (testing "document bookmarks are included in ordering"+ (mt/with-temp [:model/Card card {:name "Test Card"}]+ (mt/with-model-cleanup [:model/BookmarkOrdering]+ (bookmark-models (mt/user->id :rasta) document card)+ (mt/user-http-request :rasta :put 204 "bookmark/ordering"+ {:orderings [{:type "document" :item_id (u/the-id document)}+ {:type "card" :item_id (u/the-id card)}]})+ (is (= ["document" "card"]+ (map :type (mt/user-http-request :rasta :get 200 "bookmark"))))))))))++(deftest document-bookmarks-archived-test+ (testing "Document bookmarks on archived documents"+ (mt/with-temp [:model/Collection {coll-id :id} {:name "Test Collection"}+ :model/Document archived-document {:name "Archived Document"+ :collection_id coll-id+ :archived true}]+ (bookmark-models (mt/user->id :rasta) archived-document)+ (testing "archived documents don't appear in bookmark list"+ (is (empty? (filter #(= (:type %) "document")+ (mt/user-http-request :rasta :get 200 "bookmark"))))))))diff --git a/test/metabase/comments/api_test.clj b/test/metabase/comments/api_test.cljnew file mode 100644index 00000000000..59501ca7c76--- /dev/null+++ b/test/metabase/comments/api_test.clj@@ -0,0 +1,318 @@+(ns metabase.comments.api-test+ "Tests for /api/comment/ endpoints."+ (:require+ [clojure.set :as set]+ [clojure.string :as str]+ [clojure.test :refer :all]+ [metabase.analytics.sdk :as sdk]+ [metabase.notification.seed :as notification.seed]+ [metabase.test :as mt]+ [metabase.util :as u]+ [toucan2.core :as t2]))++(defn- relaxed-re [& s]+ (re-pattern (str "(?s).*" (str/join ".*" s) ".*")))++;;; tiptap helpers++(defn- render-tiptap [node]+ (if (string? node)+ {:type "text" :text node}+ (let [tag (case (first node)+ :p "paragraph"+ (name (first node)))+ block? #{"paragraph"}+ attrs (when (map? (second node)) (second node))+ content (if attrs (drop 2 node) (drop 1 node))]+ (u/remove-nils+ {:type tag+ :attrs (cond-> attrs+ (block? tag) (assoc :_id (str (random-uuid)))+ true not-empty)+ :content (when (seq content)+ (mapv render-tiptap content))}))))++(defn tiptap+ "Little helpers to generate tiptap docs"+ [& content]+ {:type "doc"+ :content (mapv render-tiptap content)})++(deftest tiptap-helpers-test+ (testing "can generate some content but less verbose"+ (is (=? {:type "doc"+ :content+ [{:type "paragraph"+ :attrs {:_id string?},+ :content+ [{:type "text" :text "omg is that you? "}+ {:type "smartLink"+ :attrs {:entityId 6 :model "user"}}]}]}+ (tiptap [:p+ "omg is that you? "+ [:smartLink {:entityId 6 :model "user"}]])))))++(deftest basic-comments-test+ (testing "GET /api/comment/"+ (mt/with-temporary-setting-values [site-url "http://localhost:3000"]+ (mt/with-temp [:model/Document {doc-id :id doc :document} {:name "New Document"+ :creator_id (mt/user->id :lucky)}]+ (mt/with-model-cleanup [:model/CommentReaction+ :model/Comment+ :model/Notification]+ (mt/with-fake-inbox+ (notification.seed/seed-notification!)+ (is (set/subset? #{:event/comment-created}+ (t2/select-fn-set :event_name :model/NotificationSubscription)))+ (testing "returns empty comments list for entity with no comments"+ (is (= {:comments []}+ (mt/user-http-request :rasta :get 200 "comment/"+ :target_type "document"+ :target_id doc-id))))+ (testing "creates and returns comments for entity"+ (let [content (tiptap [:p "New comment"])+ created (mt/user-http-request :rasta :post 200 "comment/"+ {:target_type "document"+ :target_id doc-id+ :content content+ :html "<p>New comment</p>"})+ expected1 {:id int?+ :content content+ :target_type "document"+ :target_id doc-id+ :creator {:id (mt/user->id :rasta)}+ :reactions []}]+ (is (=? expected1 created))+ (is (=? {:comments [expected1]}+ (mt/user-http-request :rasta :get 200 "comment/"+ :target_type "document"+ :target_id doc-id)))+ (testing "document creator receives notifications for top-level comments"+ (is (=? {(:email (mt/fetch-user :lucky))+ [{:subject "Comment on New Document"+ :body [{:content (relaxed-re+ (str (:common_name (mt/fetch-user :rasta)) " left a comment")+ (format "http://localhost:\\d+/document/%s#comment-%s"+ doc-id+ (:id created)))}]}]}+ (first (swap-vals! mt/inbox empty)))))++ (testing "creates a reply to an existing comment"+ (let [content2 (tiptap [:p "Other comment"])+ child (mt/user-http-request :crowberto :post 200 "comment/"+ {:target_type "document"+ :target_id doc-id+ :parent_comment_id (:id created)+ :content content2+ :html "<p>Other comment</p>"})+ expected2 {:id int?+ :content content2+ :target_type "document"+ :target_id doc-id+ :creator {:id (mt/user->id :crowberto)}+ :parent_comment_id (:id created)+ :reactions []}]+ (is (=? expected2 child))+ (is (=? {:comments [expected1 expected2]}+ (mt/user-http-request :rasta :get 200 "comment/"+ :target_type "document"+ :target_id doc-id)))+ (testing "participants in the thread receive notifications for new replies"+ (is (=? {(:email (mt/fetch-user :rasta))+ [{:subject "Comment on New Document"+ :body [{:content (relaxed-re+ (str (:common_name (mt/fetch-user :crowberto)) " replied to a thread"))}]}]}+ (first (swap-vals! mt/inbox empty)))))))++ (testing "comment in a thread should send emails to all participants of the thread"+ (let [_another (mt/user-http-request :lucky :post 200 "comment/"+ {:target_type "document"+ :target_id doc-id+ :parent_comment_id (:id created)+ :content (tiptap [:p "Third comment in a thread"])+ :html "<p>Third comment in a thread</p>"})]+ (is (=? {(:email (mt/fetch-user :rasta))+ [{:subject "Comment on New Document"+ :body [{:content (relaxed-re+ (str (:common_name (mt/fetch-user :lucky)) " replied to a thread"))}]}]+ (:email (mt/fetch-user :crowberto))+ [{:subject "Comment on New Document"+ :body [{:content (relaxed-re+ (str (:common_name (mt/fetch-user :lucky)) " replied to a thread"))}]}]}+ (first (swap-vals! mt/inbox empty))))))))++ (testing "creates a comment for part of an entity"+ (let [part-id (-> doc :content first :attrs :_id)+ created (mt/user-http-request :rasta :post 200 "comment/"+ {:target_type "document"+ :target_id doc-id+ :child_target_id part-id+ :content (tiptap [:p "Part comment"])+ :html "<p>Part comment</p>"})]+ (is (=? {:id int?+ :content {:type "doc"}+ :target_type "document"+ :target_id doc-id+ :child_target_id part-id+ :creator {:id (mt/user->id :rasta)}+ :reactions []}+ created))+ (testing "Comments on concrete paragraphs are also sent as notifications"+ (is (=? {(:email (mt/fetch-user :lucky))+ [{:subject "Comment on New Document"+ :body [{:content (relaxed-re (format "http://localhost:\\d+/document/%s/comments/%s#comment-%s"+ doc-id+ part-id+ (:id created)))}]}]}+ (first (swap-vals! mt/inbox empty)))))))++ (testing "Comments with mentions send notification emails"+ (let [_created (mt/user-http-request :rasta :post 200 "comment/"+ {:target_type "document"+ :target_id doc-id+ :content (tiptap+ [:smartLink {:model "user"+ :entityId (mt/user->id :crowberto)}])+ :html "<p>Mention of @crowberto :)</p>"})]+ (is (=? {(:email (mt/fetch-user :lucky)) [{:subject "Comment on New Document"}]+ (:email (mt/fetch-user :crowberto)) [{:subject "Comment on New Document"}]}+ (first (swap-vals! mt/inbox empty))))))))))))++(deftest update-comment-test+ (testing "PUT /api/comment/:comment-id"+ (mt/with-temp [:model/Document {doc-id :id} {}+ :model/Comment {comment-id :id} {:target_id doc-id}]+ (testing "updates comment content"+ (is (=? {:content {:text "Updated content"}}+ (mt/user-http-request :rasta :put 200 (str "comment/" comment-id)+ {:content {"text" "Updated content"}}))))++ (testing "updates comment resolution status"+ (is (=? {:is_resolved true}+ (mt/user-http-request :rasta :put 200 (str "comment/" comment-id)+ {:is_resolved true})))))))++(deftest delete-comment-test+ (testing "DELETE /api/comment/:comment-id"+ (mt/with-temp [:model/Document {doc-id :id} {}+ :model/Comment {c1 :id} {:target_id doc-id}+ :model/Comment {c2 :id} {:target_id doc-id}+ :model/Comment {c3 :id} {:target_id doc-id+ :parent_comment_id c2}]+ (testing "soft deletes a comment"+ (is (= nil+ (mt/user-http-request :rasta :delete 204 (str "comment/" c1))))+ (testing "comment is marked as deleted in database"+ (let [comment (t2/select-one :model/Comment :id c1)]+ (is (some? (:deleted_at comment)))))+ (testing "deleting a comment twice leaves sour taste in the mouth"+ ;; NOTE: maybe it's fine and we should just noop here rather than return an error?+ (is (= "Comment is already deleted"+ (mt/user-http-request :rasta :delete 400 (str "comment/" c1))))))++ (testing "deleting parent comment still leaves it in a response"+ (is (= nil+ (mt/user-http-request :rasta :delete 204 (str "comment/" c2))))+ (is (=? {:comments [{:id c2+ :deleted_at some?}+ {:id c3+ :deleted_at nil}]}+ (mt/user-http-request :rasta :get 200 "comment/"+ :target_type "document"+ :target_id doc-id)))))))++(deftest toggle-reaction-test+ (testing "POST /api/comment/:comment-id/reaction"+ (mt/with-temp [:model/Document {doc-id :id} {}+ :model/Comment {comment-id :id} {:target_id doc-id}]+ (testing "adds a reaction to a comment"+ (is (=? {:reacted true}+ (mt/user-http-request :rasta :post 200 (str "comment/" comment-id "/reaction")+ {:emoji "👍"})))++ (is (=? {:comments [{:id comment-id+ :reactions [{:emoji "👍"+ :count 1+ :users [{:id (mt/user->id :rasta)}]}]}]}+ (mt/user-http-request :rasta :get 200 "comment/"+ :target_type "document"+ :target_id doc-id))))++ (testing "removes an existing reaction when toggled again"+ (is (=? {:reacted false}+ (mt/user-http-request :rasta :post 200 (str "comment/" comment-id "/reaction")+ {:emoji "👍"})))++ (is (=? {:comments [{:id comment-id+ :reactions []}]}+ (mt/user-http-request :rasta :get 200 "comment/"+ :target_type "document"+ :target_id doc-id)))))))++(deftest comments-permissions-test+ (testing "Comment permissions - users without document access cannot read or write comments"+ (mt/with-non-admin-groups-no-root-collection-perms+ (mt/with-temp [:model/Collection {restricted-col :id} {:name "Restricted Collection"}+ :model/Document {restricted-doc-id :id} {:collection_id restricted-col+ :name "Restricted Document"}+ :model/Comment {restricted-comment-id :id} {:target_id restricted-doc-id}]++ (mt/with-model-cleanup [:model/Comment]+ (testing "GET /api/comment/ - users without document read permissions cannot see comments"+ (is (= "You don't have permissions to do that."+ (mt/user-http-request :lucky :get 403 "comment/"+ :target_type "document"+ :target_id restricted-doc-id))))++ (testing "POST /api/comment/ - users without document read permissions cannot create comments"+ (is (= "You don't have permissions to do that."+ (mt/user-http-request :lucky :post 403 "comment/"+ {:target_type "document"+ :target_id restricted-doc-id+ :content (tiptap "Comment by lucky")+ :html "You shall not pass"}))))++ (testing "PUT /api/comment/:id - users without document access cannot update comments"+ (is (= "You don't have permissions to do that."+ (mt/user-http-request :lucky :put 403 (str "comment/" restricted-comment-id)+ {:content {:text "Updated by lucky"}}))))++ (testing "DELETE /api/comment/:id - users without document access cannot delete comments"+ (is (= "You don't have permissions to do that."+ (mt/user-http-request :lucky :delete 403 (str "comment/" restricted-comment-id)))))++ (testing "POST /api/comment/:id/reaction - users without document access cannot react to comments"+ (is (= "You don't have permissions to do that."+ (mt/user-http-request :lucky :post 403 (str "comment/" restricted-comment-id "/reaction")+ {:emoji "👍"})))))))))++(deftest mention-entities-test+ (testing "We can get users to mention"+ (is (=? {:data [{:id int? :common_name "Crowberto Corv" :model "user"}+ {:id int? :common_name "Lucky Pigeon" :model "user"}+ {:id int? :common_name "Rasta Toucan" :model "user"}]+ :total int?+ :limit 50+ :offset 0}+ (-> (mt/user-http-request :rasta :get 200 "comment/mentions" :limit 50)+ (update :data #(filter mt/test-user? %)))))))++(deftest iframe-comments-test+ (testing "comments are disabled inside of an iframe"+ (mt/with-temp [:model/Document {doc-id :id} {}+ :model/Comment {comment-id :id} {:target_id doc-id}]+ (testing "Comments are not shown if in iframe"+ (is (=? {:comments [{:id comment-id}]}+ (mt/user-http-request :rasta :get 200 "comment/"+ :target_type "document"+ :target_id doc-id)))+ (is (=? {:comments []+ :disabled true}+ (mt/user-http-request :rasta :get 200 "comment/"+ {:request-options {:headers {"x-metabase-client" @#'sdk/embedding-iframe-client}}}+ :target_type "document"+ :target_id doc-id))))+ (testing "Users mentions are not available either"+ (is (= "Not found."+ (mt/user-http-request :rasta :get 404 "comment/mentions"+ {:request-options {:headers {"x-metabase-client" @#'sdk/embedding-iframe-client}}})))))))diff --git a/enterprise/backend/test/metabase_enterprise/comments/models/comment_test.clj b/test/metabase/comments/models/comment_test.cljsimilarity index 71%rename from enterprise/backend/test/metabase_enterprise/comments/models/comment_test.cljrename to test/metabase/comments/models/comment_test.cljindex 37c7ebdf562..3170920184b 100644--- a/enterprise/backend/test/metabase_enterprise/comments/models/comment_test.clj+++ b/test/metabase/comments/models/comment_test.clj@@ -1,8 +1,8 @@-(ns metabase-enterprise.comments.models.comment-test+(ns metabase.comments.models.comment-test(:require[clojure.test :refer :all]- [metabase-enterprise.comments.api-test :as at]- [metabase-enterprise.comments.models.comment :as comment]))+ [metabase.comments.api-test :as at]+ [metabase.comments.models.comment :as comment]))(deftest comment-test(testing "mentions are parsed correctly"diff --git a/test/metabase/documents/api/collection_test.clj b/test/metabase/documents/api/collection_test.cljnew file mode 100644index 00000000000..4ca2f512358--- /dev/null+++ b/test/metabase/documents/api/collection_test.clj@@ -0,0 +1,215 @@+(ns metabase.documents.api.collection-test+ (:require+ [clojure.test :refer :all]+ [metabase.collections.models.collection :as collection]+ [metabase.test :as mt]))++(deftest document-cards-do-not-appear-in-collection-items+ (testing "GET /api/collection/:id/items excludes cards with document_id"+ (mt/with-temp [:model/Collection {coll-id :id} {}+ :model/Document {doc-id :id} {}+ :model/Card {normal-card-id :id} {:collection_id coll-id}+ :model/Card _ {:collection_id coll-id+ :document_id doc-id}+ :model/Dashboard {dash-id :id} {:collection_id coll-id}]+ (testing "Normal cards and dashboards appear, but in_document cards do not"+ (is (= #{[normal-card-id "card"]+ [dash-id "dashboard"]}+ (set (map (juxt :id :model)+ (:data (mt/user-http-request :rasta :get 200+ (str "collection/" coll-id "/items"))))))))+ (testing "Even with show_dashboard_questions=true, in_document cards do not appear"+ (is (= #{[normal-card-id "card"]+ [dash-id "dashboard"]}+ (set (map (juxt :id :model)+ (:data (mt/user-http-request :rasta :get 200+ (str "collection/" coll-id "/items?show_dashboard_questions=true")))))))))))++(deftest document-cards-do-not-appear-in-root-items+ (testing "GET /api/collection/root/items excludes cards with document_id"+ (mt/with-temp [:model/Document {doc-id :id} {}+ :model/Card {normal-card-id :id} {:collection_id nil+ :name "Normal Root Card"}+ :model/Card {in-document-card-id :id} {:collection_id nil+ :document_id doc-id+ :name "In Document Root Card"}+ :model/Dashboard {dash-id :id} {:collection_id nil+ :name "Root Dashboard"}]+ (testing "Normal cards and dashboards in root appear, but in_document cards do not"+ (let [items (mt/user-http-request :rasta :get 200 "collection/root/items")+ root-test-items (filter #(#{normal-card-id dash-id in-document-card-id} (:id %))+ (:data items))]+ (is (= #{[normal-card-id "card"]+ [dash-id "dashboard"]}+ (set (map (juxt :id :model) root-test-items))))))+ (testing "Even with show_dashboard_questions=true, in_document cards do not appear"+ (let [items (mt/user-http-request :rasta :get 200 "collection/root/items?show_dashboard_questions=true")+ root-test-items (filter #(#{normal-card-id dash-id in-document-card-id} (:id %))+ (:data items))]+ (is (= #{[normal-card-id "card"]+ [dash-id "dashboard"]}+ (set (map (juxt :id :model) root-test-items)))))))))++(deftest documents-appear-in-collection-items+ (testing "GET /api/collection/:id/items includes documents"+ (mt/with-temp [:model/Collection {coll-id :id} {}+ :model/Document {doc-id :id} {:collection_id coll-id+ :name "Test Document"}+ :model/Card {card-id :id} {:collection_id coll-id}+ :model/Dashboard {dash-id :id} {:collection_id coll-id}]+ (testing "Documents appear alongside cards and dashboards"+ (is (= #{[doc-id "document"]+ [card-id "card"]+ [dash-id "dashboard"]}+ (set (map (juxt :id :model)+ (:data (mt/user-http-request :rasta :get 200+ (str "collection/" coll-id "/items")))))))))))++(deftest documents-appear-in-root-items+ (testing "GET /api/collection/root/items includes documents"+ (mt/with-temp [:model/Document {doc-id :id} {:collection_id nil+ :name "Root Document"}+ :model/Card {card-id :id} {:collection_id nil+ :name "Root Card"}+ :model/Dashboard {dash-id :id} {:collection_id nil+ :name "Root Dashboard"}]+ (testing "Documents appear alongside cards and dashboards in root"+ (let [items (mt/user-http-request :rasta :get 200 "collection/root/items")+ root-test-items (filter #(#{doc-id card-id dash-id} (:id %))+ (:data items))]+ (is (= #{[doc-id "document"]+ [card-id "card"]+ [dash-id "dashboard"]}+ (set (map (juxt :id :model) root-test-items)))))))))++(deftest archived-documents-appear-in-trash-items+ (testing "GET /api/collection/trash/items includes documents with archived_directly true"+ (mt/with-temp [:model/Document {archived-doc-id :id} {:collection_id nil+ :name "Archived Document"+ :archived true+ :archived_directly true}+ :model/Document {normal-doc-id :id} {:collection_id nil+ :name "Normal Document"+ :archived_directly false}+ :model/Card {archived-card-id :id} {:collection_id nil+ :name "Archived Card"+ :archived true+ :archived_directly true}+ :model/Dashboard {archived-dash-id :id} {:collection_id nil+ :name "Archived Dashboard"+ :archived true+ :archived_directly true}]+ (testing "Archived documents appear alongside other archived items in trash"+ (let [items (mt/user-http-request :rasta :get 200 (format "collection/%d/items" (collection/trash-collection-id)))+ trash-test-items (filter #(#{archived-doc-id normal-doc-id archived-card-id archived-dash-id} (:id %))+ (:data items))]+ (is (= #{[archived-doc-id "document" true true]+ [archived-card-id "card" true true]+ [archived-dash-id "dashboard" true true]}+ (set (map (juxt :id :model :can_delete :can_restore) trash-test-items))))+ (testing "Non-archived documents do not appear in trash"+ (is (not (some #(= normal-doc-id (:id %)) trash-test-items)))))))))++(deftest document-pinning-collection-items+ (testing "GET /api/collection/:id/items supports pinned_state parameter for documents"+ (mt/with-temp [:model/Collection {coll-id :id} {}+ :model/Document {pinned-doc-id :id} {:collection_id coll-id+ :name "Pinned Document"+ :collection_position 1}+ :model/Document {unpinned-doc-id :id} {:collection_id coll-id+ :name "Unpinned Document"+ :collection_position nil}+ :model/Card {pinned-card-id :id} {:collection_id coll-id+ :name "Pinned Card"+ :collection_position 2}+ :model/Card {unpinned-card-id :id} {:collection_id coll-id+ :name "Unpinned Card"+ :collection_position nil}]+ (testing "pinned_state=is_pinned returns only pinned documents and cards"+ (let [items (:data (mt/user-http-request :rasta :get 200+ (str "collection/" coll-id "/items?pinned_state=is_pinned")))+ item-ids (set (map (juxt :model :id) items))]+ (is (contains? item-ids ["document" pinned-doc-id]))+ (is (contains? item-ids ["card" pinned-card-id]))+ (is (not (contains? item-ids ["document" unpinned-doc-id])))+ (is (not (contains? item-ids ["card" unpinned-card-id])))))++ (testing "pinned_state=is_not_pinned returns only unpinned documents and cards"+ (let [items (:data (mt/user-http-request :rasta :get 200+ (str "collection/" coll-id "/items?pinned_state=is_not_pinned")))+ item-ids (set (map (juxt :model :id) items))]+ (is (not (contains? item-ids ["document" pinned-doc-id])))+ (is (not (contains? item-ids ["card" pinned-card-id])))+ (is (contains? item-ids ["document" unpinned-doc-id]))+ (is (contains? item-ids ["card" unpinned-card-id]))))++ (testing "pinned_state=all returns all documents and cards"+ (let [items (:data (mt/user-http-request :rasta :get 200+ (str "collection/" coll-id "/items?pinned_state=all")))+ item-ids (set (map (juxt :model :id) items))]+ (is (contains? item-ids ["document" pinned-doc-id]))+ (is (contains? item-ids ["card" pinned-card-id]))+ (is (contains? item-ids ["document" unpinned-doc-id]))+ (is (contains? item-ids ["card" unpinned-card-id])))))))++(deftest document-pinning-root-items+ (testing "GET /api/collection/root/items supports pinned_state parameter for documents"+ (mt/with-temp [:model/Document {pinned-doc-id :id} {:collection_id nil+ :name "Pinned Root Document"+ :collection_position 1}+ :model/Document {unpinned-doc-id :id} {:collection_id nil+ :name "Unpinned Root Document"+ :collection_position nil}+ :model/Card {pinned-card-id :id} {:collection_id nil+ :name "Pinned Root Card"+ :collection_position 2}+ :model/Card {unpinned-card-id :id} {:collection_id nil+ :name "Unpinned Root Card"+ :collection_position nil}]+ (testing "pinned_state=is_pinned returns only pinned root documents and cards"+ (let [items (:data (mt/user-http-request :rasta :get 200 "collection/root/items?pinned_state=is_pinned"))+ test-item-ids (set (map (juxt :model :id) items))]+ (is (contains? test-item-ids ["document" pinned-doc-id]))+ (is (contains? test-item-ids ["card" pinned-card-id]))+ (is (not (contains? test-item-ids ["document" unpinned-doc-id])))+ (is (not (contains? test-item-ids ["card" unpinned-card-id])))))++ (testing "pinned_state=is_not_pinned returns only unpinned root documents and cards"+ (let [items (:data (mt/user-http-request :rasta :get 200 "collection/root/items?pinned_state=is_not_pinned"))+ test-item-ids (set (map (juxt :model :id) items))]+ (is (not (contains? test-item-ids ["document" pinned-doc-id])))+ (is (not (contains? test-item-ids ["card" pinned-card-id])))+ (is (contains? test-item-ids ["document" unpinned-doc-id]))+ (is (contains? test-item-ids ["card" unpinned-card-id])))))))++(deftest mixed-pinned-unpinned-documents-collection-view+ (testing "Integration test for mixed pinned/unpinned documents in collection view"+ (mt/with-temp [:model/Collection {coll-id :id} {}+ :model/Document {doc1-id :id} {:collection_id coll-id+ :name "Document A"+ :collection_position 1}+ :model/Document _ {:collection_id coll-id+ :name "Document B"+ :collection_position nil}+ :model/Document {doc3-id :id} {:collection_id coll-id+ :name "Document C"+ :collection_position 3}]+ (testing "Default view includes all documents with collection_position field"+ (let [items (:data (mt/user-http-request :rasta :get 200+ (str "collection/" coll-id "/items")))+ docs (filter #(= "document" (:model %)) items)+ doc-positions (map :collection_position docs)]+ (is (= 3 (count docs)))+ ;; Verify collection_position is included in the response+ (is (some #(= 1 %) doc-positions))+ (is (some nil? doc-positions))+ (is (some #(= 3 %) doc-positions))))++ (testing "Pinned documents have higher collection_position values and appear before unpinned"+ (let [items (:data (mt/user-http-request :rasta :get 200+ (str "collection/" coll-id "/items?pinned_state=is_pinned")))+ pinned-docs (filter #(= "document" (:model %)) items)]+ (is (= 2 (count pinned-docs)))+ ;; Verify all pinned docs have non-nil collection_position+ (is (every? #(some? (:collection_position %)) pinned-docs))+ (is (= #{doc1-id doc3-id} (set (map :id pinned-docs)))))))))diff --git a/enterprise/backend/test/metabase_enterprise/documents/api/document_test.clj b/test/metabase/documents/api/document_test.cljsimilarity index 79%rename from enterprise/backend/test/metabase_enterprise/documents/api/document_test.cljrename to test/metabase/documents/api/document_test.cljindex 9e87e0dda53..a8094da4974 100644--- a/enterprise/backend/test/metabase_enterprise/documents/api/document_test.clj+++ b/test/metabase/documents/api/document_test.clj@@ -1,10 +1,10 @@-(ns metabase-enterprise.documents.api.document-test+(ns metabase.documents.api.document-test(:require[clojure.set :as set][clojure.test :refer :all][medley.core :as m]- [metabase-enterprise.documents.test-util :as documents.test-util][metabase.collections.models.collection :as collection]+ [metabase.documents.test-util :as documents.test-util][metabase.events.core :as events][metabase.permissions.core :as perms][metabase.permissions.models.data-permissions :as data-perms]@@ -13,68 +13,67 @@[toucan2.core :as t2]))(use-fixtures :once (fixtures/initialize :db :test-users :test-users-personal-collections))-(use-fixtures :each (fn [f] (mt/with-premium-features #{:documents} (f))))(deftest post-document-basic-creation-test- (testing "POST /api/ee/document/ - basic document creation"+ (testing "POST /api/document/ - basic document creation"(mt/with-model-cleanup [:model/Document](let [result (mt/user-http-request :crowberto- :post 200 "ee/document/" {:name "Document 1"- :document (documents.test-util/text->prose-mirror-ast "Doc 1")})+ :post 200 "document/" {:name "Document 1"+ :document (documents.test-util/text->prose-mirror-ast "Doc 1")})document-row (t2/select-one :model/Document :id (:id result))](is (partial= {:name "Document 1" :document (documents.test-util/text->prose-mirror-ast "Doc 1")} result))(is (pos? (:id result)))(is (partial= {:name "Document 1" :document (documents.test-util/text->prose-mirror-ast "Doc 1")} document-row))))))(deftest post-document-creation-non-blank-name-test- (testing "POST /api/ee/document/ - basic document creation"+ (testing "POST /api/document/ - basic document creation"(mt/with-model-cleanup [:model/Document](is (=? {:errors {:name "value must be a non-blank string between 1 and 254 characters."}}(mt/user-http-request :crowberto- :post 400 "ee/document/" {:name ""- :document (documents.test-util/text->prose-mirror-ast "Doc 1")}))))))+ :post 400 "document/" {:name ""+ :document (documents.test-util/text->prose-mirror-ast "Doc 1")}))))))(deftest post-document-creation-long-name-test- (testing "POST /api/ee/document/id - basic document update"+ (testing "POST /api/document/id - basic document update"(is (=? {:errors {:name "value must be a non-blank string between 1 and 254 characters."}}(mt/user-http-request :crowberto- :post 400 "ee/document"+ :post 400 "document"{:name (apply str (repeat 255 "c")):document (documents.test-util/text->prose-mirror-ast "Doc 1")})))))(deftest put-document-basic-update-test- (testing "PUT /api/ee/document/id - basic document update"+ (testing "PUT /api/document/id - basic document update"(mt/with-temp [:model/Document {document-id :id} {:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Initial Doc")}](let [result (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" document-id) {:name "Document 2" :document (documents.test-util/text->prose-mirror-ast "Doc 2")})]+ :put 200 (format "document/%s" document-id) {:name "Document 2" :document (documents.test-util/text->prose-mirror-ast "Doc 2")})](is (partial= {:name "Document 2":document (documents.test-util/text->prose-mirror-ast "Doc 2")} result))))))(deftest put-document-update-non-blank-name-test- (testing "PUT /api/ee/document/id - basic document update"+ (testing "PUT /api/document/id - basic document update"(mt/with-temp [:model/Document {document-id :id} {:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Initial Doc")}](is (=? {:errors {:name "value must be a non-blank string between 1 and 254 characters."}}(mt/user-http-request :crowberto- :put 400 (format "ee/document/%s" document-id)+ :put 400 (format "document/%s" document-id){:name "":document (documents.test-util/text->prose-mirror-ast "Doc 1")}))))))(deftest put-document-update-long-name-test- (testing "PUT /api/ee/document/id - basic document update"+ (testing "PUT /api/document/id - basic document update"(mt/with-temp [:model/Document {document-id :id} {:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Initial Doc")}](is (=? {:errors {:name "value must be a non-blank string between 1 and 254 characters."}}(mt/user-http-request :crowberto- :put 400 (format "ee/document/%s" document-id)+ :put 400 (format "document/%s" document-id){:name (apply str (repeat 255 "c")):document (documents.test-util/text->prose-mirror-ast "Doc 1")}))))))(deftest put-document-nonexistent-document-test- (testing "PUT /api/ee/document/id - should return 404 for non-existent document"+ (testing "PUT /api/document/id - should return 404 for non-existent document"(mt/user-http-request :crowberto- :put 404 "ee/document/99999" {:name "Non-existent Document" :document (documents.test-util/text->prose-mirror-ast "Doc")})))+ :put 404 "document/99999" {:name "Non-existent Document" :document (documents.test-util/text->prose-mirror-ast "Doc")})))(deftest put-document-with-no-perms-test(mt/with-temp [:model/Collection {coll-id :id} {}@@ -82,66 +81,57 @@:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Doc 1")}](mt/with-non-admin-groups-no-collection-perms coll-id- (mt/user-http-request :rasta :put 403 (str "ee/document/" document-id)+ (mt/user-http-request :rasta :put 403 (str "document/" document-id){:name "Meow"}))))(deftest put-document-archived-test- (testing "PUT /api/ee/document/:id - cannot update archived document"+ (testing "PUT /api/document/:id - cannot update archived document"(mt/with-temp [:model/Document {doc-id :id} {:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Initial"):archived true}](testing "editing archived document returns 404"(is (= "The object has been archived."(:message (mt/user-http-request :crowberto- :put 404 (format "ee/document/%s" doc-id)+ :put 404 (format "document/%s" doc-id){:name "Updated Name"}))))))))(deftest post-document-with-no-perms-test(mt/with-temp [:model/Collection {coll-id :id} {}](mt/with-non-admin-groups-no-collection-perms coll-id- (mt/user-http-request :rasta :post 403 "ee/document/"+ (mt/user-http-request :rasta :post 403 "document/"{:name "Foo":document (documents.test-util/text->prose-mirror-ast "Bar"):collection_id coll-id}))))-(deftest get-document-test-requires-documents-feature- (testing "GET /api/ee/document/id"- (mt/with-premium-features #{}- (mt/with-temp [:model/Document {document-id :id} {:name "Test Document"- :document (documents.test-util/text->prose-mirror-ast "Doc 1")}]- (testing "should not get the document"- (mt/user-http-request :crowberto- :get 402 (format "ee/document/%s" document-id)))))))-(deftest get-document-test- (testing "GET /api/ee/document/id"+ (testing "GET /api/document/id"(mt/with-temp [:model/Document {document-id :id} {:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Doc 1")}](testing "should get the document"(let [result (mt/user-http-request :crowberto- :get 200 (format "ee/document/%s" document-id))]+ :get 200 (format "document/%s" document-id))](is (partial= {:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Doc 1")} result))result))(testing "should return 404 for non-existent document"(mt/user-http-request :crowberto- :get 404 "ee/document/99999")))))+ :get 404 "document/99999")))))(deftest get-documents-test- (testing "GET /api/ee/document"+ (testing "GET /api/document"(mt/with-temp [:model/Document _ {:name "Document 1":document (documents.test-util/text->prose-mirror-ast "Initial Doc 1")}:model/Document _ {:name "Document 2":document (documents.test-util/text->prose-mirror-ast "Initial Doc 2")}](testing "should get existing documents"(let [result (:items (mt/user-http-request :crowberto- :get 200 "ee/document/"))]+ :get 200 "document/"))](is (set/subset? #{"Document 1" "Document 2"} (set (map :name result))))(is (set/subset? #{(documents.test-util/text->prose-mirror-ast "Initial Doc 1") (documents.test-util/text->prose-mirror-ast "Initial Doc 2")} (set (map :document result))))result))))(testing "should return 404 for non-existent document"(mt/user-http-request :crowberto- :get 404 "ee/document/99999")))+ :get 404 "document/99999")))(deftest document-collection-sync-integration-test(testing "End-to-end collection synchronization through API"@@ -165,10 +155,10 @@:collection_id old-collection-id:dataset_query (mt/mbql-query venues)}]- (testing "PUT /api/ee/document/:id with collection change syncs cards"+ (testing "PUT /api/document/:id with collection change syncs cards";; Update document through API to move to new collection(let [response (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" document-id)+ :put 200 (format "document/%s" document-id){:collection_id new-collection-id})](is (= new-collection-id (:collection_id response)))@@ -184,7 +174,7 @@(testing "Moving to root collection (nil) works"(let [response (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" document-id)+ :put 200 (format "document/%s" document-id){:collection_id nil})](is (nil? (:collection_id response)))@@ -214,7 +204,7 @@(mt/with-non-admin-groups-no-collection-perms collection1-id(mt/with-non-admin-groups-no-collection-perms collection2-id(mt/user-http-request user-id- :put 403 (format "ee/document/%s" document-id)+ :put 403 (format "document/%s" document-id){:collection_id collection2-id});; Verify nothing changed@@ -225,7 +215,7 @@;; Should fail with 403(mt/with-non-admin-groups-no-collection-perms collection1-id(mt/user-http-request user-id- :put 403 (format "ee/document/%s" document-id)+ :put 403 (format "document/%s" document-id){:collection_id collection2-id});; Verify nothing changed@@ -236,7 +226,7 @@;; Should fail with 403(mt/with-non-admin-groups-no-collection-perms collection2-id(mt/user-http-request user-id- :put 403 (format "ee/document/%s" document-id)+ :put 403 (format "document/%s" document-id){:collection_id collection2-id});; Verify nothing changed@@ -245,7 +235,7 @@(testing "moving to non-existent collection fails gracefully"(mt/user-http-request :crowberto- :put 400 (format "ee/document/%s" document-id)+ :put 400 (format "document/%s" document-id){:collection_id 99999});; Verify nothing changed@@ -253,7 +243,7 @@(is (= collection1-id (:collection_id (t2/select-one :model/Card :id card-id)))))))))(deftest post-document-with-cards-to-create-test- (testing "POST /api/ee/document/ - create document with new cards via cards"+ (testing "POST /api/document/ - create document with new cards via cards"(mt/with-model-cleanup [:model/Document :model/Card](mt/with-temp [:model/Collection {col-id :id} {}](let [cards-to-create {-1 {:name "Generated Card 1"@@ -267,7 +257,7 @@:display :scalar:visualization_settings {}}}result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Document with Generated Cards":document {:type "doc":content [{:type "cardEmbed"@@ -319,27 +309,27 @@(is (= col-id (:collection_id document))))))))))(deftest post-document-with-empty-cards-to-create-test- (testing "POST /api/ee/document/ - handle empty cards gracefully"+ (testing "POST /api/document/ - handle empty cards gracefully"(mt/with-model-cleanup [:model/Document](let [result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Document with Empty Cards To Create":document (documents.test-util/text->prose-mirror-ast "Doc with empty cards"):cards {}})](is (pos? (:id result)))))))(deftest post-document-with-nil-cards-to-create-test- (testing "POST /api/ee/document/ - handle nil cards gracefully"+ (testing "POST /api/document/ - handle nil cards gracefully"(mt/with-model-cleanup [:model/Document](let [result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Document with Nil Cards To Create":document (documents.test-util/text->prose-mirror-ast "Doc with nil cards"):cards nil})](is (pos? (:id result)))))))(deftest put-document-with-cards-to-create-test- (testing "PUT /api/ee/document/:id - update document with new cards via cards"+ (testing "PUT /api/document/:id - update document with new cards via cards"(mt/with-temp [:model/Collection {col-id :id} {}:model/Document {document-id :id} {:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Initial Doc")@@ -355,7 +345,7 @@:display :bar:visualization_settings {}}}result (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" document-id)+ :put 200 (format "document/%s" document-id){:name "Updated Document with Generated Cards":document {:type "doc":content [{:type "cardEmbed"@@ -408,11 +398,11 @@(is (= col-id (:collection_id document)))))))))(deftest cards-to-create-schema-validation-test- (testing "POST /api/ee/document/ - cards schema validation"+ (testing "POST /api/document/ - cards schema validation"(mt/with-model-cleanup [:model/Document](testing "should reject non-negative integer keys"(mt/user-http-request :crowberto- :post 400 "ee/document/"+ :post 400 "document/"{:name "Document with Invalid Keys":document (documents.test-util/text->prose-mirror-ast "Doc"):cards {1 {:name "Invalid Key Card"@@ -423,20 +413,20 @@(testing "should reject missing required card fields"(mt/user-http-request :crowberto- :post 400 "ee/document/"+ :post 400 "document/"{:name "Document with Invalid Card":document (documents.test-util/text->prose-mirror-ast "Doc"):cards {-1 {:name "Incomplete Card"}}})) ; missing required fields(testing "should reject non-map card data"(mt/user-http-request :crowberto- :post 400 "ee/document/"+ :post 400 "document/"{:name "Document with Invalid Card Data":document (documents.test-util/text->prose-mirror-ast "Doc"):cards {-1 "not a map"}})))))(deftest cards-to-create-transaction-rollback-test- (testing "POST /api/ee/document/ - transaction rollback on card creation failure"+ (testing "POST /api/document/ - transaction rollback on card creation failure"(mt/with-model-cleanup [:model/Document :model/Card](let [invalid-cards {-1 {:name "Card with Invalid Query":type :question@@ -444,7 +434,7 @@:display :table:visualization_settings {}}}](mt/user-http-request :crowberto- :post 403 "ee/document/"+ :post 403 "document/"{:name "Document That Should Rollback":document (documents.test-util/text->prose-mirror-ast "Doc that should rollback"):cards invalid-cards})@@ -453,7 +443,7 @@(is (zero? (t2/count :model/Document :name "Document That Should Rollback")))))))(deftest put-document-cards-to-create-transaction-rollback-test- (testing "PUT /api/ee/document/:id - transaction rollback on card creation failure"+ (testing "PUT /api/document/:id - transaction rollback on card creation failure"(mt/with-temp [:model/Document {document-id :id} {:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Initial Doc")}](let [initial-document (t2/select-one :model/Document :id document-id)@@ -464,7 +454,7 @@:visualization_settings {}}}](mt/user-http-request :crowberto- :put 403 (format "ee/document/%s" document-id)+ :put 403 (format "document/%s" document-id){:name "Document That Should Rollback":document (documents.test-util/text->prose-mirror-ast "Doc that should rollback"):cards invalid-cards})@@ -484,7 +474,7 @@:display :table:visualization_settings {}}}result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Root Collection Document":document (documents.test-util/text->prose-mirror-ast "Doc in root collection"):collection_id nil@@ -497,7 +487,7 @@(is (= (:id result) (:document_id card))))))))(deftest post-document-cards-type-normalization-test- (testing "POST /api/ee/document/ - normalizes card type from :model to :question and removes dashboard_id"+ (testing "POST /api/document/ - normalizes card type from :model to :question and removes dashboard_id"(mt/with-model-cleanup [:model/Document :model/Card](mt/with-temp [:model/Collection {col-id :id} {}:model/Dashboard {dash-id :id} {:name "Test Dashboard"}]@@ -508,7 +498,7 @@:visualization_settings {}:dashboard_id dash-id}}result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Document with Model Card":document {:type "doc":content [{:type "cardEmbed"@@ -538,7 +528,7 @@(is (= :table (:display card)))))))))(deftest put-document-cards-type-normalization-test- (testing "PUT /api/ee/document/:id - normalizes card type from :model to :question and removes dashboard_id"+ (testing "PUT /api/document/:id - normalizes card type from :model to :question and removes dashboard_id"(mt/with-temp [:model/Collection {col-id :id} {}:model/Document {document-id :id} {:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Initial Doc")@@ -551,7 +541,7 @@:visualization_settings {}:dashboard_id dash-id}}result (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" document-id)+ :put 200 (format "document/%s" document-id){:name "Updated Document with Model Card":document {:type "doc":content [{:type "cardEmbed"@@ -581,7 +571,7 @@(is (= :bar (:display card))))))))(deftest cards-type-normalization-mixed-types-test- (testing "POST /api/ee/document/ - handles mixed card types correctly"+ (testing "POST /api/document/ - handles mixed card types correctly"(mt/with-model-cleanup [:model/Document :model/Card](mt/with-temp [:model/Collection {col-id :id} {}:model/Dashboard {dash-id :id} {:name "Test Dashboard"}]@@ -597,7 +587,7 @@:display :scalar:visualization_settings {}}}result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Document with Mixed Card Types":document {:type "doc":content [{:type "cardEmbed"@@ -626,7 +616,7 @@(is (nil? (:dashboard_id question-card)))))))))(deftest post-document-clone-existing-cards-test- (testing "POST /api/ee/document/ - clones existing cards and substitutes IDs in AST"+ (testing "POST /api/document/ - clones existing cards and substitutes IDs in AST"(mt/with-model-cleanup [:model/Document :model/Card](mt/with-temp [:model/Collection {col-id :id} {}:model/Card {existing-card-1 :id} {:name "Existing Card 1"@@ -640,7 +630,7 @@:display :bar:visualization_settings {}}](let [result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Document with Cloned Cards":document {:type "doc":content [{:type "cardEmbed"@@ -690,7 +680,7 @@(is (nil? (:document_id original-2))))))))))(deftest post-document-mixed-cloned-and-new-cards-test- (testing "POST /api/ee/document/ - handles both cloned existing cards and new cards"+ (testing "POST /api/document/ - handles both cloned existing cards and new cards"(mt/with-model-cleanup [:model/Document :model/Card](mt/with-temp [:model/Collection {col-id :id} {}:model/Card {existing-card :id} {:name "Existing Card"@@ -699,7 +689,7 @@:display :table:visualization_settings {}}](let [result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Document with Mixed Cards":document {:type "doc":content [{:type "cardEmbed"@@ -745,7 +735,7 @@(get-in new-embed [:attrs :id]))))))))))))(deftest post-document-no-skip-already-associated-cards-test- (testing "POST /api/ee/document/ - does not skip cloning cards already associated with a document"+ (testing "POST /api/document/ - does not skip cloning cards already associated with a document"(mt/with-model-cleanup [:model/Document :model/Card](mt/with-temp [:model/Collection {col-id :id} {}:model/Document {other-doc-id :id} {:name "Other Document"@@ -763,7 +753,7 @@:display :bar:visualization_settings {}}](let [result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Document with Mixed Association Cards":document {:type "doc":content [{:type "cardEmbed"@@ -814,7 +804,7 @@:visualization_settings {}}];; Update the document with both cards(let [result (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" document-id)+ :put 200 (format "document/%s" document-id){:document {:type "doc":content [{:type "cardEmbed":attrs {:id existing-card-in-doc@@ -849,7 +839,7 @@associated-ids))))))))))(deftest put-document-clone-existing-cards-test- (testing "PUT /api/ee/document/:id - clones existing cards and substitutes IDs in AST"+ (testing "PUT /api/document/:id - clones existing cards and substitutes IDs in AST"(mt/with-temp [:model/Collection {col-id :id} {}:model/Document {document-id :id} {:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Initial Doc")@@ -865,7 +855,7 @@:display :bar:visualization_settings {}}](let [result (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" document-id)+ :put 200 (format "document/%s" document-id){:name "Updated Document with Cloned Cards":document {:type "doc":content [{:type "cardEmbed"@@ -910,7 +900,7 @@(is (nil? (:document_id original-2)))))))))(deftest put-document-mixed-cloned-and-new-cards-test- (testing "PUT /api/ee/document/:id - handles both cloned existing cards and new cards"+ (testing "PUT /api/document/:id - handles both cloned existing cards and new cards"(mt/with-temp [:model/Collection {col-id :id} {}:model/Document {document-id :id} {:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Initial Doc")@@ -921,7 +911,7 @@:display :table:visualization_settings {}}](let [result (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" document-id)+ :put 200 (format "document/%s" document-id){:name "Updated Document with Mixed Cards":document {:type "doc":content [{:type "cardEmbed"@@ -979,7 +969,7 @@(mt/with-non-admin-groups-no-collection-perms restricted-col(testing "user without read permissions cannot clone card"(mt/user-http-request :rasta- :post 403 "ee/document/"+ :post 403 "document/"{:name "Document with Restricted Card":document {:type "doc":content [{:type "cardEmbed"@@ -988,7 +978,7 @@:collection_id allowed-col})))))))(deftest document-cloning-nested-ast-test- (testing "POST /api/ee/document/ - handles card IDs in nested AST structures"+ (testing "POST /api/document/ - handles card IDs in nested AST structures"(mt/with-model-cleanup [:model/Document :model/Card](mt/with-temp [:model/Collection {col-id :id} {}:model/Card {card-1 :id} {:name "Card 1"@@ -1002,7 +992,7 @@:display :bar:visualization_settings {}}](let [result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Document with Nested Cards":document {:type "doc":content [{:type "bulletList"@@ -1063,7 +1053,7 @@:name "Category":slug "category"}]}](let [result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Document with Complex Card":document {:type "doc":content [{:type "cardEmbed"@@ -1108,7 +1098,7 @@:visualization_settings {}}];; First update - should clone the card(mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" document-id)+ :put 200 (format "document/%s" document-id){:document {:type "doc":content [{:type "cardEmbed":attrs {:id existing-card@@ -1121,7 +1111,7 @@;; Second update with the already-cloned card ID - should NOT create another clone(let [second-result (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" document-id)+ :put 200 (format "document/%s" document-id){:document {:type "doc":content [{:type "cardEmbed":attrs {:id first-cloned-id@@ -1151,10 +1141,10 @@(perms/grant-collection-readwrite-permissions! group write-col);; No permissions for no-access-col (implicitly)- (testing "POST /api/ee/document/ - :rasta can create documents in collections with write access"+ (testing "POST /api/document/ - :rasta can create documents in collections with write access"(mt/with-model-cleanup [:model/Document](let [result (mt/user-http-request :rasta- :post 200 "ee/document/"+ :post 200 "document/"{:name "Rasta's Document":document (documents.test-util/text->prose-mirror-ast "Created by Rasta"):collection_id write-col})]@@ -1162,16 +1152,16 @@(is (= "Rasta's Document" (:name result)))(is (= write-col (:collection_id result))))))- (testing "POST /api/ee/document/ - :rasta cannot create documents in read-only collections"+ (testing "POST /api/document/ - :rasta cannot create documents in read-only collections"(mt/user-http-request :rasta- :post 403 "ee/document/"+ :post 403 "document/"{:name "Should Fail":document (documents.test-util/text->prose-mirror-ast "Should not be created"):collection_id read-only-col}))- (testing "POST /api/ee/document/ - :rasta cannot create documents in no-access collections"+ (testing "POST /api/document/ - :rasta cannot create documents in no-access collections"(mt/user-http-request :rasta- :post 403 "ee/document/"+ :post 403 "document/"{:name "Should Fail":document (documents.test-util/text->prose-mirror-ast "Should not be created"):collection_id no-access-col})))))))@@ -1191,32 +1181,32 @@(perms/grant-collection-readwrite-permissions! group write-col);; No permissions for no-access-col (implicitly)- (testing "PUT /api/ee/document/:id - :rasta can update documents in collections with write access"+ (testing "PUT /api/document/:id - :rasta can update documents in collections with write access"(mt/with-temp [:model/Document {doc-id :id} {:name "Original Document":document (documents.test-util/text->prose-mirror-ast "Original content"):collection_id write-col}](let [result (mt/user-http-request :rasta- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:name "Updated by Rasta":document (documents.test-util/text->prose-mirror-ast "Updated content")})](is (= doc-id (:id result)))(is (= "Updated by Rasta" (:name result)))(is (= (documents.test-util/text->prose-mirror-ast "Updated content") (:document result))))))- (testing "PUT /api/ee/document/:id - :rasta cannot update documents in read-only collections"+ (testing "PUT /api/document/:id - :rasta cannot update documents in read-only collections"(mt/with-temp [:model/Document {doc-id :id} {:name "Read Only Document":document (documents.test-util/text->prose-mirror-ast "Read only content"):collection_id read-only-col}](mt/user-http-request :rasta- :put 403 (format "ee/document/%s" doc-id)+ :put 403 (format "document/%s" doc-id){:name "Should not update"})))- (testing "PUT /api/ee/document/:id - :rasta cannot update documents in no-access collections"+ (testing "PUT /api/document/:id - :rasta cannot update documents in no-access collections"(mt/with-temp [:model/Document {doc-id :id} {:name "No Access Document":document (documents.test-util/text->prose-mirror-ast "No access content"):collection_id no-access-col}](mt/user-http-request :rasta- :put 403 (format "ee/document/%s" doc-id)+ :put 403 (format "document/%s" doc-id){:name "Should not update"}))))))))(deftest rasta-document-move-permissions-test@@ -1235,34 +1225,34 @@;; Grant write access to destination-col(perms/grant-collection-readwrite-permissions! group destination-col)- (testing "PUT /api/ee/document/:id - :rasta can move documents between collections with write access to both"+ (testing "PUT /api/document/:id - :rasta can move documents between collections with write access to both"(mt/with-temp [:model/Document {doc-id :id} {:name "Document to Move":document (documents.test-util/text->prose-mirror-ast "Moving document"):collection_id write-col}](let [result (mt/user-http-request :rasta- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:collection_id destination-col})](is (= doc-id (:id result)))(is (= destination-col (:collection_id result)));; Verify document was actually moved(is (= destination-col (:collection_id (t2/select-one :model/Document :id doc-id)))))))- (testing "PUT /api/ee/document/:id - :rasta cannot move documents from collections without write access"+ (testing "PUT /api/document/:id - :rasta cannot move documents from collections without write access"(mt/with-temp [:model/Document {doc-id :id} {:name "Cannot Move From Here":document (documents.test-util/text->prose-mirror-ast "No permission to move"):collection_id read-only-col}](mt/user-http-request :rasta- :put 403 (format "ee/document/%s" doc-id)+ :put 403 (format "document/%s" doc-id){:collection_id destination-col});; Verify document wasn't moved(is (= read-only-col (:collection_id (t2/select-one :model/Document :id doc-id))))))- (testing "PUT /api/ee/document/:id - :rasta cannot move documents to collections without write access"+ (testing "PUT /api/document/:id - :rasta cannot move documents to collections without write access"(mt/with-temp [:model/Document {doc-id :id} {:name "Cannot Move To There":document (documents.test-util/text->prose-mirror-ast "No permission for destination"):collection_id write-col}](mt/user-http-request :rasta- :put 403 (format "ee/document/%s" doc-id)+ :put 403 (format "document/%s" doc-id){:collection_id read-only-col});; Verify document wasn't moved(is (= write-col (:collection_id (t2/select-one :model/Document :id doc-id)))))))))))@@ -1282,34 +1272,34 @@(perms/grant-collection-readwrite-permissions! group write-col);; No permissions for no-access-col (implicitly)- (testing "GET /api/ee/document/:id - :rasta can read documents from collections with write access"+ (testing "GET /api/document/:id - :rasta can read documents from collections with write access"(mt/with-temp [:model/Document {doc-id :id} {:name "Write Access Document":document (documents.test-util/text->prose-mirror-ast "Can read with write access"):collection_id write-col}](let [result (mt/user-http-request :rasta- :get 200 (format "ee/document/%s" doc-id))]+ :get 200 (format "document/%s" doc-id))](is (= "Write Access Document" (:name result)))(is (= (documents.test-util/text->prose-mirror-ast "Can read with write access") (:document result)))(testing "includes can_write=true for collections with write access"(is (true? (get result :can_write)))))))- (testing "GET /api/ee/document/:id - :rasta can read documents from collections with read access"+ (testing "GET /api/document/:id - :rasta can read documents from collections with read access"(mt/with-temp [:model/Document {doc-id :id} {:name "Read Access Document":document (documents.test-util/text->prose-mirror-ast "Can read with read access"):collection_id read-only-col}](let [result (mt/user-http-request :rasta- :get 200 (format "ee/document/%s" doc-id))]+ :get 200 (format "document/%s" doc-id))](is (= "Read Access Document" (:name result)))(is (= (documents.test-util/text->prose-mirror-ast "Can read with read access") (:document result)))(testing "includes can_write=false for collections with only read access"(is (false? (get result :can_write)))))))- (testing "GET /api/ee/document/:id - :rasta cannot read documents from collections without access"+ (testing "GET /api/document/:id - :rasta cannot read documents from collections without access"(mt/with-temp [:model/Document {doc-id :id} {:name "No Access Document":document (documents.test-util/text->prose-mirror-ast "Cannot read this"):collection_id no-access-col}](mt/user-http-request :rasta- :get 403 (format "ee/document/%s" doc-id)))))))))+ :get 403 (format "document/%s" doc-id)))))))))(deftest rasta-document-list-permissions-test(testing "Document list permissions for non-admin user :rasta"@@ -1326,7 +1316,7 @@(perms/grant-collection-readwrite-permissions! group write-col);; No permissions for no-access-col (implicitly)- (testing "GET /api/ee/document - :rasta only sees documents from accessible collections"+ (testing "GET /api/document - :rasta only sees documents from accessible collections"(mt/with-temp [:model/Document _ {:name "Doc in Write Collection":document (documents.test-util/text->prose-mirror-ast "In write collection"):collection_id write-col}@@ -1336,7 +1326,7 @@:model/Document _ {:name "Doc in No Access Collection":document (documents.test-util/text->prose-mirror-ast "In no access collection"):collection_id no-access-col}]- (let [result (mt/user-http-request :rasta :get 200 "ee/document/")+ (let [result (mt/user-http-request :rasta :get 200 "document/")doc-names (set (map :name (:items result)))](testing "includes documents from write-access collections"(is (contains? doc-names "Doc in Write Collection")))@@ -1352,14 +1342,14 @@(is (false? (get doc :can_write))))))))))))))(deftest document-archive-basic-test- (testing "PUT /api/ee/document/:id - basic document archiving"+ (testing "PUT /api/document/:id - basic document archiving"(mt/with-temp [:model/Collection {coll-id :id} {}:model/Document {doc-id :id} {:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Test content"):collection_id coll-id}](testing "can archive document with archived=true"(let [result (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:archived true})](is (true? (:archived result)))@@ -1367,12 +1357,12 @@(is (true? (:archived (t2/select-one :model/Document :id doc-id))))))(testing "archived document doesn't appear in normal listings"- (let [documents (mt/user-http-request :crowberto :get 200 "ee/document/")]+ (let [documents (mt/user-http-request :crowberto :get 200 "document/")](is (not (some #(= doc-id (:id %)) (:items documents))))))(testing "can unarchive document with archived=false"(let [result (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:archived false})](is (false? (:archived result)))@@ -1399,7 +1389,7 @@(testing "archiving document archives associated cards"(mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:archived true});; Verify document is archived@@ -1414,7 +1404,7 @@(testing "unarchiving document unarchives associated cards"(mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:archived false});; Verify document is unarchived@@ -1447,13 +1437,13 @@(testing "user with write permissions can archive document"(let [result (mt/user-http-request :rasta- :put 200 (format "ee/document/%s" write-doc-id)+ :put 200 (format "document/%s" write-doc-id){:archived true})](is (true? (:archived result)))))(testing "user without write permissions cannot archive document"(mt/user-http-request :rasta- :put 403 (format "ee/document/%s" read-only-doc-id)+ :put 403 (format "document/%s" read-only-doc-id){:archived true});; Verify document wasn't archived@@ -1461,7 +1451,7 @@(testing "user with write permissions can unarchive document"(let [result (mt/user-http-request :rasta- :put 200 (format "ee/document/%s" write-doc-id)+ :put 200 (format "document/%s" write-doc-id){:archived false})](is (false? (:archived result))))))))))@@ -1538,7 +1528,7 @@(testing "directly archiving document sets archived_directly=true"(mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:archived true})(let [doc (t2/select-one :model/Document :id doc-id)@@ -1550,7 +1540,7 @@(testing "unarchiving directly archived document works"(mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:archived false})(let [doc (t2/select-one :model/Document :id doc-id)@@ -1576,10 +1566,10 @@(testing "directly archived documents stay archived when collection is unarchived";; First, directly archive the document(mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:archived false})(mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:archived true});; Then unarchive the collection@@ -1606,18 +1596,18 @@:collection_id coll-id:archived true}]- (testing "GET /api/ee/document/ excludes archived documents"- (let [documents (mt/user-http-request :crowberto :get 200 "ee/document/")+ (testing "GET /api/document/ excludes archived documents"+ (let [documents (mt/user-http-request :crowberto :get 200 "document/")document-names (set (map :name (:items documents)))](is (contains? document-names "Active Document"))(is (not (contains? document-names "Archived Document")))))- (testing "GET /api/ee/document/:id returns 200 for archived documents"+ (testing "GET /api/document/:id returns 200 for archived documents";; Active document should be accessible- (mt/user-http-request :crowberto :get 200 (format "ee/document/%s" active-doc-id))+ (mt/user-http-request :crowberto :get 200 (format "document/%s" active-doc-id));; Archived document should return 404- (mt/user-http-request :crowberto :get 200 (format "ee/document/%s" archived-doc-id)))+ (mt/user-http-request :crowberto :get 200 (format "document/%s" archived-doc-id)))(testing "Collection items endpoint excludes archived documents"(let [items (mt/user-http-request :crowberto :get 200 (format "collection/%s/items" coll-id))@@ -1636,7 +1626,7 @@(with-redefs [events/publish-event! (fn [topic event](swap! events conj {:topic topic :event event}))](mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:archived true});; Should have published document-archive event@@ -1648,7 +1638,7 @@(with-redefs [events/publish-event! (fn [topic event](swap! events conj {:topic topic :event event}))](mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:archived false});; Should have published document-update event (not archive event)@@ -1670,7 +1660,7 @@(throw (ex-info "Simulated card archive failure" {}))(t2/update! model id updates)))](mt/user-http-request :crowberto- :put 500 (format "ee/document/%s" doc-id)+ :put 500 (format "document/%s" doc-id){:archived true});; Verify document wasn't archived due to rollback@@ -1722,7 +1712,7 @@:archived true:archived_directly true}](let [result (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:archived true})](is (true? (:archived result)))(is (true? (:archived_directly (t2/select-one :model/Document :id doc-id)))))))@@ -1731,7 +1721,7 @@(mt/with-temp [:model/Document {doc-id :id} {:name "Already Active":document (documents.test-util/text->prose-mirror-ast "Already active")}](let [result (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:archived false})](is (false? (:archived result))))))@@ -1742,7 +1732,7 @@:collection_id trash-collection-id}];; Should be able to archive document in trash(let [result (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:archived true})](is (true? (:archived result)))))))@@ -1750,7 +1740,7 @@(mt/with-temp [:model/Document {doc-id :id} {:name "No Cards Document":document (documents.test-util/text->prose-mirror-ast "No cards")}](let [result (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:archived true})](is (true? (:archived result)));; Should not fail even with no associated cards@@ -1760,7 +1750,7 @@(mt/with-temp [:model/Document {doc-id :id} {:name "Original Name":document (documents.test-util/text->prose-mirror-ast "Original")}](let [result (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)+ :put 200 (format "document/%s" doc-id){:archived true:name "Updated Name":document (documents.test-util/text->prose-mirror-ast "Updated content")})]@@ -1769,32 +1759,32 @@(is (= (documents.test-util/text->prose-mirror-ast "Updated content") (:document result))))))))(deftest delete-document-basic-test- (testing "DELETE /api/ee/document/:id - basic document deletion"+ (testing "DELETE /api/document/:id - basic document deletion"(mt/with-temp [:model/Document {doc-id :id} {:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Test content"):archived true}](testing "can delete archived document"- (mt/user-http-request :crowberto :delete (format "ee/document/%s" doc-id))+ (mt/user-http-request :crowberto :delete (format "document/%s" doc-id));; Verify document is actually deleted from database(is (nil? (t2/select-one :model/Document :id doc-id))))(testing "cannot delete same document twice"- (mt/user-http-request :crowberto :delete 404 (format "ee/document/%s" doc-id))))))+ (mt/user-http-request :crowberto :delete 404 (format "document/%s" doc-id))))))(deftest delete-document-not-archived-test- (testing "DELETE /api/ee/document/:id - cannot delete non-archived document"+ (testing "DELETE /api/document/:id - cannot delete non-archived document"(mt/with-temp [:model/Document {doc-id :id} {:name "Active Document":document (documents.test-util/text->prose-mirror-ast "Active content"):archived false}](testing "returns 400 error when trying to delete non-archived document"- (mt/user-http-request :crowberto :delete 400 (format "ee/document/%s" doc-id))+ (mt/user-http-request :crowberto :delete 400 (format "document/%s" doc-id));; Verify document still exists(is (some? (t2/select-one :model/Document :id doc-id)))))))(deftest delete-document-permissions-test- (testing "DELETE /api/ee/document/:id - permission requirements"+ (testing "DELETE /api/document/:id - permission requirements"(mt/with-non-admin-groups-no-root-collection-perms(mt/with-temp [:model/Collection {read-only-col :id} {}:model/Collection {write-col :id} {}@@ -1814,19 +1804,19 @@(perms/grant-collection-readwrite-permissions! group write-col)(testing "user with write permissions can delete archived document"- (mt/user-http-request :rasta :delete (format "ee/document/%s" write-doc-id))+ (mt/user-http-request :rasta :delete (format "document/%s" write-doc-id));; Verify document is deleted(is (nil? (t2/select-one :model/Document :id write-doc-id))))(testing "user without write permissions cannot delete archived document"- (mt/user-http-request :rasta :delete 403 (format "ee/document/%s" read-only-doc-id))+ (mt/user-http-request :rasta :delete 403 (format "document/%s" read-only-doc-id));; Verify document still exists(is (some? (t2/select-one :model/Document :id read-only-doc-id)))))))))(deftest delete-document-with-cards-test- (testing "DELETE /api/ee/document/:id - deletes document with associated cards"+ (testing "DELETE /api/document/:id - deletes document with associated cards"(mt/with-temp [:model/Collection {coll-id :id} {}:model/Document {doc-id :id} {:name "Document with Cards":document (documents.test-util/text->prose-mirror-ast "Doc with cards")@@ -1847,7 +1837,7 @@:dataset_query (mt/mbql-query venues)}](testing "deleting document also deletes associated cards via cascade"- (mt/user-http-request :crowberto :delete (format "ee/document/%s" doc-id))+ (mt/user-http-request :crowberto :delete (format "document/%s" doc-id));; Verify document is deleted(is (nil? (t2/select-one :model/Document :id doc-id)))@@ -1860,18 +1850,18 @@(is (some? (t2/select-one :model/Card :id other-card-id)))))))(deftest delete-document-nonexistent-test- (testing "DELETE /api/ee/document/:id - returns 404 for nonexistent document"- (mt/user-http-request :crowberto :delete 404 "ee/document/999999")))+ (testing "DELETE /api/document/:id - returns 404 for nonexistent document"+ (mt/user-http-request :crowberto :delete 404 "document/999999")))(deftest delete-document-events-test- (testing "DELETE /api/ee/document/:id - publishes delete event"+ (testing "DELETE /api/document/:id - publishes delete event"(mt/with-temp [:model/Document {doc-id :id} {:name "Event Test Document":document (documents.test-util/text->prose-mirror-ast "Event test"):archived true}](let [events (atom [])](with-redefs [events/publish-event! (fn [topic event](swap! events conj {:topic topic :event event}))]- (mt/user-http-request :crowberto :delete 204 (format "ee/document/%s" doc-id))+ (mt/user-http-request :crowberto :delete 204 (format "document/%s" doc-id));; Should have published document-delete event(is (some #(= :event/document-delete (:topic %)) @events))@@ -1884,7 +1874,7 @@(mt/with-temp [:model/Collection {collection-id :id} {:name "Test Collection"}];; Create existing document with position 3 via API(let [existing-doc-result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Existing Document":document (documents.test-util/text->prose-mirror-ast "Existing doc"):collection_id collection-id@@ -1894,7 +1884,7 @@(testing "inserting document at existing position shifts others";; Insert new document at position 3 via API - should shift existing document(let [new-doc-result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "New Document":document (documents.test-util/text->prose-mirror-ast "New doc"):collection_id collection-id@@ -1908,7 +1898,7 @@(testing "inserting document without position works"(let [no-position-result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "No Position Document":document (documents.test-util/text->prose-mirror-ast "No position doc"):collection_id collection-id})]@@ -1919,19 +1909,19 @@(mt/with-temp [:model/Collection {collection-id :id} {:name "Test Collection"}];; Create documents with positions via API(let [doc1-result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Document 1":document (documents.test-util/text->prose-mirror-ast "Doc 1"):collection_id collection-id:collection_position 1})doc2-result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Document 2":document (documents.test-util/text->prose-mirror-ast "Doc 2"):collection_id collection-id:collection_position 2})doc3-result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Document 3":document (documents.test-util/text->prose-mirror-ast "Doc 3"):collection_id collection-id@@ -1943,7 +1933,7 @@(testing "moving document to different position reconciles others";; Move document 3 to position 1 via API - should shift others(let [updated-doc3 (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc3-id)+ :put 200 (format "document/%s" doc3-id){:collection_position 1})];; Document 3 should now be at position 1(is (= 1 (:collection_position updated-doc3)))@@ -1959,7 +1949,7 @@(mt/with-temp [:model/Collection {other-collection-id :id} {:name "Other Collection"}];; Move document 1 to other collection at position 1 via API(let [moved-doc (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc1-id)+ :put 200 (format "document/%s" doc1-id){:collection_id other-collection-id:collection_position 1})];; Moved document should be in new collection at position 1@@ -1975,7 +1965,7 @@(mt/with-temp [:model/Collection {collection-id :id} {:name "Test Collection"}](testing "collection_position is stored and retrieved correctly"(let [document-result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Positioned Document":document (documents.test-util/text->prose-mirror-ast "Positioned doc"):collection_id collection-id@@ -1984,27 +1974,27 @@(testing "collection_position can be updated"(let [document-result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Update Position Document":document (documents.test-util/text->prose-mirror-ast "Update position doc"):collection_id collection-id:collection_position 5})document-id (:id document-result)updated-result (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" document-id)+ :put 200 (format "document/%s" document-id){:collection_position 10})](is (= 10 (:collection_position updated-result)))))(testing "collection_position can be set to nil"(let [document-result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Nil Position Document":document (documents.test-util/text->prose-mirror-ast "Nil position doc"):collection_id collection-id:collection_position 5})document-id (:id document-result)updated-result (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" document-id)+ :put 200 (format "document/%s" document-id){:collection_position nil})](is (nil? (:collection_position updated-result))))))))@@ -2027,7 +2017,7 @@(shared-document)overrides))-;;; -------------------------------------- POST /api/ee/document/:id/public-link ---------------------------------------+;;; -------------------------------------- POST /api/document/:id/public-link ---------------------------------------(deftest share-document-test(mt/with-temporary-setting-values [enable-public-sharing true]@@ -2035,68 +2025,68 @@(mt/with-temp [:model/Document document {:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Test content")}](let [{uuid :uuid} (mt/user-http-request :crowberto :post 200- (format "ee/document/%d/public-link" (:id document)))]+ (format "document/%d/public-link" (:id document)))](is (t2/exists? :model/Document :id (:id document), :public_uuid uuid))(testing "Test that if a Document has already been shared we reuse the existing UUID"(is (= uuid(:uuid (mt/user-http-request :crowberto :post 200- (format "ee/document/%d/public-link" (:id document))))))))))+ (format "document/%d/public-link" (:id document))))))))))(mt/with-temp [:model/Document document {:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Test content")}](testing "Test that we *cannot* share a Document if we aren't admins"(is (= "You don't have permissions to do that."- (mt/user-http-request :rasta :post 403 (format "ee/document/%d/public-link" (:id document))))))+ (mt/user-http-request :rasta :post 403 (format "document/%d/public-link" (:id document))))))(testing "Test that we *cannot* share a Document if the setting is disabled"(mt/with-temporary-setting-values [enable-public-sharing false](is (= "Public sharing is not enabled."- (mt/user-http-request :crowberto :post 400 (format "ee/document/%d/public-link" (:id document))))))))+ (mt/user-http-request :crowberto :post 400 (format "document/%d/public-link" (:id document))))))))(testing "Test that we get a 404 if the Document doesn't exist"(is (= "Not found."- (mt/user-http-request :crowberto :post 404 (format "ee/document/%d/public-link" Integer/MAX_VALUE)))))))+ (mt/user-http-request :crowberto :post 404 (format "document/%d/public-link" Integer/MAX_VALUE)))))))(deftest delete-public-link-test- (testing "DELETE /api/ee/document/:id/public-link"+ (testing "DELETE /api/document/:id/public-link"(mt/with-temporary-setting-values [enable-public-sharing true](testing "Test that we can unshare a Document"(mt/with-temp [:model/Document document (document-with-public-link {})]- (mt/user-http-request :crowberto :delete 204 (format "ee/document/%d/public-link" (:id document)))+ (mt/user-http-request :crowberto :delete 204 (format "document/%d/public-link" (:id document)))(is (not (t2/exists? :model/Document :id (:id document), :public_uuid (:public_uuid document))))))(testing "Test that we *cannot* unshare a Document if we are not admins"(mt/with-temp [:model/Document document (document-with-public-link {})](is (= "You don't have permissions to do that."- (mt/user-http-request :rasta :delete 403 (format "ee/document/%d/public-link" (:id document)))))))+ (mt/user-http-request :rasta :delete 403 (format "document/%d/public-link" (:id document)))))))(testing "Test that we get a 404 if Document isn't shared"(mt/with-temp [:model/Document document {:name "Test Document":document (documents.test-util/text->prose-mirror-ast "Test content")}](is (= "Not found."- (mt/user-http-request :crowberto :delete 404 (format "ee/document/%d/public-link" (:id document)))))))+ (mt/user-http-request :crowberto :delete 404 (format "document/%d/public-link" (:id document)))))))(testing "Test that we get a 404 if Document doesn't exist"(is (= "Not found."- (mt/user-http-request :crowberto :delete 404 (format "ee/document/%d/public-link" Integer/MAX_VALUE))))))))+ (mt/user-http-request :crowberto :delete 404 (format "document/%d/public-link" Integer/MAX_VALUE))))))))(deftest fetch-public-documents-test- (testing "GET /api/ee/document/public"+ (testing "GET /api/document/public"(mt/with-temporary-setting-values [enable-public-sharing true](mt/with-temp [:model/Document _document (document-with-public-link {:name "Public Document":document (documents.test-util/text->prose-mirror-ast "Public content")})](testing "Test that it requires superuser"(is (= "You don't have permissions to do that."- (mt/user-http-request :rasta :get 403 "ee/document/public"))))+ (mt/user-http-request :rasta :get 403 "document/public"))))(testing "Test that superusers can fetch a list of publicly-accessible documents"(is (= [{:name true, :id true, :public_uuid true}]- (for [doc (mt/user-http-request :crowberto :get 200 "ee/document/public")]+ (for [doc (mt/user-http-request :crowberto :get 200 "document/public")](m/map-vals boolean doc)))))))))-;;; ---------------------------------------- GET /api/ee/public/document/:uuid ----------------------------------------------+;;; ---------------------------------------- GET /api/public/document/:uuid ----------------------------------------------(deftest fetch-public-document-test- (testing "GET /api/ee/public/document/:uuid"+ (testing "GET /api/public/document/:uuid"(testing "Test that we can fetch a public Document"(mt/with-temporary-setting-values [enable-public-sharing true](mt/with-temp [:model/Document document (document-with-public-link {:name "Public Test Document"@@ -2104,14 +2094,14 @@(is (partial= {:name "Public Test Document":document (documents.test-util/text->prose-mirror-ast "Public test content"):id (:id document)}- (mt/client :get 200 (str "ee/public/document/" (:public_uuid document))))))))))+ (mt/client :get 200 (str "public/document/" (:public_uuid document))))))))))(deftest public-document-returns-only-safe-fields-test- (testing "GET /api/ee/public/document/:uuid should only return safe fields"+ (testing "GET /api/public/document/:uuid should only return safe fields"(mt/with-temporary-setting-values [enable-public-sharing true](mt/with-temp [:model/Document document (document-with-public-link {:name "Public Test Document":document (documents.test-util/text->prose-mirror-ast "Public test content")})]- (let [result (mt/client :get 200 (str "ee/public/document/" (:public_uuid document)))]+ (let [result (mt/client :get 200 (str "public/document/" (:public_uuid document)))](testing "Should include safe fields"(is (contains? result :id))(is (contains? result :name))@@ -2125,58 +2115,58 @@(is (not (contains? result :description)))))))))(deftest get-public-document-errors-test- (testing "GET /api/ee/public/document/:uuid"+ (testing "GET /api/public/document/:uuid"(testing "Shouldn't be able to fetch a public Document if public sharing is disabled"(mt/with-temporary-setting-values [enable-public-sharing false](mt/with-temp [:model/Document document (document-with-public-link {})](is (= "API endpoint does not exist."- (mt/client :get 404 (str "ee/public/document/" (:public_uuid document))))))))+ (mt/client :get 404 (str "public/document/" (:public_uuid document))))))))(testing "Should get a 404 if the Document doesn't exist"(mt/with-temporary-setting-values [enable-public-sharing true](is (= "Not found."- (mt/client :get 404 (str "ee/public/document/" (random-uuid)))))))))+ (mt/client :get 404 (str "public/document/" (random-uuid)))))))))(deftest share-archived-document-test- (testing "POST /api/ee/document/:id/public-link should not work for archived documents"+ (testing "POST /api/document/:id/public-link should not work for archived documents"(mt/with-temporary-setting-values [enable-public-sharing true](mt/with-temp [:model/Document document {:name "Archived Document":document (documents.test-util/text->prose-mirror-ast "Archived content"):archived true}](is (= "Not found."- (mt/user-http-request :crowberto :post 404 (format "ee/document/%d/public-link" (:id document)))))))))+ (mt/user-http-request :crowberto :post 404 (format "document/%d/public-link" (:id document)))))))))(deftest unshare-archived-document-test- (testing "DELETE /api/ee/document/:id/public-link should not work for archived documents"+ (testing "DELETE /api/document/:id/public-link should not work for archived documents"(mt/with-temporary-setting-values [enable-public-sharing true](mt/with-temp [:model/Document document (document-with-public-link {:name "Archived Shared Document":document (documents.test-util/text->prose-mirror-ast "Archived shared content"):archived true})](is (= "Not found."- (mt/user-http-request :crowberto :delete 404 (format "ee/document/%d/public-link" (:id document)))))))))+ (mt/user-http-request :crowberto :delete 404 (format "document/%d/public-link" (:id document)))))))))(deftest public-document-not-accessible-when-archived-test- (testing "GET /api/ee/public/document/:uuid should not work for archived documents"+ (testing "GET /api/public/document/:uuid should not work for archived documents"(mt/with-temporary-setting-values [enable-public-sharing true](mt/with-temp [:model/Document document (document-with-public-link {})](let [uuid (:public_uuid document)](testing "Document is accessible when not archived"(is (= 200- (:status (mt/client-full-response :get (str "ee/public/document/" uuid))))))+ (:status (mt/client-full-response :get (str "public/document/" uuid))))))(testing "Document is not accessible after archiving"(t2/update! :model/Document (:id document) {:archived true})(is (= "Not found."- (mt/client :get 404 (str "ee/public/document/" uuid))))))))))+ (mt/client :get 404 (str "public/document/" uuid))))))))))(deftest public-document-listing-excludes-archived-test- (testing "GET /api/ee/document/public should not include archived documents"+ (testing "GET /api/document/public should not include archived documents"(mt/with-temporary-setting-values [enable-public-sharing true](mt/with-temp [:model/Document active-doc (document-with-public-link {:name "Active Public Document":document (documents.test-util/text->prose-mirror-ast "Active content")}):model/Document _archived-doc (document-with-public-link {:name "Archived Public Document":document (documents.test-util/text->prose-mirror-ast "Archived content"):archived true})]- (let [public-docs (mt/user-http-request :crowberto :get 200 "ee/document/public")+ (let [public-docs (mt/user-http-request :crowberto :get 200 "document/public")public-doc-ids (set (map :id public-docs))](testing "Active document should be in the list"(is (contains? public-doc-ids (:id active-doc))))@@ -2184,7 +2174,7 @@(is (= 1 (count public-docs)))))))))(deftest download-document-card-test- (testing "POST /api/ee/document/:document-id/card/:card-id/query/:export-format"+ (testing "POST /api/document/:document-id/card/:card-id/query/:export-format"(mt/with-non-admin-groups-no-root-collection-perms(mt/with-temp [:model/Collection {coll-id :id} {}:model/Card {card-id :id} {:name "Test Card"@@ -2203,7 +2193,7 @@(perms/grant-collection-read-permissions! group coll-id)(let [response (mt/user-http-request :rasta:post 200- (format "ee/document/%s/card/%s/query/csv" doc-id card-id)+ (format "document/%s/card/%s/query/csv" doc-id card-id){:parameters []:format_rows false:pivot_results false})]@@ -2214,7 +2204,7 @@(perms/revoke-collection-permissions! group coll-id)(mt/user-http-request :rasta:post 403- (format "ee/document/%s/card/%s/query/csv" doc-id card-id)+ (format "document/%s/card/%s/query/csv" doc-id card-id){:parameters []:format_rows false:pivot_results false}))@@ -2227,7 +2217,7 @@:collection_id coll-id}](mt/user-http-request :rasta:post 404- (format "ee/document/%s/card/%s/query/csv" doc-id other-card-id)+ (format "document/%s/card/%s/query/csv" doc-id other-card-id){:parameters []:format_rows false:pivot_results false})))@@ -2236,70 +2226,72 @@(t2/update! :model/Document doc-id {:archived true})(mt/user-http-request :rasta:post 404- (format "ee/document/%s/card/%s/query/csv" doc-id card-id)+ (format "document/%s/card/%s/query/csv" doc-id card-id){:parameters []:format_rows false:pivot_results false})))))))(deftest download-document-card-respects-download-permissions-test- (testing "POST /api/ee/document/:document-id/card/:card-id/query/:export-format respects database download permissions"- (mt/with-premium-features #{:documents :advanced-permissions}- (mt/with-non-admin-groups-no-root-collection-perms- (mt/with-temp [:model/Collection {coll-id :id} {}- :model/Card {card-id :id} {:name "Test Card"- :dataset_query (mt/mbql-query venues {:limit 10})- :display :table- :collection_id coll-id}- :model/Document {doc-id :id} {:name "Test Document"- :collection_id coll-id- :document {:type "doc"- :content [{:type "cardEmbed"- :attrs {:id card-id}}]}}]- (t2/update! :model/Card card-id {:document_id doc-id})-- (let [all-users-group (perms/all-users-group)]- ;; Grant collection read permissions so user can access the document- (perms/grant-collection-read-permissions! all-users-group coll-id)-- (testing "User without download permissions yields permissions error in body (streaming uses 200)"- ;; Set download permissions to :no (no downloads allowed) for All Users group- (data-perms/set-database-permission! all-users-group (mt/id) :perms/download-results :no)-- (is (malli= [:map- [:status [:= "failed"]]- [:error_type [:= "missing-required-permissions"]]- [:ex-data [:map- [:permissions-error? [:= true]]]]]- (mt/user-http-request :rasta- :post 200- (format "ee/document/%s/card/%s/query/csv" doc-id card-id)- {:parameters []- :format_rows false- :pivot_results false}))))-- (testing "User with limited download permissions (10k rows) can download"- (data-perms/set-database-permission! all-users-group (mt/id) :perms/download-results :ten-thousand-rows)-- (let [response (mt/user-http-request :rasta- :post 200- (format "ee/document/%s/card/%s/query/csv" doc-id card-id)- {:parameters []- :format_rows false- :pivot_results false})]- (is (some? response))- (is (string? response))))-- (testing "User with full download permissions can download"- (data-perms/set-database-permission! all-users-group (mt/id) :perms/download-results :one-million-rows)-- (let [response (mt/user-http-request :rasta- :post 200- (format "ee/document/%s/card/%s/query/csv" doc-id card-id)- {:parameters []- :format_rows false- :pivot_results false})]- (is (some? response))- (is (string? response))))))))))+ (testing "POST /api/document/:document-id/card/:card-id/query/:export-format respects database download permissions"+ (mt/when-ee-evailable+ (mt/with-premium-features #{:advanced-permissions}+ (mt/with-non-admin-groups-no-root-collection-perms+ (mt/with-temp [:model/Collection {coll-id :id} {}+ :model/Card {card-id :id} {:name "Test Card"+ :dataset_query (mt/mbql-query venues {:limit 10})+ :display :table+ :collection_id coll-id}+ :model/Document {doc-id :id} {:name "Test Document"+ :collection_id coll-id+ :document {:type "doc"+ :content [{:type "cardEmbed"+ :attrs {:id card-id}}]}}]+ (t2/update! :model/Card card-id {:document_id doc-id})++ (let [all-users-group (perms/all-users-group)]+ ;; Grant collection read permissions so user can access the document+ (perms/grant-collection-read-permissions! all-users-group coll-id)++ (testing "User without download permissions yields permissions error in body (streaming uses 200)"+ ;; Set download permissions to :no (no downloads allowed) for All Users group+ (data-perms/set-database-permission! all-users-group (mt/id) :perms/download-results :no)++ (is (malli= [:map+ [:status [:= "failed"]]+ [:error_type [:= "missing-required-permissions"]]+ [:ex-data [:map+ [:permissions-error? [:= true]]]]]+ (mt/user-http-request :rasta+ :post 200+ (format "document/%s/card/%s/query/csv" doc-id card-id)+ {:parameters []+ :format_rows false+ :pivot_results false}))))++ (testing "User with limited download permissions (10k rows) can download"+ (data-perms/set-database-permission! all-users-group (mt/id) :perms/download-results :ten-thousand-rows)++ (let [response (mt/user-http-request :rasta+ :post 200+ (format "document/%s/card/%s/query/csv" doc-id card-id)+ {:parameters []+ :format_rows false+ :pivot_results false})]+ (is (some? response))+ (is (string? response))))++ (testing "User with full download permissions can download"+ (data-perms/set-database-permission! all-users-group (mt/id) :perms/download-results :one-million-rows)++ (let [response (mt/user-http-request :rasta+ :post 200+ (format "document/%s/card/%s/query/csv" doc-id card-id)+ {:parameters []+ :format_rows false+ :pivot_results false})]+ (is (some? response))+ (is (string? response)))))))))))+(defn- prose-mirror-with-smartlink"Create a ProseMirror AST with a smartlink to a card."[text card-id]@@ -2312,251 +2304,261 @@:entityId card-id}}]}]})(deftest create-document-in-remote-synced-with-non-remote-synced-smartlink-test- (testing "POST /api/ee/document/ - creating document in remote-synced collection with smartlink to non-remote-synced item"- (mt/with-temporary-setting-values [remote-sync-type :read-write]- (mt/with-model-cleanup [:model/Document]- (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"- :location "/"- :is_remote_synced true}- :model/Collection {regular-id :id} {:name "Regular Collection"- :location "/"- :type nil}- :model/Card {card-id :id} {:name "Regular Card"- :collection_id regular-id- :dataset_query (mt/mbql-query venues)}]-- (testing "Throws exception when document references non-remote-synced item"- (let [response (mt/user-http-request :crowberto- :post 400 "ee/document/"- {:name "Doc with bad reference"- :collection_id remote-synced-id- :document (prose-mirror-with-smartlink "Link to card" card-id)})]- (is (= "Uses content that is not remote synced." (:message response))- "Should report non-remote-synced dependencies"))))))))+ (testing "POST /api/document/ - creating document in remote-synced collection with smartlink to non-remote-synced item"+ (mt/when-ee-evailable+ (mt/with-temporary-setting-values [remote-sync-type :read-write]+ (mt/with-model-cleanup [:model/Document]+ (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"+ :location "/"+ :is_remote_synced true}+ :model/Collection {regular-id :id} {:name "Regular Collection"+ :location "/"+ :type nil}+ :model/Card {card-id :id} {:name "Regular Card"+ :collection_id regular-id+ :dataset_query (mt/mbql-query venues)}]++ (testing "Throws exception when document references non-remote-synced item"+ (let [response (mt/user-http-request :crowberto+ :post 400 "document/"+ {:name "Doc with bad reference"+ :collection_id remote-synced-id+ :document (prose-mirror-with-smartlink "Link to card" card-id)})]+ (is (= "Uses content that is not remote synced." (:message response))+ "Should report non-remote-synced dependencies")))))))))(deftest create-document-in-remote-synced-with-remote-synced-smartlink-test- (testing "POST /api/ee/document/ - creating document in remote-synced collection with smartlink to remote-synced item"- (mt/with-temporary-setting-values [remote-sync-type :read-write]- (mt/with-model-cleanup [:model/Document]- (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"- :location "/"- :is_remote_synced true}- :model/Card {card-id :id} {:name "Remote-Synced Card"- :collection_id remote-synced-id- :dataset_query (mt/mbql-query venues)}]-- (testing "Successfully creates document when referencing remote-synced item"- (let [response (mt/user-http-request :crowberto- :post 200 "ee/document/"- {:name "Doc with valid reference"- :collection_id remote-synced-id- :document (prose-mirror-with-smartlink "Link to card" card-id)})]- (is (= "Doc with valid reference" (:name response)))- (is (= remote-synced-id (:collection_id response))))))))))+ (testing "POST /api/document/ - creating document in remote-synced collection with smartlink to remote-synced item"+ (mt/when-ee-evailable+ (mt/with-temporary-setting-values [remote-sync-type :read-write]+ (mt/with-model-cleanup [:model/Document]+ (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"+ :location "/"+ :is_remote_synced true}+ :model/Card {card-id :id} {:name "Remote-Synced Card"+ :collection_id remote-synced-id+ :dataset_query (mt/mbql-query venues)}]++ (testing "Successfully creates document when referencing remote-synced item"+ (let [response (mt/user-http-request :crowberto+ :post 200 "document/"+ {:name "Doc with valid reference"+ :collection_id remote-synced-id+ :document (prose-mirror-with-smartlink "Link to card" card-id)})]+ (is (= "Doc with valid reference" (:name response)))+ (is (= remote-synced-id (:collection_id response)))))))))))(deftest create-document-in-regular-collection-with-any-smartlink-test- (testing "POST /api/ee/document/ - creating document in regular collection can reference any item"- (mt/with-temporary-setting-values [remote-sync-type :read-write]- (mt/with-model-cleanup [:model/Document]- (mt/with-temp [:model/Collection {regular-id :id} {:name "Regular Collection"- :location "/"- :type nil}- :model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"- :location "/"- :is_remote_synced true}- :model/Card {remote-card-id :id} {:name "Remote-Synced Card"- :collection_id remote-synced-id- :dataset_query (mt/mbql-query venues)}- :model/Card {regular-card-id :id} {:name "Regular Card"- :collection_id regular-id- :dataset_query (mt/mbql-query venues)}]-- (testing "Can reference remote-synced item"- (let [response (mt/user-http-request :crowberto- :post 200 "ee/document/"- {:name "Doc with remote ref"- :collection_id regular-id- :document (prose-mirror-with-smartlink "Link" remote-card-id)})]- (is (= "Doc with remote ref" (:name response)))))-- (testing "Can reference regular item"- (let [response (mt/user-http-request :crowberto- :post 200 "ee/document/"- {:name "Doc with regular ref"- :collection_id regular-id- :document (prose-mirror-with-smartlink "Link" regular-card-id)})]- (is (= "Doc with regular ref" (:name response))))))))))+ (testing "POST /api/document/ - creating document in regular collection can reference any item"+ (mt/when-ee-evailable+ (mt/with-temporary-setting-values [remote-sync-type :read-write]+ (mt/with-model-cleanup [:model/Document]+ (mt/with-temp [:model/Collection {regular-id :id} {:name "Regular Collection"+ :location "/"+ :type nil}+ :model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"+ :location "/"+ :is_remote_synced true}+ :model/Card {remote-card-id :id} {:name "Remote-Synced Card"+ :collection_id remote-synced-id+ :dataset_query (mt/mbql-query venues)}+ :model/Card {regular-card-id :id} {:name "Regular Card"+ :collection_id regular-id+ :dataset_query (mt/mbql-query venues)}]++ (testing "Can reference remote-synced item"+ (let [response (mt/user-http-request :crowberto+ :post 200 "document/"+ {:name "Doc with remote ref"+ :collection_id regular-id+ :document (prose-mirror-with-smartlink "Link" remote-card-id)})]+ (is (= "Doc with remote ref" (:name response)))))-(deftest update-document-in-remote-synced-with-non-remote-synced-smartlink-test- (testing "PUT /api/ee/document/:id - updating document in remote-synced collection to add non-remote-synced reference"- (mt/with-temporary-setting-values [remote-sync-type :read-write]- (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"- :location "/"- :is_remote_synced true}- :model/Collection {regular-id :id} {:name "Regular Collection"- :location "/"- :type nil}- :model/Document {doc-id :id} {:name "Test Document"- :collection_id remote-synced-id- :document (documents.test-util/text->prose-mirror-ast "Initial")}- :model/Card {card-id :id} {:name "Regular Card"- :collection_id regular-id- :dataset_query (mt/mbql-query venues)}]+ (testing "Can reference regular item"+ (let [response (mt/user-http-request :crowberto+ :post 200 "document/"+ {:name "Doc with regular ref"+ :collection_id regular-id+ :document (prose-mirror-with-smartlink "Link" regular-card-id)})]+ (is (= "Doc with regular ref" (:name response)))))))))))- (testing "Throws exception when updating to reference non-remote-synced item"- (let [response (mt/user-http-request :crowberto- :put 400 (format "ee/document/%s" doc-id)- {:document (prose-mirror-with-smartlink "Bad link" card-id)})]- (is (= "Uses content that is not remote synced." (:message response)))))))))+(deftest update-document-in-remote-synced-with-non-remote-synced-smartlink-test+ (testing "PUT /api/document/:id - updating document in remote-synced collection to add non-remote-synced reference"+ (mt/when-ee-evailable+ (mt/with-temporary-setting-values [remote-sync-type :read-write]+ (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"+ :location "/"+ :is_remote_synced true}+ :model/Collection {regular-id :id} {:name "Regular Collection"+ :location "/"+ :type nil}+ :model/Document {doc-id :id} {:name "Test Document"+ :collection_id remote-synced-id+ :document (documents.test-util/text->prose-mirror-ast "Initial")}+ :model/Card {card-id :id} {:name "Regular Card"+ :collection_id regular-id+ :dataset_query (mt/mbql-query venues)}]++ (testing "Throws exception when updating to reference non-remote-synced item"+ (let [response (mt/user-http-request :crowberto+ :put 400 (format "document/%s" doc-id)+ {:document (prose-mirror-with-smartlink "Bad link" card-id)})]+ (is (= "Uses content that is not remote synced." (:message response))))))))))(deftest update-document-in-remote-synced-with-remote-synced-smartlink-test- (testing "PUT /api/ee/document/:id - updating document in remote-synced collection to add remote-synced reference"- (mt/with-temporary-setting-values [remote-sync-type :read-write]- (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"- :location "/"- :is_remote_synced true}- :model/Document {doc-id :id} {:name "Test Document"- :collection_id remote-synced-id- :document (documents.test-util/text->prose-mirror-ast "Initial")}- :model/Card {card-id :id} {:name "Remote-Synced Card"- :collection_id remote-synced-id- :dataset_query (mt/mbql-query venues)}]-- (testing "Successfully updates when referencing remote-synced item"- (let [response (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)- {:document (prose-mirror-with-smartlink "Good link" card-id)})]- (is (= "Test Document" (:name response)))- (is (= remote-synced-id (:collection_id response)))))))))+ (testing "PUT /api/document/:id - updating document in remote-synced collection to add remote-synced reference"+ (mt/when-ee-evailable+ (mt/with-temporary-setting-values [remote-sync-type :read-write]+ (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"+ :location "/"+ :is_remote_synced true}+ :model/Document {doc-id :id} {:name "Test Document"+ :collection_id remote-synced-id+ :document (documents.test-util/text->prose-mirror-ast "Initial")}+ :model/Card {card-id :id} {:name "Remote-Synced Card"+ :collection_id remote-synced-id+ :dataset_query (mt/mbql-query venues)}]++ (testing "Successfully updates when referencing remote-synced item"+ (let [response (mt/user-http-request :crowberto+ :put 200 (format "document/%s" doc-id)+ {:document (prose-mirror-with-smartlink "Good link" card-id)})]+ (is (= "Test Document" (:name response)))+ (is (= remote-synced-id (:collection_id response))))))))))(deftest move-document-with-remote-synced-refs-out-of-remote-synced-collection-test- (testing "PUT /api/ee/document/:id - moving document with remote-synced references out of remote-synced collection"- (mt/with-temporary-setting-values [remote-sync-type :read-write]- (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"- :location "/"- :is_remote_synced true}- :model/Collection {regular-id :id} {:name "Regular Collection"- :location "/"- :type nil}- :model/Card {card-id :id} {:name "Remote-Synced Card"- :collection_id remote-synced-id- :dataset_query (mt/mbql-query venues)}- :model/Document {doc-id :id} {:name "Doc with remote ref"- :collection_id remote-synced-id- :document (prose-mirror-with-smartlink "Link" card-id)}]+ (testing "PUT /api/document/:id - moving document with remote-synced references out of remote-synced collection"+ (mt/when-ee-evailable+ (mt/with-temporary-setting-values [remote-sync-type :read-write]+ (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"+ :location "/"+ :is_remote_synced true}+ :model/Collection {regular-id :id} {:name "Regular Collection"+ :location "/"+ :type nil}+ :model/Card {card-id :id} {:name "Remote-Synced Card"+ :collection_id remote-synced-id+ :dataset_query (mt/mbql-query venues)}+ :model/Document {doc-id :id} {:name "Doc with remote ref"+ :collection_id remote-synced-id+ :document (prose-mirror-with-smartlink "Link" card-id)}]- (testing "Does not throw an exception"- (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)- {:collection_id regular-id})+ (testing "Does not throw an exception"+ (mt/user-http-request :crowberto+ :put 200 (format "document/%s" doc-id)+ {:collection_id regular-id})- (is (= regular-id (:collection_id (t2/select-one :model/Document :id doc-id)))))))))+ (is (= regular-id (:collection_id (t2/select-one :model/Document :id doc-id))))))))))(deftest move-document-with-remote-synced-refs-to-root-collection-test- (testing "PUT /api/ee/document/:id - moving document with remote-synced references to root collection"- (mt/with-temporary-setting-values [remote-sync-type :read-write]- (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"- :location "/"- :is_remote_synced true}- :model/Card {card-id :id} {:name "Remote-Synced Card"- :collection_id remote-synced-id- :dataset_query (mt/mbql-query venues)}- :model/Document {doc-id :id} {:name "Doc with remote ref"- :collection_id remote-synced-id- :document (prose-mirror-with-smartlink "Link" card-id)}]+ (testing "PUT /api/document/:id - moving document with remote-synced references to root collection"+ (mt/when-ee-evailable+ (mt/with-temporary-setting-values [remote-sync-type :read-write]+ (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"+ :location "/"+ :is_remote_synced true}+ :model/Card {card-id :id} {:name "Remote-Synced Card"+ :collection_id remote-synced-id+ :dataset_query (mt/mbql-query venues)}+ :model/Document {doc-id :id} {:name "Doc with remote ref"+ :collection_id remote-synced-id+ :document (prose-mirror-with-smartlink "Link" card-id)}]- (testing "Does not throw an exception"- (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)- {:collection_id nil})+ (testing "Does not throw an exception"+ (mt/user-http-request :crowberto+ :put 200 (format "document/%s" doc-id)+ {:collection_id nil})- (is (nil? (:collection_id (t2/select-one :model/Document :id doc-id)))))))))+ (is (nil? (:collection_id (t2/select-one :model/Document :id doc-id))))))))))(deftest move-document-without-remote-synced-refs-out-of-remote-synced-collection-test- (testing "PUT /api/ee/document/:id - moving document without remote-synced references out of remote-synced collection"- (mt/with-temporary-setting-values [remote-sync-type :read-write]- (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"- :location "/"- :is_remote_synced true}- :model/Collection {regular-id :id} {:name "Regular Collection"- :location "/"- :type nil}- :model/Document {doc-id :id} {:name "Doc without refs"- :collection_id remote-synced-id- :document (documents.test-util/text->prose-mirror-ast "No references")}]-- (testing "Successfully moves when document has no remote-synced references"- (let [response (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)- {:collection_id regular-id})]- (is (= regular-id (:collection_id response)))- (is (= regular-id (:collection_id (t2/select-one :model/Document :id doc-id))))))))))+ (testing "PUT /api/document/:id - moving document without remote-synced references out of remote-synced collection"+ (mt/when-ee-evailable+ (mt/with-temporary-setting-values [remote-sync-type :read-write]+ (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"+ :location "/"+ :is_remote_synced true}+ :model/Collection {regular-id :id} {:name "Regular Collection"+ :location "/"+ :type nil}+ :model/Document {doc-id :id} {:name "Doc without refs"+ :collection_id remote-synced-id+ :document (documents.test-util/text->prose-mirror-ast "No references")}]++ (testing "Successfully moves when document has no remote-synced references"+ (let [response (mt/user-http-request :crowberto+ :put 200 (format "document/%s" doc-id)+ {:collection_id regular-id})]+ (is (= regular-id (:collection_id response)))+ (is (= regular-id (:collection_id (t2/select-one :model/Document :id doc-id)))))))))))(deftest move-document-into-remote-synced-collection-with-non-remote-synced-refs-test- (testing "PUT /api/ee/document/:id - moving document into remote-synced collection when it has non-remote-synced references"- (mt/with-temporary-setting-values [remote-sync-type :read-write]- (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"- :location "/"- :is_remote_synced true}- :model/Collection {regular-id :id} {:name "Regular Collection"- :location "/"- :type nil}- :model/Card {card-id :id} {:name "Regular Card"- :collection_id regular-id- :dataset_query (mt/mbql-query venues)}- :model/Document {doc-id :id} {:name "Doc with regular ref"- :collection_id regular-id- :document (prose-mirror-with-smartlink "Link" card-id)}]+ (testing "PUT /api/document/:id - moving document into remote-synced collection when it has non-remote-synced references"+ (mt/when-ee-evailable+ (mt/with-temporary-setting-values [remote-sync-type :read-write]+ (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"+ :location "/"+ :is_remote_synced true}+ :model/Collection {regular-id :id} {:name "Regular Collection"+ :location "/"+ :type nil}+ :model/Card {card-id :id} {:name "Regular Card"+ :collection_id regular-id+ :dataset_query (mt/mbql-query venues)}+ :model/Document {doc-id :id} {:name "Doc with regular ref"+ :collection_id regular-id+ :document (prose-mirror-with-smartlink "Link" card-id)}]- (testing "Throws exception when moving into remote-synced collection"- (let [response (mt/user-http-request :crowberto- :put 400 (format "ee/document/%s" doc-id)- {:collection_id remote-synced-id})]- (is (= "Uses content that is not remote synced." (:message response)))+ (testing "Throws exception when moving into remote-synced collection"+ (let [response (mt/user-http-request :crowberto+ :put 400 (format "document/%s" doc-id)+ {:collection_id remote-synced-id})]+ (is (= "Uses content that is not remote synced." (:message response)))- ;; Verify document was NOT moved- (is (= regular-id (:collection_id (t2/select-one :model/Document :id doc-id)))- "Document should remain in regular collection")))))))+ ;; Verify document was NOT moved+ (is (= regular-id (:collection_id (t2/select-one :model/Document :id doc-id)))+ "Document should remain in regular collection"))))))))(deftest update-and-move-document-simultaneously-test- (mt/with-temporary-setting-values [remote-sync-type :read-write]- (testing "PUT /api/ee/document/:id - updating content and moving collection simultaneously"- (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"- :location "/"- :is_remote_synced true}- :model/Collection {regular-id :id} {:name "Regular Collection"- :location "/"- :type nil}- :model/Card {remote-card-id :id} {:name "Remote-Synced Card"- :collection_id remote-synced-id- :dataset_query (mt/mbql-query venues)}- :model/Card {regular-card-id :id} {:name "Regular Card"- :collection_id regular-id+ (mt/when-ee-evailable+ (mt/with-temporary-setting-values [remote-sync-type :read-write]+ (testing "PUT /api/document/:id - updating content and moving collection simultaneously"+ (mt/with-temp [:model/Collection {remote-synced-id :id} {:name "Remote-Synced Collection"+ :location "/"+ :is_remote_synced true}+ :model/Collection {regular-id :id} {:name "Regular Collection"+ :location "/"+ :type nil}+ :model/Card {remote-card-id :id} {:name "Remote-Synced Card"+ :collection_id remote-synced-id:dataset_query (mt/mbql-query venues)}- :model/Document {doc-id :id} {:name "Test Doc"- :collection_id remote-synced-id- :document (documents.test-util/text->prose-mirror-ast "Initial")}]-- (testing "Throws exception when adding non-remote-synced ref and staying in remote-synced collection"- (let [response (mt/user-http-request :crowberto- :put 400 (format "ee/document/%s" doc-id)- {:document (prose-mirror-with-smartlink "Bad" regular-card-id)- :collection_id remote-synced-id})]- (is (= "Uses content that is not remote synced." (:message response)))))-- (testing "Does not throw when moving to a regular collection"- (mt/user-http-request :crowberto- :put 200 (format "ee/document/%s" doc-id)- {:document (prose-mirror-with-smartlink "Good" remote-card-id)- :collection_id regular-id}))))))+ :model/Card {regular-card-id :id} {:name "Regular Card"+ :collection_id regular-id+ :dataset_query (mt/mbql-query venues)}+ :model/Document {doc-id :id} {:name "Test Doc"+ :collection_id remote-synced-id+ :document (documents.test-util/text->prose-mirror-ast "Initial")}]++ (testing "Throws exception when adding non-remote-synced ref and staying in remote-synced collection"+ (let [response (mt/user-http-request :crowberto+ :put 400 (format "document/%s" doc-id)+ {:document (prose-mirror-with-smartlink "Bad" regular-card-id)+ :collection_id remote-synced-id})]+ (is (= "Uses content that is not remote synced." (:message response)))))++ (testing "Does not throw when moving to a regular collection"+ (mt/user-http-request :crowberto+ :put 200 (format "document/%s" doc-id)+ {:document (prose-mirror-with-smartlink "Good" remote-card-id)+ :collection_id regular-id})))))))(deftest post-document-to-personal-collection-test- (testing "POST /api/ee/document/ - creating a document in a personal collection"+ (testing "POST /api/document/ - creating a document in a personal collection"(mt/with-model-cleanup [:model/Document](let [personal-coll-id (t2/select-one-pk :model/Collection :personal_owner_id (mt/user->id :rasta))](testing "User can create a document in their own personal collection"(let [result (mt/user-http-request :rasta- :post 200 "ee/document/"+ :post 200 "document/"{:name "Personal Document":document (documents.test-util/text->prose-mirror-ast "My personal notes"):collection_id personal-coll-id})]@@ -2570,7 +2572,7 @@(is (= "Personal Document" (:name doc)))))))(testing "Admin can also create a document in someone else's personal collection"(let [result (mt/user-http-request :crowberto- :post 200 "ee/document/"+ :post 200 "document/"{:name "Admin Document in Personal Collection":document (documents.test-util/text->prose-mirror-ast "Admin's notes"):collection_id personal-coll-id})]@@ -2578,7 +2580,7 @@(is (= personal-coll-id (:collection_id result)))))(testing "Other users cannot create documents in someone else's personal collection"(mt/user-http-request :lucky- :post 403 "ee/document/"+ :post 403 "document/"{:name "Should Fail":document (documents.test-util/text->prose-mirror-ast "Should not be created"):collection_id personal-coll-id}))))))diff --git a/enterprise/backend/test/metabase_enterprise/documents/models/dashboard_card_test.clj b/test/metabase/documents/models/dashboard_card_test.cljsimilarity index 98%rename from enterprise/backend/test/metabase_enterprise/documents/models/dashboard_card_test.cljrename to test/metabase/documents/models/dashboard_card_test.cljindex 9378a589722..d7a631b7649 100644--- a/enterprise/backend/test/metabase_enterprise/documents/models/dashboard_card_test.clj+++ b/test/metabase/documents/models/dashboard_card_test.clj@@ -1,4 +1,4 @@-(ns metabase-enterprise.documents.models.dashboard-card-test+(ns metabase.documents.models.dashboard-card-test(:require[clojure.test :refer :all][metabase.dashboards.models.dashboard-card :as dashboard-card]diff --git a/enterprise/backend/test/metabase_enterprise/documents/models/document_test.clj b/test/metabase/documents/models/document_test.cljsimilarity index 99%rename from enterprise/backend/test/metabase_enterprise/documents/models/document_test.cljrename to test/metabase/documents/models/document_test.cljindex 62e70c74d7c..a081c27ebd5 100644--- a/enterprise/backend/test/metabase_enterprise/documents/models/document_test.clj+++ b/test/metabase/documents/models/document_test.clj@@ -1,8 +1,8 @@-(ns metabase-enterprise.documents.models.document-test+(ns metabase.documents.models.document-test(:require[clojure.test :refer :all]- [metabase-enterprise.documents.models.document :as document][metabase.collections.models.collection :as collection]+ [metabase.documents.models.document :as document][metabase.models.serialization :as serdes][metabase.permissions.core :as perms][metabase.test :as mt]diff --git a/enterprise/backend/test/metabase_enterprise/documents/prose_mirror_test.clj b/test/metabase/documents/prose_mirror_test.cljsimilarity index 99%rename from enterprise/backend/test/metabase_enterprise/documents/prose_mirror_test.cljrename to test/metabase/documents/prose_mirror_test.cljindex 2952b8c4ee5..d9c4d8d45b7 100644--- a/enterprise/backend/test/metabase_enterprise/documents/prose_mirror_test.clj+++ b/test/metabase/documents/prose_mirror_test.clj@@ -1,7 +1,7 @@-(ns metabase-enterprise.documents.prose-mirror-test+(ns metabase.documents.prose-mirror-test(:require[clojure.test :refer :all]- [metabase-enterprise.documents.prose-mirror :as prose-mirror]))+ [metabase.documents.prose-mirror :as prose-mirror]))(deftest ^:parallel update-ast-basic-test(testing "updates nodes that match predicate"diff --git a/test/metabase/documents/recent_views_test.clj b/test/metabase/documents/recent_views_test.cljnew file mode 100644index 00000000000..b218f86a50e--- /dev/null+++ b/test/metabase/documents/recent_views_test.clj@@ -0,0 +1,171 @@+(ns metabase.documents.recent-views-test+ (:require+ [clojure.test :refer :all]+ [metabase.activity-feed.core :as activity-feed]+ [metabase.activity-feed.models.recent-views :as recent-views.model]+ [metabase.events.core :as events]+ [metabase.test :as mt]+ [toucan2.core :as t2]))++(defn- most-recent-view+ [user-id model-id model-type]+ (t2/select-one [:model/RecentViews :user_id :model :model_id]+ :user_id user-id+ :model_id model-id+ :model model-type+ {:order-by [[:id :desc]]}))++(deftest card-query-test+ (mt/with-test-user :rasta+ (testing "document cards should not be counted"+ (mt/with-temp [:model/Document {doc-id :id} {}+ :model/Card card-3 {:creator_id (mt/user->id :rasta)+ :document_id doc-id}]+ (events/publish-event! :event/card-query {:card-id (:id card-3)+ :user-id (mt/user->id :rasta)+ :context :question})+ (is (nil? (most-recent-view (mt/user->id :rasta) (:id card-3) "card")))))))++(deftest legacy-card-read-test+ (testing "in_document cards should not be counted even with context :question"+ (mt/with-temp [:model/Document {doc-id :id} {}+ :model/Card card {:creator_id (mt/user->id :rasta)+ :document_id doc-id}]+ (mt/with-test-user :rasta+ (events/publish-event! :event/card-read {:object-id (:id card)+ :user-id (mt/user->id :rasta)+ :context :question})+ (is (nil? (most-recent-view (mt/user->id :rasta) (:id card) "card")))))))++(deftest select-documents-for-recents-empty-input-test+ (testing "returns empty vector when given empty document-ids"+ (is (= [] (#'recent-views.model/document-recents [])))+ (is (= [] (#'recent-views.model/document-recents nil)))))++(deftest select-documents-for-recents-with-collection-test+ (testing "returns documents with collection information"+ (mt/with-temp [:model/Collection {coll-id :id} {:name "Test Collection"+ :authority_level "official"+ :archived false}+ :model/Document {doc1-id :id} {:name "Document 1"+ :collection_id coll-id+ :archived false}+ :model/Document {doc2-id :id} {:name "Document 2"+ :collection_id coll-id+ :archived false}]+ (let [results (#'recent-views.model/document-recents [doc1-id doc2-id])]+ (is (= 2 (count results)))++ ;; Check first document+ (let [doc1 (first (filter #(= (:id %) doc1-id) results))]+ (is (= "Document 1" (:name doc1)))+ (is (= false (:archived doc1)))+ (is (= coll-id (:entity-coll-id doc1)))+ (is (= coll-id (:collection_id doc1)))+ (is (= "Test Collection" (:collection_name doc1)))+ (is (= "official" (:collection_authority_level doc1))))++ ;; Check second document+ (let [doc2 (first (filter #(= (:id %) doc2-id) results))]+ (is (= "Document 2" (:name doc2)))+ (is (= false (:archived doc2))))))))++(deftest select-documents-for-recents-without-collection-test+ (testing "returns documents without collection when collection_id is nil"+ (mt/with-temp [:model/Document {doc-id :id} {:name "Orphan Document"+ :collection_id nil+ :archived false}]+ (let [results (#'recent-views.model/document-recents [doc-id])]+ (is (= 1 (count results)))+ (let [doc (first results)]+ (is (= "Orphan Document" (:name doc)))+ (is (= false (:archived doc)))+ (is (nil? (:entity-coll-id doc)))+ (is (nil? (:collection_id doc)))+ (is (nil? (:collection_name doc)))+ (is (nil? (:collection_authority_level doc))))))))++(deftest select-documents-for-recents-archived-collections-test+ (testing "excludes documents from archived collections via left join"+ (mt/with-temp [:model/Collection {archived-coll-id :id} {:name "Archived Collection"+ :authority_level "official"+ :archived true}+ :model/Collection {active-coll-id :id} {:name "Active Collection"+ :authority_level "official"+ :archived false}+ :model/Document {doc1-id :id} {:name "Document in Archived Collection"+ :collection_id archived-coll-id+ :archived false}+ :model/Document {doc2-id :id} {:name "Document in Active Collection"+ :collection_id active-coll-id+ :archived false}]+ (let [results (#'recent-views.model/document-recents [doc1-id doc2-id])]+ (is (= 2 (count results)))++ ;; Document from archived collection should have nil collection info+ (let [doc1 (first (filter #(= (:id %) doc1-id) results))]+ (is (= "Document in Archived Collection" (:name doc1)))+ (is (= archived-coll-id (:entity-coll-id doc1)))+ (is (nil? (:collection_id doc1)))+ (is (nil? (:collection_name doc1)))+ (is (nil? (:collection_authority_level doc1))))++ ;; Document from active collection should have collection info+ (let [doc2 (first (filter #(= (:id %) doc2-id) results))]+ (is (= "Document in Active Collection" (:name doc2)))+ (is (= active-coll-id (:entity-coll-id doc2)))+ (is (= active-coll-id (:collection_id doc2)))+ (is (= "Active Collection" (:collection_name doc2)))+ (is (= "official" (:collection_authority_level doc2))))))))++(deftest select-documents-for-recents-archived-documents-test+ (testing "includes archived documents in results"+ (mt/with-temp [:model/Collection {coll-id :id} {:name "Test Collection"+ :archived false}+ :model/Document {doc-id :id} {:name "Archived Document"+ :collection_id coll-id+ :archived true}]+ (let [results (#'recent-views.model/document-recents [doc-id])]+ (is (= 1 (count results)))+ (let [doc (first results)]+ (is (= "Archived Document" (:name doc)))+ (is (true? (:archived doc))))))))++(deftest select-documents-for-recents-nonexistent-ids-test+ (testing "handles non-existent document IDs gracefully"+ (let [results (#'recent-views.model/document-recents [999999 888888])]+ (is (= [] results)))))++(deftest select-documents-for-recents-mixed-ids-test+ (testing "handles mixed existing and non-existing document IDs"+ (mt/with-temp [:model/Document {doc-id :id} {:name "Existing Document"+ :archived false}]+ (let [results (#'recent-views.model/document-recents [doc-id 999999])]+ (is (= 1 (count results)))+ (is (= "Existing Document" (:name (first results))))))))++(deftest select-documents-for-recents-duplicates-test+ (testing "preserves order and handles duplicates in document-ids"+ (mt/with-temp [:model/Document {doc1-id :id} {:name "Document 1" :archived false}+ :model/Document {doc2-id :id} {:name "Document 2" :archived false}]+ (let [results (#'recent-views.model/document-recents [doc1-id doc2-id doc1-id])]+ ;; Should return unique documents even if IDs are duplicated+ (is (= 2 (count results)))+ (is (= #{doc1-id doc2-id} (set (map :id results)))))))++ (deftest recents-api-with-documents-premium-feature-test+ (testing "/recents API returns documents when :document premium feature is enabled"+ (mt/with-temp [:model/Collection {coll-id :id} {:name "Test Collection"}+ :model/Document {doc-id :id} {:name "Test Document"+ :collection_id coll-id+ :archived false}]+ ;; Add document to recent views+ (activity-feed/update-users-recent-views! (mt/user->id :rasta) :model/Document doc-id :view)++ ;; Call the API+ (let [response (mt/user-http-request :rasta :get 200 "activity/recents" :context [:views])]+ (is (some #(and (= (:model %) "document")+ (= (:id %) doc-id)+ (= (:name %) "Test Document"))+ (:recents response))+ "Document should be present in recents when premium feature is enabled"))))))diff --git a/enterprise/backend/test/metabase_enterprise/documents/revisions/impl_test.clj b/test/metabase/documents/revisions/impl_test.cljsimilarity index 96%rename from enterprise/backend/test/metabase_enterprise/documents/revisions/impl_test.cljrename to test/metabase/documents/revisions/impl_test.cljindex b15b5b20942..1765aee539e 100644--- a/enterprise/backend/test/metabase_enterprise/documents/revisions/impl_test.clj+++ b/test/metabase/documents/revisions/impl_test.clj@@ -1,8 +1,8 @@-(ns metabase-enterprise.documents.revisions.impl-test+(ns metabase.documents.revisions.impl-test"Unit tests for Document revision serialization and reversion functionality."(:require[clojure.test :refer :all]- [metabase-enterprise.documents.revisions.impl]+ [metabase.documents.revisions.impl][metabase.revisions.models.revision :as revision][metabase.test :as mt][toucan2.core :as t2]))@@ -93,7 +93,7 @@(deftest excluded-columns-test(testing "excluded columns constant contains expected fields"- (let [excluded-columns @#'metabase-enterprise.documents.revisions.impl/excluded-columns-for-document-revision]+ (let [excluded-columns @#'metabase.documents.revisions.impl/excluded-columns-for-document-revision](is (contains? excluded-columns :id))(is (contains? excluded-columns :creator_id))(is (contains? excluded-columns :created_at))diff --git a/test/metabase/documents/revisions/integration_test.clj b/test/metabase/documents/revisions/integration_test.cljnew file mode 100644index 00000000000..1f04ef07983--- /dev/null+++ b/test/metabase/documents/revisions/integration_test.clj@@ -0,0 +1,262 @@+(ns metabase.documents.revisions.integration-test+ "Integration tests for Document revision history including API endpoints, events, and permissions."+ (:require+ [clojure.string :as str]+ [clojure.test :refer :all]+ [metabase.config.core :as config]+ [metabase.documents.revisions.impl]+ [metabase.events.core :as events]+ [metabase.revisions.models.revision :as revision]+ [metabase.test :as mt]+ [metabase.util :as u]+ [toucan2.core :as t2]))++(def ^:private rasta-revision-info+ (delay {:id (mt/user->id :rasta)+ :first_name "Rasta"+ :last_name "Toucan"+ :common_name "Rasta Toucan"}))++(defn- create-document-revision!+ "Helper function to create a Document revision manually for testing."+ [document-id is-creation? user]+ (revision/push-revision!+ {:object (t2/select-one :model/Document :id document-id)+ :entity :model/Document+ :id document-id+ :user-id (mt/user->id user)+ :is-creation? is-creation?}))++(defn- get-document-revisions+ "Helper function to get revisions for a Document via API."+ [document-id]+ (mt/user-http-request :rasta :get 200 (format "revision/document/%d" document-id)))++(deftest document-create-event-triggers-revision-test+ (testing "Document creation triggers revision creation via events"+ (mt/with-temp [:model/Document {doc-id :id, :as document} {:name "Test Document"+ :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Hello World"}]}]}+ :creator_id (mt/user->id :crowberto)}]+ (events/publish-event! :event/document-create {:object document :user-id (mt/user->id :crowberto)})+ (let [revision (t2/select-one :model/Revision :model "Document" :model_id doc-id)]+ (is revision "Revision should be created")+ (is (= "Document" (:model revision)))+ (is (= doc-id (:model_id revision)))+ (is (= (mt/user->id :crowberto) (:user_id revision)))+ (is (:is_creation revision))+ (is (not (:is_reversion revision)))+ (testing "serialized object excludes metadata fields"+ (let [object (:object revision)]+ (is (= "Test Document" (:name object)))+ (is (= {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Hello World"}]}]} (:document object)))+ (is (not (contains? object :id)))+ (is (not (contains? object :creator_id)))+ (is (not (contains? object :created_at)))+ (is (not (contains? object :updated_at)))+ (is (not (contains? object :collection_id)))))))))++(deftest document-update-event-triggers-revision-test+ (testing "Document update triggers revision creation via events"+ (mt/with-temp [:model/Document {doc-id :id, :as document} {:name "Original Document"+ :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Original content"}]}]}+ :creator_id (mt/user->id :crowberto)}]+ (let [updated-document (assoc document+ :name "Updated Document"+ :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Updated content"}]}]})]+ (events/publish-event! :event/document-update {:object updated-document :user-id (mt/user->id :rasta)})+ (let [revision (t2/select-one :model/Revision :model "Document" :model_id doc-id :user_id (mt/user->id :rasta))]+ (is revision "Revision should be created for update")+ (is (= "Document" (:model revision)))+ (is (= doc-id (:model_id revision)))+ (is (= (mt/user->id :rasta) (:user_id revision)))+ (is (not (:is_creation revision)))+ (is (not (:is_reversion revision)))+ (testing "serialized object contains updated data"+ (let [object (:object revision)]+ (is (= "Updated Document" (:name object)))+ (is (= {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Updated content"}]}]} (:document object))))))))))++(deftest document-revision-api-endpoints-test+ (testing "Document revision API endpoints work correctly"+ (mt/with-temp [:model/Document {doc-id :id} {:name "Test Document"+ :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Initial content"}]}]}+ :creator_id (mt/user->id :rasta)}]+ (create-document-revision! doc-id true :rasta)++ (testing "GET /api/revision/document/:id returns Document revisions"+ (let [revisions (get-document-revisions doc-id)]+ (is (= 1 (count revisions)))+ (let [revision (first revisions)]+ (is (:is_creation revision))+ (is (not (:is_reversion revision)))+ (is (= "created this." (:description revision)))+ (is (=? @rasta-revision-info (:user revision)))+ (is (= config/mb-version-string (:metabase_version revision))))))++ (testing "Multiple revisions are returned in correct order"+ (t2/update! :model/Document doc-id {:name "Updated Document"})+ (create-document-revision! doc-id false :rasta)++ (let [revisions (get-document-revisions doc-id)]+ (is (= 2 (count revisions)))+ (let [[latest-revision creation-revision] revisions]+ (is (not (:is_creation latest-revision)))+ (is (:is_creation creation-revision))+ (is (= "created this." (:description creation-revision)))+ (is (not= "created this." (:description latest-revision)))))))))++(deftest document-reversion-api-test+ (testing "Document reversion via API works correctly"+ (mt/with-temp [:model/Document {doc-id :id} {:name "Original Document"+ :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Original content"}]}]}+ :creator_id (mt/user->id :rasta)}]+ (create-document-revision! doc-id true :rasta)++ (testing "Document can be updated and reverted"+ (t2/update! :model/Document doc-id {:name "Updated Document"+ :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Updated content"}]}]}})+ (create-document-revision! doc-id false :rasta)++ (let [revisions (revision/revisions :model/Document doc-id)+ [_ {original-revision-id :id}] revisions]++ (testing "Revert via API endpoint"+ (let [revert-response (mt/user-http-request :rasta :post "revision/revert"+ {:entity :document+ :id doc-id+ :revision_id original-revision-id})]+ (is (:is_reversion revert-response))+ (is (= "reverted to an earlier version." (:description revert-response)))+ (is (=? @rasta-revision-info (:user revert-response)))))++ (testing "Document state is restored"+ (let [reverted-document (t2/select-one :model/Document :id doc-id)]+ (is (= "Original Document" (:name reverted-document)))+ (is (= {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Original content"}]}]}+ (:document reverted-document)))))++ (testing "Reversion creates new revision entry"+ (let [final-revisions (get-document-revisions doc-id)]+ (is (= 3 (count final-revisions)))+ (let [latest-revision (first final-revisions)]+ (is (:is_reversion latest-revision))+ (is (= "reverted to an earlier version." (:description latest-revision)))))))))))++(deftest document-revision-permission-checks-test+ (testing "Document revision API respects permissions"+ (mt/with-non-admin-groups-no-root-collection-perms+ (mt/with-temp [:model/Collection collection {:name "Private collection"}+ :model/Document document {:collection_id (u/the-id collection)+ :name "Private document"+ :document {:type "doc" :content []}+ :creator_id (mt/user->id :crowberto)}]+ (create-document-revision! (:id document) true :crowberto)+ (t2/update! :model/Document (:id document) {:name "Updated Private Document"})+ (create-document-revision! (:id document) false :crowberto)++ (let [document-id (u/the-id document)+ [_ {prev-rev-id :id}] (revision/revisions :model/Document document-id)]++ (testing "User without permissions cannot access revisions"+ (is (= "You don't have permissions to do that."+ (mt/user-http-request :rasta :get 403 (format "revision/document/%d" document-id)))))++ (testing "User without permissions cannot revert"+ (is (= "You don't have permissions to do that."+ (mt/user-http-request :rasta :post 403 "revision/revert"+ {:entity :document+ :id document-id+ :revision_id prev-rev-id})))))))))++(deftest document-revision-cross-boundary-integration-test+ (testing "Document revisions integrate properly with OSS revision system"+ (mt/with-temp [:model/Document {doc-id :id} {:name "Cross-boundary Document"+ :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Enterprise content"}]}]}+ :creator_id (mt/user->id :rasta)}]++ (testing "Document revisions work with OSS revision/revisions function"+ (create-document-revision! doc-id true :rasta)+ (let [revisions (revision/revisions :model/Document doc-id)]+ (is (seq revisions))+ (is (= 1 (count revisions)))+ (let [revision (first revisions)]+ (is (= doc-id (:model_id revision)))+ (is (= "Document" (:model revision))))))++ (testing "Document revisions work with OSS revision API routes"+ (let [revisions-response (mt/user-http-request :rasta :get (format "revision/document/%d" doc-id))]+ (is (seq revisions-response))+ (is (every? #(contains? % :is_creation) revisions-response))+ (is (every? #(contains? % :description) revisions-response))))++ (testing "Document reversion integrates with OSS revert endpoint"+ (t2/update! :model/Document doc-id {:name "Modified Document"})+ (create-document-revision! doc-id false :rasta)++ (let [[_ {original-rev-id :id}] (revision/revisions :model/Document doc-id)+ revert-response (mt/user-http-request :rasta :post "revision/revert"+ {:entity :document+ :id doc-id+ :revision_id original-rev-id})]+ (is (:is_reversion revert-response))+ (let [reverted-doc (t2/select-one :model/Document :id doc-id)]+ (is (= "Cross-boundary Document" (:name reverted-doc)))))))))++(deftest document-revision-event-handler-integration-test+ (testing "Document revision events are published and handled correctly"+ (let [original-event events/publish-event!+ events-received (atom [])]+ (with-redefs [events/publish-event! (fn [topic event]+ (swap! events-received conj [topic event])+ (original-event topic event))]+ (mt/with-temp [:model/Document {doc-id :id, :as document} {:name "Event Test Document"+ :document {:type "doc" :content []}+ :creator_id (mt/user->id :rasta)}]++ (testing "Create event triggers revision creation"+ (events/publish-event! :event/document-create {:object document :user-id (mt/user->id :rasta)})+ (let [revision (t2/select-one :model/Revision :model "Document" :model_id doc-id)]+ (is revision)+ (is (:is_creation revision))))++ (testing "Update event triggers revision creation"+ (let [updated-document (assoc document :name "Updated Event Document")]+ (events/publish-event! :event/document-update {:object updated-document :user-id (mt/user->id :rasta)})+ (let [revisions (t2/select :model/Revision :model "Document" :model_id doc-id {:order-by [[:id :desc]]})]+ (is (= 2 (count revisions)))+ (let [latest-revision (first revisions)]+ (is (not (:is_creation latest-revision)))+ (is (= "Updated Event Document" (get-in latest-revision [:object :name])))))))++ (testing "Events were published correctly"+ (is (>= (count @events-received) 2))+ (is (some #(= :event/document-create (first %)) @events-received))+ (is (some #(= :event/document-update (first %)) @events-received))))))))++(deftest document-revision-diff-and-descriptions-test+ (testing "Document revision diffs and descriptions work correctly"+ (mt/with-temp [:model/Document {doc-id :id} {:name "Original Title"+ :document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "Original content"}]}]}+ :creator_id (mt/user->id :rasta)}]+ (create-document-revision! doc-id true :rasta)++ (testing "Name change produces correct diff and description"+ (t2/update! :model/Document doc-id {:name "Updated Title"})+ (create-document-revision! doc-id false :rasta)++ (let [revisions (get-document-revisions doc-id)+ update-revision (first revisions)]+ (is (= "Original Title" (get-in update-revision [:diff :before :name])))+ (is (= "Updated Title" (get-in update-revision [:diff :after :name])))+ (is (str/includes? (:description update-revision) "renamed"))))++ (testing "Content change produces diff"+ (t2/update! :model/Document doc-id {:document {:type "doc" :content [{:type "paragraph" :content [{:type "text" :text "New content"}]}]}})+ (create-document-revision! doc-id false :rasta)++ (let [revisions (get-document-revisions doc-id)+ content-revision (first revisions)]+ (is (= {:content [{:content [{:text "Original content"}]}]}+ (get-in content-revision [:diff :before :document])))+ (is (= {:content [{:content [{:text "New content"}]}]}+ (get-in content-revision [:diff :after :document]))))))))diff --git a/test/metabase/documents/search_test.clj b/test/metabase/documents/search_test.cljnew file mode 100644index 00000000000..3df6cef09f0--- /dev/null+++ b/test/metabase/documents/search_test.clj@@ -0,0 +1,145 @@+(ns metabase.documents.search-test+ (:require+ [clojure.test :refer :all]+ [java-time.api :as t]+ [metabase.events.core :as events]+ [metabase.permissions.core :as perms]+ [metabase.permissions.models.permissions-group :as perms-group]+ [metabase.search.test-util :as search.tu]+ [metabase.test :as mt]+ [metabase.test.fixtures :as fixtures]+ [metabase.util :as u]+ [toucan2.core :as t2]))++(defn- text->prose-mirror-ast+ "Convert plain text to a ProseMirror AST structure."+ [text]+ (if (empty? text)+ {:type "doc" :content []}+ {:type "doc"+ :content [{:type "paragraph"+ :content [{:type "text"+ :text text}]}]}))++(use-fixtures :once (fixtures/initialize :db :test-users))++(defn card-with-name-and-query+ ([]+ (card-with-name-and-query (mt/random-name)))+ ([card-name]+ {:name card-name+ :display "scalar"+ :dataset_query (mt/mbql-query venues)+ :visualization_settings {:global {:title nil}}}))++(deftest card-search-exclusion-test+ (testing "Cards with document_id are excluded from search indexing"+ (let [card-name (mt/random-name)+ regular-card-name (str card-name "-regular")]+ (search.tu/with-temp-index-table+ (mt/with-temp [:model/Document document {:name "Test Document"+ :document (text->prose-mirror-ast "")}+ :model/Card document-card (-> (card-with-name-and-query card-name)+ (assoc :document_id (u/the-id document)))+ :model/Card regular-card (card-with-name-and-query regular-card-name)]++ (testing "Search API excludes document cards"+ (let [results (mt/user-http-request :crowberto :get 200 "search" :q card-name :models "card")]+ (is (not (some #(= (:id %) (u/the-id document-card)) (:data results)))+ "Document card should not appear in search results"))+ (let [regular-results (mt/user-http-request :crowberto :get 200 "search" :q regular-card-name :models "card")]+ (is (some #(= (:id %) (u/the-id regular-card)) (:data regular-results))+ "Regular card should appear in search results"))))))))++(deftest document-permission-filtering-test+ (testing "Document search respects collection-based permissions"+ (mt/with-non-admin-groups-no-root-collection-perms+ (search.tu/with-temp-index-table+ (mt/with-temp [:model/Collection {coll-id :id} {}+ :model/Collection {private-coll-id :id} {}+ :model/Document {doc-in-public-coll :id} {:name "Public Document"+ :collection_id coll-id+ :document (text->prose-mirror-ast "content")}+ :model/Document {doc-in-private-coll :id} {:name "Private Document"+ :collection_id private-coll-id+ :document (text->prose-mirror-ast "content")}+ :model/Document {doc-archived :id} {:name "Archived Document"+ :collection_id coll-id+ :archived true+ :document (text->prose-mirror-ast "content")}]+ ;; Give user read access to first collection only+ (perms/grant-collection-read-permissions! (perms-group/all-users) coll-id)++ (testing "Regular user sees only documents in accessible collections"+ (let [results (mt/user-http-request :rasta :get 200 "search" :q "Document" :models "document")]+ (is (= #{doc-in-public-coll}+ (set (map :id (:data results))))+ "Should only see document in accessible collection")))++ (testing "Regular user cannot see archived documents (no write perms)"+ (let [results (mt/user-http-request :rasta :get 200 "search" :q "Archived" :archived true :models "document")]+ (is (empty? (:data results))+ "Should not see archived document without write permissions")))++ (testing "Admin can see all documents including archived"+ (let [regular-results (mt/user-http-request :crowberto :get 200 "search" :q "Document" :models "document")+ archived-results (mt/user-http-request :crowberto :get 200 "search" :q "Archived" :archived true :models "document")]+ (is (= #{doc-in-public-coll doc-in-private-coll}+ (set (map :id (:data regular-results))))+ "Admin should see all non-archived documents")+ (is (= #{doc-archived}+ (set (map :id (:data archived-results))))+ "Admin should see archived documents")))++ (testing "User with write permissions can see archived documents"+ ;; Give user write access to first collection+ (perms/grant-collection-readwrite-permissions! (perms-group/all-users) coll-id)+ (let [archived-results (mt/user-http-request :rasta :get 200 "search" :q "Archived" :archived true :models "document")]+ (is (= #{doc-archived}+ (set (map :id (:data archived-results))))+ "User with write permissions should see archived documents in accessible collections"))))))))++(deftest document-view-tracking-integration-test+ (testing "Document view tracking integrates with search"+ (mt/with-temp [:model/Document {doc-id :id} {:name "Viewed Document"+ :document (text->prose-mirror-ast "content")+ :view_count 0}]++ (testing "Document has initial state"+ (let [doc (t2/select-one :model/Document :id doc-id)]+ (is (= 0 (:view_count doc)))+ ;; last_viewed_at has a default timestamp from migration, not nil+ (is (some? (:last_viewed_at doc)))))++ (testing "Publishing document-read event works without errors"+ ;; The actual view count increment is batched and asynchronous+ ;; So we test that the event publishes successfully+ (is (some? (events/publish-event! :event/document-read+ {:object-id doc-id+ :user-id (mt/user->id :crowberto)}))+ "Document read event should publish successfully"))++ (testing "Document with higher view count appears in search"+ ;; Manually set view count to test search integration+ (t2/update! :model/Document doc-id {:view_count 5+ :last_viewed_at (t/offset-date-time)})+ (search.tu/with-temp-index-table+ (let [results (mt/user-http-request :crowberto :get 200 "search" {:q "Viewed" :models "document"})+ doc-results (filter #(= "document" (:model %)) (:data results))]+ (when (seq doc-results)+ (let [doc-result (first doc-results)]+ (is (= doc-id (:id doc-result)))+ ;; View count affects scoring but isn't directly in result+ (is (some #(= "view-count" (:name %)) (:scores doc-result))))))))++ (testing "Document with recent view appears in search results"+ (let [recent-time (t/minus (t/offset-date-time) (t/minutes 5))]+ (t2/update! :model/Document doc-id {:last_viewed_at recent-time})+ (search.tu/with-temp-index-table+ (let [results (mt/user-http-request :crowberto :get 200 "search" {:q "Viewed" :models "document"})+ doc-results (filter #(= "document" (:model %)) (:data results))]+ (when (seq doc-results)+ (let [doc-result (first doc-results)]+ (is (= doc-id (:id doc-result)))+ ;; User recency affects scoring+ (is (some #(= "user-recency" (:name %)) (:scores doc-result))))))))))))diff --git a/enterprise/backend/test/metabase_enterprise/documents/test_util.clj b/test/metabase/documents/test_util.cljsimilarity index 85%rename from enterprise/backend/test/metabase_enterprise/documents/test_util.cljrename to test/metabase/documents/test_util.cljindex 686af8e1a02..7cf84e6f752 100644--- a/enterprise/backend/test/metabase_enterprise/documents/test_util.clj+++ b/test/metabase/documents/test_util.clj@@ -1,4 +1,4 @@-(ns metabase-enterprise.documents.test-util+(ns metabase.documents.test-util"Shared test utilities for document tests.")(defn text->prose-mirror-astdiff --git a/test/metabase/documents/view_log_test.clj b/test/metabase/documents/view_log_test.cljnew file mode 100644index 00000000000..6620cd171e1--- /dev/null+++ b/test/metabase/documents/view_log_test.clj@@ -0,0 +1,144 @@+(ns metabase.documents.view-log-test+ (:require+ [clojure.test :refer :all]+ [java-time.api :as t]+ [metabase.documents.view-log :as documents.view-log]+ [metabase.events.core :as events]+ [metabase.test :as mt]+ [toucan2.core :as t2]))++(set! *warn-on-reflection* true)++(defn latest-view+ "Returns the most recent view for a given user and document ID"+ [user-id document-id]+ (t2/select-one :model/ViewLog+ :user_id user-id+ :model "document"+ :model_id document-id+ {:order-by [[:id :desc]]}))++(deftest document-read-ee-test+ (mt/with-premium-features #{:audit-app}+ (mt/with-temp [:model/Collection collection {}+ :model/User user {}+ :model/Document document {:collection_id (:id collection)+ :name "Test Document"+ :document "{\"type\":\"doc\",\"content\":[]}"+ :creator_id (:id user)}]+ (testing "A basic document read event is recorded in EE"+ (events/publish-event! :event/document-read {:object-id (:id document) :user-id (:id user)})+ (is (partial=+ {:user_id (:id user)+ :model "document"+ :model_id (:id document)+ :has_access true+ :context nil}+ (latest-view (:id user) (:id document))))))))++(deftest document-read-oss-no-view-logging-test+ (mt/with-temp [:model/Collection collection {}+ :model/User user {}+ :model/Document document {:collection_id (:id collection)+ :name "Test Document"+ :document "{\"type\":\"doc\",\"content\":[]}"+ :creator_id (:id user)}]+ (testing "A basic document read event is not recorded without audit-app"+ (events/publish-event! :event/document-read {:object-id (:id document) :user-id (:id user)})+ (is (nil? (latest-view (:id user) (:id document)))+ "view log entries should not be made without audit-app feature"))))++(deftest document-read-view-count-test+ (mt/test-helpers-set-global-values!+ (mt/with-temporary-setting-values [synchronous-batch-updates true]+ (mt/with-temp [:model/Collection collection {}+ :model/User user {}+ :model/Document document {:collection_id (:id collection)+ :name "Test Document"+ :document "{\"type\":\"doc\",\"content\":[]}"+ :creator_id (:id user)+ :view_count 0}]+ (testing "Document read events are recorded by a document's view_count"+ (is (= 0 (:view_count document))+ "view_count should be 0 before the event is published")+ (events/publish-event! :event/document-read {:object-id (:id document) :user-id (:id user)})+ (is (= 1 (t2/select-one-fn :view_count :model/Document (:id document))))+ (events/publish-event! :event/document-read {:object-id (:id document) :user-id (:id user)})+ (is (= 2 (t2/select-one-fn :view_count :model/Document (:id document)))))))))++(deftest update-document-last-viewed-at-test+ (let [now (-> (t/offset-date-time)+ (.withNano 0))+ one-hour-ago (t/minus now (t/hours 1))+ two-hours-ago (t/minus now (t/hours 2))]+ (testing "update with multiple documents of the same IDs will set timestamp to the latest"+ (mt/with-temp [:model/Collection collection {}+ :model/User user {}+ :model/Document document {:collection_id (:id collection)+ :name "Test Document"+ :document "{\"type\":\"doc\",\"content\":[]}"+ :creator_id (:id user)+ :last_viewed_at two-hours-ago}]+ (#'documents.view-log/update-document-last-viewed-at!* [{:id (:id document) :timestamp one-hour-ago}+ {:id (:id document) :timestamp two-hours-ago}])+ (is (= one-hour-ago+ (-> (t2/select-one-fn :last_viewed_at :model/Document (:id document))+ t/offset-date-time+ (.withNano 0))))))++ (testing "if the existing last_viewed_at is greater than the updating values, do not override it"+ (mt/with-temp [:model/Collection collection {}+ :model/User user {}+ :model/Document document {:collection_id (:id collection)+ :name "Test Document"+ :document "{\"type\":\"doc\",\"content\":[]}"+ :creator_id (:id user)+ :last_viewed_at now}]+ (#'documents.view-log/update-document-last-viewed-at!* [{:id (:id document) :timestamp one-hour-ago}])+ (is (= now+ (-> (t2/select-one-fn :last_viewed_at :model/Document (:id document))+ t/offset-date-time+ (.withNano 0))))))))++(deftest document-event-derivation-test+ (testing "Document events are properly derived from base events"+ (is (isa? :metabase.documents.view-log/document-read :metabase/event))+ (is (isa? :event/document-read :metabase.documents.view-log/document-read))))++(deftest document-read-error-handling-test+ (testing "Document read event handles missing document gracefully"+ ;; This should not throw an exception+ (is (some? (events/publish-event! :event/document-read {:object-id 999999 :user-id (mt/user->id :rasta)})))))++(deftest document-statistics-lock-test+ (testing "Document statistics lock is properly defined"+ (is (= :metabase.documents.view-log/document-statistics-lock+ @#'documents.view-log/document-statistics-lock))))++(deftest document-read-updates-recent-views-test+ (mt/with-premium-features #{:audit-app}+ (mt/with-temp [:model/Collection collection {}+ :model/User user {}+ :model/Document document {:collection_id (:id collection)+ :name "Test Document"+ :document "{\"type\":\"doc\",\"content\":[]}"+ :creator_id (:id user)}]+ (testing "Document read event updates user's recent views"+ ;; Verify no recent views initially+ (is (empty? (t2/select :model/RecentViews+ :user_id (:id user)+ :model "document"+ :model_id (:id document))))++ ;; Publish document read event+ (events/publish-event! :event/document-read {:object-id (:id document) :user-id (:id user)})++ ;; Verify recent view was created+ (let [recent-view (t2/select-one :model/RecentViews+ :user_id (:id user)+ :model "document"+ :model_id (:id document))]+ (is (some? recent-view) "Recent view should be created")+ (is (= (:id user) (:user_id recent-view)))+ (is (= "document" (:model recent-view)))+ (is (= (:id document) (:model_id recent-view))))))))diff --git a/test/metabase/public_sharing_rest/api_documents_test.clj b/test/metabase/public_sharing_rest/api_documents_test.cljnew file mode 100644index 00000000000..3efa392f0d2--- /dev/null+++ b/test/metabase/public_sharing_rest/api_documents_test.clj@@ -0,0 +1,165 @@+(ns metabase.public-sharing-rest.api-documents-test+ "Tests for public sharing endpoints for Documents.++ These tests verify that public document endpoints work correctly."+ (:require+ [clojure.test :refer :all]+ [metabase.documents.test-util :as documents.test-util]+ [metabase.test :as mt]+ [toucan2.core :as t2]))++(defn- document-with-public-link+ "Create test Document data including a public UUID and made_public_by_id."+ [overrides]+ (merge {:name "Test Document"+ :document (documents.test-util/text->prose-mirror-ast "Test content")+ :public_uuid (str (random-uuid))+ :made_public_by_id (mt/user->id :crowberto)}+ overrides))++;;; ---------------------------------------- Unauthenticated Access -------------------------------------------------------++(deftest unauthenticated-public-document-access-test+ (testing "Public document endpoints should work without authentication"+ (mt/with-temporary-setting-values [enable-public-sharing true]+ (mt/with-temp [:model/Document document (document-with-public-link {:name "Unauthenticated Test Document"+ :document (documents.test-util/text->prose-mirror-ast "Public content")})]+ (testing "Can access public document without authentication at /api/public/document"+ (let [response (mt/client-full-response :get (str "public/document/" (:public_uuid document)))]+ (is (= 200 (:status response))+ "Should return 200 OK for public document without auth")+ (is (contains? (:body response) :name)+ "Should return document data in response body")))))))++;;; ---------------------------------------- GET /api/public/document/:uuid ----------------------------------------------++(deftest fetch-public-document-test+ (testing "GET /api/public/document/:uuid"+ (testing "Can fetch a public Document via EE public sharing routes"+ (mt/with-temporary-setting-values [enable-public-sharing true]+ (mt/with-temp [:model/Document document (document-with-public-link {:name "Public Test Document"+ :document (documents.test-util/text->prose-mirror-ast "Public test content")})]+ (is (partial= {:name "Public Test Document"+ :document (documents.test-util/text->prose-mirror-ast "Public test content")+ :id (:id document)}+ (mt/client :get 200 (str "public/document/" (:public_uuid document))))))))))++(deftest public-document-returns-only-safe-fields-test+ (testing "GET /api/public/document/:uuid should only return safe fields"+ (mt/with-temporary-setting-values [enable-public-sharing true]+ (mt/with-temp [:model/Document document (document-with-public-link {:name "Public Test Document"+ :document (documents.test-util/text->prose-mirror-ast "Public test content")})]+ (let [result (mt/client :get 200 (str "public/document/" (:public_uuid document)))]+ (testing "Should include safe fields"+ (is (contains? result :id))+ (is (contains? result :name))+ (is (contains? result :document))+ (is (contains? result :created_at))+ (is (contains? result :updated_at)))+ (testing "Should not include sensitive fields"+ (is (not (contains? result :public_uuid)))+ (is (not (contains? result :made_public_by_id)))+ (is (not (contains? result :collection_id)))))))))++(deftest public-document-hydrates-cards-test+ (testing "GET /api/public/document/:uuid hydrates cards for public access"+ (mt/with-temporary-setting-values [enable-public-sharing true]+ (mt/with-temp [:model/Document document (document-with-public-link {:name "Document with Cards"})+ :model/Card {card1-id :id} {:name "Card 1"+ :dataset_query (mt/mbql-query venues {:limit 5})+ :document_id (:id document)}+ :model/Card {card2-id :id} {:name "Card 2"+ :dataset_query (mt/mbql-query venues {:limit 10})+ :document_id (:id document)}]+ (let [result (mt/client :get 200 (str "public/document/" (:public_uuid document)))]+ (testing "response includes cards field"+ (is (contains? result :cards)))++ (testing "cards are returned as a map keyed by card ID"+ (is (map? (:cards result)))+ (is (= 2 (count (:cards result))))+ (is (contains? (:cards result) card1-id))+ (is (contains? (:cards result) card2-id)))++ (testing "cards contain expected metadata"+ (is (= "Card 1" (get-in result [:cards card1-id :name])))+ (is (= "Card 2" (get-in result [:cards card2-id :name])))+ (is (= card1-id (get-in result [:cards card1-id :id])))+ (is (= card2-id (get-in result [:cards card2-id :id]))))++ (testing "cards do not include sensitive fields"+ (is (not (contains? (get-in result [:cards card1-id]) :collection_id)))+ (is (not (contains? (get-in result [:cards card1-id]) :creator_id)))))))))++(deftest get-public-document-errors-test+ (testing "GET /api/public/document/:uuid"+ (testing "Cannot fetch a public Document if public sharing is disabled"+ (mt/with-temporary-setting-values [enable-public-sharing false]+ (mt/with-temp [:model/Document document (document-with-public-link {})]+ (is (= "API endpoint does not exist."+ (mt/client :get 404 (str "public/document/" (:public_uuid document)))))))))++ (testing "Returns 404 if the Document doesn't exist"+ (mt/with-temporary-setting-values [enable-public-sharing true]+ (is (= "Not found."+ (mt/client :get 404 (str "public/document/" (random-uuid))))))))++(deftest public-document-not-accessible-when-archived-test+ (testing "GET /api/public/document/:uuid should not work for archived documents"+ (mt/with-temporary-setting-values [enable-public-sharing true]+ (mt/with-temp [:model/Document document (document-with-public-link {})]+ (let [uuid (:public_uuid document)]+ (testing "Document is accessible when not archived"+ (is (= 200+ (:status (mt/client-full-response :get (str "public/document/" uuid))))))+ (testing "Document is not accessible after archiving"+ (t2/update! :model/Document (:id document) {:archived true})+ (is (= "Not found."+ (mt/client :get 404 (str "public/document/" uuid))))))))))++;;; ------------------------------ GET /api/public/document/:uuid/card/:card-id ---------------------------------------++(deftest fetch-public-document-card-test+ (testing "GET /api/public/document/:uuid/card/:card-id"+ (testing "Can run query for card embedded in public document"+ (mt/with-temporary-setting-values [enable-public-sharing true]+ (mt/with-temp [:model/Document document (document-with-public-link {})+ :model/Card card {:name "Test Card"+ :dataset_query (mt/mbql-query venues {:limit 5})+ :document_id (:id document)}]+ (let [result (mt/client :get 202 (format "public/document/%s/card/%d" (:public_uuid document) (:id card)))]+ (is (some? result))+ (is (= "completed" (:status result)))))))))++(deftest public-document-card-validates-association-test+ (testing "GET /api/public/document/:uuid/card/:card-id validates card is associated with document"+ (mt/with-temporary-setting-values [enable-public-sharing true]+ (mt/with-temp [:model/Document document (document-with-public-link {})+ :model/Card card {:name "Unassociated Card"+ :dataset_query (mt/mbql-query venues {:limit 5})}]+ (is (= "Not found."+ (mt/client :get 404 (format "public/document/%s/card/%d" (:public_uuid document) (:id card)))))))))++;;; ----------------------- POST /api/public/document/:uuid/card/:card-id/:export-format -------------------------------++(deftest export-public-document-card-test+ (testing "POST /api/public/document/:uuid/card/:card-id/:export-format"+ (mt/with-temporary-setting-values [enable-public-sharing true]+ (mt/with-temp [:model/Document document (document-with-public-link {})+ :model/Card card {:name "Export Test Card"+ :dataset_query (mt/mbql-query venues {:limit 5})+ :document_id (:id document)}]+ (testing "Can export card results as CSV"+ (let [response (mt/client-full-response :post (format "public/document/%s/card/%d/csv"+ (:public_uuid document)+ (:id card))+ {})]+ (is (= 200 (:status response)))+ (is (= "text/csv" (get-in response [:headers "Content-Type"])))))++ (testing "Can export card results as JSON"+ (let [response (mt/client-full-response :post (format "public/document/%s/card/%d/json"+ (:public_uuid document)+ (:id card))+ {})]+ (is (= 200 (:status response)))))))))diff --git a/test/metabase/search/appdb/index_test.clj b/test/metabase/search/appdb/index_test.cljindex 4cab69f948b..6236db9a6c9 100644--- a/test/metabase/search/appdb/index_test.clj+++ b/test/metabase/search/appdb/index_test.clj@@ -542,8 +542,8 @@(def ^:private model->deleted-descendants;; Note that these refer to the table names, not the search-model names.- {"core_user" (cond-> #{"action" "collection" "model_index_value" "report_card" "report_dashboard" "segment"}- config/ee-available? (conj "document" "transform"))+ {"core_user" (cond-> #{"action" "collection" "document" "model_index_value" "report_card" "report_dashboard" "segment"}+ config/ee-available? (conj "transform"))"model_index" #{"model_index_value"}"metabase_database" #{"action" "metabase_table" "model_index_value" "report_card" "segment"}"metabase_table" #{"action" "model_index_value" "report_card" "segment"}diff --git a/test/metabase/search/filter_test.clj b/test/metabase/search/filter_test.cljindex 36bac613653..0169809ae6f 100644--- a/test/metabase/search/filter_test.clj+++ b/test/metabase/search/filter_test.clj@@ -66,8 +66,7 @@(search.filter/search-context->applicable-models (with-all-models-and-regular-user {:archived? false})))))(testing "We only search for certain models in the trash"- (is (= (cond-> #{"dashboard" "dataset" "segment" "collection" "action" "metric" "card"}- config/ee-available? (conj "document"))+ (is (= #{"dashboard" "dataset" "document" "segment" "collection" "action" "metric" "card"}(search.filter/search-context->applicable-models (with-all-models-and-regular-user {:archived? true})))))(testing "Indexed entities and transforms (which are admin-only) are not visible for sandboxed users"@@ -124,8 +123,8 @@:from :somewhere;; This :where clause is a set to avoid flakes, since the clause order will be non-deterministic.:where #{:and- [:in :search_index.model (cond-> #{"dashboard" "table" "segment" "collection" "database" "action" "indexed-entity" "metric" "card"}- config/ee-available? (conj "document" "transform"))]+ [:in :search_index.model (cond-> #{"dashboard" "table" "segment" "collection" "database" "action" "indexed-entity" "metric" "card" "document"}+ config/ee-available? (conj "transform"))][:in :search_index.model_id ["1" "2" "3" "4"]][:in :search_index.model ["card" "dataset" "metric" "dashboard" "action"]][:= :search_index.archived true]diff --git a/test/metabase/search/in_place/filter_test.clj b/test/metabase/search/in_place/filter_test.cljindex b5021a4c505..92190271cd6 100644--- a/test/metabase/search/in_place/filter_test.clj+++ b/test/metabase/search/in_place/filter_test.clj@@ -38,8 +38,7 @@(deftest ^:parallel ->applicable-models-test-2(testing "optional filters will return intersection of support models and provided models\n"(testing "created by"- (is (= (cond-> #{"dashboard" "dataset" "action" "card" "metric"}- config/ee-available? (conj "document"))+ (is (= #{"dashboard" "dataset" "document" "action" "card" "metric"}(search.filter/search-context->applicable-models(merge default-search-ctx{:created-by #{1}}))))@@ -51,8 +50,8 @@:created-by #{1}})))))(testing "created at"- (is (= (cond-> #{"dashboard" "table" "dataset" "collection" "database" "action" "card" "metric"}- config/ee-available? (conj "document" "transform"))+ (is (= (cond-> #{"dashboard" "table" "dataset" "document" "collection" "database" "action" "card" "metric"}+ config/ee-available? (conj "transform"))(search.filter/search-context->applicable-models(merge default-search-ctx{:created-at "past3days"}))))