Skip to content

Commit

Permalink
bug fix (maybe)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Gorzala committed Jan 14, 2024
1 parent 473a8f4 commit 1cda31d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/net/dancier/dancer/contact/ContactService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static net.dancier.dancer.authentication.Constants.ROLE_USER;

Expand All @@ -28,9 +29,13 @@ public class ContactService {

void send(ContactDto contactDto, AuthenticatedUser authenticatedUserOfSender) {
log.info("Having authenticated: {}", authenticatedUserOfSender);
String senderMailAddress = authenticatedUserOfSender.getAuthorities().contains(ROLE_USER)
? authenticatedUserOfSender.getEmail()
: contactDto.getSender();
String senderMailAddress;
if (authenticatedUserOfSender.getAuthorities().stream().map(GrantedAuthority::getAuthority).anyMatch(s -> s.equals(ROLE_USER))) {
log.info("Overwriting sender...");
senderMailAddress = authenticatedUserOfSender.getEmail();
} else {
senderMailAddress = contactDto.getSender();
}
log.info("Using this: {} as sender address", senderMailAddress);
SimpleMailMessage mailToSender = mailCreationService.createDancierMessageFromTemplate(
senderMailAddress,
Expand Down

0 comments on commit 1cda31d

Please sign in to comment.