deactivate a user from organization

This commit is contained in:
Charles 2025-08-28 14:40:08 +02:00
parent 84e5d7c87a
commit 218923dfb7
2 changed files with 44 additions and 1 deletions

View File

@ -103,6 +103,7 @@ class UserController extends AbstractController
'user' => $user,
'uoas' => $uoa ?? null,
'orgs' => $orgs ?? null,
'organizationId' => $orgId ?? null, // specific for single organization context and deactivate user from said org
]);
}
@ -211,4 +212,37 @@ class UserController extends AbstractController
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
}
#[Route('/organization/deactivate/{id}', name: 'deactivate_organization', methods: ['GET', 'POST'])]
public function deactivateUserInOrganization(int $id, Request $request): Response
{
$this->denyAccessUnlessGranted('ROLE_ADMIN');
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier());
if ($this->userService->hasAccessTo($actingUser, true)) {
$orgId = $request->get('organizationId');
$org = $this->entityManager->getRepository(Organizations::class)->find($orgId);
if (!$org) {
throw $this->createNotFoundException(self::NOT_FOUND);
}
$user = $this->entityManager->getRepository(User::class)->find($id);
if (!$user) {
throw $this->createNotFoundException(self::NOT_FOUND);
}
$uo = $this->entityManager->getRepository(UsersOrganizations::class)->findOneBy(['users' => $user,
'organization' => $org,
'isActive' => true]);
if (!$uo) {
throw $this->createNotFoundException(self::NOT_FOUND);
}
$uo->setIsActive(false);
$this->userOrganizationAppService->deactivateAllUserOrganizationsAppLinks($uo);
$this->entityManager->persist($uo);
$this->entityManager->flush();
$this->actionService->createAction("Deactivate user in organization", $actingUser, $org, $org->getName()." for user ".$user->getUserIdentifier());
return $this->redirectToRoute('user_index');
}
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
}
}

View File

@ -7,7 +7,16 @@
<h2>{{ user.surname|capitalize }} {{ user.name|capitalize }}</h2>
</div>
<a href="{{ path('user_edit', {'id': user.id}) }}" class="btn btn-primary">Modifier</a>
<div class="d-flex gap-2">
{% if organizationId is not null %}
<form method="post" action="{{ path('user_deactivate_organization', {'id': user.id}) }}"
onsubmit="return confirm('Vous allez retirer l\'utilisateur de cette organization, êtes vous sûre?');">
<input type="hidden" name="organizationId" value="{{ organizationId }}">
<button class="btn btn-danger" type="submit">Désactiver</button>
</form>
{% endif %}
<a href="{{ path('user_edit', {'id': user.id}) }}" class="btn btn-primary">Modifier</a>
</div>
</div>
<div class="card-body">
<p> <b>Email: </b>{{ user.email }}</p>