Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify the organization name in the email subject #810

Merged
merged 5 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import it.infn.mw.iam.audit.events.aup.AupSignedEvent;
import it.infn.mw.iam.audit.events.aup.AupSignedOnBehalfEvent;
import it.infn.mw.iam.core.time.TimeProvider;
import it.infn.mw.iam.notification.NotificationFactory;
import it.infn.mw.iam.persistence.model.IamAccount;
import it.infn.mw.iam.persistence.model.IamAup;
import it.infn.mw.iam.persistence.model.IamAupSignature;
Expand All @@ -69,15 +70,17 @@ public class AupSignatureController {
private final IamAupRepository aupRepo;
private final TimeProvider timeProvider;
private final ApplicationEventPublisher eventPublisher;
private final NotificationFactory notificationFactory;
public AupSignatureController(AupSignatureConverter conv, AccountUtils utils,
IamAupSignatureRepository signatureRepo, IamAupRepository aupRepo, TimeProvider timeProvider,
ApplicationEventPublisher publisher) {
ApplicationEventPublisher publisher, NotificationFactory notificationFactory) {
this.signatureConverter = conv;
this.accountUtils = utils;
this.signatureRepo = signatureRepo;
this.aupRepo = aupRepo;
this.timeProvider = timeProvider;
this.eventPublisher = publisher;
this.notificationFactory = notificationFactory;
}

private Supplier<AupNotFoundError> aupNotFoundException() {
Expand Down Expand Up @@ -194,6 +197,7 @@ public void deleteSignatureForAccount(@PathVariable String accountId,
eventPublisher
.publishEvent(AupSignatureDeletedEvent.deletedByClient(this, principal, signature.get()));
}
notificationFactory.createAupSignatureRequestMessage(signatureAccount);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public IamEmailNotification createAccountRestoredMessage(IamAccount account) {
model.put(RECIPIENT_FIELD, recipient);
model.put(ORGANISATION_NAME, organisationName);

String subject = "Account restored";
String subject = String.format("[%s IAM] Account restored", organisationName);

IamEmailNotification notification = createMessage("accountRestored.ftl", model,
IamNotificationType.ACCOUNT_RESTORED, subject, asList(account.getUserInfo().getEmail()));
Expand All @@ -410,14 +410,15 @@ protected IamEmailNotification createMessage(String templateName, Map<String, Ob
IamNotificationType messageType, String subject, List<String> receiverAddress) {

try {
String formattedSubject = String.format("[%s IAM] %s", organisationName, subject);
Template template = freeMarkerConfiguration.getTemplate(templateName);
String body = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);

IamEmailNotification message = new IamEmailNotification();

message.setUuid(UUID.randomUUID().toString());
message.setType(messageType);
message.setSubject(subject);
message.setSubject(formattedSubject);
message.setBody(body);
message.setCreationTime(new Date());
message.setDeliveryStatus(IamDeliveryStatus.PENDING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public void tearDown() throws InterruptedException {
notificationDelivery.clearDeliveredNotifications();
}

public String formatSubject(String key) {
return String.format("[%s IAM] %s", organisationName, properties.getSubject().get(key));
}

@Test
public void testSendWithEmptyQueue() {

Expand Down Expand Up @@ -145,7 +149,7 @@ public void testApproveFlowNotifications() throws Exception {

IamEmailNotification message = notificationDelivery.getDeliveredNotifications().get(0);

assertThat(message.getSubject(), equalTo(properties.getSubject().get("confirmation")));
assertThat(message.getSubject(), equalTo(formatSubject("confirmation")));

notificationDelivery.clearDeliveredNotifications();

Expand All @@ -161,7 +165,7 @@ public void testApproveFlowNotifications() throws Exception {

message = notificationDelivery.getDeliveredNotifications().get(0);

assertThat(message.getSubject(), equalTo(properties.getSubject().get("adminHandleRequest")));
assertThat(message.getSubject(), equalTo(formatSubject("adminHandleRequest")));

assertThat(message.getReceivers(), hasSize(1));
assertThat(message.getReceivers().get(0).getEmailAddress(),
Expand All @@ -180,7 +184,7 @@ public void testApproveFlowNotifications() throws Exception {

message = notificationDelivery.getDeliveredNotifications().get(0);

assertThat(message.getSubject(), equalTo(properties.getSubject().get("activated")));
assertThat(message.getSubject(), equalTo(formatSubject("activated")));
assertThat(message.getBody(), containsString(request.getUsername()));

}
Expand Down Expand Up @@ -212,7 +216,7 @@ public void testRejectFlowNoMotivationNotifications() throws Exception {

IamEmailNotification message = notificationDelivery.getDeliveredNotifications().get(0);

assertThat(message.getSubject(), equalTo(properties.getSubject().get("confirmation")));
assertThat(message.getSubject(), equalTo(formatSubject("confirmation")));

notificationDelivery.clearDeliveredNotifications();

Expand All @@ -228,7 +232,7 @@ public void testRejectFlowNoMotivationNotifications() throws Exception {

message = notificationDelivery.getDeliveredNotifications().get(0);

assertThat(message.getSubject(), equalTo(properties.getSubject().get("adminHandleRequest")));
assertThat(message.getSubject(), equalTo(formatSubject("adminHandleRequest")));

assertThat(message.getReceivers(), hasSize(1));
assertThat(message.getReceivers().get(0).getEmailAddress(),
Expand All @@ -247,7 +251,7 @@ public void testRejectFlowNoMotivationNotifications() throws Exception {

message = notificationDelivery.getDeliveredNotifications().get(0);

assertThat(message.getSubject(), equalTo(properties.getSubject().get("rejected")));
assertThat(message.getSubject(), equalTo(formatSubject("rejected")));
assertThat(message.getBody(),
not(containsString("The administrator has provided the following motivation")));

Expand Down Expand Up @@ -280,7 +284,7 @@ public void testRejectFlowMotivationNotifications() throws Exception {

IamEmailNotification message = notificationDelivery.getDeliveredNotifications().get(0);

assertThat(message.getSubject(), equalTo(properties.getSubject().get("confirmation")));
assertThat(message.getSubject(), equalTo(formatSubject("confirmation")));

notificationDelivery.clearDeliveredNotifications();

Expand All @@ -296,7 +300,7 @@ public void testRejectFlowMotivationNotifications() throws Exception {

message = notificationDelivery.getDeliveredNotifications().get(0);

assertThat(message.getSubject(), equalTo(properties.getSubject().get("adminHandleRequest")));
assertThat(message.getSubject(), equalTo(formatSubject("adminHandleRequest")));

assertThat(message.getReceivers(), hasSize(1));
assertThat(message.getReceivers().get(0).getEmailAddress(),
Expand All @@ -317,11 +321,10 @@ public void testRejectFlowMotivationNotifications() throws Exception {

message = notificationDelivery.getDeliveredNotifications().get(0);

assertThat(message.getSubject(), equalTo(properties.getSubject().get("rejected")));
assertThat(message.getSubject(), equalTo(formatSubject("rejected")));
assertThat(message.getBody(),
containsString("The administrator has provided the following motivation"));
assertThat(message.getBody(),
containsString("We hate you"));
assertThat(message.getBody(), containsString("We hate you"));

}

Expand Down
Loading