Search in sources :

Example 1 with SetAssigneeOp

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()));
    }
}
Also used : ReviewerSet(com.google.gerrit.server.ReviewerSet) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AuthException(com.google.gerrit.extensions.restapi.AuthException) ReviewerModification(com.google.gerrit.server.change.ReviewerModifier.ReviewerModification) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) SetAssigneeOp(com.google.gerrit.server.change.SetAssigneeOp)

Aggregations

AuthException (com.google.gerrit.extensions.restapi.AuthException)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1 ReviewerSet (com.google.gerrit.server.ReviewerSet)1 ReviewerModification (com.google.gerrit.server.change.ReviewerModifier.ReviewerModification)1 SetAssigneeOp (com.google.gerrit.server.change.SetAssigneeOp)1 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)1