Skip to content

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

Fix deleted documents were editable (#65136)

Mahatthana (Kelvin) Nomsawadicbcb70a438a8
diff --git a/e2e/test/scenarios/documents/documents.cy.spec.ts b/e2e/test/scenarios/documents/documents.cy.spec.ts
index 27e1ca1039f..38a82fa2f5d 100644
--- a/e2e/test/scenarios/documents/documents.cy.spec.ts
+++ b/e2e/test/scenarios/documents/documents.cy.spec.ts
@@ -145,7 +145,15 @@ H.describeWithSnowplowEE("documents", () => {
// Force the click since this is hidden behind a toast notification
H.navigationSidebar().findByText("Trash").click({ force: true });
- H.getUnpinnedSection().findByText("Test Document").should("exist");
+ H.getUnpinnedSection().findByText("Test Document").should("exist").click();
+
+ cy.log("test that deleted documents cannot be edited (metabase#63112)");
+ cy.findByRole("textbox", { name: "Document Title" })
+ .should("be.visible")
+ .and("have.attr", "readonly");
+ H.documentContent()
+ .findByRole("textbox")
+ .should("have.attr", "contenteditable", "false");
});
it("should handle navigating from /new to /new gracefully", () => {
diff --git a/enterprise/backend/src/metabase_enterprise/documents/api/document.clj b/enterprise/backend/src/metabase_enterprise/documents/api/document.clj
index e68b0711556..288f4ca9371 100644
--- a/enterprise/backend/src/metabase_enterprise/documents/api/document.clj
+++ b/enterprise/backend/src/metabase_enterprise/documents/api/document.clj
@@ -197,6 +197,8 @@
_query-params
{:keys [name document collection_id collection_position cards] :as body} :- DocumentUpdateOptions]
(let [existing-document (api/check-404 (get-document document-id))]
+ (when-not (contains? body :archived)
+ (api/check-not-archived existing-document))
(api/write-check existing-document)
(when (api/column-will-change? :collection_id existing-document body)
(m.document/validate-collection-move-permissions (:collection_id existing-document) collection_id))
diff --git a/enterprise/backend/test/metabase_enterprise/documents/api/document_test.clj b/enterprise/backend/test/metabase_enterprise/documents/api/document_test.clj
index 1810593d09f..6f28d540349 100644
--- a/enterprise/backend/test/metabase_enterprise/documents/api/document_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/documents/api/document_test.clj
@@ -85,6 +85,17 @@
(mt/user-http-request :rasta :put 403 (str "ee/document/" document-id)
{:name "Meow"}))))
+(deftest put-document-archived-test
+ (testing "PUT /api/ee/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)
+ {: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
diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx b/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx
index d73787991c2..e90023b05da 100644
--- a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx
@@ -138,7 +138,8 @@ export const DocumentPage = ({
const hasComments =
!!commentsData?.comments && commentsData.comments.length > 0;
- const canWrite = isNewDocument || documentData?.can_write;
+ const canWrite =
+ !documentData?.archived && (isNewDocument || documentData?.can_write);
useEffect(() => {
if (error) {