Skip to content
Snippets Groups Projects
Commit 9894b250 authored by Camille Simiand's avatar Camille Simiand
Browse files

Add user confirmation before removing editors

parent 0c8f978a
Branches
No related tags found
1 merge request!48tuleap-133-change-the-video-url-of-a-capsule
......@@ -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,6 +264,7 @@ class CapsuleEditorController extends AbstractController
]);
}
if ($form->isSubmitted() && $form->isValid()) {
$capsule->removeEditor($editor);
$this->entity_manager->flush();
......@@ -278,13 +284,24 @@ class CapsuleEditorController extends AbstractController
]);
}
return $this->render('capsule/editors/remove_editor.html.twig', [
'removeEditorForm' => $form->createView(),
'editor_email' => $editor->getEmail(),
'capsule_id' => $capsule_id
]);
}
/**
* @Route("/capsule/{capsule_id}/pending_editor/{pending_editor_invitation_id}/remove", name="remove_pending_editor")
*/
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,6 +326,7 @@ class CapsuleEditorController extends AbstractController
]);
}
if ($form->isSubmitted() && $form->isValid()) {
$this->entity_manager->remove($pending_editor_invitation);
$this->entity_manager->flush();
......@@ -327,4 +345,11 @@ class CapsuleEditorController extends AbstractController
'capsule_id' => $capsule_id
]);
}
return $this->render('capsule/editors/remove_pending_editor.html.twig', [
'removeEditorForm' => $form->createView(),
'editor_email' => $pending_editor_invitation->getEmail(),
'capsule_id' => $capsule_id
]);
}
}
<?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([]);
}
}
{% 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
{% 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
......@@ -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.
......
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment