diff --git a/CHANGELOG.md b/CHANGELOG.md
index bf6452b..945c886 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,7 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
## x.y.z
### Added
-- Add an FE editor (#864, #872, #874)
+- Add an FE editor (#864, #872, #874, #876)
- Add automerging of green Dependabot PRs (#756)
### Changed
diff --git a/Classes/Controller/FrontEndEditorController.php b/Classes/Controller/FrontEndEditorController.php
index 1ef5d4c..4ae6387 100644
--- a/Classes/Controller/FrontEndEditorController.php
+++ b/Classes/Controller/FrontEndEditorController.php
@@ -9,6 +9,7 @@ use TTN\Tea\Domain\Model\Product\Tea;
use TTN\Tea\Domain\Repository\Product\TeaRepository;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Annotation as Extbase;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
/**
@@ -89,4 +90,16 @@ class FrontEndEditorController extends ActionController
return $this->redirect('index');
}
+
+ /**
+ * @Extbase\IgnoreValidation("tea")
+ */
+ public function deleteAction(Tea $tea): ResponseInterface
+ {
+ $this->checkIfUserIsOwner($tea);
+
+ $this->teaRepository->remove($tea);
+
+ return $this->redirect('index');
+ }
}
diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf
index 4eb8ad4..7357618 100644
--- a/Resources/Private/Language/de.locallang.xlf
+++ b/Resources/Private/Language/de.locallang.xlf
@@ -71,6 +71,10 @@
Neuen Tee anlegen
+
+
+ Löschen
+
Neuen Tee anlegen
diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf
index 93a33dc..7f219ef 100644
--- a/Resources/Private/Language/locallang.xlf
+++ b/Resources/Private/Language/locallang.xlf
@@ -54,6 +54,9 @@
+
+
+
diff --git a/Resources/Private/Templates/FrontEndEditor/Index.html b/Resources/Private/Templates/FrontEndEditor/Index.html
index f492ab4..fd89ad4 100644
--- a/Resources/Private/Templates/FrontEndEditor/Index.html
+++ b/Resources/Private/Templates/FrontEndEditor/Index.html
@@ -23,7 +23,7 @@
|
-
+ |
|
@@ -40,6 +40,12 @@
+
+
+
+
+ |
diff --git a/Tests/Unit/Controller/FrontEndEditorControllerTest.php b/Tests/Unit/Controller/FrontEndEditorControllerTest.php
index 9b4a1f4..bd54303 100644
--- a/Tests/Unit/Controller/FrontEndEditorControllerTest.php
+++ b/Tests/Unit/Controller/FrontEndEditorControllerTest.php
@@ -373,4 +373,67 @@ final class FrontEndEditorControllerTest extends UnitTestCase
$this->subject->updateAction($tea);
}
+
+ /**
+ * @test
+ */
+ public function deleteActionWithOwnTeaRemovesProvidedTea(): void
+ {
+ $userUid = 5;
+ $this->setUidOfLoggedInUser($userUid);
+ $tea = new Tea();
+ $tea->setOwnerUid($userUid);
+ $this->stubRedirect('index');
+
+ $this->teaRepositoryMock->expects(self::once())->method('remove')->with($tea);
+
+ $this->subject->deleteAction($tea);
+ }
+
+ /**
+ * @test
+ */
+ public function deleteActionWithOwnTeaRedirectsToIndexAction(): void
+ {
+ $userUid = 5;
+ $this->setUidOfLoggedInUser($userUid);
+ $tea = new Tea();
+ $tea->setOwnerUid($userUid);
+
+ $this->mockRedirect('index');
+
+ $this->subject->deleteAction($tea);
+ }
+
+ /**
+ * @test
+ */
+ public function deleteActionWithTeaFromOtherUserThrowsException(): void
+ {
+ $this->setUidOfLoggedInUser(1);
+ $tea = new Tea();
+ $tea->setOwnerUid(2);
+
+ $this->expectException(\RuntimeException::class);
+ $this->expectExceptionMessage('You do not have the permissions to edit this tea.');
+ $this->expectExceptionCode(1687363749);
+
+ $this->subject->deleteAction($tea);
+ }
+
+ /**
+ * @test
+ */
+ public function deleteActionWithTeaWithoutOwnerThrowsException(): void
+ {
+ $this->setUidOfLoggedInUser(1);
+ $tea = new Tea();
+ $tea->setOwnerUid(0);
+
+ $this->expectException(\RuntimeException::class);
+ $this->expectExceptionMessage('You do not have the permissions to edit this tea.');
+ $this->expectExceptionCode(1687363749);
+
+ $this->subject->deleteAction($tea);
+ }
}
diff --git a/ext_localconf.php b/ext_localconf.php
index 49faa72..76fb8c7 100644
--- a/ext_localconf.php
+++ b/ext_localconf.php
@@ -42,12 +42,12 @@ ExtensionUtility::configurePlugin(
'TeaFrontEndEditor',
// all actions
[
- FrontEndEditorController::class => 'index, edit, update, create, new',
+ FrontEndEditorController::class => 'index, edit, update, create, new, delete',
],
// non-cacheable actions
[
// All actions need to be non-cacheable because they either contain dynamic data,
// or because they are specific to the logged-in FE user (while FE content is cached by FE groups).
- FrontEndEditorController::class => 'index, edit, update, create, new',
+ FrontEndEditorController::class => 'index, edit, update, create, new, delete',
]
);