PostReviewers: Add notify handling for reviewers added email
Change-Id: I99fa47548e2bd80584260e5f4e7093d246b27539
This commit is contained in:
parent
8178e0e3f2
commit
4d64f9764a
@ -5632,6 +5632,11 @@ Whether adding the reviewer is confirmed. +
|
|||||||
The Gerrit server may be configured to
|
The Gerrit server may be configured to
|
||||||
link:config-gerrit.html#addreviewer.maxWithoutConfirmation[require a
|
link:config-gerrit.html#addreviewer.maxWithoutConfirmation[require a
|
||||||
confirmation] when adding a group as reviewer that has many members.
|
confirmation] when adding a group as reviewer that has many members.
|
||||||
|
|`notify` |optional|
|
||||||
|
Notify handling that defines to whom email notifications should be sent
|
||||||
|
after the reviewer is added. +
|
||||||
|
Allowed values are `NONE`, `OWNER`, `OWNER_REVIEWERS` and `ALL`. +
|
||||||
|
If not set, the default is `ALL`.
|
||||||
|===========================
|
|===========================
|
||||||
|
|
||||||
[[revision-info]]
|
[[revision-info]]
|
||||||
|
@ -24,6 +24,7 @@ public class AddReviewerInput {
|
|||||||
public String reviewer;
|
public String reviewer;
|
||||||
public Boolean confirmed;
|
public Boolean confirmed;
|
||||||
public ReviewerState state;
|
public ReviewerState state;
|
||||||
|
public NotifyHandling notify;
|
||||||
|
|
||||||
public boolean confirmed() {
|
public boolean confirmed() {
|
||||||
return (confirmed != null) ? confirmed : false;
|
return (confirmed != null) ? confirmed : false;
|
||||||
|
@ -25,6 +25,7 @@ import com.google.gerrit.common.data.GroupDescription;
|
|||||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||||
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
|
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
|
||||||
import com.google.gerrit.extensions.api.changes.AddReviewerResult;
|
import com.google.gerrit.extensions.api.changes.AddReviewerResult;
|
||||||
|
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewerInfo;
|
import com.google.gerrit.extensions.api.changes.ReviewerInfo;
|
||||||
import com.google.gerrit.extensions.client.ReviewerState;
|
import com.google.gerrit.extensions.client.ReviewerState;
|
||||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||||
@ -169,16 +170,17 @@ public class PostReviewers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return putAccount(input.reviewer, reviewerFactory.create(rsrc, accountId),
|
return putAccount(input.reviewer, reviewerFactory.create(rsrc, accountId),
|
||||||
input.state());
|
input.state(), input.notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Addition putAccount(String reviewer, ReviewerResource rsrc,
|
private Addition putAccount(String reviewer, ReviewerResource rsrc,
|
||||||
ReviewerState state) throws UnprocessableEntityException {
|
ReviewerState state, NotifyHandling notify)
|
||||||
|
throws UnprocessableEntityException {
|
||||||
Account member = rsrc.getReviewerUser().getAccount();
|
Account member = rsrc.getReviewerUser().getAccount();
|
||||||
ChangeControl control = rsrc.getReviewerControl();
|
ChangeControl control = rsrc.getReviewerControl();
|
||||||
if (isValidReviewer(member, control)) {
|
if (isValidReviewer(member, control)) {
|
||||||
return new Addition(reviewer, rsrc.getChangeResource(),
|
return new Addition(reviewer, rsrc.getChangeResource(),
|
||||||
ImmutableMap.of(member.getId(), control), state);
|
ImmutableMap.of(member.getId(), control), state, notify);
|
||||||
}
|
}
|
||||||
if (member.isActive()) {
|
if (member.isActive()) {
|
||||||
throw new UnprocessableEntityException(
|
throw new UnprocessableEntityException(
|
||||||
@ -235,7 +237,8 @@ public class PostReviewers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Addition(input.reviewer, rsrc, reviewers, input.state());
|
return new Addition(input.reviewer, rsrc, reviewers, input.state(),
|
||||||
|
input.notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isValidReviewer(Account member, ChangeControl control) {
|
private boolean isValidReviewer(Account member, ChangeControl control) {
|
||||||
@ -266,11 +269,12 @@ public class PostReviewers
|
|||||||
private final Map<Account.Id, ChangeControl> reviewers;
|
private final Map<Account.Id, ChangeControl> reviewers;
|
||||||
|
|
||||||
protected Addition(String reviewer) {
|
protected Addition(String reviewer) {
|
||||||
this(reviewer, null, null, REVIEWER);
|
this(reviewer, null, null, REVIEWER, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Addition(String reviewer, ChangeResource rsrc,
|
protected Addition(String reviewer, ChangeResource rsrc,
|
||||||
Map<Account.Id, ChangeControl> reviewers, ReviewerState state) {
|
Map<Account.Id, ChangeControl> reviewers, ReviewerState state,
|
||||||
|
NotifyHandling notify) {
|
||||||
result = new AddReviewerResult(reviewer);
|
result = new AddReviewerResult(reviewer);
|
||||||
if (reviewers == null) {
|
if (reviewers == null) {
|
||||||
this.reviewers = ImmutableMap.of();
|
this.reviewers = ImmutableMap.of();
|
||||||
@ -278,7 +282,7 @@ public class PostReviewers
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.reviewers = reviewers;
|
this.reviewers = reviewers;
|
||||||
op = new Op(rsrc, reviewers, state);
|
op = new Op(rsrc, reviewers, state, notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gatherResults() throws OrmException {
|
void gatherResults() throws OrmException {
|
||||||
@ -308,6 +312,7 @@ public class PostReviewers
|
|||||||
class Op extends BatchUpdate.Op {
|
class Op extends BatchUpdate.Op {
|
||||||
final Map<Account.Id, ChangeControl> reviewers;
|
final Map<Account.Id, ChangeControl> reviewers;
|
||||||
final ReviewerState state;
|
final ReviewerState state;
|
||||||
|
final NotifyHandling notify;
|
||||||
List<PatchSetApproval> addedReviewers;
|
List<PatchSetApproval> addedReviewers;
|
||||||
Collection<Account.Id> addedCCs;
|
Collection<Account.Id> addedCCs;
|
||||||
|
|
||||||
@ -315,10 +320,11 @@ public class PostReviewers
|
|||||||
private PatchSet patchSet;
|
private PatchSet patchSet;
|
||||||
|
|
||||||
Op(ChangeResource rsrc, Map<Account.Id, ChangeControl> reviewers,
|
Op(ChangeResource rsrc, Map<Account.Id, ChangeControl> reviewers,
|
||||||
ReviewerState state) {
|
ReviewerState state, NotifyHandling notify) {
|
||||||
this.rsrc = rsrc;
|
this.rsrc = rsrc;
|
||||||
this.reviewers = reviewers;
|
this.reviewers = reviewers;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
|
this.notify = notify;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -354,7 +360,7 @@ public class PostReviewers
|
|||||||
if (addedCCs == null) {
|
if (addedCCs == null) {
|
||||||
addedCCs = new ArrayList<>();
|
addedCCs = new ArrayList<>();
|
||||||
}
|
}
|
||||||
emailReviewers(rsrc.getChange(), addedReviewers, addedCCs);
|
emailReviewers(rsrc.getChange(), addedReviewers, addedCCs, notify);
|
||||||
if (!addedReviewers.isEmpty()) {
|
if (!addedReviewers.isEmpty()) {
|
||||||
List<Account.Id> reviewers =
|
List<Account.Id> reviewers =
|
||||||
Lists.transform(addedReviewers, PatchSetApproval::getAccountId);
|
Lists.transform(addedReviewers, PatchSetApproval::getAccountId);
|
||||||
@ -366,7 +372,7 @@ public class PostReviewers
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void emailReviewers(Change change, List<PatchSetApproval> added,
|
private void emailReviewers(Change change, List<PatchSetApproval> added,
|
||||||
Collection<Account.Id> copied) {
|
Collection<Account.Id> copied, NotifyHandling notify) {
|
||||||
if (added.isEmpty() && copied.isEmpty()) {
|
if (added.isEmpty() && copied.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -393,7 +399,7 @@ public class PostReviewers
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
AddReviewerSender cm = addReviewerSenderFactory
|
AddReviewerSender cm = addReviewerSenderFactory
|
||||||
.create(change.getProject(), change.getId());
|
.create(change.getProject(), change.getId(), notify);
|
||||||
cm.setFrom(userId);
|
cm.setFrom(userId);
|
||||||
cm.addReviewers(toMail);
|
cm.addReviewers(toMail);
|
||||||
cm.addExtraCC(toCopy);
|
cm.addExtraCC(toCopy);
|
||||||
|
@ -14,7 +14,9 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.mail;
|
package com.google.gerrit.server.mail;
|
||||||
|
|
||||||
|
import com.google.gerrit.common.Nullable;
|
||||||
import com.google.gerrit.common.errors.EmailException;
|
import com.google.gerrit.common.errors.EmailException;
|
||||||
|
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
@ -24,15 +26,20 @@ import com.google.inject.assistedinject.Assisted;
|
|||||||
/** Asks a user to review a change. */
|
/** Asks a user to review a change. */
|
||||||
public class AddReviewerSender extends NewChangeSender {
|
public class AddReviewerSender extends NewChangeSender {
|
||||||
public interface Factory {
|
public interface Factory {
|
||||||
AddReviewerSender create(Project.NameKey project, Change.Id id);
|
AddReviewerSender create(Project.NameKey project, Change.Id id,
|
||||||
|
NotifyHandling notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AddReviewerSender(EmailArguments ea,
|
public AddReviewerSender(EmailArguments ea,
|
||||||
@Assisted Project.NameKey project,
|
@Assisted Project.NameKey project,
|
||||||
@Assisted Change.Id id)
|
@Assisted Change.Id id,
|
||||||
|
@Assisted @Nullable NotifyHandling notify)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
super(ea, newChangeData(ea, project, id));
|
super(ea, newChangeData(ea, project, id));
|
||||||
|
if (notify != null) {
|
||||||
|
setNotify(notify);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user