use of com.google.gerrit.server.change.SetAssigneeOp 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