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
Collections are delete-able (#64414)
John Swansona893803cfb98
diff --git a/e2e/test/scenarios/collections/trash.cy.spec.js b/e2e/test/scenarios/collections/trash.cy.spec.jsindex a4f50ce8367..4d4e6408c47 100644--- a/e2e/test/scenarios/collections/trash.cy.spec.js+++ b/e2e/test/scenarios/collections/trash.cy.spec.js@@ -48,14 +48,12 @@ describe("scenarios > collections > trash", () => {cy.findByText("Deleted at");});- cy.log(- "trashed items in collection should not have option to move to trash",- );+ cy.log("trashed items in collection should have option to move to trash");toggleEllipsisMenuFor("Collection A");H.popover().within(() => {cy.findByText("Move to trash").should("not.exist");cy.findByText("Restore").should("exist");- cy.findByText("Delete permanently").should("not.exist");+ cy.findByText("Delete permanently").should("exist");});toggleEllipsisMenuFor("Collection A");@@ -432,15 +430,15 @@ describe("scenarios > collections > trash", () => {cy.log("can delete from trash list");toggleEllipsisMenuFor("Collection A");- // FUTURE: replace following two lines with commented out code when collections can be deleted- H.popover().findByText("Delete permanently").should("not.exist");- toggleEllipsisMenuFor("Collection A");- // popover().findByText("Delete permanently").click();- // modal().findByText("Delete Collection A permanently?").should("exist");- // modal().findByText("Delete permanently").click();- // collectionTable().within(() => {- // cy.findByText("Collection A").should("not.exist");- // });+ H.popover()+ .should("contain", "Delete permanently")+ .findByText("Delete permanently")+ .click();+ H.modal().findByText("Delete Collection A permanently?").should("exist");+ H.modal().findByText("Delete permanently").click();+ collectionTable().within(() => {+ cy.findByText("Collection A").should("not.exist");+ });toggleEllipsisMenuFor("Dashboard A");H.popover()@@ -469,14 +467,12 @@ describe("scenarios > collections > trash", () => {cy.findByText("Collection B").click();});// FUTURE: replace following two lines with commented out code when collections can be deleted- archiveBanner().findByText("Delete permanently").should("not.exist");- cy.visit("/trash");- // archiveBanner().findByText("Delete permanently").click();- // modal().findByText("Delete Collection B permanently?").should("exist");- // modal().findByText("Delete permanently").click();- // collectionTable().within(() => {- // cy.findByText("Collection B").should("not.exist");- // });+ archiveBanner().findByText("Delete permanently").click();+ H.modal().findByText("Delete Collection B permanently?").should("exist");+ H.modal().findByText("Delete permanently").click();+ collectionTable().within(() => {+ cy.findByText("Collection B").should("not.exist");+ });collectionTable().within(() => {cy.findByText("Dashboard B").click();diff --git a/src/metabase/collections/models/collection.clj b/src/metabase/collections/models/collection.cljindex de88ff11b00..d57c8d997e7 100644--- a/src/metabase/collections/models/collection.clj+++ b/src/metabase/collections/models/collection.clj@@ -1779,8 +1779,9 @@(when (seq items)(for [item items](assoc item :can_delete (boolean (and- (not (or (= :model/Collection (t2/model item))- (collection.root/is-root-collection? item)))+ (not (collection.root/is-root-collection? item))+ (or (not (= :model/Collection (t2/model item)))+ api/*is-superuser?*)(:archived item)(mi/can-write? item)))))))diff --git a/test/metabase/collections/models/collection_test.clj b/test/metabase/collections/models/collection_test.cljindex b635597025a..52cb219dcb1 100644--- a/test/metabase/collections/models/collection_test.clj+++ b/test/metabase/collections/models/collection_test.clj@@ -1801,3 +1801,27 @@query (t2/select :model/Collection{:where [:and [:= :id (:id sample-collection)] hsql-clause]})](is (empty? query))))))))++(deftest can-delete-works+ (mt/with-temp [:model/Collection collection {:archived true}+ :model/Dashboard dash {:archived true}+ :model/Card card {:archived true}+ :model/Collection non-archived-collection {:archived false}+ :model/Dashboard non-archived-dash {:archived false}+ :model/Card non-archived-card {:archived false}]+ (testing "Admins can permanently delete collections"+ (mt/with-test-user :crowberto+ (is (= [true true true]+ (map :can_delete (collection/can-delete [collection dash card]))))))+ (testing "Regular users can permanently delete non-collections"+ (mt/with-test-user :rasta+ (is (= [false true true]+ (map :can_delete (collection/can-delete [collection dash card]))))))+ (testing "The root collection cannot be deleted"+ (mt/with-test-user :crowberto+ (is (= false (:can_delete (first (collection/can-delete [collection/root-collection])))))))+ (testing "Non-archived things cannot be deleted"+ (mt/with-test-user :crowberto+ (is (= [false false false] (map :can_delete (collection/can-delete [non-archived-collection+ non-archived-dash+ non-archived-card]))))))))