messages sent to 'registeredBy' email are now sent to the currently authenticated user as well

This commit is contained in:
Konstantinos Spyrou 2023-01-30 19:49:33 +02:00
parent d3bcea79c0
commit 287f476bd2
1 changed files with 21 additions and 6 deletions

View File

@ -5,6 +5,7 @@ import eu.dnetlib.domain.functionality.validator.JobForValidation;
import eu.dnetlib.repo.manager.domain.InterfaceComplianceRequest; import eu.dnetlib.repo.manager.domain.InterfaceComplianceRequest;
import eu.dnetlib.repo.manager.domain.Repository; import eu.dnetlib.repo.manager.domain.Repository;
import eu.dnetlib.repo.manager.domain.RepositoryInterface; import eu.dnetlib.repo.manager.domain.RepositoryInterface;
import eu.dnetlib.repo.manager.domain.dto.User;
import eu.dnetlib.repo.manager.exception.ValidationServiceException; import eu.dnetlib.repo.manager.exception.ValidationServiceException;
import eu.dnetlib.utils.MailLibrary; import eu.dnetlib.utils.MailLibrary;
import org.mitre.openid.connect.model.OIDCAuthenticationToken; import org.mitre.openid.connect.model.OIDCAuthenticationToken;
@ -17,8 +18,7 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Collections; import java.util.*;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component("emailUtils") @Component("emailUtils")
@ -259,7 +259,12 @@ public class EmailUtilsImpl implements EmailUtils {
"This message has been generated automatically."; "This message has been generated automatically.";
message = createUserMail(message, authentication); message = createUserMail(message, authentication);
this.sendMail(repository.getRegisteredby(), subject, message); Collection<String> emailTo = new HashSet<>();
if (repository.getRegisteredby() != null) {
emailTo.add(repository.getRegisteredby());
}
emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail());
this.sendMail(emailTo, subject, message);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error while sending registration of interface notification email to user: " + repository.getRegisteredby(), e); logger.error("Error while sending registration of interface notification email to user: " + repository.getRegisteredby(), e);
@ -288,7 +293,12 @@ public class EmailUtilsImpl implements EmailUtils {
"If you have any questions, write to 'helpdesk@openaire.eu'."; "If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication); message = createUserMail(message, authentication);
this.sendMail(repository.getRegisteredby(), subject, message); Collection<String> emailTo = new HashSet<>();
if (repository.getRegisteredby() != null) {
emailTo.add(repository.getRegisteredby());
}
emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail());
this.sendMail(emailTo, subject, message);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e); logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
@ -346,7 +356,12 @@ public class EmailUtilsImpl implements EmailUtils {
"If you have any questions, write to 'helpdesk@openaire.eu'."; "If you have any questions, write to 'helpdesk@openaire.eu'.";
message = createUserMail(message, authentication); message = createUserMail(message, authentication);
this.sendMail(repository.getRegisteredby(), subject, message); Collection<String> emailTo = new HashSet<>();
if (repository.getRegisteredby() != null) {
emailTo.add(repository.getRegisteredby());
}
emailTo.add(User.from(((OIDCAuthenticationToken) authentication).getUserInfo()).getEmail());
this.sendMail(emailTo, subject, message);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e); logger.error("Error while sending registration notification email to user: " + repository.getRegisteredby(), e);
@ -781,7 +796,7 @@ public class EmailUtilsImpl implements EmailUtils {
this.sendMail(Collections.singletonList(email), subject, message); this.sendMail(Collections.singletonList(email), subject, message);
} }
public void sendMail(List<String> recipients, String subject, String message) { public void sendMail(Collection<String> recipients, String subject, String message) {
try { try {
logger.debug("Sending e-mail\nRecipients: {}\nSubject: {}\nMessage: {}", recipients, subject, message); logger.debug("Sending e-mail\nRecipients: {}\nSubject: {}\nMessage: {}", recipients, subject, message);
mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message); mailLibrary.sendEmail(recipients.toArray(new String[]{}), subject, message);