Search in sources :

Example 6 with ReviewerModification

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

Example 7 with ReviewerModification

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()));
    }
}
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

ReviewerModification (com.google.gerrit.server.change.ReviewerModifier.ReviewerModification)7 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)6 Change (com.google.gerrit.entities.Change)4 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)4 ChangeUpdate (com.google.gerrit.server.notedb.ChangeUpdate)4 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)4 Account (com.google.gerrit.entities.Account)3 Address (com.google.gerrit.entities.Address)3 LabelTypes (com.google.gerrit.entities.LabelTypes)3 PatchSet (com.google.gerrit.entities.PatchSet)3 AuthException (com.google.gerrit.extensions.restapi.AuthException)3 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)3 ReviewerSet (com.google.gerrit.server.ReviewerSet)3 ChangeData (com.google.gerrit.server.query.change.ChangeData)3 AutoValue (com.google.auto.value.AutoValue)2 Joiner (com.google.common.base.Joiner)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)2 Strings (com.google.common.base.Strings)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2