Search in sources :

Example 1 with AddToAttentionSetOp

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

the class ReplyAttentionSetUpdates method addToAttentionSet.

/**
 * Adds the user to the attention set
 *
 * @param bu BatchUpdate to perform the updates to the attention set
 * @param changeNotes current change
 * @param user user to add to the attention set
 * @param reason reason for adding
 * @param notify whether or not to notify about this addition
 */
private void addToAttentionSet(BatchUpdate bu, ChangeNotes changeNotes, Account.Id user, String reason, boolean notify) {
    AddToAttentionSetOp addOwnerToAttentionSet = addToAttentionSetOpFactory.create(user, reason, notify);
    bu.addOp(changeNotes.getChangeId(), addOwnerToAttentionSet);
}
Also used : AddToAttentionSetOp(com.google.gerrit.server.change.AddToAttentionSetOp)

Example 2 with AddToAttentionSetOp

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

the class AddToAttentionSet method apply.

@Override
public Response<AccountInfo> apply(ChangeResource changeResource, AttentionSetInput input) throws Exception {
    AttentionSetUtil.validateInput(input);
    Account.Id attentionUserId = AttentionSetUtil.resolveAccount(accountResolver, changeResource.getNotes(), input.user);
    if (serviceUserClassifier.isServiceUser(attentionUserId)) {
        throw new BadRequestException(String.format("%s is a robot, and robots can't be added to the attention set.", input.user));
    }
    try {
        permissionBackend.absentUser(attentionUserId).change(changeResource.getNotes()).check(ChangePermission.READ);
    } catch (AuthException e) {
        throw new AuthException("read not permitted for " + attentionUserId, e);
    }
    try (BatchUpdate bu = updateFactory.create(changeResource.getChange().getProject(), changeResource.getUser(), TimeUtil.now())) {
        AddToAttentionSetOp op = opFactory.create(attentionUserId, input.reason, true);
        bu.addOp(changeResource.getId(), op);
        NotifyHandling notify = input.notify == null ? NotifyHandling.OWNER : input.notify;
        NotifyResolver.Result notifyResult = notifyResolver.resolve(notify, input.notifyDetails);
        bu.setNotify(notifyResult);
        bu.execute();
        return Response.ok(accountLoaderFactory.create(true).fillOne(attentionUserId));
    }
}
Also used : Account(com.google.gerrit.entities.Account) NotifyResolver(com.google.gerrit.server.change.NotifyResolver) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AuthException(com.google.gerrit.extensions.restapi.AuthException) AddToAttentionSetOp(com.google.gerrit.server.change.AddToAttentionSetOp) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Aggregations

AddToAttentionSetOp (com.google.gerrit.server.change.AddToAttentionSetOp)2 Account (com.google.gerrit.entities.Account)1 NotifyHandling (com.google.gerrit.extensions.api.changes.NotifyHandling)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 NotifyResolver (com.google.gerrit.server.change.NotifyResolver)1 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)1