Deactivate user

This commit is contained in:
Charles 2025-07-16 15:59:56 +02:00
parent 65ff838dd9
commit c99b575814
2 changed files with 26 additions and 6 deletions

View File

@ -32,7 +32,7 @@ class UserController extends AbstractController
]); ]);
} }
#[Route('/{id}', name: 'view')] #[Route('/{id}', name: 'view', methods: ['GET'])]
public function userProfile(Request $request, EntityManagerInterface $entityManager): Response public function userProfile(Request $request, EntityManagerInterface $entityManager): Response
{ {
if ($this->isGranted('ROLE_SUDALYS_ADMIN')) { if ($this->isGranted('ROLE_SUDALYS_ADMIN')) {
@ -42,10 +42,30 @@ class UserController extends AbstractController
throw $this->createNotFoundException('User not found'); throw $this->createNotFoundException('User not found');
} }
$userOrganizations = $this->userOrganizationService->getUserOrganizations($user); $userOrganizations = $this->userOrganizationService->getUserOrganizations($user);
return $this->render('user/profile.html.twig', [
'user' => $user,
'userOrganizations' => $userOrganizations,
]);
} }
return $this->render('user/profile.html.twig', [ return new Response('Unauthorized', Response::HTTP_UNAUTHORIZED);
'user' => $user,
'userOrganizations' => $userOrganizations,
]);
} }
#[Route('/deactivate/{id}', name: 'deactivate', methods: ['GET'])]
public function userDeactivate(Request $request, EntityManagerInterface $entityManager): Response
{
if ($this->isGranted('ROLE_SUDALYS_ADMIN')) {
$userId = $request->attributes->get('id');
$user = $entityManager->getRepository(User::class)->find($userId);
if (!$user) {
throw $this->createNotFoundException('User not found');
}
$user->setIsActive(false);
$entityManager->persist($user);
$entityManager->flush();
return $this->redirectToRoute('user_dashboard');
}
return new Response('Unauthorized', Response::HTTP_UNAUTHORIZED);
}
} }

View File

@ -5,7 +5,7 @@
<div class="col-md-10 m-auto p-5"> <div class="col-md-10 m-auto p-5">
<div class="col d-flex justify-content-between align-items-center "> <div class="col d-flex justify-content-between align-items-center ">
<h1 class="mb-4">Gestion Utilisateur</h1> <h1 class="mb-4">Gestion Utilisateur</h1>
<a href="#" class="btn btn-danger">Désactiver</a> <a href="{{ path('user_deactivate', {'id': user.id}) }}" class="btn btn-danger">Désactiver</a>
</div> </div>
{% include 'elements/userInformation.html.twig' %} {% include 'elements/userInformation.html.twig' %}