remove user from organization

This commit is contained in:
Charles 2025-07-25 11:03:21 +02:00
parent 0a602fb52e
commit fed351b433
2 changed files with 25 additions and 2 deletions

View File

@ -187,6 +187,11 @@ class UserController extends AbstractController
}
/**
* GET /user/deactivate/{id} - Deactivate user
* This method is used to deactivate a user without deleting them.
* The user will still exist in the database but will not be active.
*/
#[Route('/deactivate/{id}', name: 'deactivate', methods: ['GET'])]
public function deactivate(Request $request, EntityManagerInterface $entityManager): Response
{
@ -284,4 +289,22 @@ class UserController extends AbstractController
'selectedAppIds' => $selectedApps,]);
}
/**
* GET /user/deactivateOrganization/{id} - Deactivate user
* This method is used to deactivate a user without deleting them in an organization.
* The user will still exist in the database but will not be active.
*/
#[Route('/organizationDeactivate/{id}', name: 'organization_deactivate', requirements: ['id' => '\d+'], methods: ['GET'])]
public function deactivateUserOrganization(int $id, Request $request, EntityManagerInterface $entityManager): Response
{
$this->denyAccessUnlessGranted('ROLE_ADMIN');
$userOrganization = $entityManager->getRepository(UsersOrganizations::class)->find($id) ?? throw $this->createNotFoundException(self::NOT_FOUND);
$user = $userOrganization->getUsers() ?? throw $this->createNotFoundException(self::NOT_FOUND);
$organization = $userOrganization->getOrganization() ?? throw $this->createNotFoundException(self::NOT_FOUND);
$this->userOrganizationService->deactivateAllUserRoles($user, $organization);
return $this->redirectToRoute('user_show', ['id' => $user->getId()]);
}
}

View File

@ -12,10 +12,10 @@
Modification de : <b>{{ user.name|capitalize }} {{ user.surname|capitalize }} </b> chez
<b> {{ uo.organization.name }}</b>
</h3>
<a href="{{ path('user_delete', {'id': user.id}) }}" class="btn btn-danger">Supprimer</a>
<a href="{{ path('user_organization_deactivate', {'id': uo.uoId}) }}" class="btn btn-danger">Supprimer</a>
</div>
<div class="card-body">
<form method="POST" action="{{ path('user_organization_edit', {'id': 4}) }}"
<form method="POST" action="{{ path('user_organization_edit', {'id' : uo.uoId}) }}"
data-controller="user"
data-user-roles-array-value="{{ rolesArray|json_encode }}"
data-user-selected-role-ids-value="{{ selectedRoleIds|json_encode }}"