Add an emailOnlyAuthors property to AccountGroups
When this property is set on a group, actions and comments from members of this group will only cause emails to be sent to change authors. This is particularly useful to quiet actions from automation users. Change-Id: Ibcde6e07045ec00d095028c86e8dd47cef3cf582
This commit is contained in:
@@ -54,11 +54,28 @@ public abstract class ChangeEmail extends OutgoingEmail {
|
||||
|
||||
protected ProjectState projectState;
|
||||
protected ChangeData changeData;
|
||||
protected Set<Account.Id> authors;
|
||||
protected boolean emailOnlyAuthors;
|
||||
|
||||
protected ChangeEmail(EmailArguments ea, final Change c, final String mc) {
|
||||
super(ea, mc);
|
||||
change = c;
|
||||
changeData = change != null ? new ChangeData(change) : null;
|
||||
emailOnlyAuthors = false;
|
||||
}
|
||||
|
||||
public void setFrom(final Account.Id id) {
|
||||
super.setFrom(id);
|
||||
|
||||
/** Is the from user in an email squelching group? */
|
||||
final IdentifiedUser user = args.identifiedUserFactory.create(id);
|
||||
final Set<AccountGroup.Id> gids = user.getEffectiveGroups();
|
||||
for (final AccountGroup.Id gid : gids) {
|
||||
if (args.groupCache.get(gid).isEmailOnlyAuthors()) {
|
||||
emailOnlyAuthors = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setPatchSet(final PatchSet ps) {
|
||||
@@ -123,6 +140,7 @@ public abstract class ChangeEmail extends OutgoingEmail {
|
||||
patchSetInfo = null;
|
||||
}
|
||||
}
|
||||
authors = getAuthors();
|
||||
|
||||
super.init();
|
||||
|
||||
@@ -264,13 +282,8 @@ public abstract class ChangeEmail extends OutgoingEmail {
|
||||
|
||||
/** TO or CC all vested parties (change owner, patch set uploader, author). */
|
||||
protected void rcptToAuthors(final RecipientType rt) {
|
||||
add(rt, change.getOwner());
|
||||
if (patchSet != null) {
|
||||
add(rt, patchSet.getUploader());
|
||||
}
|
||||
if (patchSetInfo != null) {
|
||||
add(rt, patchSetInfo.getAuthor());
|
||||
add(rt, patchSetInfo.getCommitter());
|
||||
for (final Account.Id id : authors) {
|
||||
add(rt, id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,6 +393,12 @@ public abstract class ChangeEmail extends OutgoingEmail {
|
||||
}
|
||||
}
|
||||
|
||||
protected void add(final RecipientType rt, final Account.Id to) {
|
||||
if (! emailOnlyAuthors || authors.contains(to)) {
|
||||
super.add(rt, to);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isVisibleTo(final Account.Id to) {
|
||||
return projectState == null
|
||||
|| change == null
|
||||
@@ -387,6 +406,21 @@ public abstract class ChangeEmail extends OutgoingEmail {
|
||||
.controlFor(change).isVisible();
|
||||
}
|
||||
|
||||
/** Find all users who are authors of any part of this change. */
|
||||
protected Set<Account.Id> getAuthors() {
|
||||
Set<Account.Id> authors = new HashSet<Account.Id>();
|
||||
|
||||
authors.add(change.getOwner());
|
||||
if (patchSet != null) {
|
||||
authors.add(patchSet.getUploader());
|
||||
}
|
||||
if (patchSetInfo != null) {
|
||||
authors.add(patchSetInfo.getAuthor().getAccount());
|
||||
authors.add(patchSetInfo.getCommitter().getAccount());
|
||||
}
|
||||
return authors;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupVelocityContext() {
|
||||
super.setupVelocityContext();
|
||||
|
@@ -19,6 +19,7 @@ import com.google.gerrit.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.IdentifiedUser.GenericFactory;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.account.GroupCache;
|
||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.server.config.WildProjectName;
|
||||
@@ -36,6 +37,7 @@ import javax.annotation.Nullable;
|
||||
class EmailArguments {
|
||||
final GitRepositoryManager server;
|
||||
final ProjectCache projectCache;
|
||||
final GroupCache groupCache;
|
||||
final AccountCache accountCache;
|
||||
final PatchListCache patchListCache;
|
||||
final FromAddressGenerator fromAddressGenerator;
|
||||
@@ -52,9 +54,9 @@ class EmailArguments {
|
||||
|
||||
@Inject
|
||||
EmailArguments(GitRepositoryManager server, ProjectCache projectCache,
|
||||
AccountCache accountCache, PatchListCache patchListCache,
|
||||
FromAddressGenerator fromAddressGenerator, EmailSender emailSender,
|
||||
PatchSetInfoFactory patchSetInfoFactory,
|
||||
GroupCache groupCache, AccountCache accountCache,
|
||||
PatchListCache patchListCache, FromAddressGenerator fromAddressGenerator,
|
||||
EmailSender emailSender, PatchSetInfoFactory patchSetInfoFactory,
|
||||
GenericFactory identifiedUserFactory,
|
||||
@CanonicalWebUrl @Nullable Provider<String> urlProvider,
|
||||
@WildProjectName Project.NameKey wildProject,
|
||||
@@ -63,6 +65,7 @@ class EmailArguments {
|
||||
SitePaths site) {
|
||||
this.server = server;
|
||||
this.projectCache = projectCache;
|
||||
this.groupCache = groupCache;
|
||||
this.accountCache = accountCache;
|
||||
this.patchListCache = patchListCache;
|
||||
this.fromAddressGenerator = fromAddressGenerator;
|
||||
|
Reference in New Issue
Block a user