Delete User

This commit is contained in:
Charles 2025-08-28 16:08:06 +02:00
parent 446f585cc9
commit 245f044a40
2 changed files with 30 additions and 3 deletions

View File

@ -279,4 +279,23 @@ class UserController extends AbstractController
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
}
#[Route('/delete/{id}', name: 'delete', methods: ['GET'])]
public function delete(int $id, Request $request): Response
{
$this->denyAccessUnlessGranted("ROLE_SUPER_ADMIN");
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
$user = $this->entityManager->getRepository(User::class)->find($id);
if (!$user) {
throw $this->createNotFoundException(self::NOT_FOUND);
}
$user->setIsActive(false);
$user->setModifiedAt(new \DateTimeImmutable('now'));
$this->userOrganizationService->deactivateAllUserOrganizationLinks($user, $actingUser);
$user->setIsDeleted(true);
$this->entityManager->persist($user);
$this->entityManager->flush();
$this->actionService->createAction("Delete user", $actingUser, null, $user->getUserIdentifier());
return $this->redirectToRoute('user_index');
}
}

View File

@ -3,10 +3,18 @@
{% block body %}
<div class="col-md-10 m-auto p-5">
{% if is_granted("ROLE_ADMIN") %}
<div class="col d-flex justify-content-between align-items-center ">
<h1 class="mb-4">Gestion Utilisateur</h1>
<a href="{{ path('user_deactivate', {'id': user.id}) }}" class="btn btn-danger">Désactiver</a>
<div>
{% if is_granted("ROLE_SUPER_ADMIN") %}
<a href="{{ path('user_delete', {'id': user.id}) }}" class="btn btn-danger">Supprimer</a>
{% endif %}
<a href="{{ path('user_deactivate', {'id': user.id}) }}" class="btn btn-danger">Désactiver</a>
</div>
</div>
{% endif %}
{% include 'user/userInformation.html.twig' %}
@ -15,12 +23,12 @@
<h1 class="mt-5 mb-4">Vos applications</h1>
{% elseif orgs|length == 1 %}
{% for org in orgs %}
<h1 class="mt-5 mb-4">{{ org.name }}</h1>
<h1 class="mt-5 mb-4">{{ org.name }}</h1>
{% endfor %}
{% else %}
<h1 class="mt-5 mb-4">Aucune application</h1>
{% endif %}
<div class="d-flex ">
<div class="d-flex ">
{% for uoa in uoas %}
{% include 'user/application/information.html.twig' %}
{% endfor %}