Make 'Anonymous Coward' configurable
Make the username that is displayed for users that haven't set a full name configurable. 'Anonymous Coward' that was hard-coded in Gerrit before was seen by some users as unprofessional and insulting. This is why for corporate environments it makes sense to configure another name. Signed-off-by: Edwin Kempin <edwin.kempin@sap.com> Change-Id: Ib2edee2af342b17df676e87cef99f92448895abe
This commit is contained in:
@@ -2068,6 +2068,13 @@ If not set, Gerrit generates this as "gerrit@`hostname`", where
|
||||
+
|
||||
By default, not set, generating the value at startup.
|
||||
|
||||
[[user.anonymousCoward]]user.anonymousCoward::
|
||||
+
|
||||
Username that this displayed in the Gerrit WebUI and in e-mail
|
||||
notifications if the full name of the user is not set.
|
||||
+
|
||||
By default "Anonymous Coward" is used.
|
||||
|
||||
|
||||
File `etc/secure.config`
|
||||
-------------------------
|
||||
|
@@ -42,6 +42,7 @@ public class GerritConfig implements Cloneable {
|
||||
protected List<RegexFindReplace> commentLinks;
|
||||
protected boolean documentationAvailable;
|
||||
protected boolean testChangeMerge;
|
||||
protected String anonymousCowardName;
|
||||
|
||||
public String getRegisterUrl() {
|
||||
return registerUrl;
|
||||
@@ -169,4 +170,12 @@ public class GerritConfig implements Cloneable {
|
||||
public void setTestChangeMerge(final boolean test) {
|
||||
testChangeMerge = test;
|
||||
}
|
||||
|
||||
public String getAnonymousCowardName() {
|
||||
return anonymousCowardName;
|
||||
}
|
||||
|
||||
public void setAnonymousCowardName(final String anonymousCowardName) {
|
||||
this.anonymousCowardName = anonymousCowardName;
|
||||
}
|
||||
}
|
||||
|
@@ -109,7 +109,7 @@ public class FormatUtil {
|
||||
public static String nameEmail(final AccountInfo acct) {
|
||||
String name = acct.getFullName();
|
||||
if (name == null) {
|
||||
name = Gerrit.C.anonymousCoward();
|
||||
name = Gerrit.getConfig().getAnonymousCowardName();
|
||||
}
|
||||
|
||||
final StringBuilder b = new StringBuilder();
|
||||
|
@@ -82,7 +82,6 @@ public interface GerritConstants extends Constants {
|
||||
String searchButton();
|
||||
|
||||
String rpcStatusLoading();
|
||||
String anonymousCoward();
|
||||
|
||||
String sectionNavigation();
|
||||
String sectionActions();
|
||||
|
@@ -65,7 +65,6 @@ searchHint = Change #, SHA-1, tr:id, owner:email or reviewer:email
|
||||
searchButton = Search
|
||||
|
||||
rpcStatusLoading = Loading ...
|
||||
anonymousCoward = Anonymous Coward
|
||||
|
||||
sectionNavigation = Navigation
|
||||
sectionActions = Actions
|
||||
|
@@ -20,6 +20,7 @@ import com.google.gerrit.common.data.GitwebLink;
|
||||
import com.google.gerrit.reviewdb.Account;
|
||||
import com.google.gerrit.server.account.Realm;
|
||||
import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.gerrit.server.config.AuthConfig;
|
||||
import com.google.gerrit.server.config.DownloadSchemeConfig;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
@@ -56,13 +57,14 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
||||
private EmailSender emailSender;
|
||||
private final ContactStore contactStore;
|
||||
private final ServletContext servletContext;
|
||||
private final String anonymousCowardName;
|
||||
|
||||
@Inject
|
||||
GerritConfigProvider(final Realm r, @GerritServerConfig final Config gsc,
|
||||
final AuthConfig ac, final GitWebConfig gwc,
|
||||
final AllProjectsName wp, final SshInfo si,
|
||||
final ApprovalTypes at, final ContactStore cs, final ServletContext sc,
|
||||
final DownloadSchemeConfig dc) {
|
||||
final AuthConfig ac, final GitWebConfig gwc, final AllProjectsName wp,
|
||||
final SshInfo si, final ApprovalTypes at, final ContactStore cs,
|
||||
final ServletContext sc, final DownloadSchemeConfig dc,
|
||||
final @AnonymousCowardName String acn) {
|
||||
realm = r;
|
||||
cfg = gsc;
|
||||
authConfig = ac;
|
||||
@@ -73,6 +75,7 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
||||
approvalTypes = at;
|
||||
contactStore = cs;
|
||||
servletContext = sc;
|
||||
anonymousCowardName = acn;
|
||||
}
|
||||
|
||||
@Inject(optional = true)
|
||||
@@ -104,6 +107,7 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
||||
.getResource("/Documentation/index.html") != null);
|
||||
config.setTestChangeMerge(cfg.getBoolean("changeMerge",
|
||||
"test", false));
|
||||
config.setAnonymousCowardName(anonymousCowardName);
|
||||
|
||||
final Set<Account.FieldName> fields = new HashSet<Account.FieldName>();
|
||||
for (final Account.FieldName n : Account.FieldName.values()) {
|
||||
|
@@ -27,6 +27,7 @@ import com.google.gerrit.reviewdb.Project;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.server.events.ApprovalAttribute;
|
||||
@@ -107,6 +108,8 @@ public class ChangeHookRunner {
|
||||
/** Filename of the cla signed hook. */
|
||||
private final File claSignedHook;
|
||||
|
||||
private final String anonymousCowardName;
|
||||
|
||||
/** Repository Manager. */
|
||||
private final GitRepositoryManager repoManager;
|
||||
|
||||
@@ -133,11 +136,12 @@ public class ChangeHookRunner {
|
||||
@Inject
|
||||
public ChangeHookRunner(final WorkQueue queue,
|
||||
final GitRepositoryManager repoManager,
|
||||
@GerritServerConfig final Config config, final SitePaths sitePath,
|
||||
final ProjectCache projectCache,
|
||||
final AccountCache accountCache,
|
||||
final ApprovalTypes approvalTypes,
|
||||
final @GerritServerConfig Config config,
|
||||
final @AnonymousCowardName String anonymousCowardName,
|
||||
final SitePaths sitePath, final ProjectCache projectCache,
|
||||
final AccountCache accountCache, final ApprovalTypes approvalTypes,
|
||||
final EventFactory eventFactory) {
|
||||
this.anonymousCowardName = anonymousCowardName;
|
||||
this.repoManager = repoManager;
|
||||
this.hookQueue = queue.createQueue(1, "hook");
|
||||
this.projectCache = projectCache;
|
||||
@@ -465,14 +469,14 @@ public class ChangeHookRunner {
|
||||
*/
|
||||
private String getDisplayName(final Account account) {
|
||||
if (account != null) {
|
||||
String result = (account.getFullName() == null) ? "Anonymous Coward" : account.getFullName();
|
||||
String result = (account.getFullName() == null) ? anonymousCowardName : account.getFullName();
|
||||
if (account.getPreferredEmail() != null) {
|
||||
result += " (" + account.getPreferredEmail() + ")";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return "Anonymous Coward";
|
||||
return anonymousCowardName;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -26,6 +26,7 @@ import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.account.CapabilityControl;
|
||||
import com.google.gerrit.server.account.GroupIncludeCache;
|
||||
import com.google.gerrit.server.account.Realm;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.gerrit.server.config.AuthConfig;
|
||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
@@ -66,6 +67,7 @@ public class IdentifiedUser extends CurrentUser {
|
||||
public static class GenericFactory {
|
||||
private final CapabilityControl.Factory capabilityControlFactory;
|
||||
private final AuthConfig authConfig;
|
||||
private final String anonymousCowardName;
|
||||
private final Provider<String> canonicalUrl;
|
||||
private final Realm realm;
|
||||
private final AccountCache accountCache;
|
||||
@@ -75,11 +77,13 @@ public class IdentifiedUser extends CurrentUser {
|
||||
GenericFactory(
|
||||
CapabilityControl.Factory capabilityControlFactory,
|
||||
final AuthConfig authConfig,
|
||||
final @AnonymousCowardName String anonymousCowardName,
|
||||
final @CanonicalWebUrl Provider<String> canonicalUrl,
|
||||
final Realm realm, final AccountCache accountCache,
|
||||
final GroupIncludeCache groupIncludeCache) {
|
||||
this.capabilityControlFactory = capabilityControlFactory;
|
||||
this.authConfig = authConfig;
|
||||
this.anonymousCowardName = anonymousCowardName;
|
||||
this.canonicalUrl = canonicalUrl;
|
||||
this.realm = realm;
|
||||
this.accountCache = accountCache;
|
||||
@@ -92,15 +96,15 @@ public class IdentifiedUser extends CurrentUser {
|
||||
|
||||
public IdentifiedUser create(Provider<ReviewDb> db, Account.Id id) {
|
||||
return new IdentifiedUser(capabilityControlFactory, AccessPath.UNKNOWN,
|
||||
authConfig, canonicalUrl, realm, accountCache, groupIncludeCache,
|
||||
null, db, id);
|
||||
authConfig, anonymousCowardName, canonicalUrl, realm, accountCache,
|
||||
groupIncludeCache, null, db, id);
|
||||
}
|
||||
|
||||
public IdentifiedUser create(AccessPath accessPath,
|
||||
Provider<SocketAddress> remotePeerProvider, Account.Id id) {
|
||||
return new IdentifiedUser(capabilityControlFactory, accessPath,
|
||||
authConfig, canonicalUrl, realm, accountCache, groupIncludeCache,
|
||||
remotePeerProvider, null, id);
|
||||
authConfig, anonymousCowardName, canonicalUrl, realm, accountCache,
|
||||
groupIncludeCache, remotePeerProvider, null, id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +118,7 @@ public class IdentifiedUser extends CurrentUser {
|
||||
public static class RequestFactory {
|
||||
private final CapabilityControl.Factory capabilityControlFactory;
|
||||
private final AuthConfig authConfig;
|
||||
private final String anonymousCowardName;
|
||||
private final Provider<String> canonicalUrl;
|
||||
private final Realm realm;
|
||||
private final AccountCache accountCache;
|
||||
@@ -126,6 +131,7 @@ public class IdentifiedUser extends CurrentUser {
|
||||
RequestFactory(
|
||||
CapabilityControl.Factory capabilityControlFactory,
|
||||
final AuthConfig authConfig,
|
||||
final @AnonymousCowardName String anonymousCowardName,
|
||||
final @CanonicalWebUrl Provider<String> canonicalUrl,
|
||||
final Realm realm, final AccountCache accountCache,
|
||||
final GroupIncludeCache groupIncludeCache,
|
||||
@@ -134,6 +140,7 @@ public class IdentifiedUser extends CurrentUser {
|
||||
final Provider<ReviewDb> dbProvider) {
|
||||
this.capabilityControlFactory = capabilityControlFactory;
|
||||
this.authConfig = authConfig;
|
||||
this.anonymousCowardName = anonymousCowardName;
|
||||
this.canonicalUrl = canonicalUrl;
|
||||
this.realm = realm;
|
||||
this.accountCache = accountCache;
|
||||
@@ -146,8 +153,8 @@ public class IdentifiedUser extends CurrentUser {
|
||||
public IdentifiedUser create(final AccessPath accessPath,
|
||||
final Account.Id id) {
|
||||
return new IdentifiedUser(capabilityControlFactory, accessPath,
|
||||
authConfig, canonicalUrl, realm, accountCache, groupIncludeCache,
|
||||
remotePeerProvider, dbProvider, id);
|
||||
authConfig, anonymousCowardName, canonicalUrl, realm, accountCache,
|
||||
groupIncludeCache, remotePeerProvider, dbProvider, id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,6 +188,7 @@ public class IdentifiedUser extends CurrentUser {
|
||||
private final AccountCache accountCache;
|
||||
private final GroupIncludeCache groupIncludeCache;
|
||||
private final AuthConfig authConfig;
|
||||
private final String anonymousCowardName;
|
||||
|
||||
@Nullable
|
||||
private final Provider<SocketAddress> remotePeerProvider;
|
||||
@@ -199,7 +207,9 @@ public class IdentifiedUser extends CurrentUser {
|
||||
private IdentifiedUser(
|
||||
CapabilityControl.Factory capabilityControlFactory,
|
||||
final AccessPath accessPath,
|
||||
final AuthConfig authConfig, final Provider<String> canonicalUrl,
|
||||
final AuthConfig authConfig,
|
||||
final String anonymousCowardName,
|
||||
final Provider<String> canonicalUrl,
|
||||
final Realm realm, final AccountCache accountCache,
|
||||
final GroupIncludeCache groupIncludeCache,
|
||||
@Nullable final Provider<SocketAddress> remotePeerProvider,
|
||||
@@ -210,6 +220,7 @@ public class IdentifiedUser extends CurrentUser {
|
||||
this.accountCache = accountCache;
|
||||
this.groupIncludeCache = groupIncludeCache;
|
||||
this.authConfig = authConfig;
|
||||
this.anonymousCowardName = anonymousCowardName;
|
||||
this.remotePeerProvider = remotePeerProvider;
|
||||
this.dbProvider = dbProvider;
|
||||
this.accountId = id;
|
||||
@@ -343,7 +354,7 @@ public class IdentifiedUser extends CurrentUser {
|
||||
name = ua.getPreferredEmail();
|
||||
}
|
||||
if (name == null || name.isEmpty()) {
|
||||
name = "Anonymous Coward";
|
||||
name = anonymousCowardName;
|
||||
}
|
||||
|
||||
String user = getUserName();
|
||||
@@ -403,7 +414,7 @@ public class IdentifiedUser extends CurrentUser {
|
||||
if (0 < at) {
|
||||
name = email.substring(0, at);
|
||||
} else {
|
||||
name = "Anonymous Coward";
|
||||
name = anonymousCowardName;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2011 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.config;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import com.google.inject.BindingAnnotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
|
||||
/** Special name for a user that hasn't set a name. */
|
||||
@Retention(RUNTIME)
|
||||
@BindingAnnotation
|
||||
public @interface AnonymousCowardName {
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2011 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server.config;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
public class AnonymousCowardNameProvider implements Provider<String> {
|
||||
|
||||
private final String anonymousCoward;
|
||||
|
||||
@Inject
|
||||
public AnonymousCowardNameProvider(@GerritServerConfig final Config cfg) {
|
||||
String anonymousCoward = cfg.getString("user", null, "anonymousCoward");
|
||||
if (anonymousCoward == null) {
|
||||
anonymousCoward = "Anonymous Coward";
|
||||
}
|
||||
this.anonymousCoward = anonymousCoward;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return anonymousCoward;
|
||||
}
|
||||
}
|
@@ -24,6 +24,7 @@ import com.google.gerrit.reviewdb.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.server.GerritPersonIdent;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.ResultSet;
|
||||
@@ -76,6 +77,7 @@ public class CreateCodeReviewNotes {
|
||||
private final AccountCache accountCache;
|
||||
private final ApprovalTypes approvalTypes;
|
||||
private final String canonicalWebUrl;
|
||||
private final String anonymousCowardName;
|
||||
private final Repository db;
|
||||
private final RevWalk revWalk;
|
||||
private final ObjectInserter inserter;
|
||||
@@ -95,15 +97,17 @@ public class CreateCodeReviewNotes {
|
||||
@GerritPersonIdent final PersonIdent gerritIdent,
|
||||
final AccountCache accountCache,
|
||||
final ApprovalTypes approvalTypes,
|
||||
@Nullable @CanonicalWebUrl final String canonicalWebUrl,
|
||||
@Assisted ReviewDb reviewDb,
|
||||
@Assisted final Repository db) {
|
||||
final @Nullable @CanonicalWebUrl String canonicalWebUrl,
|
||||
final @AnonymousCowardName String anonymousCowardName,
|
||||
final @Assisted ReviewDb reviewDb,
|
||||
final @Assisted Repository db) {
|
||||
schema = reviewDb;
|
||||
this.author = gerritIdent;
|
||||
this.gerritIdent = gerritIdent;
|
||||
this.accountCache = accountCache;
|
||||
this.approvalTypes = approvalTypes;
|
||||
this.canonicalWebUrl = canonicalWebUrl;
|
||||
this.anonymousCowardName = anonymousCowardName;
|
||||
this.db = db;
|
||||
|
||||
revWalk = new RevWalk(db);
|
||||
@@ -185,7 +189,8 @@ public class CreateCodeReviewNotes {
|
||||
throws CodeReviewNoteCreationException, IOException {
|
||||
try {
|
||||
ReviewNoteHeaderFormatter formatter =
|
||||
new ReviewNoteHeaderFormatter(author.getTimeZone());
|
||||
new ReviewNoteHeaderFormatter(author.getTimeZone(),
|
||||
anonymousCowardName);
|
||||
final List<String> idList = commit.getFooterLines(CHANGE_ID);
|
||||
if (idList.isEmpty())
|
||||
formatter.appendChangeId(change.getKey());
|
||||
|
@@ -37,12 +37,14 @@ import java.util.TimeZone;
|
||||
class ReviewNoteHeaderFormatter {
|
||||
|
||||
private final DateFormat rfc2822DateFormatter;
|
||||
private final String anonymousCowardName;
|
||||
private final StringBuilder sb = new StringBuilder();
|
||||
|
||||
ReviewNoteHeaderFormatter(TimeZone tz) {
|
||||
ReviewNoteHeaderFormatter(TimeZone tz, String anonymousCowardName) {
|
||||
rfc2822DateFormatter =
|
||||
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
|
||||
rfc2822DateFormatter.setCalendar(Calendar.getInstance(tz, Locale.US));
|
||||
this.anonymousCowardName = anonymousCowardName;
|
||||
}
|
||||
|
||||
void appendChangeId(Change.Key changeKey) {
|
||||
@@ -76,7 +78,7 @@ class ReviewNoteHeaderFormatter {
|
||||
}
|
||||
|
||||
if (!wroteData) {
|
||||
sb.append("Anonymous Coward #").append(user.getId());
|
||||
sb.append(anonymousCowardName).append(" #").append(user.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.mail;
|
||||
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
@@ -26,8 +27,9 @@ public class AbandonedSender extends ReplyToChangeSender {
|
||||
}
|
||||
|
||||
@Inject
|
||||
public AbandonedSender(EmailArguments ea, @Assisted Change c) {
|
||||
super(ea, c, "abandon");
|
||||
public AbandonedSender(EmailArguments ea,
|
||||
@AnonymousCowardName String anonymousCowardName, @Assisted Change c) {
|
||||
super(ea, anonymousCowardName, c, "abandon");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.mail;
|
||||
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.gerrit.server.ssh.SshInfo;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
@@ -26,9 +27,10 @@ public class AddReviewerSender extends NewChangeSender {
|
||||
}
|
||||
|
||||
@Inject
|
||||
public AddReviewerSender(EmailArguments ea, SshInfo sshInfo,
|
||||
public AddReviewerSender(EmailArguments ea,
|
||||
@AnonymousCowardName String anonymousCowardName, SshInfo sshInfo,
|
||||
@Assisted Change c) {
|
||||
super(ea, sshInfo, c);
|
||||
super(ea, anonymousCowardName, sshInfo, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -57,8 +57,9 @@ public abstract class ChangeEmail extends OutgoingEmail {
|
||||
protected Set<Account.Id> authors;
|
||||
protected boolean emailOnlyAuthors;
|
||||
|
||||
protected ChangeEmail(EmailArguments ea, final Change c, final String mc) {
|
||||
super(ea, mc);
|
||||
protected ChangeEmail(EmailArguments ea, final String anonymousCowardName,
|
||||
final Change c, final String mc) {
|
||||
super(ea, anonymousCowardName, mc);
|
||||
change = c;
|
||||
changeData = change != null ? new ChangeData(change) : null;
|
||||
emailOnlyAuthors = false;
|
||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.server.mail;
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
import com.google.gerrit.reviewdb.Patch;
|
||||
import com.google.gerrit.reviewdb.PatchLineComment;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.gerrit.server.patch.PatchFile;
|
||||
import com.google.gerrit.server.patch.PatchList;
|
||||
import com.google.inject.Inject;
|
||||
@@ -41,8 +42,9 @@ public class CommentSender extends ReplyToChangeSender {
|
||||
private List<PatchLineComment> inlineComments = Collections.emptyList();
|
||||
|
||||
@Inject
|
||||
public CommentSender(EmailArguments ea, @Assisted Change c) {
|
||||
super(ea, c, "comment");
|
||||
public CommentSender(EmailArguments ea,
|
||||
@AnonymousCowardName String anonymousCowardName, @Assisted Change c) {
|
||||
super(ea, anonymousCowardName, c, "comment");
|
||||
}
|
||||
|
||||
public void setPatchLineComments(final List<PatchLineComment> plc) {
|
||||
|
@@ -21,6 +21,7 @@ import com.google.gerrit.reviewdb.AccountProjectWatch;
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
import com.google.gerrit.reviewdb.AccountProjectWatch.NotifyType;
|
||||
import com.google.gerrit.server.account.GroupCache;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.gerrit.server.ssh.SshInfo;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
@@ -38,9 +39,10 @@ public class CreateChangeSender extends NewChangeSender {
|
||||
private final GroupCache groupCache;
|
||||
|
||||
@Inject
|
||||
public CreateChangeSender(EmailArguments ea, SshInfo sshInfo,
|
||||
public CreateChangeSender(EmailArguments ea,
|
||||
@AnonymousCowardName String anonymousCowardName, SshInfo sshInfo,
|
||||
GroupCache groupCache, @Assisted Change c) {
|
||||
super(ea, sshInfo, c);
|
||||
super(ea, anonymousCowardName, sshInfo, c);
|
||||
this.groupCache = groupCache;
|
||||
}
|
||||
|
||||
|
@@ -18,6 +18,7 @@ import com.google.gerrit.common.data.ParameterizedString;
|
||||
import com.google.gerrit.reviewdb.Account;
|
||||
import com.google.gerrit.server.GerritPersonIdent;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
@@ -34,6 +35,7 @@ public class FromAddressGeneratorProvider implements
|
||||
|
||||
@Inject
|
||||
FromAddressGeneratorProvider(@GerritServerConfig final Config cfg,
|
||||
final @AnonymousCowardName String anonymousCowardName,
|
||||
@GerritPersonIdent final PersonIdent myIdent,
|
||||
final AccountCache accountCache) {
|
||||
|
||||
@@ -42,7 +44,9 @@ public class FromAddressGeneratorProvider implements
|
||||
|
||||
if (from == null || "MIXED".equalsIgnoreCase(from)) {
|
||||
ParameterizedString name = new ParameterizedString("${user} (Code Review)");
|
||||
generator = new PatternGen(srvAddr, accountCache, name, srvAddr.email);
|
||||
generator =
|
||||
new PatternGen(srvAddr, accountCache, anonymousCowardName, name,
|
||||
srvAddr.email);
|
||||
|
||||
} else if ("USER".equalsIgnoreCase(from)) {
|
||||
generator = new UserGen(accountCache, srvAddr);
|
||||
@@ -56,7 +60,9 @@ public class FromAddressGeneratorProvider implements
|
||||
if (name == null || name.getParameterNames().isEmpty()) {
|
||||
generator = new ServerGen(a);
|
||||
} else {
|
||||
generator = new PatternGen(srvAddr, accountCache, name, a.email);
|
||||
generator =
|
||||
new PatternGen(srvAddr, accountCache, anonymousCowardName, name,
|
||||
a.email);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,13 +124,16 @@ public class FromAddressGeneratorProvider implements
|
||||
private final String senderEmail;
|
||||
private final Address serverAddress;
|
||||
private final AccountCache accountCache;
|
||||
private final String anonymousCowardName;
|
||||
private final ParameterizedString namePattern;
|
||||
|
||||
PatternGen(final Address serverAddress, final AccountCache accountCache,
|
||||
final String anonymousCowardName,
|
||||
final ParameterizedString namePattern, final String senderEmail) {
|
||||
this.senderEmail = senderEmail;
|
||||
this.serverAddress = serverAddress;
|
||||
this.accountCache = accountCache;
|
||||
this.anonymousCowardName = anonymousCowardName;
|
||||
this.namePattern = namePattern;
|
||||
}
|
||||
|
||||
@@ -141,7 +150,7 @@ public class FromAddressGeneratorProvider implements
|
||||
final Account account = accountCache.get(fromId).getAccount();
|
||||
String fullName = account.getFullName();
|
||||
if (fullName == null || "".equals(fullName)) {
|
||||
fullName = "Anonymous Coward";
|
||||
fullName = anonymousCowardName;
|
||||
}
|
||||
senderName = namePattern.replace("user", fullName).toString();
|
||||
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.mail;
|
||||
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
@@ -25,8 +26,9 @@ public class MergeFailSender extends ReplyToChangeSender {
|
||||
}
|
||||
|
||||
@Inject
|
||||
public MergeFailSender(EmailArguments ea, @Assisted Change c) {
|
||||
super(ea, c, "merge-failed");
|
||||
public MergeFailSender(EmailArguments ea,
|
||||
@AnonymousCowardName String anonymousCowardName, @Assisted Change c) {
|
||||
super(ea, anonymousCowardName, c, "merge-failed");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -23,6 +23,7 @@ import com.google.gerrit.reviewdb.ApprovalCategory;
|
||||
import com.google.gerrit.reviewdb.ApprovalCategoryValue;
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
import com.google.gerrit.reviewdb.PatchSetApproval;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
@@ -39,8 +40,10 @@ public class MergedSender extends ReplyToChangeSender {
|
||||
private final ApprovalTypes approvalTypes;
|
||||
|
||||
@Inject
|
||||
public MergedSender(EmailArguments ea, ApprovalTypes at, @Assisted Change c) {
|
||||
super(ea, c, "merged");
|
||||
public MergedSender(EmailArguments ea,
|
||||
@AnonymousCowardName String anonymousCowardName, ApprovalTypes at,
|
||||
@Assisted Change c) {
|
||||
super(ea, anonymousCowardName, c, "merged");
|
||||
approvalTypes = at;
|
||||
}
|
||||
|
||||
|
@@ -32,8 +32,9 @@ public abstract class NewChangeSender extends ChangeEmail {
|
||||
private final Set<Account.Id> reviewers = new HashSet<Account.Id>();
|
||||
private final Set<Account.Id> extraCC = new HashSet<Account.Id>();
|
||||
|
||||
protected NewChangeSender(EmailArguments ea, SshInfo sshInfo, Change c) {
|
||||
super(ea, c, "newchange");
|
||||
protected NewChangeSender(EmailArguments ea, String anonymousCowardName,
|
||||
SshInfo sshInfo, Change c) {
|
||||
super(ea, anonymousCowardName, c, "newchange");
|
||||
this.sshInfo = sshInfo;
|
||||
}
|
||||
|
||||
|
@@ -54,10 +54,14 @@ public abstract class OutgoingEmail {
|
||||
protected VelocityContext velocityContext;
|
||||
|
||||
protected final EmailArguments args;
|
||||
private final String anonymousCowardName;
|
||||
protected Account.Id fromId;
|
||||
|
||||
protected OutgoingEmail(EmailArguments ea, final String mc) {
|
||||
|
||||
protected OutgoingEmail(EmailArguments ea, final String anonymousCowardName,
|
||||
final String mc) {
|
||||
args = ea;
|
||||
this.anonymousCowardName = anonymousCowardName;
|
||||
messageClass = mc;
|
||||
headers = new LinkedHashMap<String, EmailHeader>();
|
||||
}
|
||||
@@ -226,7 +230,7 @@ public abstract class OutgoingEmail {
|
||||
/** Lookup a human readable name for an account, usually the "full name". */
|
||||
protected String getNameFor(final Account.Id accountId) {
|
||||
if (accountId == null) {
|
||||
return "Anonymous Coward";
|
||||
return anonymousCowardName;
|
||||
}
|
||||
|
||||
final Account userAccount = args.accountCache.get(accountId).getAccount();
|
||||
@@ -235,7 +239,7 @@ public abstract class OutgoingEmail {
|
||||
name = userAccount.getPreferredEmail();
|
||||
}
|
||||
if (name == null) {
|
||||
name = "Anonymous Coward #" + accountId;
|
||||
name = anonymousCowardName + " #" + accountId;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
@@ -254,7 +258,7 @@ public abstract class OutgoingEmail {
|
||||
return email;
|
||||
|
||||
} else /* (name == null && email == null) */{
|
||||
return "Anonymous Coward #" + accountId;
|
||||
return anonymousCowardName + " #" + accountId;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.mail;
|
||||
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.gerrit.server.config.AuthConfig;
|
||||
import com.google.gwtjsonrpc.server.XsrfException;
|
||||
import com.google.inject.Inject;
|
||||
@@ -33,8 +34,9 @@ public class RegisterNewEmailSender extends OutgoingEmail {
|
||||
|
||||
@Inject
|
||||
public RegisterNewEmailSender(EmailArguments ea, AuthConfig ac,
|
||||
@AnonymousCowardName String anonymousCowardName,
|
||||
@Assisted final String address) {
|
||||
super(ea, "registernewemail");
|
||||
super(ea, anonymousCowardName, "registernewemail");
|
||||
authConfig = ac;
|
||||
addr = address;
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@ package com.google.gerrit.server.mail;
|
||||
|
||||
import com.google.gerrit.reviewdb.Account;
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.gerrit.server.ssh.SshInfo;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
@@ -39,8 +40,10 @@ public class ReplacePatchSetSender extends ReplyToChangeSender {
|
||||
private final SshInfo sshInfo;
|
||||
|
||||
@Inject
|
||||
public ReplacePatchSetSender(EmailArguments ea, SshInfo si, @Assisted Change c) {
|
||||
super(ea, c, "newpatchset");
|
||||
public ReplacePatchSetSender(EmailArguments ea,
|
||||
@AnonymousCowardName String anonymousCowardName, SshInfo si,
|
||||
@Assisted Change c) {
|
||||
super(ea, anonymousCowardName, c, "newpatchset");
|
||||
sshInfo = si;
|
||||
}
|
||||
|
||||
|
@@ -22,8 +22,9 @@ public abstract class ReplyToChangeSender extends ChangeEmail {
|
||||
public T create(Change change);
|
||||
}
|
||||
|
||||
protected ReplyToChangeSender(EmailArguments ea, Change c, String mc) {
|
||||
super(ea, c, mc);
|
||||
protected ReplyToChangeSender(EmailArguments ea, String anonymousCowardName,
|
||||
Change c, String mc) {
|
||||
super(ea, anonymousCowardName, c, mc);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.mail;
|
||||
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
@@ -26,8 +27,9 @@ public class RestoredSender extends ReplyToChangeSender {
|
||||
}
|
||||
|
||||
@Inject
|
||||
public RestoredSender(EmailArguments ea, @Assisted Change c) {
|
||||
super(ea, c, "restore");
|
||||
public RestoredSender(EmailArguments ea,
|
||||
@AnonymousCowardName String anonymousCowardName, @Assisted Change c) {
|
||||
super(ea, anonymousCowardName, c, "restore");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.mail;
|
||||
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
@@ -25,8 +26,9 @@ public class RevertedSender extends ReplyToChangeSender {
|
||||
}
|
||||
|
||||
@Inject
|
||||
public RevertedSender(EmailArguments ea, @Assisted Change c) {
|
||||
super(ea, c, "revert");
|
||||
public RevertedSender(EmailArguments ea,
|
||||
@AnonymousCowardName String anonymousCowardName, @Assisted Change c) {
|
||||
super(ea, anonymousCowardName, c, "revert");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -21,6 +21,8 @@ import com.google.gerrit.server.GerritPersonIdent;
|
||||
import com.google.gerrit.server.GerritPersonIdentProvider;
|
||||
import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.gerrit.server.config.AllProjectsNameProvider;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.gerrit.server.config.AnonymousCowardNameProvider;
|
||||
import com.google.gerrit.server.config.FactoryModule;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.git.LocalDiskRepositoryManager;
|
||||
@@ -40,6 +42,9 @@ public class SchemaModule extends FactoryModule {
|
||||
.toProvider(AllProjectsNameProvider.class)
|
||||
.in(SINGLETON);
|
||||
|
||||
bind(String.class).annotatedWith(AnonymousCowardName.class).toProvider(
|
||||
AnonymousCowardNameProvider.class);
|
||||
|
||||
bind(GitRepositoryManager.class).to(LocalDiskRepositoryManager.class);
|
||||
install(new LifecycleModule() {
|
||||
@Override
|
||||
|
@@ -47,7 +47,8 @@ public class FromAddressGeneratorProviderTest extends TestCase {
|
||||
}
|
||||
|
||||
private FromAddressGenerator create() {
|
||||
return new FromAddressGeneratorProvider(config, ident, accountCache).get();
|
||||
return new FromAddressGeneratorProvider(config, "Anonymous Coward", ident,
|
||||
accountCache).get();
|
||||
}
|
||||
|
||||
private void setFrom(final String newFrom) {
|
||||
|
Reference in New Issue
Block a user