activate a user from organization
This commit is contained in:
parent
218923dfb7
commit
446f585cc9
|
|
@ -79,10 +79,11 @@ class UserController extends AbstractController
|
||||||
$orgId = $request->query->get('organizationId');
|
$orgId = $request->query->get('organizationId');
|
||||||
if ($orgId) {
|
if ($orgId) {
|
||||||
$orgs = $this->entityManager->getRepository(Organizations::class)->findBy(['id' => $orgId]);
|
$orgs = $this->entityManager->getRepository(Organizations::class)->findBy(['id' => $orgId]);
|
||||||
$uo = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users' => $user, 'organization' => $orgs, 'isActive' => true]);
|
$uo = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users' => $user, 'organization' => $orgs]);
|
||||||
if (!$uo) {
|
if (!$uo) {
|
||||||
throw $this->createNotFoundException(self::NOT_FOUND);
|
throw $this->createNotFoundException(self::NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
$uoActive = $uo[0]->isActive();
|
||||||
} else {
|
} else {
|
||||||
$uo = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users' => $user, 'isActive' => true]);
|
$uo = $this->entityManager->getRepository(UsersOrganizations::class)->findBy(['users' => $user, 'isActive' => true]);
|
||||||
foreach ($uo as $u) {
|
foreach ($uo as $u) {
|
||||||
|
|
@ -103,7 +104,8 @@ 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
|
'organizationId' => $orgId ?? null,
|
||||||
|
'uoActive' => $uoActive ?? null// specific for single organization context and deactivate user from said org
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -245,4 +247,36 @@ class UserController extends AbstractController
|
||||||
|
|
||||||
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
|
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route('/organization/activate/{id}', name: 'activate_organization', methods: ['GET', 'POST'])]
|
||||||
|
public function activateUserInOrganization(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' => false]);
|
||||||
|
if (!$uo) {
|
||||||
|
throw $this->createNotFoundException(self::NOT_FOUND);
|
||||||
|
}
|
||||||
|
$uo->setIsActive(true);
|
||||||
|
$this->entityManager->persist($uo);
|
||||||
|
$this->entityManager->flush();
|
||||||
|
$this->actionService->createAction("Activate user in organization", $actingUser, $org, $org->getName()." for user ".$user->getUserIdentifier());
|
||||||
|
|
||||||
|
return $this->redirectToRoute('user_index');
|
||||||
|
}
|
||||||
|
|
||||||
|
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,24 +3,34 @@
|
||||||
<div class="card border-0">
|
<div class="card border-0">
|
||||||
<div class="card-title shadow-sm p-3 d-flex justify-content-between align-items-center">
|
<div class="card-title shadow-sm p-3 d-flex justify-content-between align-items-center">
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<img src="{{ asset(user.pictureUrl) }}" alt="user" class="me-3 rounded-circle" style="width: 50px; height: 50px;">
|
<img src="{{ asset(user.pictureUrl) }}" alt="user" class="me-3 rounded-circle"
|
||||||
|
style="width: 50px; height: 50px;">
|
||||||
<h2>{{ user.surname|capitalize }} {{ user.name|capitalize }}</h2>
|
<h2>{{ user.surname|capitalize }} {{ user.name|capitalize }}</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="d-flex gap-2">
|
<div class="d-flex gap-2">
|
||||||
{% if organizationId is not null %}
|
{% if organizationId is not null %}
|
||||||
<form method="post" action="{{ path('user_deactivate_organization', {'id': user.id}) }}"
|
{% if uoActive %}
|
||||||
onsubmit="return confirm('Vous allez retirer l\'utilisateur de cette organization, êtes vous sûre?');">
|
<form method="post" action="{{ path('user_deactivate_organization', {'id': user.id}) }}"
|
||||||
<input type="hidden" name="organizationId" value="{{ organizationId }}">
|
onsubmit="return confirm('Vous allez retirer l\'utilisateur de cette organisation, êtes vous sûre?');">
|
||||||
<button class="btn btn-danger" type="submit">Désactiver</button>
|
<input type="hidden" name="organizationId" value="{{ organizationId }}">
|
||||||
</form>
|
<button class="btn btn-danger" type="submit">Désactiver</button>
|
||||||
|
</form>
|
||||||
|
{% else %}
|
||||||
|
<form method="post" action="{{ path('user_activate_organization', {'id': user.id}) }}"
|
||||||
|
onsubmit="return confirm('Vous allez activer cette utilisateur dans votre organisation, êtes vous sûre?');">
|
||||||
|
<input type="hidden" name="organizationId" value="{{ organizationId }}">
|
||||||
|
<button class="btn btn-primary" type="submit">Réactiver</button>
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="{{ path('user_edit', {'id': user.id}) }}" class="btn btn-primary">Modifier</a>
|
<a href="{{ path('user_edit', {'id': user.id}) }}" class="btn btn-primary">Modifier</a>
|
||||||
</div>
|
</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>
|
||||||
<p><b>Dernière connection: </b>{{ user.lastConnection|date('d/m/Y') }} à {{ user.lastConnection|date('H:m:s') }} </p>
|
<p><b>Dernière connection: </b>{{ user.lastConnection|date('d/m/Y') }}
|
||||||
|
à {{ user.lastConnection|date('H:m:s') }} </p>
|
||||||
<p><b>Compte crée le: </b>{{ user.createdAt|date('d/m/Y') }}</p>
|
<p><b>Compte crée le: </b>{{ user.createdAt|date('d/m/Y') }}</p>
|
||||||
<p><b>Numéro de téléphone: </b>{{ user.phoneNumber ? user.phoneNumber : 'Non renseigné' }}</p>
|
<p><b>Numéro de téléphone: </b>{{ user.phoneNumber ? user.phoneNumber : 'Non renseigné' }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue