From 3bae31d5497a0689516f31e33e27046279e88ef8 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Fri, 11 Oct 2024 16:52:52 +0100 Subject: [PATCH] [5.x] Fix error when deleting collections (#10908) Co-authored-by: duncanmcclean Co-authored-by: Jason Varga --- resources/js/components/collections/Listing.vue | 12 ------------ resources/lang/ar.json | 1 - resources/lang/az.json | 1 - resources/lang/cs.json | 1 - resources/lang/da.json | 1 - resources/lang/de.json | 1 - resources/lang/de_CH.json | 1 - resources/lang/es.json | 1 - resources/lang/fa.json | 1 - resources/lang/fr.json | 1 - resources/lang/hu.json | 1 - resources/lang/id.json | 1 - resources/lang/it.json | 1 - resources/lang/ja.json | 1 - resources/lang/ms.json | 1 - resources/lang/nb.json | 1 - resources/lang/nl.json | 1 - resources/lang/pl.json | 1 - resources/lang/pt.json | 1 - resources/lang/pt_BR.json | 1 - resources/lang/ru.json | 1 - resources/lang/sl.json | 1 - resources/lang/sv.json | 1 - resources/lang/tr.json | 1 - resources/lang/uk.json | 1 - resources/lang/zh_CN.json | 1 - resources/lang/zh_TW.json | 1 - resources/views/collections/show.blade.php | 11 ----------- src/Actions/Delete.php | 11 +++++++++++ .../CP/Collections/CollectionsController.php | 2 +- .../Collections/ViewCollectionListingTest.php | 4 ++-- 31 files changed, 14 insertions(+), 52 deletions(-) diff --git a/resources/js/components/collections/Listing.vue b/resources/js/components/collections/Listing.vue index e4b1a7b4a0..e9dc3946c4 100644 --- a/resources/js/components/collections/Listing.vue +++ b/resources/js/components/collections/Listing.vue @@ -18,18 +18,6 @@ :actions="collection.actions" @completed="actionCompleted" > - - - - diff --git a/resources/lang/ar.json b/resources/lang/ar.json index 37fb2a0316..01d5151115 100644 --- a/resources/lang/ar.json +++ b/resources/lang/ar.json @@ -302,7 +302,6 @@ "Delete": "حذف", "Delete :resource": "حذف :resource", "Delete child entry|Delete :count child entries": "حذف الإدخال الفرعي|حذف :count الإدخالات الفرعية", - "Delete Collection": "حذف المجموعة", "Delete Column": "حذف العمود", "Delete Container": "حذف الحاوية", "Delete Entry": "حذف الإدخال", diff --git a/resources/lang/az.json b/resources/lang/az.json index c33f32cf8d..bb0b3e1e70 100644 --- a/resources/lang/az.json +++ b/resources/lang/az.json @@ -318,7 +318,6 @@ "Delete": "Sil", "Delete :resource": "Bunu sil: :resource", "Delete child entry|Delete :count child entries": "Uşaq girişi sil|:count uşaq girişi sil", - "Delete Collection": "Kolleksiyanı Sil", "Delete Column": "Sütunu Sil", "Delete Container": "Konteyneri Sil", "Delete Entry": "Girişi Sil", diff --git a/resources/lang/cs.json b/resources/lang/cs.json index f1c23ee5e9..d73514ca14 100644 --- a/resources/lang/cs.json +++ b/resources/lang/cs.json @@ -227,7 +227,6 @@ "Delete": "Smazat", "Delete :resource": "Smazat :resource", "Delete child entry|Delete :count child entries": "Smazat podzáznam|Smazat :count podzáznamů", - "Delete Collection": "Smazat kolekci", "Delete Column": "Smazat sloupec", "Delete Container": "Smazat kontejner", "Delete Entry": "Smazat záznam", diff --git a/resources/lang/da.json b/resources/lang/da.json index cdd4711a9e..4ac8d38df2 100644 --- a/resources/lang/da.json +++ b/resources/lang/da.json @@ -211,7 +211,6 @@ "Delete": "Slet", "Delete :resource": "Slet :resource", "Delete child entry|Delete :count child entries": "Slet underordnet post | Slet :count underordnede poster", - "Delete Collection": "Slet samling", "Delete Column": "Slet kolonne", "Delete Container": "Slet beholder", "Delete Entry": "Slet post", diff --git a/resources/lang/de.json b/resources/lang/de.json index 4113c5ef78..30c229a406 100644 --- a/resources/lang/de.json +++ b/resources/lang/de.json @@ -313,7 +313,6 @@ "Delete": "Löschen", "Delete :resource": ":resource löschen", "Delete child entry|Delete :count child entries": "Untergeordneten Eintrag löschen|:count untergeordnete Einträge löschen", - "Delete Collection": "Sammlung löschen", "Delete Column": "Spalte löschen", "Delete Container": "Container löschen", "Delete Entry": "Eintrag löschen", diff --git a/resources/lang/de_CH.json b/resources/lang/de_CH.json index 43ea1fa270..e449b90ac7 100644 --- a/resources/lang/de_CH.json +++ b/resources/lang/de_CH.json @@ -313,7 +313,6 @@ "Delete": "Löschen", "Delete :resource": ":resource löschen", "Delete child entry|Delete :count child entries": "Untergeordneten Eintrag löschen|:count untergeordnete Einträge löschen", - "Delete Collection": "Sammlung löschen", "Delete Column": "Spalte löschen", "Delete Container": "Container löschen", "Delete Entry": "Eintrag löschen", diff --git a/resources/lang/es.json b/resources/lang/es.json index 17bdd4880b..7504854f4a 100644 --- a/resources/lang/es.json +++ b/resources/lang/es.json @@ -211,7 +211,6 @@ "Delete": "Eliminar", "Delete :resource": "Eliminar :resource", "Delete child entry|Delete :count child entries": "Eliminar entrada interna|Eliminar :count entradas internas", - "Delete Collection": "Eliminar colección", "Delete Column": "Eliminar columna", "Delete Container": "Eliminar contenedor", "Delete Entry": "Eliminar entrada", diff --git a/resources/lang/fa.json b/resources/lang/fa.json index 40275f32fc..9f561d5e19 100644 --- a/resources/lang/fa.json +++ b/resources/lang/fa.json @@ -329,7 +329,6 @@ "Delete": "حذف", "Delete :resource": "حذف :resource", "Delete child entry|Delete :count child entries": "حذف مطلب فرزند|حذف :count مطلب فرزند", - "Delete Collection": "حذف کالکشن", "Delete Column": "حذف ستون", "Delete Container": "حذف کانتینر", "Delete Entry": "حذف مطلب", diff --git a/resources/lang/fr.json b/resources/lang/fr.json index 25cc31dccd..3a69ed0f27 100644 --- a/resources/lang/fr.json +++ b/resources/lang/fr.json @@ -313,7 +313,6 @@ "Delete": "Supprimer", "Delete :resource": "Supprimer :resource", "Delete child entry|Delete :count child entries": "Supprimer l'entrée enfant|Supprimer :count entrées enfants", - "Delete Collection": "Supprimer la collection", "Delete Column": "Supprimer la colonne", "Delete Container": "Supprimer le conteneur", "Delete Entry": "Supprimer l'entrée", diff --git a/resources/lang/hu.json b/resources/lang/hu.json index b60cabfbab..b14f33a651 100644 --- a/resources/lang/hu.json +++ b/resources/lang/hu.json @@ -217,7 +217,6 @@ "Delete": "Töröl", "Delete :resource": ":resource törlése", "Delete child entry|Delete :count child entries": "Gyermek bejegyzés törlése|:count gyermek bejegyzés törlése", - "Delete Collection": "Gyűjtemény törlése", "Delete Column": "Oszlop törlése", "Delete Container": "Tároló törlése", "Delete Entry": "Bejegyzés törlése", diff --git a/resources/lang/id.json b/resources/lang/id.json index 90949b5d5b..dc1fb002e1 100644 --- a/resources/lang/id.json +++ b/resources/lang/id.json @@ -211,7 +211,6 @@ "Delete": "Hapus", "Delete :resource": "Hapus :resource", "Delete child entry|Delete :count child entries": "Hapus entri anak|Hapus :count entru anak", - "Delete Collection": "Hapus Koleksi", "Delete Column": "Hapus Kolom", "Delete Container": "Hapus Penampung", "Delete Entry": "Hapus Entri", diff --git a/resources/lang/it.json b/resources/lang/it.json index 76c22f3a4e..efbca93243 100644 --- a/resources/lang/it.json +++ b/resources/lang/it.json @@ -211,7 +211,6 @@ "Delete": "Elimina", "Delete :resource": "Elimina :resource", "Delete child entry|Delete :count child entries": "Elimina voce figlio|Elimina :count voci figlio", - "Delete Collection": "Elimina raccolta", "Delete Column": "Elimina colonna", "Delete Container": "Elimina contenitore", "Delete Entry": "Elimina voce", diff --git a/resources/lang/ja.json b/resources/lang/ja.json index d04901a8a1..cb2beb1f94 100644 --- a/resources/lang/ja.json +++ b/resources/lang/ja.json @@ -295,7 +295,6 @@ "Delete": "消去", "Delete :resource": "削除:resource", "Delete child entry|Delete :count child entries": "子エントリの削除| :countの子エントリを削除", - "Delete Collection": "コレクションの削除", "Delete Column": "列の削除", "Delete Container": "コンテナの削除", "Delete Entry": "記入を消す", diff --git a/resources/lang/ms.json b/resources/lang/ms.json index b5cd29eee5..d6b9f757f6 100644 --- a/resources/lang/ms.json +++ b/resources/lang/ms.json @@ -211,7 +211,6 @@ "Delete": "Hapus", "Delete :resource": "Hapus :resource", "Delete child entry|Delete :count child entries": "Hapus entri anak|Hapus :count entri anak", - "Delete Collection": "Hapus Koleksi", "Delete Column": "Hapus Lajur", "Delete Container": "Hapus Penampung", "Delete Entry": "Hapus Entri", diff --git a/resources/lang/nb.json b/resources/lang/nb.json index 612b44abdf..6baced9b84 100644 --- a/resources/lang/nb.json +++ b/resources/lang/nb.json @@ -302,7 +302,6 @@ "Delete": "Slett", "Delete :resource": "Slett :resource", "Delete child entry|Delete :count child entries": "Slett underordnet oppføring|Slett :count underordnede oppføringer", - "Delete Collection": "Slett samling", "Delete Column": "Slett kolonne", "Delete Container": "Slett beholder", "Delete Entry": "Slett oppføring", diff --git a/resources/lang/nl.json b/resources/lang/nl.json index c2e65ce364..8303f9fd63 100644 --- a/resources/lang/nl.json +++ b/resources/lang/nl.json @@ -302,7 +302,6 @@ "Delete": "Verwijderen", "Delete :resource": "Verwijder :resource", "Delete child entry|Delete :count child entries": "Verwijder child entry|Verwijder :count child entries", - "Delete Collection": "Verwijderd collectie", "Delete Column": "Verwijderd kolom", "Delete Container": "Verwijder container", "Delete Entry": "Verwijder entry", diff --git a/resources/lang/pl.json b/resources/lang/pl.json index 941bdd0ec6..fd4b11b4f9 100644 --- a/resources/lang/pl.json +++ b/resources/lang/pl.json @@ -229,7 +229,6 @@ "Delete": "Usuń", "Delete :resource": "Usuń :resource", "Delete child entry|Delete :count child entries": "Usuń podrzędnyrekord|Usuń :count rekordy/ów podrzędne", - "Delete Collection": "Usuń kolekcję", "Delete Column": "Usuń kolumnę", "Delete Container": "Usuń kontener", "Delete Entry": "Usuń rekord", diff --git a/resources/lang/pt.json b/resources/lang/pt.json index fc27d34556..d1c06c4902 100644 --- a/resources/lang/pt.json +++ b/resources/lang/pt.json @@ -211,7 +211,6 @@ "Delete": "Eliminar", "Delete :resource": "Eliminar :resource", "Delete child entry|Delete :count child entries": "Eliminar entrada-filho:Eliminar :count entrada(s)-filho(s)", - "Delete Collection": "Eliminar Coleção", "Delete Column": "Eliminar Coluna", "Delete Container": "Eliminar Biblioteca", "Delete Entry": "Eliminar Entrada", diff --git a/resources/lang/pt_BR.json b/resources/lang/pt_BR.json index a8829c24cd..56192a8d7c 100644 --- a/resources/lang/pt_BR.json +++ b/resources/lang/pt_BR.json @@ -237,7 +237,6 @@ "Delete": "Excluir", "Delete :resource": "Excluir :resource", "Delete child entry|Delete :count child entries": "Excluir entrada-filha|Excluir :count entradas-filhas", - "Delete Collection": "Excluir Coleção", "Delete Column": "Exlucir Coluna", "Delete Container": "Excluir Contêiner", "Delete Entry": "Excluir Entrada", diff --git a/resources/lang/ru.json b/resources/lang/ru.json index 6c8fdbc151..fcb3a6a09f 100644 --- a/resources/lang/ru.json +++ b/resources/lang/ru.json @@ -296,7 +296,6 @@ "Delete": "Удалить", "Delete :resource": "Удалить :resource", "Delete child entry|Delete :count child entries": "Удалить дочернюю запись|Удалить :count дочерние записи|Удалить :count дочерних записей", - "Delete Collection": "Удалить коллекцию", "Delete Column": "Удалить столбец", "Delete Container": "Удалить контейнер", "Delete Entry": "Удалить запись", diff --git a/resources/lang/sl.json b/resources/lang/sl.json index 6b82885b25..1a3c44e682 100644 --- a/resources/lang/sl.json +++ b/resources/lang/sl.json @@ -211,7 +211,6 @@ "Delete": "Izbriši", "Delete :resource": "Izbriši :resource", "Delete child entry|Delete :count child entries": "Izbriši podrejeni vnos | Izbriši :count podrejene vnose", - "Delete Collection": "Izbriši zbirko", "Delete Column": "Izbriši stolpec", "Delete Container": "Izbriši vsebnik", "Delete Entry": "Izbriši vnos", diff --git a/resources/lang/sv.json b/resources/lang/sv.json index 091f13c1d8..ba9474b068 100644 --- a/resources/lang/sv.json +++ b/resources/lang/sv.json @@ -229,7 +229,6 @@ "Delete": "Radera", "Delete :resource": "Radera :resource", "Delete child entry|Delete :count child entries": "Radera underordnat inlägg|Radera :count underordnade inlägg", - "Delete Collection": "Radera samling", "Delete Column": "Radera kolumn", "Delete Container": "Radera behållare", "Delete Entry": "Radera inlägg", diff --git a/resources/lang/tr.json b/resources/lang/tr.json index 5a0bb71881..83107a8b69 100644 --- a/resources/lang/tr.json +++ b/resources/lang/tr.json @@ -334,7 +334,6 @@ "Delete": "Sil", "Delete :resource": ":resource sil", "Delete child entry|Delete :count child entries": "Alt girdiyi sil|:count alt girdiyi sil", - "Delete Collection": "Koleksiyonu Sil", "Delete Column": "Sütunu Sil", "Delete Container": "Konteyneri Sil", "Delete Entry": "Girişi Sil", diff --git a/resources/lang/uk.json b/resources/lang/uk.json index c44acd9121..c9304347d1 100644 --- a/resources/lang/uk.json +++ b/resources/lang/uk.json @@ -295,7 +295,6 @@ "Delete": "Видалити", "Delete :resource": "Видалити :resource", "Delete child entry|Delete :count child entries": "Видалити дочірній запис|Видалити :count дочірніх записів", - "Delete Collection": "Видалити колекцію", "Delete Column": "Видалити стовпець", "Delete Container": "Видалити контейнер", "Delete Entry": "Видалити запис", diff --git a/resources/lang/zh_CN.json b/resources/lang/zh_CN.json index 0ee862b9a3..799f64b77f 100644 --- a/resources/lang/zh_CN.json +++ b/resources/lang/zh_CN.json @@ -236,7 +236,6 @@ "Delete": "删除", "Delete :resource": "删除 :resource", "Delete child entry|Delete :count child entries": "删除子条目|删除 :count 子条目", - "Delete Collection": "删除条目集合", "Delete Column": "删除列", "Delete Container": "删除容器", "Delete Entry": "删除条目", diff --git a/resources/lang/zh_TW.json b/resources/lang/zh_TW.json index af17f6caa9..c8d9be1409 100644 --- a/resources/lang/zh_TW.json +++ b/resources/lang/zh_TW.json @@ -236,7 +236,6 @@ "Delete": "刪除", "Delete :resource": "刪除 :resource", "Delete child entry|Delete :count child entries": "刪除子條目|刪除 :count 個子條目", - "Delete Collection": "刪除條目集", "Delete Column": "刪除欄位", "Delete Container": "刪除容器", "Delete Entry": "刪除條目", diff --git a/resources/views/collections/show.blade.php b/resources/views/collections/show.blade.php index 81d122a540..07a0916e25 100644 --- a/resources/views/collections/show.blade.php +++ b/resources/views/collections/show.blade.php @@ -53,17 +53,6 @@ :actions="{{ $actions }}" @completed="actionCompleted" > - @can('delete', $collection) - - - - @endcan - @endif diff --git a/src/Actions/Delete.php b/src/Actions/Delete.php index 4c6da3259f..446d8a2174 100644 --- a/src/Actions/Delete.php +++ b/src/Actions/Delete.php @@ -19,6 +19,7 @@ public function visibleTo($item) case $item instanceof Contracts\Entries\Entry && $item->collection()->sites()->count() === 1: return ! $item->page()?->isRoot(); break; + case $item instanceof Contracts\Entries\Collection: case $item instanceof Contracts\Taxonomies\Term: case $item instanceof Contracts\Assets\Asset: case $item instanceof Contracts\Assets\AssetFolder: @@ -52,6 +53,14 @@ public function confirmationText() return 'Are you sure you want to delete this?|Are you sure you want to delete these :count items?'; } + public function warningText() + { + if ($this->items->first() instanceof Contracts\Entries\Collection) { + /** @translation */ + return 'This will delete the collection and all of its entries.|This will delete the collections and all of their entries.'; + } + } + public function bypassesDirtyWarning(): bool { return true; @@ -85,6 +94,8 @@ public function redirect($items, $values) $item = $items->first(); switch (true) { + case $item instanceof Contracts\Entries\Collection: + return cp_route('collections.index'); case $item instanceof Contracts\Entries\Entry: return cp_route('collections.show', $item->collection()->handle()); case $item instanceof Contracts\Taxonomies\Term: diff --git a/src/Http/Controllers/CP/Collections/CollectionsController.php b/src/Http/Controllers/CP/Collections/CollectionsController.php index a435f4b2db..e482e809ba 100644 --- a/src/Http/Controllers/CP/Collections/CollectionsController.php +++ b/src/Http/Controllers/CP/Collections/CollectionsController.php @@ -121,7 +121,7 @@ public function show(Request $request, $collection) ->all(), 'canCreate' => User::current()->can('create', [EntryContract::class, $collection]) && $collection->hasVisibleEntryBlueprint(), 'canChangeLocalizationDeleteBehavior' => count($authorizedSites) > 1 && (count($authorizedSites) == $collection->sites()->count()), - 'actions' => Action::for($collection), + 'actions' => Action::for($collection, ['view' => 'form']), ]; if ($collection->queryEntries()->count() === 0) { diff --git a/tests/Feature/Collections/ViewCollectionListingTest.php b/tests/Feature/Collections/ViewCollectionListingTest.php index d1afb2bc82..7be7e695f6 100644 --- a/tests/Feature/Collections/ViewCollectionListingTest.php +++ b/tests/Feature/Collections/ViewCollectionListingTest.php @@ -44,7 +44,7 @@ public function it_shows_a_list_of_collections() 'editable' => true, 'blueprint_editable' => true, 'available_in_selected_site' => true, - 'actions' => collect(), + 'actions' => Facades\Action::for($collectionA, ['view' => 'list']), 'actions_url' => 'http://localhost/cp/collections/foo/actions', ], [ @@ -61,7 +61,7 @@ public function it_shows_a_list_of_collections() 'editable' => true, 'blueprint_editable' => true, 'available_in_selected_site' => true, - 'actions' => collect(), + 'actions' => Facades\Action::for($collectionB, ['view' => 'list']), 'actions_url' => 'http://localhost/cp/collections/bar/actions', ], ]))