Search in sources :

Example 1 with AttentionSetUnchangedOp

use of com.google.gerrit.server.change.AttentionSetUnchangedOp in project gerrit by GerritCodeReview.

the class DeleteVote method apply.

@Override
public Response<Object> apply(VoteResource rsrc, DeleteVoteInput input) throws RestApiException, UpdateException, IOException, ConfigInvalidException {
    if (input == null) {
        input = new DeleteVoteInput();
    }
    if (input.label != null && !rsrc.getLabel().equals(input.label)) {
        throw new BadRequestException("label must match URL");
    }
    if (input.notify == null) {
        input.notify = NotifyHandling.ALL;
    }
    ReviewerResource r = rsrc.getReviewer();
    Change change = r.getChange();
    if (r.getRevisionResource() != null && !r.getRevisionResource().isCurrent()) {
        throw new MethodNotAllowedException("Cannot delete vote on non-current patch set");
    }
    try (BatchUpdate bu = updateFactory.create(change.getProject(), r.getChangeResource().getUser(), TimeUtil.now())) {
        bu.setNotify(notifyResolver.resolve(firstNonNull(input.notify, NotifyHandling.ALL), input.notifyDetails));
        bu.addOp(change.getId(), new Op(projectCache.get(r.getChange().getProject()).orElseThrow(illegalState(r.getChange().getProject())), r.getReviewerUser().state(), rsrc.getLabel(), input));
        if (!input.ignoreAutomaticAttentionSetRules && !r.getReviewerUser().getAccountId().equals(currentUserProvider.get().getAccountId())) {
            bu.addOp(change.getId(), attentionSetOpFactory.create(r.getReviewerUser().getAccountId(), /* reason= */
            "Their vote was deleted", /* notify= */
            false));
        }
        if (input.ignoreAutomaticAttentionSetRules) {
            bu.addOp(change.getId(), new AttentionSetUnchangedOp());
        }
        bu.execute();
    }
    return Response.none();
}
Also used : DeleteVoteInput(com.google.gerrit.extensions.api.changes.DeleteVoteInput) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) AddToAttentionSetOp(com.google.gerrit.server.change.AddToAttentionSetOp) AttentionSetUnchangedOp(com.google.gerrit.server.change.AttentionSetUnchangedOp) ReviewerResource(com.google.gerrit.server.change.ReviewerResource) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AttentionSetUnchangedOp(com.google.gerrit.server.change.AttentionSetUnchangedOp) Change(com.google.gerrit.entities.Change) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 2 with AttentionSetUnchangedOp

use of com.google.gerrit.server.change.AttentionSetUnchangedOp in project gerrit by GerritCodeReview.

the class ReplyAttentionSetUpdates method updateAttentionSet.

/**
 * Adjusts the attention set by adding and removing users. If the same user should be added and
 * removed or added/removed twice, the user will only be added/removed once, based on first
 * addition/removal.
 */
public void updateAttentionSet(BatchUpdate bu, ChangeNotes changeNotes, ReviewInput input, CurrentUser currentUser) throws BadRequestException, IOException, PermissionBackendException, UnprocessableEntityException, ConfigInvalidException {
    processManualUpdates(bu, changeNotes, input);
    if (input.ignoreAutomaticAttentionSetRules) {
        // If we ignore automatic attention set rules it means we need to pass this information to
        // ChangeUpdate. Also, we should stop all other attention set updates that are part of
        // this method and happen in PostReview.
        bu.addOp(changeNotes.getChangeId(), new AttentionSetUnchangedOp());
        return;
    }
    boolean isReadyForReview = isReadyForReview(changeNotes, input);
    if (isReadyForReview && serviceUserClassifier.isServiceUser(currentUser.getAccountId())) {
        botsWithNegativeLabelsAddOwnerAndUploader(bu, changeNotes, input);
        return;
    }
    processRules(bu, changeNotes, isReadyForReview, currentUser, getAllNewComments(changeNotes, input, currentUser));
}
Also used : AttentionSetUnchangedOp(com.google.gerrit.server.change.AttentionSetUnchangedOp)

Aggregations

AttentionSetUnchangedOp (com.google.gerrit.server.change.AttentionSetUnchangedOp)2 Change (com.google.gerrit.entities.Change)1 DeleteVoteInput (com.google.gerrit.extensions.api.changes.DeleteVoteInput)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)1 AddToAttentionSetOp (com.google.gerrit.server.change.AddToAttentionSetOp)1 ReviewerResource (com.google.gerrit.server.change.ReviewerResource)1 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)1 BatchUpdateOp (com.google.gerrit.server.update.BatchUpdateOp)1