Move sendemail.allowRegisterNewEmail to auth.allowRegisterNewEmail

The sendemail section of the configuration is for settings related to how
Gerrit sends emails to users. allowRegisterEmail controls whether or not
users are allowed to register a new email address, which is not related
to Gerrit's sending of email.

Move the setting to the auth section, which is a more appropriate place
for it.

Change-Id: I06d9c4870060eb85bc4a05b536645d42df44e041
This commit is contained in:
David Pursehouse
2015-11-27 00:15:42 +09:00
parent d4b57bea6a
commit 21bd07bc97
5 changed files with 19 additions and 22 deletions

View File

@@ -482,6 +482,16 @@ editing gerrit.config and restarting the server.
+
Default is true.
[[auth.allowRegisterNewEmail]]auth.allowRegisterNewEmail::
+
Whether users are allowed to register new email addresses.
+
In addition for the HTTP authentication type
link:#auth.httpemailheader[auth.httpemailheader] must *not* be set to
enable registration of new email addresses.
+
By default, true.
[[cache]]
=== Section cache
@@ -3154,16 +3164,6 @@ and all other properties of section sendemail are ignored.
+
By default, true, allowing notifications to be sent.
[[sendemail.allowRegisterNewEmail]]sendemail.allowRegisterNewEmail::
+
Whether users are allowed to register new email addresses.
+
In addition for the HTTP authentication type
link:#auth.httpemailheader[auth.httpemailheader] must *not* be set to
enable registration of new email addresses.
+
By default, true.
[[sendemail.connectTimeout]]sendemail.connectTimeout::
+
The connection timeout of opening a socket connected to a

View File

@@ -19,7 +19,6 @@ import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gerrit.server.mail.EmailSettings;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -28,17 +27,14 @@ import java.util.Set;
@Singleton
public class DefaultRealm extends AbstractRealm {
private final EmailExpander emailExpander;
private final EmailSettings emailSettings;
private final AccountByEmailCache byEmail;
private final AuthConfig authConfig;
@Inject
DefaultRealm(EmailExpander emailExpander,
EmailSettings emailSettings,
AccountByEmailCache byEmail,
AuthConfig authConfig) {
this.emailExpander = emailExpander;
this.emailSettings = emailSettings;
this.byEmail = byEmail;
this.authConfig = authConfig;
}
@@ -52,7 +48,7 @@ public class DefaultRealm extends AbstractRealm {
case FULL_NAME:
return Strings.emptyToNull(authConfig.getHttpDisplaynameHeader()) == null;
case REGISTER_NEW_EMAIL:
return emailSettings.allowRegisterNewEmail
return authConfig.isAllowRegisterNewEmail()
&& Strings.emptyToNull(authConfig.getHttpEmailHeader()) == null;
default:
return true;
@@ -60,7 +56,7 @@ public class DefaultRealm extends AbstractRealm {
} else {
switch (field) {
case REGISTER_NEW_EMAIL:
return emailSettings.allowRegisterNewEmail;
return authConfig.isAllowRegisterNewEmail();
default:
return true;
}

View File

@@ -33,7 +33,6 @@ import com.google.gerrit.server.account.EmailExpander;
import com.google.gerrit.server.auth.AuthenticationUnavailableException;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.mail.EmailSettings;
import com.google.gwtorm.server.SchemaFactory;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -79,7 +78,6 @@ public class LdapRealm extends AbstractRealm {
Helper helper,
AuthConfig authConfig,
EmailExpander emailExpander,
EmailSettings emailSettings,
@Named(LdapModule.GROUP_CACHE) final LoadingCache<String, Set<AccountGroup.UUID>> membershipCache,
@Named(LdapModule.USERNAME_CACHE) final LoadingCache<String, Optional<Account.Id>> usernameCache,
@GerritServerConfig final Config config) {
@@ -98,7 +96,7 @@ public class LdapRealm extends AbstractRealm {
if (optdef(config, "accountSshUserName", "DEFAULT") != null) {
readOnlyAccountFields.add(Account.FieldName.USER_NAME);
}
if (!emailSettings.allowRegisterNewEmail) {
if (!authConfig.isAllowRegisterNewEmail()) {
readOnlyAccountFields.add(Account.FieldName.REGISTER_NEW_EMAIL);
}

View File

@@ -60,6 +60,7 @@ public class AuthConfig {
private final String cookiePath;
private final boolean cookieSecure;
private final SignedToken emailReg;
private final boolean allowRegisterNewEmail;
@Inject
AuthConfig(@GerritServerConfig final Config cfg)
@@ -90,7 +91,7 @@ public class AuthConfig {
useContributorAgreements =
cfg.getBoolean("auth", "contributoragreements", false);
userNameToLowerCase = cfg.getBoolean("auth", "userNameToLowerCase", false);
allowRegisterNewEmail = cfg.getBoolean("auth", "allowRegisterNewEmail", true);
String key = cfg.getString("auth", null, "registerEmailPrivateKey");
if (key != null && !key.isEmpty()) {
@@ -297,4 +298,8 @@ public class AuthConfig {
return authType == AuthType.LDAP ||
authType == AuthType.LDAP_BIND;
}
public boolean isAllowRegisterNewEmail() {
return allowRegisterNewEmail;
}
}

View File

@@ -22,13 +22,11 @@ import org.eclipse.jgit.lib.Config;
@Singleton
public class EmailSettings {
public final boolean allowRegisterNewEmail;
public final boolean includeDiff;
public final int maximumDiffSize;
@Inject
EmailSettings(@GerritServerConfig Config cfg) {
allowRegisterNewEmail = cfg.getBoolean("sendemail", "allowRegisterNewEmail", true);
includeDiff = cfg.getBoolean("sendemail", "includeDiff", false);
maximumDiffSize = cfg.getInt("sendemail", "maximumDiffSize", 256 << 10);
}