Removed useless code

This commit is contained in:
Charles 2026-02-11 11:56:44 +01:00
parent e64afa87db
commit 2fce2dd8a5
1 changed files with 48 additions and 48 deletions

View File

@ -79,18 +79,18 @@ class UserController extends AbstractController
$this->denyAccessUnlessGranted('ROLE_USER'); $this->denyAccessUnlessGranted('ROLE_USER');
// Utilisateur courant (acting user) via UserService // Utilisateur courant (acting user) via UserService
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $actingUser = $this->getUser();
// Chargement de l'utilisateur cible à afficher // Chargement de l'utilisateur cible à afficher
$user = $this->userRepository->find($id); $user = $this->userRepository->find($id);
if (!$user) { if (!$user) {
$this->loggerService->logEntityNotFound('User', ['id' => $id], $actingUser->getId()); $this->loggerService->logEntityNotFound('User', ['id' => $id], $actingUser->getUserIdentifier());
$this->addFlash('danger', "L'utilisateur demandé n'existe pas."); $this->addFlash('danger', "L'utilisateur demandé n'existe pas.");
throw $this->createNotFoundException(self::NOT_FOUND); throw $this->createNotFoundException(self::NOT_FOUND);
} }
//if hasAccessTo is false, turn to true and denie access //if hasAccessTo is false, turn to true and denie access
if (!$this->userService->hasAccessTo($user)) { if (!$this->userService->isAdminOfUser($user)) {
$this->loggerService->logAccessDenied($actingUser->getId()); $this->loggerService->logAccessDenied($actingUser->getUserIdentifier());
$this->addFlash('danger', "Vous n'avez pas accès à cette information."); $this->addFlash('danger', "Vous n'avez pas accès à cette information.");
throw new AccessDeniedHttpException (self::ACCESS_DENIED); throw new AccessDeniedHttpException (self::ACCESS_DENIED);
} }
@ -105,7 +105,7 @@ class UserController extends AbstractController
} catch (\Exception $e) { } catch (\Exception $e) {
$this->loggerService->logError('error while loading user information', [ $this->loggerService->logError('error while loading user information', [
'target_user_id' => $id, 'target_user_id' => $id,
'acting_user_id' => $actingUser->getId(), 'acting_user_id' => $actingUser->getUserIdentifier(),
'error' => $e->getMessage(), 'error' => $e->getMessage(),
]); ]);
$this->addFlash('danger', 'Une erreur est survenue lors du chargement des informations utilisateur.'); $this->addFlash('danger', 'Une erreur est survenue lors du chargement des informations utilisateur.');
@ -122,15 +122,15 @@ class UserController extends AbstractController
public function edit(int $id, Request $request): Response public function edit(int $id, Request $request): Response
{ {
$this->denyAccessUnlessGranted('ROLE_USER'); $this->denyAccessUnlessGranted('ROLE_USER');
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $actingUser = $this->getUser();
$user = $this->userRepository->find($id); $user = $this->userRepository->find($id);
if (!$user) { if (!$user) {
$this->loggerService->logEntityNotFound('User', ['id' => $id], $actingUser->getId()); $this->loggerService->logEntityNotFound('User', ['id' => $id], $actingUser->getUserIdentifier());
$this->addFlash('danger', "L'utilisateur demandé n'existe pas."); $this->addFlash('danger', "L'utilisateur demandé n'existe pas.");
throw $this->createNotFoundException(self::NOT_FOUND); throw $this->createNotFoundException(self::NOT_FOUND);
} }
try { try {
if ($this->userService->hasAccessTo($user)) { if ($this->userService->isAdminOfUser($user)) {
$form = $this->createForm(UserForm::class, $user); $form = $this->createForm(UserForm::class, $user);
$form->handleRequest($request); $form->handleRequest($request);
@ -144,31 +144,31 @@ class UserController extends AbstractController
$this->entityManager->flush(); $this->entityManager->flush();
//log and action //log and action
$this->loggerService->logUserAction($user->getId(), $actingUser->getId(), 'User information edited'); $this->loggerService->logUserAction($user->getId(), $actingUser->getUserIdentifier(), 'User information edited');
$orgId = $request->get('organizationId'); $orgId = $request->get('organizationId');
if ($orgId) { if ($orgId) {
$org = $this->organizationRepository->find($orgId); $org = $this->organizationRepository->find($orgId);
if ($org) { if ($org) {
$this->actionService->createAction("Edit user information", $actingUser, $org, $user->getUserIdentifier()); $this->actionService->createAction("Edit user information", $actingUser, $org, $user->getUserIdentifier());
$this->loggerService->logUserAction($user->getId(), $actingUser->getId(), 'User information edited'); $this->loggerService->logUserAction($user->getId(), $actingUser->getUserIdentifier(), 'User information edited');
if ($this->isGranted('ROLE_SUPER_ADMIN')) { if ($this->isGranted('ROLE_SUPER_ADMIN')) {
$this->loggerService->logSuperAdmin( $this->loggerService->logSuperAdmin(
$user->getId(), $user->getId(),
$actingUser->getId(), $actingUser->getUserIdentifier(),
"Super Admin accessed user edit page", "Super Admin accessed user edit page",
); );
} }
$this->addFlash('success', 'Information modifié avec success.'); $this->addFlash('success', 'Information modifié avec success.');
return $this->redirectToRoute('user_show', ['id' => $user->getId(), 'organizationId' => $orgId]); return $this->redirectToRoute('user_show', ['id' => $user->getId(), 'organizationId' => $orgId]);
} }
$this->loggerService->logEntityNotFound('Organization', ['id' => $orgId], $actingUser->getId()); $this->loggerService->logEntityNotFound('Organization', ['id' => $orgId], $actingUser->getUserIdentifier());
$this->addFlash('danger', "L'organisation n'existe pas."); $this->addFlash('danger', "L'organisation n'existe pas.");
throw $this->createNotFoundException(self::NOT_FOUND); throw $this->createNotFoundException(self::NOT_FOUND);
} }
if ($this->isGranted('ROLE_SUPER_ADMIN')) { if ($this->isGranted('ROLE_SUPER_ADMIN')) {
$this->loggerService->logSuperAdmin( $this->loggerService->logSuperAdmin(
$user->getId(), $user->getId(),
$actingUser->getId(), $actingUser->getUserIdentifier(),
"Super Admin accessed user edit page", "Super Admin accessed user edit page",
); );
} }
@ -183,7 +183,7 @@ class UserController extends AbstractController
'organizationId' => $request->get('organizationId') 'organizationId' => $request->get('organizationId')
]); ]);
} }
$this->loggerService->logAccessDenied($actingUser->getId()); $this->loggerService->logAccessDenied($actingUser->getUserIdentifier());
$this->addFlash('danger', "Accès non autorisé."); $this->addFlash('danger', "Accès non autorisé.");
throw $this->createAccessDeniedException(self::ACCESS_DENIED); throw $this->createAccessDeniedException(self::ACCESS_DENIED);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -200,7 +200,7 @@ class UserController extends AbstractController
{ {
$this->denyAccessUnlessGranted('ROLE_USER'); $this->denyAccessUnlessGranted('ROLE_USER');
try { try {
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $actingUser =$this->getUser();
$user = new User(); $user = new User();
$form = $this->createForm(UserForm::class, $user); $form = $this->createForm(UserForm::class, $user);
@ -210,17 +210,17 @@ class UserController extends AbstractController
if ($orgId) { if ($orgId) {
$org = $this->organizationRepository->find($orgId); $org = $this->organizationRepository->find($orgId);
if (!$org) { if (!$org) {
$this->loggerService->logEntityNotFound('Organization', ['id' => $orgId], $actingUser->getId()); $this->loggerService->logEntityNotFound('Organization', ['id' => $orgId], $actingUser->getUserIdentifier());
$this->addFlash('danger', "L'organisation n'existe pas."); $this->addFlash('danger', "L'organisation n'existe pas.");
throw $this->createNotFoundException(self::NOT_FOUND); throw $this->createNotFoundException(self::NOT_FOUND);
} }
if (!$this->isGranted('ROLE_ADMIN') && !$this->userService->isAdminOfOrganization($org)) { if (!$this->isGranted('ROLE_ADMIN') && !$this->userService->isAdminOfOrganization($org)) {
$this->loggerService->logAccessDenied($actingUser->getId()); $this->loggerService->logAccessDenied($actingUser->getUserIdentifier());
$this->addFlash('danger', "Accès non autorisé."); $this->addFlash('danger', "Accès non autorisé.");
throw $this->createAccessDeniedException(self::ACCESS_DENIED); throw $this->createAccessDeniedException(self::ACCESS_DENIED);
} }
} else{ } else{
$this->loggerService->logAccessDenied($actingUser->getId()); $this->loggerService->logAccessDenied($actingUser->getUserIdentifier());
$this->addFlash('danger', "Accès non autorisé."); $this->addFlash('danger', "Accès non autorisé.");
throw $this->createAccessDeniedException(self::ACCESS_DENIED); throw $this->createAccessDeniedException(self::ACCESS_DENIED);
} }
@ -238,7 +238,7 @@ class UserController extends AbstractController
if ($this->isGranted('ROLE_ADMIN')) { if ($this->isGranted('ROLE_ADMIN')) {
$this->loggerService->logSuperAdmin( $this->loggerService->logSuperAdmin(
$existingUser->getId(), $existingUser->getId(),
$actingUser->getId(), $actingUser->getUserIdentifier(),
"Super Admin linked user to organization", "Super Admin linked user to organization",
$org->getId(), $org->getId(),
); );
@ -287,12 +287,12 @@ class UserController extends AbstractController
{ {
$this->denyAccessUnlessGranted('ROLE_ADMIN'); $this->denyAccessUnlessGranted('ROLE_ADMIN');
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $actingUser =$this->getUser();
$status = $request->request->get('status'); $status = $request->request->get('status');
try { try {
$user = $this->userRepository->find($id); $user = $this->userRepository->find($id);
if (!$user) { if (!$user) {
$this->loggerService->logEntityNotFound('User', ['id' => $id], $actingUser->getId()); $this->loggerService->logEntityNotFound('User', ['id' => $id], $actingUser->getUserIdentifier());
throw $this->createNotFoundException(self::NOT_FOUND); throw $this->createNotFoundException(self::NOT_FOUND);
} }
@ -308,12 +308,12 @@ class UserController extends AbstractController
$user->setModifiedAt(new \DateTimeImmutable('now')); $user->setModifiedAt(new \DateTimeImmutable('now'));
$this->entityManager->persist($user); $this->entityManager->persist($user);
$this->entityManager->flush(); $this->entityManager->flush();
$this->loggerService->logUserAction($user->getId(), $actingUser->getId(), 'User deactivated'); $this->loggerService->logUserAction($user->getId(), $actingUser->getUserIdentifier(), 'User deactivated');
if ($this->isGranted('ROLE_SUPER_ADMIN')) { if ($this->isGranted('ROLE_SUPER_ADMIN')) {
$this->loggerService->logSuperAdmin( $this->loggerService->logSuperAdmin(
$user->getId(), $user->getId(),
$actingUser->getId(), $actingUser->getUserIdentifier(),
'Super admin deactivated user' 'Super admin deactivated user'
); );
} }
@ -329,13 +329,13 @@ class UserController extends AbstractController
$user->setModifiedAt(new \DateTimeImmutable('now')); $user->setModifiedAt(new \DateTimeImmutable('now'));
$this->entityManager->persist($user); $this->entityManager->persist($user);
$this->entityManager->flush(); $this->entityManager->flush();
$this->loggerService->logUserAction($user->getId(), $actingUser->getId(), 'User activated'); $this->loggerService->logUserAction($user->getId(), $actingUser->getUserIdentifier(), 'User activated');
if ($this->isGranted('ROLE_SUPER_ADMIN')) { if ($this->isGranted('ROLE_SUPER_ADMIN')) {
$this->loggerService->logSuperAdmin( $this->loggerService->logSuperAdmin(
$user->getId(), $user->getId(),
$actingUser->getId(), $actingUser->getUserIdentifier(),
'Super admin activated user' 'Super admin activated user'
); );
} }
@ -370,18 +370,18 @@ class UserController extends AbstractController
public function activateStatusOrganization(int $id, Request $request): JsonResponse public function activateStatusOrganization(int $id, Request $request): JsonResponse
{ {
$this->denyAccessUnlessGranted('ROLE_USER'); $this->denyAccessUnlessGranted('ROLE_USER');
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $actingUser = $this->getUser();
try { try {
$user = $this->userRepository->find($id); $user = $this->userRepository->find($id);
if (!$user) { if (!$user) {
$this->loggerService->logEntityNotFound('User', ['id' => $id], $actingUser->getId()); $this->loggerService->logEntityNotFound('User', ['id' => $id], $actingUser->getUserIdentifier());
throw $this->createNotFoundException(self::NOT_FOUND); throw $this->createNotFoundException(self::NOT_FOUND);
} }
if ($this->userService->isAdminOfUser($user)) { if ($this->userService->isAdminOfUser($user)) {
$orgId = $request->get('organizationId'); $orgId = $request->get('organizationId');
$org = $this->organizationRepository->find($orgId); $org = $this->organizationRepository->find($orgId);
if (!$org) { if (!$org) {
$this->loggerService->logEntityNotFound('Organization', ['id' => $orgId], $actingUser->getId()); $this->loggerService->logEntityNotFound('Organization', ['id' => $orgId], $actingUser->getUserIdentifier());
throw $this->createNotFoundException(self::NOT_FOUND); throw $this->createNotFoundException(self::NOT_FOUND);
} }
@ -389,7 +389,7 @@ class UserController extends AbstractController
'organization' => $org]); 'organization' => $org]);
if (!$uo) { if (!$uo) {
$this->loggerService->logEntityNotFound('UsersOrganization', ['user_id' => $user->getId(), $this->loggerService->logEntityNotFound('UsersOrganization', ['user_id' => $user->getId(),
'organization_id' => $org->getId()], $actingUser->getId()); 'organization_id' => $org->getId()], $actingUser->getUserIdentifier());
throw $this->createNotFoundException(self::NOT_FOUND); throw $this->createNotFoundException(self::NOT_FOUND);
} }
$status = $request->get('status'); $status = $request->get('status');
@ -401,7 +401,7 @@ class UserController extends AbstractController
$data = ['user' => $user, $data = ['user' => $user,
'organization' => $org]; 'organization' => $org];
$this->organizationsService->notifyOrganizationAdmins($data, "USER_DEACTIVATED"); $this->organizationsService->notifyOrganizationAdmins($data, "USER_DEACTIVATED");
$this->loggerService->logOrganizationInformation($org->getId(), $actingUser->getId(), "UO link deactivated with uo id : {$uo->getId()}"); $this->loggerService->logOrganizationInformation($org->getId(), $actingUser->getUserIdentifier(), "UO link deactivated with uo id : {$uo->getId()}");
$this->actionService->createAction("Deactivate user in organization", $actingUser, $org, $org->getName() . " for user " . $user->getUserIdentifier()); $this->actionService->createAction("Deactivate user in organization", $actingUser, $org, $org->getName() . " for user " . $user->getUserIdentifier());
return new JsonResponse(['status' => 'deactivated'], Response::HTTP_OK); return new JsonResponse(['status' => 'deactivated'], Response::HTTP_OK);
} }
@ -409,7 +409,7 @@ class UserController extends AbstractController
$uo->setIsActive(true); $uo->setIsActive(true);
$this->entityManager->persist($uo); $this->entityManager->persist($uo);
$this->entityManager->flush(); $this->entityManager->flush();
$this->loggerService->logOrganizationInformation($orgId, $actingUser->getId(), "UO link activated with uo id : {$uo->getId()}"); $this->loggerService->logOrganizationInformation($orgId, $actingUser->getUserIdentifier(), "UO link activated with uo id : {$uo->getId()}");
$this->actionService->createAction("Activate user in organization", $actingUser, $org, $org->getName() . " for user " . $user->getUserIdentifier()); $this->actionService->createAction("Activate user in organization", $actingUser, $org, $org->getName() . " for user " . $user->getUserIdentifier());
$data = ['user' => $user, $data = ['user' => $user,
'organization' => $org]; 'organization' => $org];
@ -435,13 +435,13 @@ class UserController extends AbstractController
{ {
$this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN'); $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $actingUser = $this->getUser();
try { try {
$user = $this->userRepository->find($id); $user = $this->userRepository->find($id);
if (!$user) { if (!$user) {
// Security/audit log for missing user // Security/audit log for missing user
$this->loggerService->logEntityNotFound('User', ['id' => $id], $actingUser->getId()); $this->loggerService->logEntityNotFound('User', ['id' => $id], $actingUser->getUserIdentifier());
$this->addFlash('danger', "L'utilisateur demandé n'existe pas."); $this->addFlash('danger', "L'utilisateur demandé n'existe pas.");
throw $this->createNotFoundException(self::NOT_FOUND); throw $this->createNotFoundException(self::NOT_FOUND);
} }
@ -454,7 +454,7 @@ class UserController extends AbstractController
$user->setModifiedAt(new \DateTimeImmutable('now')); $user->setModifiedAt(new \DateTimeImmutable('now'));
// Deactivate all org links // Deactivate all org links
$this->userOrganizationService->deactivateAllUserOrganizationLinks($actingUser, $user); $this->userOrganizationService->deactivateAllUserOrganizationLinks($actingUser, $user);
$this->loggerService->logOrganizationInformation($user->getId(), $actingUser->getId(), 'All user organization links deactivated'); $this->loggerService->logOrganizationInformation($user->getId(), $actingUser->getUserIdentifier(), 'All user organization links deactivated');
// Revoke tokens if connected // Revoke tokens if connected
if ($this->userService->isUserConnected($user->getUserIdentifier())) { if ($this->userService->isUserConnected($user->getUserIdentifier())) {
@ -464,13 +464,13 @@ class UserController extends AbstractController
$this->entityManager->flush(); $this->entityManager->flush();
// User management log // User management log
$this->loggerService->logUserAction($user->getId(), $actingUser->getId(), 'User deleted'); $this->loggerService->logUserAction($user->getId(), $actingUser->getUserIdentifier(), 'User deleted');
// Super admin log (standardized style) // Super admin log (standardized style)
if ($this->isGranted('ROLE_SUPER_ADMIN')) { if ($this->isGranted('ROLE_SUPER_ADMIN')) {
$this->loggerService->logSuperAdmin( $this->loggerService->logSuperAdmin(
$user->getId(), $user->getId(),
$actingUser->getId(), $actingUser->getUserIdentifier(),
'Super admin deleted user' 'Super admin deleted user'
); );
} }
@ -514,18 +514,18 @@ class UserController extends AbstractController
public function applicationRole(int $id, Request $request): Response public function applicationRole(int $id, Request $request): Response
{ {
$this->denyAccessUnlessGranted("ROLE_ADMIN"); $this->denyAccessUnlessGranted("ROLE_ADMIN");
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $actingUser = $this->getUser();
if ($this->userService->hasAccessTo($actingUser, true)) { if ($this->userService->hasAccessTo($actingUser, true)) {
$uo = $this->entityManager->getRepository(UsersOrganizations::class)->find($id); $uo = $this->entityManager->getRepository(UsersOrganizations::class)->find($id);
if (!$uo) { if (!$uo) {
$this->loggerService->logEntityNotFound('UsersOrganization', ['id' => $id], $actingUser->getId()); $this->loggerService->logEntityNotFound('UsersOrganization', ['id' => $id], $actingUser->getUserIdentifier());
$this->addFlash('danger', "La liaison utilisateur-organisation n'existe pas."); $this->addFlash('danger', "La liaison utilisateur-organisation n'existe pas.");
throw new NotFoundHttpException("UserOrganization not found"); throw new NotFoundHttpException("UserOrganization not found");
} }
$application = $this->entityManager->getRepository(Apps::class)->find($request->get('appId')); $application = $this->entityManager->getRepository(Apps::class)->find($request->get('appId'));
if (!$application) { if (!$application) {
$this->loggerService->logEntityNotFound('Application', ['id' => $request->get('appId')], $actingUser->getId()); $this->loggerService->logEntityNotFound('Application', ['id' => $request->get('appId')], $actingUser->getUserIdentifier());
$this->addFlash('danger', "L'application demandée n'existe pas."); $this->addFlash('danger', "L'application demandée n'existe pas.");
throw $this->createNotFoundException(self::NOT_FOUND); throw $this->createNotFoundException(self::NOT_FOUND);
} }
@ -533,7 +533,7 @@ class UserController extends AbstractController
$selectedRolesIds = $request->get('roles', []); $selectedRolesIds = $request->get('roles', []);
$roleUser = $this->entityManager->getRepository(Roles::class)->findOneBy(['name' => 'USER']); $roleUser = $this->entityManager->getRepository(Roles::class)->findOneBy(['name' => 'USER']);
if (!$roleUser) { if (!$roleUser) {
$this->loggerService->logEntityNotFound('Role', ['name' => 'USER'], $actingUser->getId()); $this->loggerService->logEntityNotFound('Role', ['name' => 'USER'], $actingUser->getUserIdentifier());
$this->addFlash('danger', "Le role de l'utilisateur n'existe pas."); $this->addFlash('danger', "Le role de l'utilisateur n'existe pas.");
throw $this->createNotFoundException('User role not found'); throw $this->createNotFoundException('User role not found');
} }
@ -638,7 +638,7 @@ class UserController extends AbstractController
#[Route(path: '/data/new', name: 'dataNew', methods: ['GET'])] #[Route(path: '/data/new', name: 'dataNew', methods: ['GET'])]
public function dataNew(Request $request): JsonResponse public function dataNew(Request $request): JsonResponse
{ {
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $actingUser = $this->getUser();
if ($this->userService->hasAccessTo($actingUser, true) && $this->isGranted("ROLE_USER")) { if ($this->userService->hasAccessTo($actingUser, true) && $this->isGranted("ROLE_USER")) {
$orgId = $request->query->get('orgId'); $orgId = $request->query->get('orgId');
$uos = $this->uoRepository->findBy(['organization' => $orgId, 'statut' => ["ACCEPTED", "INVITED"]], $uos = $this->uoRepository->findBy(['organization' => $orgId, 'statut' => ["ACCEPTED", "INVITED"]],
@ -674,7 +674,7 @@ class UserController extends AbstractController
#[Route(path: '/data/admin', name: 'dataAdmin', methods: ['GET'])] #[Route(path: '/data/admin', name: 'dataAdmin', methods: ['GET'])]
public function dataAdmin(Request $request): JsonResponse public function dataAdmin(Request $request): JsonResponse
{ {
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $actingUser = $this->getUser();
if ($this->userService->hasAccessTo($actingUser, true) && $this->isGranted("ROLE_USER")) { if ($this->userService->hasAccessTo($actingUser, true) && $this->isGranted("ROLE_USER")) {
$orgId = $request->query->get('orgId'); $orgId = $request->query->get('orgId');
$uos = $this->uoRepository->findBy(['organization' => $orgId]); $uos = $this->uoRepository->findBy(['organization' => $orgId]);
@ -715,7 +715,7 @@ class UserController extends AbstractController
#[Route(path: '/data/organization', name: 'dataUserOrganization', methods: ['GET'])] #[Route(path: '/data/organization', name: 'dataUserOrganization', methods: ['GET'])]
public function dataUserOrganization(Request $request): JsonResponse public function dataUserOrganization(Request $request): JsonResponse
{ {
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $actingUser = $this->getUser();
if ($this->userService->hasAccessTo($actingUser, true) && $this->isGranted("ROLE_USER")) { if ($this->userService->hasAccessTo($actingUser, true) && $this->isGranted("ROLE_USER")) {
$orgId = $request->query->get('orgId'); $orgId = $request->query->get('orgId');
@ -774,17 +774,17 @@ class UserController extends AbstractController
public function resendInvitation(int $userId, Request $request): JsonResponse public function resendInvitation(int $userId, Request $request): JsonResponse
{ {
$this->denyAccessUnlessGranted("ROLE_ADMIN"); $this->denyAccessUnlessGranted("ROLE_ADMIN");
$actingUser = $this->userService->getUserByIdentifier($this->getUser()->getUserIdentifier()); $actingUser = $this->getUser();
if ($this->userService->hasAccessTo($actingUser, true)) { if ($this->userService->hasAccessTo($actingUser, true)) {
$orgId = $request->get('organizationId'); $orgId = $request->get('organizationId');
$org = $this->organizationRepository->find($orgId); $org = $this->organizationRepository->find($orgId);
if (!$org) { if (!$org) {
$this->loggerService->logEntityNotFound('Organization', ['id' => $orgId], $actingUser->getId()); $this->loggerService->logEntityNotFound('Organization', ['id' => $orgId], $actingUser->getUserIdentifier());
throw $this->createNotFoundException(self::NOT_FOUND); throw $this->createNotFoundException(self::NOT_FOUND);
} }
$user = $this->userRepository->find($userId); $user = $this->userRepository->find($userId);
if (!$user) { if (!$user) {
$this->loggerService->logEntityNotFound('User', ['id' => $user->getId()], $actingUser->getId()); $this->loggerService->logEntityNotFound('User', ['id' => $user->getId()], $actingUser->getUserIdentifier());
throw $this->createNotFoundException(self::NOT_FOUND); throw $this->createNotFoundException(self::NOT_FOUND);
} }
$token = $this->userService->generatePasswordToken($user, $org->getId()); $token = $this->userService->generatePasswordToken($user, $org->getId());
@ -797,7 +797,7 @@ class UserController extends AbstractController
if (!$uo) { if (!$uo) {
$this->loggerService->logEntityNotFound('UsersOrganization', [ $this->loggerService->logEntityNotFound('UsersOrganization', [
'user_id' => $user->getId(), 'user_id' => $user->getId(),
'organization_id' => $orgId], $actingUser->getId()); 'organization_id' => $orgId], $actingUser->getUserIdentifier());
throw $this->createNotFoundException(self::NOT_FOUND); throw $this->createNotFoundException(self::NOT_FOUND);
} }
$uo->setModifiedAt(new \DateTimeImmutable()); $uo->setModifiedAt(new \DateTimeImmutable());
@ -811,7 +811,7 @@ class UserController extends AbstractController
$this->loggerService->logCritical('Error while resending invitation', [ $this->loggerService->logCritical('Error while resending invitation', [
'target_user_id' => $user->getId(), 'target_user_id' => $user->getId(),
'organization_id' => $orgId, 'organization_id' => $orgId,
'acting_user_id' => $actingUser->getId(), 'acting_user_id' => $actingUser->getUserIdentifier(),
'error' => $e->getMessage(), 'error' => $e->getMessage(),
]); ]);
return $this->json(['message' => 'Erreur lors de l\'envoie du mail.'], Response::HTTP_INTERNAL_SERVER_ERROR); return $this->json(['message' => 'Erreur lors de l\'envoie du mail.'], Response::HTTP_INTERNAL_SERVER_ERROR);