Search in sources :

Example 1 with DeleteReviewerInput

use of com.google.gerrit.extensions.api.changes.DeleteReviewerInput in project gerrit by GerritCodeReview.

the class DeleteReviewer method applyImpl.

@Override
protected Response<?> applyImpl(BatchUpdate.Factory updateFactory, ReviewerResource rsrc, DeleteReviewerInput input) throws RestApiException, UpdateException {
    if (input == null) {
        input = new DeleteReviewerInput();
    }
    if (input.notify == null) {
        input.notify = NotifyHandling.ALL;
    }
    try (BatchUpdate bu = updateFactory.create(dbProvider.get(), rsrc.getChangeResource().getProject(), rsrc.getChangeResource().getUser(), TimeUtil.nowTs())) {
        BatchUpdateOp op;
        if (rsrc.isByEmail()) {
            op = deleteReviewerByEmailOpFactory.create(rsrc.getReviewerByEmail(), input);
        } else {
            op = deleteReviewerOpFactory.create(rsrc.getReviewerUser().getAccount(), input);
        }
        bu.addOp(rsrc.getChange().getId(), op);
        bu.execute();
    }
    return Response.none();
}
Also used : DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp)

Example 2 with DeleteReviewerInput

use of com.google.gerrit.extensions.api.changes.DeleteReviewerInput in project gerrit by GerritCodeReview.

the class DeleteReviewersUtil method addDeleteReviewerOpToBatchUpdate.

public void addDeleteReviewerOpToBatchUpdate(BatchUpdate batchUpdate, ChangeNotes changeNotes, ReviewerInput reviewerInput) throws IOException, ConfigInvalidException, AuthException, ResourceNotFoundException {
    try {
        AccountResolver.Result result = accountResolver.resolveIgnoreVisibility(reviewerInput.reviewer);
        if (fetchAccountIds(changeNotes).contains(result.asUniqueUser().getAccountId())) {
            DeleteReviewerInput deleteReviewerInput = new DeleteReviewerInput();
            deleteReviewerInput.notify = reviewerInput.notify;
            deleteReviewerInput.notifyDetails = reviewerInput.notifyDetails;
            batchUpdate.addOp(changeNotes.getChangeId(), deleteReviewerOpFactory.create(result.asUnique().account(), deleteReviewerInput));
            return;
        }
        return;
    } catch (AccountResolver.UnresolvableAccountException e) {
        if (e.isSelf()) {
            throw new AuthException(e.getMessage(), e);
        }
    }
    Address address = Address.tryParse(reviewerInput.reviewer);
    if (address != null && changeNotes.getReviewersByEmail().all().contains(address)) {
        batchUpdate.addOp(changeNotes.getChangeId(), deleteReviewerByEmailOpFactory.create(address));
        return;
    }
    throw new ResourceNotFoundException(reviewerInput.reviewer);
}
Also used : Address(com.google.gerrit.entities.Address) AccountResolver(com.google.gerrit.server.account.AccountResolver) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) AuthException(com.google.gerrit.extensions.restapi.AuthException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 3 with DeleteReviewerInput

use of com.google.gerrit.extensions.api.changes.DeleteReviewerInput in project gerrit by GerritCodeReview.

the class ChangeNotificationsIT method removeReviewer.

private void removeReviewer(StagedChange sc, TestAccount account, NotifyHandling notify) throws Exception {
    sender.clear();
    DeleteReviewerInput in = new DeleteReviewerInput();
    in.notify = notify;
    gApi.changes().id(sc.changeId).reviewer(account.email()).remove(in);
}
Also used : DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput)

Example 4 with DeleteReviewerInput

use of com.google.gerrit.extensions.api.changes.DeleteReviewerInput in project gerrit by GerritCodeReview.

the class SetReviewersCommand method modifyOne.

private boolean modifyOne(ChangeResource changeRsrc) throws Exception {
    boolean ok = true;
    // 
    for (Account.Id reviewer : toRemove) {
        ReviewerResource rsrc = reviewerFactory.create(changeRsrc, reviewer);
        String error = null;
        try {
            deleteReviewer.apply(rsrc, new DeleteReviewerInput());
        } catch (ResourceNotFoundException e) {
            error = String.format("could not remove %s: not found", reviewer);
        } catch (Exception e) {
            error = String.format("could not remove %s: %s", reviewer, e.getMessage());
        }
        if (error != null) {
            ok = false;
            writeError("error", error);
        }
    }
    // 
    for (String reviewer : toAdd) {
        ReviewerInput input = new ReviewerInput();
        input.reviewer = reviewer;
        input.confirmed = true;
        String error;
        try {
            error = postReviewers.apply(changeRsrc, input).value().error;
        } catch (Exception e) {
            error = String.format("could not add %s: %s", reviewer, e.getMessage());
        }
        if (error != null) {
            ok = false;
            writeError("error", error);
        }
    }
    return ok;
}
Also used : Account(com.google.gerrit.entities.Account) ReviewerResource(com.google.gerrit.server.change.ReviewerResource) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) StorageException(com.google.gerrit.exceptions.StorageException) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput)

Example 5 with DeleteReviewerInput

use of com.google.gerrit.extensions.api.changes.DeleteReviewerInput in project gerrit by GerritCodeReview.

the class DeleteReviewer method apply.

@Override
public Response<Object> apply(ReviewerResource rsrc, DeleteReviewerInput input) throws RestApiException, UpdateException {
    if (input == null) {
        input = new DeleteReviewerInput();
    }
    try (BatchUpdate bu = updateFactory.create(rsrc.getChangeResource().getProject(), rsrc.getChangeResource().getUser(), TimeUtil.now())) {
        bu.setNotify(getNotify(rsrc.getChange(), input));
        BatchUpdateOp op;
        if (rsrc.isByEmail()) {
            op = deleteReviewerByEmailOpFactory.create(rsrc.getReviewerByEmail());
        } else {
            op = deleteReviewerOpFactory.create(rsrc.getReviewerUser().getAccount(), input);
        }
        bu.addOp(rsrc.getChange().getId(), op);
        bu.execute();
    }
    return Response.none();
}
Also used : DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp)

Aggregations

DeleteReviewerInput (com.google.gerrit.extensions.api.changes.DeleteReviewerInput)7 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)2 BatchUpdateOp (com.google.gerrit.server.update.BatchUpdateOp)2 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)1 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 Account (com.google.gerrit.entities.Account)1 Address (com.google.gerrit.entities.Address)1 StorageException (com.google.gerrit.exceptions.StorageException)1 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)1 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)1 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 AccountResolver (com.google.gerrit.server.account.AccountResolver)1 ReviewerResource (com.google.gerrit.server.change.ReviewerResource)1 CommitValidationMessage (com.google.gerrit.server.git.validators.CommitValidationMessage)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 Message (com.google.gerrit.testing.FakeEmailSender.Message)1 Test (org.junit.Test)1