diff --git a/src/Controller/CapsuleEditorController.php b/src/Controller/CapsuleEditorController.php index a0d047b3ba9a96eef673f608ef438c878339adef..ea8d32aaa65079d827bf91794f4e36e0ac9d2764 100644 --- a/src/Controller/CapsuleEditorController.php +++ b/src/Controller/CapsuleEditorController.php @@ -6,6 +6,7 @@ use App\Entity\Capsule; use App\Entity\PendingEditorInvitation; use App\Entity\User; use App\Form\CapsuleEditorsFormType; +use App\Form\RemoveEditorFormType; use App\Repository\CapsuleRepository; use App\Repository\PendingEditorInvitationRepository; use App\Repository\UserRepository; @@ -225,8 +226,12 @@ class CapsuleEditorController extends AbstractController */ public function removeEditor( int $capsule_id, - int $editor_id + int $editor_id, + Request $request ): Response { + $form = $this->createForm(RemoveEditorFormType::class); + $form->handleRequest($request); + $capsule = $this->capsule_repository->findOneBy(['id' => $capsule_id]); if (! $capsule instanceof Capsule) { throw new \Exception('The retrieved capsule is not an instance of Capsule.'); @@ -259,22 +264,30 @@ class CapsuleEditorController extends AbstractController ]); } - $capsule->removeEditor($editor); - $this->entity_manager->flush(); + if ($form->isSubmitted() && $form->isValid()) { + $capsule->removeEditor($editor); + $this->entity_manager->flush(); - $this->addFlash( - 'success', - $this->translator->trans( - 'editors.remove.editor.success', - [ - 'editor_email' => $editor->getEmail(), - 'capsule_name' => $capsule->getName() - ] - ) - ); + $this->addFlash( + 'success', + $this->translator->trans( + 'editors.remove.editor.success', + [ + 'editor_email' => $editor->getEmail(), + 'capsule_name' => $capsule->getName() + ] + ) + ); - return $this->redirectToRoute('edit_capsule_editors', [ - 'capsule_id' => $capsule->getId() + return $this->redirectToRoute('edit_capsule_editors', [ + 'capsule_id' => $capsule->getId() + ]); + } + + return $this->render('capsule/editors/remove_editor.html.twig', [ + 'removeEditorForm' => $form->createView(), + 'editor_email' => $editor->getEmail(), + 'capsule_id' => $capsule_id ]); } @@ -283,8 +296,12 @@ class CapsuleEditorController extends AbstractController */ public function removePendingEditor( int $pending_editor_invitation_id, - int $capsule_id + int $capsule_id, + request $request ): Response { + $form = $this->createForm(RemoveEditorFormType::class); + $form->handleRequest($request); + $capsule = $this->capsule_repository->findOneBy(['id' => $capsule_id]); if (! $capsule instanceof Capsule) { throw new \Exception('The retrieved capsule is not an instance of Capsule.'); @@ -309,21 +326,29 @@ class CapsuleEditorController extends AbstractController ]); } - $this->entity_manager->remove($pending_editor_invitation); - $this->entity_manager->flush(); + if ($form->isSubmitted() && $form->isValid()) { + $this->entity_manager->remove($pending_editor_invitation); + $this->entity_manager->flush(); - $this->addFlash( - 'success', - $this->translator->trans( - 'editors.remove.pending_editor.success', - [ - 'pending_editor_email' => $pending_editor_invitation->getEmail(), - 'capsule_name' => $capsule->getName() - ] - ) - ); + $this->addFlash( + 'success', + $this->translator->trans( + 'editors.remove.pending_editor.success', + [ + 'pending_editor_email' => $pending_editor_invitation->getEmail(), + 'capsule_name' => $capsule->getName() + ] + ) + ); + + return $this->redirectToRoute('edit_capsule_editors', [ + 'capsule_id' => $capsule_id + ]); + } - return $this->redirectToRoute('edit_capsule_editors', [ + return $this->render('capsule/editors/remove_pending_editor.html.twig', [ + 'removeEditorForm' => $form->createView(), + 'editor_email' => $pending_editor_invitation->getEmail(), 'capsule_id' => $capsule_id ]); } diff --git a/src/Form/RemoveEditorFormType.php b/src/Form/RemoveEditorFormType.php new file mode 100644 index 0000000000000000000000000000000000000000..e82285fe4680115cfee1e70d9d028f15d5ad2e1b --- /dev/null +++ b/src/Form/RemoveEditorFormType.php @@ -0,0 +1,34 @@ +<?php + +namespace App\Form; + +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ButtonType; +use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; + +class RemoveEditorFormType extends AbstractType +{ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $builder + ->add( + 'cancel', + ButtonType::class, + ['label' => 'general.cancel_button', + 'attr' => ['class' => 'button-cancel'] + ] + ) + ->add( + 'remove', + SubmitType::class, + ['label' => 'editors.remove.button'] + ); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([]); + } +} diff --git a/templates/capsule/editors/remove_editor.html.twig b/templates/capsule/editors/remove_editor.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..ddfd703f8eebfc2dde4012ad8d5bffafd9b9b4e5 --- /dev/null +++ b/templates/capsule/editors/remove_editor.html.twig @@ -0,0 +1,34 @@ +{% extends 'layout.html.twig' %} + +{% block title %} + {{ 'editors.remove.editor.title'|trans }} +{% endblock %} + +{% block body %} + + <div> + <div class="row w-100 gx-0"> + <div class="row-title-box"> + <h3 class="row-title"> + {{ 'editors.remove.editor.title'|trans }} + </h3> + </div> + </div> + + <div class="d-flex flex-column justify-content-center align-items-center"> + + <p class="text-secondary fs-5 mb-5"> + {{ 'editors.remove.editor.text'|trans({'%editor_email%': editor_email}) }} + </p> + + {{ form_start(removeEditorForm, {'attr': {novalidate: 'novalidate', 'class': 'd-flex flex-row justify-content-center'}}) }} + {{ form_row(removeEditorForm.remove, {'row_attr': {'class' : 'm-auto mb-2 me-3'}}) }} + <a href="/capsule/{{ capsule_id }}/editors"> + {{ form_row(removeEditorForm.cancel, {'row_attr': {'class' : 'm-auto mb-2 bg-secondary rounded ms-3'}}) }} + </a> + {{ form_end(removeEditorForm) }} + </div> + + </div> + +{% endblock %} \ No newline at end of file diff --git a/templates/capsule/editors/remove_pending_editor.html.twig b/templates/capsule/editors/remove_pending_editor.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..bd96a9193560995c33445dad36946b2de7114512 --- /dev/null +++ b/templates/capsule/editors/remove_pending_editor.html.twig @@ -0,0 +1,34 @@ +{% extends 'layout.html.twig' %} + +{% block title %} + {{ 'editors.remove.pending_editor.title'|trans }} +{% endblock %} + +{% block body %} + + <div> + <div class="row w-100 gx-0"> + <div class="row-title-box"> + <h3 class="row-title"> + {{ 'editors.remove.pending_editor.title'|trans }} + </h3> + </div> + </div> + + <div class="d-flex flex-column justify-content-center align-items-center"> + + <p class="text-secondary fs-5 mb-5"> + {{ 'editors.remove.pending_editor.text'|trans({'%editor_email%': editor_email}) }} + </p> + + {{ form_start(removeEditorForm, {'attr': {novalidate: 'novalidate', 'class': 'd-flex flex-row justify-content-center'}}) }} + {{ form_row(removeEditorForm.remove, {'row_attr': {'class' : 'm-auto mb-2 me-3'}}) }} + <a href="/capsule/{{ capsule_id }}/editors"> + {{ form_row(removeEditorForm.cancel, {'row_attr': {'class' : 'm-auto mb-2 bg-secondary rounded ms-3'}}) }} + </a> + {{ form_end(removeEditorForm) }} + </div> + + </div> + +{% endblock %} \ No newline at end of file diff --git a/translations/messages.en.yaml b/translations/messages.en.yaml index 1205a7bd25504c9a18efec26349f7bb3fb33cc17..5c341f9ebaeda8d1dd704b2a6575a0d88952e46d 100644 --- a/translations/messages.en.yaml +++ b/translations/messages.en.yaml @@ -137,11 +137,16 @@ editors: You can now access and edit it. You will find the capsule in your capsule list. link: Go to capsule edition page remove: + button: Remove pending_editor: + title: Remove pending editor + text: Do you really want to delete pending editor %editor_email%? link: Remove pending editor error: The email address has already been removed from pending editors of the capsule capsule_name success: The email address pending_editor_email has been successfully removed from pending editors of the capsule capsule_name editor: + title: Remove editor + text: Do you really want to delete editor %editor_email%? link: Remove editor success: User editor_email is no longer and editor of the capsule capsule_name error: You can't remove yourself as editor of your own capsule. diff --git a/translations/messages.fr.yaml b/translations/messages.fr.yaml index 43706c863bff25dd6acf715b1437b28c36fb9ab9..6342e3e9b901aa7b811755b7f530523a3684cf93 100644 --- a/translations/messages.fr.yaml +++ b/translations/messages.fr.yaml @@ -135,11 +135,16 @@ editors: Vous pouvez maintenant y accéder et l'éditer. Vous la retrouverez dans la liste de vos capsules. link: Se rendre sur la page d'édition de la capsule remove: + button: Supprimer pending_editor: + title: Supprimer l'éditeur en attente + text: Souhaitez-vous vraiment supprimer l'éditeur en attente %editor_email% ? link: Supprimer l'éditeur en attente error: L'adresse email pending_editor_email a déjà été supprimée de la liste des éditeurs en attente de la capsule capsule_name success: L'adresse email pending_editor_email a bien été supprimée de la liste des éditeurs en attente de la capsule capsule_name editor: + title: Supprimer l'éditeur + text: Souhaitez-vous vraiment supprimer l'éditeur %editor_email% ? link: Supprimer l'éditeur success: L'utilisateur editor_email ne peut plus éditer la capsule capsule_name error: You can't remove yourself as editor of your own capsule.