Improve detection and fast-fail on empty Sendgrid template paths
This commit is contained in:
@@ -27,8 +27,8 @@ import io.kamax.mxisd.http.IsAPIv1;
|
|||||||
import io.kamax.mxisd.invitation.IMatrixIdInvite;
|
import io.kamax.mxisd.invitation.IMatrixIdInvite;
|
||||||
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
||||||
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.apache.commons.lang.WordUtils;
|
import org.apache.commons.lang.WordUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import static io.kamax.mxisd.http.io.identity.StoreInviteRequest.Keys.RoomName;
|
import static io.kamax.mxisd.http.io.identity.StoreInviteRequest.Keys.RoomName;
|
||||||
import static io.kamax.mxisd.http.io.identity.StoreInviteRequest.Keys.SenderDisplayName;
|
import static io.kamax.mxisd.http.io.identity.StoreInviteRequest.Keys.SenderDisplayName;
|
||||||
@@ -46,6 +46,10 @@ public abstract class PlaceholderNotificationGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String populateForCommon(ThreePid recipient, String input) {
|
protected String populateForCommon(ThreePid recipient, String input) {
|
||||||
|
if (StringUtils.isBlank(input)) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
String domainPretty = WordUtils.capitalizeFully(mxCfg.getDomain());
|
String domainPretty = WordUtils.capitalizeFully(mxCfg.getDomain());
|
||||||
|
|
||||||
return input
|
return input
|
||||||
@@ -56,6 +60,10 @@ public abstract class PlaceholderNotificationGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String populateForInvite(IMatrixIdInvite invite, String input) {
|
protected String populateForInvite(IMatrixIdInvite invite, String input) {
|
||||||
|
if (StringUtils.isBlank(input)) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
String senderName = invite.getProperties().getOrDefault(SenderDisplayName, "");
|
String senderName = invite.getProperties().getOrDefault(SenderDisplayName, "");
|
||||||
String senderNameOrId = StringUtils.defaultIfBlank(senderName, invite.getSender().getId());
|
String senderNameOrId = StringUtils.defaultIfBlank(senderName, invite.getSender().getId());
|
||||||
String roomName = invite.getProperties().getOrDefault(RoomName, "");
|
String roomName = invite.getProperties().getOrDefault(RoomName, "");
|
||||||
@@ -72,6 +80,10 @@ public abstract class PlaceholderNotificationGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String populateForReply(IThreePidInviteReply invite, String input) {
|
protected String populateForReply(IThreePidInviteReply invite, String input) {
|
||||||
|
if (StringUtils.isBlank(input)) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
ThreePid tpid = new ThreePid(invite.getInvite().getMedium(), invite.getInvite().getAddress());
|
ThreePid tpid = new ThreePid(invite.getInvite().getMedium(), invite.getInvite().getAddress());
|
||||||
|
|
||||||
String senderName = invite.getInvite().getProperties().getOrDefault(SenderDisplayName, "");
|
String senderName = invite.getInvite().getProperties().getOrDefault(SenderDisplayName, "");
|
||||||
@@ -93,6 +105,10 @@ public abstract class PlaceholderNotificationGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String populateForValidation(IThreePidSession session, String input) {
|
protected String populateForValidation(IThreePidSession session, String input) {
|
||||||
|
if (StringUtils.isBlank(input)) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
String validationLink = srvCfg.getPublicUrl() + IsAPIv1.getValidate(
|
String validationLink = srvCfg.getPublicUrl() + IsAPIv1.getValidate(
|
||||||
session.getThreePid().getMedium(),
|
session.getThreePid().getMedium(),
|
||||||
session.getId(),
|
session.getId(),
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import io.kamax.mxisd.notification.NotificationHandler;
|
|||||||
import io.kamax.mxisd.threepid.generator.PlaceholderNotificationGenerator;
|
import io.kamax.mxisd.threepid.generator.PlaceholderNotificationGenerator;
|
||||||
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
||||||
import io.kamax.mxisd.util.FileUtil;
|
import io.kamax.mxisd.util.FileUtil;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -86,6 +86,9 @@ public class EmailSendGridNotificationHandler extends PlaceholderNotificationGen
|
|||||||
@Override
|
@Override
|
||||||
public void sendForInvite(IMatrixIdInvite invite) {
|
public void sendForInvite(IMatrixIdInvite invite) {
|
||||||
EmailTemplate template = cfg.getTemplates().getGeneric().get("matrixId");
|
EmailTemplate template = cfg.getTemplates().getGeneric().get("matrixId");
|
||||||
|
if (StringUtils.isAllBlank(template.getBody().getText(), template.getBody().getHtml())) {
|
||||||
|
throw new FeatureNotAvailable("No template has been configured for Matrix ID invite notifications");
|
||||||
|
}
|
||||||
|
|
||||||
Email email = getEmail();
|
Email email = getEmail();
|
||||||
email.setSubject(populateForInvite(invite, template.getSubject()));
|
email.setSubject(populateForInvite(invite, template.getSubject()));
|
||||||
@@ -98,6 +101,10 @@ public class EmailSendGridNotificationHandler extends PlaceholderNotificationGen
|
|||||||
@Override
|
@Override
|
||||||
public void sendForReply(IThreePidInviteReply invite) {
|
public void sendForReply(IThreePidInviteReply invite) {
|
||||||
EmailTemplate template = cfg.getTemplates().getInvite();
|
EmailTemplate template = cfg.getTemplates().getInvite();
|
||||||
|
if (StringUtils.isAllBlank(template.getBody().getText(), template.getBody().getHtml())) {
|
||||||
|
throw new FeatureNotAvailable("No template has been configured for 3PID invite notifications");
|
||||||
|
}
|
||||||
|
|
||||||
Email email = getEmail();
|
Email email = getEmail();
|
||||||
email.setSubject(populateForReply(invite, template.getSubject()));
|
email.setSubject(populateForReply(invite, template.getSubject()));
|
||||||
email.setText(populateForReply(invite, getFromFile(template.getBody().getText())));
|
email.setText(populateForReply(invite, getFromFile(template.getBody().getText())));
|
||||||
@@ -109,6 +116,10 @@ public class EmailSendGridNotificationHandler extends PlaceholderNotificationGen
|
|||||||
@Override
|
@Override
|
||||||
public void sendForValidation(IThreePidSession session) {
|
public void sendForValidation(IThreePidSession session) {
|
||||||
EmailTemplate template = cfg.getTemplates().getSession().getValidation();
|
EmailTemplate template = cfg.getTemplates().getSession().getValidation();
|
||||||
|
if (StringUtils.isAllBlank(template.getBody().getText(), template.getBody().getHtml())) {
|
||||||
|
throw new FeatureNotAvailable("No template has been configured for validation notifications");
|
||||||
|
}
|
||||||
|
|
||||||
Email email = getEmail();
|
Email email = getEmail();
|
||||||
email.setSubject(populateForValidation(session, template.getSubject()));
|
email.setSubject(populateForValidation(session, template.getSubject()));
|
||||||
email.setText(populateForValidation(session, getFromFile(template.getBody().getText())));
|
email.setText(populateForValidation(session, getFromFile(template.getBody().getText())));
|
||||||
@@ -120,6 +131,10 @@ public class EmailSendGridNotificationHandler extends PlaceholderNotificationGen
|
|||||||
@Override
|
@Override
|
||||||
public void sendForFraudulentUnbind(ThreePid tpid) {
|
public void sendForFraudulentUnbind(ThreePid tpid) {
|
||||||
EmailTemplate template = cfg.getTemplates().getSession().getUnbind().getFraudulent();
|
EmailTemplate template = cfg.getTemplates().getSession().getUnbind().getFraudulent();
|
||||||
|
if (StringUtils.isAllBlank(template.getBody().getText(), template.getBody().getHtml())) {
|
||||||
|
throw new FeatureNotAvailable("No template has been configured for fraudulent unbind notifications");
|
||||||
|
}
|
||||||
|
|
||||||
Email email = getEmail();
|
Email email = getEmail();
|
||||||
email.setSubject(populateForCommon(tpid, template.getSubject()));
|
email.setSubject(populateForCommon(tpid, template.getSubject()));
|
||||||
email.setText(populateForCommon(tpid, getFromFile(template.getBody().getText())));
|
email.setText(populateForCommon(tpid, getFromFile(template.getBody().getText())));
|
||||||
|
|||||||
Reference in New Issue
Block a user