use of com.google.gerrit.server.change.ReviewerModifier.ReviewerModification in project gerrit by GerritCodeReview.
the class PostReviewers method apply.
@Override
public Response<ReviewerResult> apply(ChangeResource rsrc, ReviewerInput input) throws IOException, RestApiException, UpdateException, PermissionBackendException, ConfigInvalidException {
if (input.reviewer == null) {
throw new BadRequestException("missing reviewer field");
}
ReviewerModification modification = reviewerModifier.prepare(rsrc.getNotes(), rsrc.getUser(), input, true);
if (modification.op == null) {
return Response.ok(modification.result);
}
try (BatchUpdate bu = updateFactory.create(rsrc.getProject(), rsrc.getUser(), TimeUtil.now())) {
bu.setNotify(resolveNotify(rsrc, input));
Change.Id id = rsrc.getChange().getId();
bu.addOp(id, modification.op);
bu.execute();
}
// Re-read change to take into account results of the update.
modification.gatherResults(changeDataFactory.create(rsrc.getProject(), rsrc.getId()));
return Response.ok(modification.result);
}
use of com.google.gerrit.server.change.ReviewerModifier.ReviewerModification in project gerrit by GerritCodeReview.
the class PutAssignee method apply.
@Override
public Response<AccountInfo> apply(ChangeResource rsrc, AssigneeInput input) throws RestApiException, UpdateException, IOException, PermissionBackendException, ConfigInvalidException {
rsrc.permissions().check(ChangePermission.EDIT_ASSIGNEE);
input.assignee = Strings.nullToEmpty(input.assignee).trim();
if (input.assignee.isEmpty()) {
throw new BadRequestException("missing assignee field");
}
IdentifiedUser assignee = accountResolver.resolve(input.assignee).asUniqueUser();
try {
permissionBackend.absentUser(assignee.getAccountId()).change(rsrc.getNotes()).check(ChangePermission.READ);
} catch (AuthException e) {
throw new AuthException("read not permitted for " + input.assignee, e);
}
try (BatchUpdate bu = updateFactory.create(rsrc.getChange().getProject(), rsrc.getUser(), TimeUtil.now())) {
SetAssigneeOp op = assigneeFactory.create(assignee);
bu.addOp(rsrc.getId(), op);
ReviewerSet currentReviewers = approvalsUtil.getReviewers(rsrc.getNotes());
if (!currentReviewers.all().contains(assignee.getAccountId())) {
ReviewerModification reviewersAddition = addAssigneeAsCC(rsrc, input.assignee);
reviewersAddition.op.suppressEmail();
bu.addOp(rsrc.getId(), reviewersAddition.op);
}
bu.execute();
return Response.ok(accountLoaderFactory.create(true).fillOne(assignee.getAccountId()));
}
}
Aggregations