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

Remove Group

parent 7fb79362
No related branches found
No related tags found
2 merge requests!55demo version for Clarisse workshop,!51tuleap-130-add-a-capsule-into-custom-groups
......@@ -6,6 +6,7 @@ use App\Entity\Capsule;
use App\Entity\Group;
use App\Entity\User;
use App\Form\CreateCapsuleGroupsFormType;
use App\Form\RemoveGroupFormType;
use App\Form\SelectCapsuleGroupsFormType;
use App\Repository\CapsuleRepository;
use App\Repository\GroupRepository;
......@@ -137,6 +138,60 @@ class CapsuleGroupController extends AbstractController
]);
}
/**
* @Route("/capsule/{capsule_id}/groups/{group_id}/remove", name="remove_group")
*/
public function remove(
int $capsule_id,
int $group_id,
Request $request
): Response {
$capsule = $this->capsule_repository->findOneBy(['id' => $capsule_id]);
if (! $capsule instanceof Capsule) {
throw new \Exception('Capsule not found');
}
$group = $this->group_repository->findOneBy(['id' => $group_id]);
if (! $group instanceof Group) {
throw new \Exception('Group not found');
}
$current_user = $this->getUser();
if (! $current_user instanceof User) {
return $this->redirectToRoute('app_logout');
}
$form = $this->createForm(RemoveGroupFormType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$capsule->removeGroup($group);
$this->entity_manager->persist($capsule);
$this->entity_manager->flush();
$this->addFlash(
'success',
$this->translator->trans(
'groups.remove.success',
[
'group_name' => $group->getName(),
'capsule_name' => $capsule->getName()
]
)
);
return $this->redirectToRoute('edit_capsule_groups', [
'capsule_id' => $capsule->getId()
]);
}
return $this->render('capsule/groups/remove.html.twig', [
'removeGroupForm' => $form->createView(),
'group_name' => $group->getName(),
'capsule_id' => $capsule_id
]);
}
/**
* @return array<Group>
*/
......
<?php
namespace App\Form;
use App\Entity\Group;
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 RemoveGroupFormType 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' => 'groups.remove.button']
);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Group::class,
]);
}
}
......@@ -40,6 +40,10 @@
{% for group in groups %}
<li class="text-capitalize text-secondary list-unstyled p-1">
{{ group.getName() }}
-
<a href="/capsule/{{ capsule.getId() }}/groups/{{ group.getId() }}/remove" class="remove-link">
{{ 'groups.remove.link'|trans }}
</a>
</li>
{% endfor %}
</ul>
......
{% extends 'layout.html.twig' %}
{% block title %}
{{ 'groups.remove.title'|trans }}
{% endblock %}
{% block body %}
<div>
<div class="row w-100 gx-0">
<div class="row-title-box">
<h3 class="row-title">
{{ 'groups.remove.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">
{{ 'groups.remove.text'|trans({'%group_name%': group_name}) }}
</p>
{{ form_start(removeGroupForm, {'attr': {novalidate: 'novalidate', 'class': 'd-flex flex-row justify-content-center'}}) }}
{{ form_row(removeGroupForm.remove, {'row_attr': {'class' : 'm-auto mb-2 me-3'}}) }}
<a href="/capsule/{{ capsule_id }}/editors">
{{ form_row(removeGroupForm.cancel, {'row_attr': {'class' : 'm-auto mb-2 bg-secondary rounded ms-3'}}) }}
</a>
{{ form_end(removeGroupForm) }}
</div>
</div>
{% endblock %}
\ No newline at end of file
......@@ -174,3 +174,9 @@ groups:
success: Group(s) groups_names has/have been added successfully to capsule capsule_name
validate: Add theses groups to the capsule
choose: Please choose one or more groups
remove:
button: Remove group
link: Remove group
text: Do you really want to remove group %group_name% ?
title: Remove group
success: Group group_name removed successfully
\ No newline at end of file
......@@ -173,3 +173,9 @@ groups:
success: Le(s) groupe(s) groups_names a/ont bien été ajouté(s) à la capsule capsule_name
validate: Ajouter ces groupes à la capsule
choose: Veuillez choisir un ou plusieurs groupes
remove:
button: Supprimer le groupe
link: Supprimer le groupe
text: Souhaitez-vous vraiment supprimer le groupe %group_name% ?
title: Supprimer le groupe
success: Le groupe group_name a bien été supprimé
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment