Log action
This commit is contained in:
parent
0d498d4570
commit
61e43dcd98
|
|
@ -7,9 +7,11 @@ use App\Entity\Apps;
|
|||
use App\Entity\Organizations;
|
||||
use App\Entity\Roles;
|
||||
use App\Entity\User;
|
||||
use App\Service\ActionService;
|
||||
use App\Service\UserService;
|
||||
use App\Entity\UsersOrganizations;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
/**
|
||||
* Service pour la gestion des organisations d'utilisateurs.
|
||||
|
|
@ -23,7 +25,9 @@ readonly class UserOrganizationService
|
|||
* @param EntityManagerInterface $entityManager Le gestionnaire d'entités Doctrine
|
||||
*/
|
||||
public function __construct(private readonly EntityManagerInterface $entityManager,
|
||||
private readonly UserService $userService)
|
||||
private readonly UserService $userService,
|
||||
private ActionService $actionService,
|
||||
private readonly Security $security)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -299,6 +303,14 @@ readonly class UserOrganizationService
|
|||
foreach ($uoEntity->getApps()->toArray() as $existingApp) {
|
||||
if (!in_array($existingApp->getId(), $selectedApps)) {
|
||||
$uoEntity->removeApp($existingApp);
|
||||
//Log action
|
||||
$actingUser = $this->security->getUser()->getUserIdentifier();
|
||||
$actingUser = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $actingUser]);
|
||||
$this->actionService->createAction("Mise à jour des applications",
|
||||
$actingUser,
|
||||
$uoEntity->getOrganization(),
|
||||
"{$actingUser->getIdentifier()} a retiré les droits d'accès à {$existingApp->getName()} à
|
||||
{$uoEntity->getUsers()->getUserIdentifier()} pour l'organisation {$uoEntity->getOrganization()->getName()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -314,6 +326,13 @@ readonly class UserOrganizationService
|
|||
$appEntity = $this->entityManager->getRepository(Apps::class)->find($appId);
|
||||
if ($appEntity && !$uoEntity->getApps()->contains($appEntity)) {
|
||||
$uoEntity->addApp($appEntity);
|
||||
$actingUser = $this->security->getUser()->getUserIdentifier();
|
||||
$actingUser = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $actingUser]);
|
||||
$this->actionService->createAction("Mise à jour des applications",
|
||||
$actingUser,
|
||||
$uoEntity->getOrganization(),
|
||||
"{$actingUser->getIdentifier()} a donné les droits d'accès à {$appEntity->getName()} à
|
||||
{$uoEntity->getUsers()->getUserIdentifier()} pour l'organisation {$uoEntity->getOrganization()->getName()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -335,11 +354,13 @@ readonly class UserOrganizationService
|
|||
foreach ($userOrganizations as $uo) {
|
||||
$uo->setIsActive(false);
|
||||
//Log action
|
||||
$action = new Actions();
|
||||
$action->setActionType("Désactivation role" );
|
||||
$action->setDescription("Désactivation du rôle " . $uo->getRole()->getName() . " pour l'utilisateur " . $user->getUserIdentifier() . " dans l'organisation " . $organization->getName());
|
||||
$action->setOrganization($organization);
|
||||
$action->setUsers($user);
|
||||
$actingUser = $this->security->getUser()->getUserIdentifier();
|
||||
$actingUser = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $actingUser]);
|
||||
$this->actionService->createAction("Mise à jour des Roles",
|
||||
$actingUser,
|
||||
$uo->getOrganization(),
|
||||
"{$actingUser->getIdentifier()} a désactivé le rôle {$uo->getRole()->getName()} de
|
||||
{$uo->getUsers()->getUserIdentifier()} pour l'organisation {$uo->getOrganization()->getName()}");
|
||||
$this->entityManager->persist($uo);
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
|
|
|
|||
Loading…
Reference in New Issue