Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenneg committed Oct 28, 2023
1 parent 3458bf0 commit f28cc47
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.redhat.cloud.notifications.connector.email.model.bop;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.HashSet;
import java.util.Set;

/**
* Represents the payload to be sent to BOP/MBOP.
*/
public class Emails {

@JsonProperty("emails")
private final Set<Email> emails;

public Emails() {
this.emails = new HashSet<>();
}

public void addEmail(final Email email) {
this.emails.add(email);
}

Set<Email> getEmails() {
return emails;
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
package com.redhat.cloud.notifications.connector.email.model.bop;

import com.fasterxml.jackson.annotation.JsonAutoDetect;

import java.util.HashSet;
import java.util.Set;

import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY;

/**
* Represents the payload to be sent to BOP/MBOP.
*/
@JsonAutoDetect(fieldVisibility = ANY)
public class SendEmailsRequest {

private final Set<Email> emails = new HashSet<>();
private final boolean skipUsersResolution;

public SendEmailsRequest(boolean skipUsersResolution) {
this.skipUsersResolution = skipUsersResolution;
}

public Set<Email> getEmails() {
return emails;
}
private final boolean skipUsersResolution = true;

public boolean isSkipUsersResolution() {
return skipUsersResolution;
public void addEmail(Email email) {
emails.add(email);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.redhat.cloud.notifications.connector.email.config.EmailConnectorConfig;
import com.redhat.cloud.notifications.connector.email.constants.ExchangeProperty;
import com.redhat.cloud.notifications.connector.email.model.bop.Email;
import com.redhat.cloud.notifications.connector.email.model.bop.Emails;
import com.redhat.cloud.notifications.connector.email.model.bop.SendEmailsRequest;
import com.redhat.cloud.notifications.connector.email.model.settings.User;
import io.vertx.core.json.JsonObject;
Expand Down Expand Up @@ -55,11 +56,19 @@ public void process(final Exchange exchange) {
recipients
);

final SendEmailsRequest request = new SendEmailsRequest(emailConnectorConfig.isSkipBopUsersResolution());
request.getEmails().add(email);
JsonObject bopBody;
if (emailConnectorConfig.isSkipBopUsersResolution()) {
final SendEmailsRequest request = new SendEmailsRequest();
request.addEmail(email);
bopBody = JsonObject.mapFrom(request);
} else {
final Emails emails = new Emails();
emails.addEmail(email);
bopBody = JsonObject.mapFrom(emails);
}

// Specify the message's payload in JSON.
exchange.getMessage().setBody(JsonObject.mapFrom(request).encode());
exchange.getMessage().setBody(bopBody.encode());

// Specify the request's method.
exchange.getMessage().setHeader(Exchange.HTTP_METHOD, HttpMethods.POST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import java.util.Set;

import static java.lang.Boolean.TRUE;

@ApplicationScoped
public class RBACUsersProcessor implements Processor {
/**
Expand Down Expand Up @@ -72,11 +74,10 @@ public void process(final Exchange exchange) {
}

private static User toUser(JsonObject rbacUser) {

User user = new User();
user.setUsername(rbacUser.getString("username"));
user.setEmail(rbacUser.getString("email"));
user.setAdmin(rbacUser.getBoolean("is_org_admin"));
user.setAdmin(TRUE.equals(rbacUser.getBoolean("is_org_admin")));
return user;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,23 @@ private JsonObject getPayload(Set<User> users, EventWrapper<?, ?> eventWrapper,
);
throw e;
}
SendEmailsRequest request = new SendEmailsRequest(featureFlipper.isSendEmailstoBop());
request.getEmails().add(buildEmail(
users,
renderedSubject,
renderedBody
));
return JsonObject.mapFrom(request);
if (featureFlipper.isSendEmailstoBop()) {
SendEmailsRequest request = new SendEmailsRequest();
request.addEmail(buildEmail(
users,
renderedSubject,
renderedBody
));
return JsonObject.mapFrom(request);
} else {
Emails emails = new Emails();
emails.addEmail(buildEmail(
users,
renderedSubject,
renderedBody
));
return JsonObject.mapFrom(emails);
}
}

@Deprecated(forRemoval = true)
Expand All @@ -212,13 +222,23 @@ private JsonObject getPayload(User user, EventWrapper<?, ?> eventWrapper, Templa
);
throw e;
}
SendEmailsRequest request = new SendEmailsRequest(featureFlipper.isSendEmailstoBop());
request.getEmails().add(buildEmail(
featureFlipper.isSendEmailstoBop() ? user.getEmail() : user.getUsername(),
renderedSubject,
renderedBody
));
return JsonObject.mapFrom(request);
if (featureFlipper.isSendEmailstoBop()) {
SendEmailsRequest request = new SendEmailsRequest();
request.addEmail(buildEmail(
user.getEmail(),
renderedSubject,
renderedBody
));
return JsonObject.mapFrom(request);
} else {
Emails emails = new Emails();
emails.addEmail(buildEmail(
user.getUsername(),
renderedSubject,
renderedBody
));
return JsonObject.mapFrom(emails);
}
}

protected HttpRequest<Buffer> buildBOPHttpRequest() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.redhat.cloud.notifications.processors.email;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.HashSet;
import java.util.Set;

public class Emails {

@JsonProperty("emails")
private final Set<Email> emails;

Emails() {
this.emails = new HashSet<>();
}

void addEmail(final Email email) {
this.emails.add(email);
}

Set<Email> getEmails() {
return emails;
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package com.redhat.cloud.notifications.processors.email;

import com.fasterxml.jackson.annotation.JsonAutoDetect;

import java.util.HashSet;
import java.util.Set;

import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY;

@JsonAutoDetect(fieldVisibility = ANY)
public class SendEmailsRequest {

private final Set<Email> emails = new HashSet<>();
private final boolean skipUsersResolution;

public SendEmailsRequest(boolean skipUsersResolution) {
this.skipUsersResolution = skipUsersResolution;
}

public Set<Email> getEmails() {
return emails;
}
private final boolean skipUsersResolution = true;

public boolean isSkipUsersResolution() {
return skipUsersResolution;
public void addEmail(Email email) {
emails.add(email);
}
}
2 changes: 1 addition & 1 deletion engine/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ quarkus.log.cloudwatch.access-key-secret=placeholder

quarkus.log.category."com.redhat.cloud.notifications.health.KafkaConsumedTotalChecker".level=DEBUG

# Should messages about failed injections be delivered as new events (and thus sendEmailsRequest to admins)
# Should messages about failed injections be delivered as new events (and thus emails to admins)
reinject.enabled=false

# Use this property to load the templates from the DB. Temp, to be removed soon.
Expand Down

0 comments on commit f28cc47

Please sign in to comment.