deactivate a user from organization
This commit is contained in:
parent
84e5d7c87a
commit
218923dfb7
|
|
@ -103,6 +103,7 @@ class UserController extends AbstractController
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
'uoas' => $uoa ?? null,
|
'uoas' => $uoa ?? null,
|
||||||
'orgs' => $orgs ?? 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);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,16 @@
|
||||||
<h2>{{ user.surname|capitalize }} {{ user.name|capitalize }}</h2>
|
<h2>{{ user.surname|capitalize }} {{ user.name|capitalize }}</h2>
|
||||||
</div>
|
</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>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<p> <b>Email: </b>{{ user.email }}</p>
|
<p> <b>Email: </b>{{ user.email }}</p>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue