Add sendemail.enable to disable email output
Some installations might be unable to connect to a SMTP relay, but are still useful through the web page UI, provided that reviewers check their dashboard periodically. In such cases we can't open a socket to a SMTP server, so we should bypass any email sending code paths to prevent errors from filling up the server logs. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -372,6 +372,13 @@ By default, false, as not all instances will deploy repo.
|
||||
Section sendemail
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
sendemail.enable::
|
||||
+
|
||||
If false Gerrit will not send email messages, for any reason,
|
||||
and all other properties of section sendemail are ignored.
|
||||
+
|
||||
By default, true, allowing notifications to be sent.
|
||||
|
||||
sendemail.smtpServer::
|
||||
+
|
||||
Hostname (or IP address) of a SMTP server that will relay
|
||||
|
||||
@@ -137,7 +137,9 @@ class ContactPanel extends Composite {
|
||||
});
|
||||
final FlowPanel emailLine = new FlowPanel();
|
||||
emailLine.add(emailPick);
|
||||
emailLine.add(registerNewEmail);
|
||||
if (Common.getGerritConfig().isAllowRegisterNewEmail()) {
|
||||
emailLine.add(registerNewEmail);
|
||||
}
|
||||
|
||||
row(infoPlainText, 0, Util.C.contactFieldFullName(), nameTxt);
|
||||
row(infoPlainText, 1, Util.C.contactFieldEmail(), emailLine);
|
||||
@@ -261,8 +263,10 @@ class ContactPanel extends Composite {
|
||||
if (emailPick.getItemCount() > 0) {
|
||||
emailPick.setVisible(true);
|
||||
emailPick.setEnabled(true);
|
||||
emailPick.addItem("... " + Util.C.buttonOpenRegisterNewEmail() + " ",
|
||||
Util.C.buttonOpenRegisterNewEmail());
|
||||
if (Common.getGerritConfig().isAllowRegisterNewEmail()) {
|
||||
final String t = Util.C.buttonOpenRegisterNewEmail();
|
||||
emailPick.addItem("... " + t + " ", t);
|
||||
}
|
||||
} else {
|
||||
emailPick.setVisible(false);
|
||||
}
|
||||
@@ -299,6 +303,10 @@ class ContactPanel extends Composite {
|
||||
}
|
||||
|
||||
private void doRegisterNewEmail() {
|
||||
if (!Common.getGerritConfig().isAllowRegisterNewEmail()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final AutoCenterDialogBox box = new AutoCenterDialogBox(true, true);
|
||||
final VerticalPanel body = new VerticalPanel();
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ public class GerritConfig implements Cloneable {
|
||||
protected List<ApprovalType> actionTypes;
|
||||
protected boolean useContributorAgreements;
|
||||
protected boolean useContactInfo;
|
||||
protected boolean allowRegisterNewEmail;
|
||||
protected SystemConfig.LoginType loginType;
|
||||
protected boolean useRepoDownload;
|
||||
protected String gitDaemonUrl;
|
||||
@@ -110,6 +111,14 @@ public class GerritConfig implements Cloneable {
|
||||
useContactInfo = r;
|
||||
}
|
||||
|
||||
public boolean isAllowRegisterNewEmail() {
|
||||
return allowRegisterNewEmail;
|
||||
}
|
||||
|
||||
public void setAllowRegisterNewEmail(final boolean r) {
|
||||
allowRegisterNewEmail = r;
|
||||
}
|
||||
|
||||
public ApprovalType getApprovalType(final ApprovalCategory.Id id) {
|
||||
if (byCategoryId == null) {
|
||||
byCategoryId = new HashMap<ApprovalCategory.Id, ApprovalType>();
|
||||
|
||||
@@ -678,6 +678,7 @@ public class GerritServer {
|
||||
r.setUseRepoDownload(getGerritConfig().getBoolean("repo", null,
|
||||
"showdownloadcommand", false));
|
||||
r.setUseContactInfo(getContactStoreURL() != null);
|
||||
r.setAllowRegisterNewEmail(isOutgoingMailEnabled());
|
||||
r.setLoginType(getLoginType());
|
||||
|
||||
final String gitwebUrl = getGerritConfig().getString("gitweb", null, "url");
|
||||
@@ -693,7 +694,15 @@ public class GerritServer {
|
||||
Common.setGerritConfig(r);
|
||||
}
|
||||
|
||||
public boolean isOutgoingMailEnabled() {
|
||||
return getGerritConfig().getBoolean("sendemail", null, "enable", true);
|
||||
}
|
||||
|
||||
public SMTPClient createOutgoingMail() throws EmailException {
|
||||
if (!isOutgoingMailEnabled()) {
|
||||
throw new EmailException("Sending email is disabled");
|
||||
}
|
||||
|
||||
final RepositoryConfig cfg = getGerritConfig();
|
||||
String smtpHost = cfg.getString("sendemail", null, "smtpserver");
|
||||
if (smtpHost == null) {
|
||||
|
||||
@@ -112,6 +112,12 @@ public abstract class OutgoingEmail {
|
||||
* @throws EmailException
|
||||
*/
|
||||
public void send() throws EmailException {
|
||||
if (!server.isOutgoingMailEnabled()) {
|
||||
// Server has explicitly disabled email sending.
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
init();
|
||||
format();
|
||||
if (shouldSendMessage()) {
|
||||
|
||||
Reference in New Issue
Block a user