Merge branch 'dev/mailing/bugfix-3' into 'develop'
resend correct mail to existing user See merge request easy-solutions/apps/easyportal!12
This commit is contained in:
commit
7dc369ee67
|
|
@ -47,17 +47,17 @@ class UserController extends AbstractController
|
||||||
private readonly UserOrganizationService $userOrganizationService,
|
private readonly UserOrganizationService $userOrganizationService,
|
||||||
private readonly UserRepository $userRepository,
|
private readonly UserRepository $userRepository,
|
||||||
private readonly UsersOrganizationsRepository $uoRepository,
|
private readonly UsersOrganizationsRepository $uoRepository,
|
||||||
private readonly OrganizationsRepository $organizationRepository,
|
private readonly OrganizationsRepository $organizationRepository,
|
||||||
private readonly LoggerInterface $userManagementLogger,
|
private readonly LoggerInterface $userManagementLogger,
|
||||||
private readonly LoggerInterface $organizationManagementLogger,
|
private readonly LoggerInterface $organizationManagementLogger,
|
||||||
private readonly LoggerInterface $errorLogger,
|
private readonly LoggerInterface $errorLogger,
|
||||||
private readonly LoggerInterface $securityLogger,
|
private readonly LoggerInterface $securityLogger,
|
||||||
private readonly LoggerService $loggerService,
|
private readonly LoggerService $loggerService,
|
||||||
private readonly EmailService $emailService,
|
private readonly EmailService $emailService,
|
||||||
private readonly AwsService $awsService,
|
private readonly AwsService $awsService,
|
||||||
private readonly OrganizationsService $organizationsService,
|
private readonly OrganizationsService $organizationsService,
|
||||||
private readonly AppsRepository $appsRepository,
|
private readonly AppsRepository $appsRepository,
|
||||||
private readonly RolesRepository $rolesRepository, private readonly AccessTokenService $accessTokenService,
|
private readonly RolesRepository $rolesRepository, private readonly AccessTokenService $accessTokenService,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -168,7 +168,7 @@ class UserController extends AbstractController
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
|
||||||
// Calcul du flag de modification : utilisateur admin ET exactement 1 UO
|
// Calcul du flag de modification : utilisateur admin ET exactement 1 UO
|
||||||
$canEdit = $this->userService->canEditRolesCheck($actingUser, $user,$this->isGranted('ROLE_ADMIN'), $singleUo, $organization);
|
$canEdit = $this->userService->canEditRolesCheck($actingUser, $user, $this->isGranted('ROLE_ADMIN'), $singleUo, $organization);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->loggerService->logError('error while loading user information', [
|
$this->loggerService->logError('error while loading user information', [
|
||||||
|
|
@ -190,7 +190,7 @@ class UserController extends AbstractController
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/edit/{id}', name: 'edit', methods: ['GET','POST'])]
|
#[Route('/edit/{id}', name: 'edit', methods: ['GET', 'POST'])]
|
||||||
public function edit(int $id, Request $request): Response
|
public function edit(int $id, Request $request): Response
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('ROLE_USER');
|
$this->denyAccessUnlessGranted('ROLE_USER');
|
||||||
|
|
@ -290,12 +290,12 @@ class UserController extends AbstractController
|
||||||
$this->addFlash('error', "L'organisation n'existe pas.");
|
$this->addFlash('error', "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) && !$this->isGranted('ROLE_SUPER_ADMIN')) {
|
if ($this->isGranted('ROLE_ADMIN') && !$this->userService->isAdminOfOrganization($org) && !$this->isGranted('ROLE_SUPER_ADMIN')) {
|
||||||
$this->loggerService->logAccessDenied($actingUser->getId());
|
$this->loggerService->logAccessDenied($actingUser->getId());
|
||||||
$this->addFlash('error', "Accès non autorisé.");
|
$this->addFlash('error', "Accès non autorisé.");
|
||||||
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
|
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
|
||||||
}
|
}
|
||||||
}elseif($this->isGranted('ROLE_ADMIN')) {
|
} elseif ($this->isGranted('ROLE_ADMIN')) {
|
||||||
$this->loggerService->logAccessDenied($actingUser->getId());
|
$this->loggerService->logAccessDenied($actingUser->getId());
|
||||||
$this->addFlash('error', "Accès non autorisé.");
|
$this->addFlash('error', "Accès non autorisé.");
|
||||||
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
|
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
|
||||||
|
|
@ -794,7 +794,7 @@ class UserController extends AbstractController
|
||||||
$user = $uo->getUsers();
|
$user = $uo->getUsers();
|
||||||
$initials = $user->getName()[0] . $user->getSurname()[0];
|
$initials = $user->getName()[0] . $user->getSurname()[0];
|
||||||
return [
|
return [
|
||||||
'pictureUrl' =>$user->getPictureUrl(),
|
'pictureUrl' => $user->getPictureUrl(),
|
||||||
'email' => $user->getEmail(),
|
'email' => $user->getEmail(),
|
||||||
'isConnected' => $this->userService->isUserConnected($user->getUserIdentifier()),
|
'isConnected' => $this->userService->isUserConnected($user->getUserIdentifier()),
|
||||||
'showUrl' => $this->generateUrl('user_show', ['id' => $user->getId()]),
|
'showUrl' => $this->generateUrl('user_show', ['id' => $user->getId()]),
|
||||||
|
|
@ -931,31 +931,35 @@ class UserController extends AbstractController
|
||||||
$this->loggerService->logEntityNotFound('User', ['id' => $user->getId()], $actingUser->getId());
|
$this->loggerService->logEntityNotFound('User', ['id' => $user->getId()], $actingUser->getId());
|
||||||
throw $this->createNotFoundException(self::NOT_FOUND);
|
throw $this->createNotFoundException(self::NOT_FOUND);
|
||||||
}
|
}
|
||||||
$uo = $this->uoRepository->findOneBy(['users' => $user,
|
$token = $this->userService->generatePasswordToken($user, $org->getId());
|
||||||
'organization' => $org,
|
if ($user->getLastConnection() !== null) {
|
||||||
'statut' => "INVITED"]);
|
$this->userService->sendExistingUserNotifications($user, $org, $actingUser);
|
||||||
if (!$uo) {
|
} else {
|
||||||
$this->loggerService->logEntityNotFound('UsersOrganization', [
|
$uo = $this->uoRepository->findOneBy(['users' => $user,
|
||||||
'user_id' => $user->getId(),
|
'organization' => $org,
|
||||||
'organization_id' => $orgId], $actingUser->getId());
|
'statut' => "INVITED"]);
|
||||||
throw $this->createNotFoundException(self::NOT_FOUND);
|
if (!$uo) {
|
||||||
}
|
$this->loggerService->logEntityNotFound('UsersOrganization', [
|
||||||
$uo->setModifiedAt(new \DateTimeImmutable());
|
'user_id' => $user->getId(),
|
||||||
try {
|
'organization_id' => $orgId], $actingUser->getId());
|
||||||
$data = ['user' => $uo->getUsers(), 'organization' => $uo->getOrganization()];
|
throw $this->createNotFoundException(self::NOT_FOUND);
|
||||||
$token = $this->userService->generatePasswordToken($user, $org->getId());
|
}
|
||||||
$this->emailService->sendPasswordSetupEmail($user, $token);
|
$uo->setModifiedAt(new \DateTimeImmutable());
|
||||||
$this->loggerService->logEmailSent($userId, $org->getId(), 'Invitation Resent');
|
try {
|
||||||
$this->organizationsService->notifyOrganizationAdmins($data, 'USER_INVITED');
|
$data = ['user' => $uo->getUsers(), 'organization' => $uo->getOrganization()];
|
||||||
return $this->json(['message' => 'Invitation envoyée avec success.'], Response::HTTP_OK);
|
$this->emailService->sendPasswordSetupEmail($user, $token);
|
||||||
} catch (\Exception $e) {
|
$this->loggerService->logEmailSent($userId, $org->getId(), 'Invitation Resent');
|
||||||
$this->loggerService->logCritical('Error while resending invitation', [
|
$this->organizationsService->notifyOrganizationAdmins($data, 'USER_INVITED');
|
||||||
'target_user_id' => $user->getId(),
|
return $this->json(['message' => 'Invitation envoyée avec success.'], Response::HTTP_OK);
|
||||||
'organization_id' => $orgId,
|
} catch (\Exception $e) {
|
||||||
'acting_user_id' => $actingUser->getId(),
|
$this->loggerService->logCritical('Error while resending invitation', [
|
||||||
'error' => $e->getMessage(),
|
'target_user_id' => $user->getId(),
|
||||||
]);
|
'organization_id' => $orgId,
|
||||||
return $this->json(['message' => 'Erreur lors de l\'envoie du mail.'], Response::HTTP_INTERNAL_SERVER_ERROR);
|
'acting_user_id' => $actingUser->getId(),
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
]);
|
||||||
|
return $this->json(['message' => 'Erreur lors de l\'envoie du mail.'], Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
|
throw $this->createAccessDeniedException(self::ACCESS_DENIED);
|
||||||
|
|
@ -972,14 +976,14 @@ class UserController extends AbstractController
|
||||||
'token' => $token,
|
'token' => $token,
|
||||||
'user_id' => $userId
|
'user_id' => $userId
|
||||||
],
|
],
|
||||||
null);
|
null);
|
||||||
throw $this->createNotFoundException('Invalid invitation link.');
|
throw $this->createNotFoundException('Invalid invitation link.');
|
||||||
}
|
}
|
||||||
$user = $this->userRepository->find($userId);
|
$user = $this->userRepository->find($userId);
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
$this->loggerService->logEntityNotFound('User not found in accept invitation', [
|
$this->loggerService->logEntityNotFound('User not found in accept invitation', [
|
||||||
'user_id' => $userId
|
'user_id' => $userId
|
||||||
],null);
|
], null);
|
||||||
throw $this->createNotFoundException(self::NOT_FOUND);
|
throw $this->createNotFoundException(self::NOT_FOUND);
|
||||||
}
|
}
|
||||||
if (!$this->userService->isPasswordTokenValid($user, $token)) {
|
if (!$this->userService->isPasswordTokenValid($user, $token)) {
|
||||||
|
|
|
||||||
|
|
@ -660,7 +660,7 @@ class UserService
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private helpers for email notifications
|
// Private helpers for email notifications
|
||||||
private function sendExistingUserNotifications(User $user, Organizations $org, User $actingUser): void
|
public function sendExistingUserNotifications(User $user, Organizations $org, User $actingUser): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$token = $this->generatePasswordToken($user, $org->getId());
|
$token = $this->generatePasswordToken($user, $org->getId());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue