Search in sources :

Example 1 with AttentionSetInfo

use of com.google.gerrit.extensions.common.AttentionSetInfo in project gerrit by GerritCodeReview.

the class GetAttentionSet method apply.

@Override
public Response<Set<AttentionSetInfo>> apply(ChangeResource changeResource) throws PermissionBackendException {
    AccountLoader accountLoader = accountLoaderFactory.create(true);
    ImmutableSet<AttentionSetInfo> response = // This filtering should match ChangeJson.
    additionsOnly(changeResource.getNotes().getAttentionSet()).stream().map(a -> AttentionSetUtil.createAttentionSetInfo(a, accountLoader)).collect(toImmutableSet());
    accountLoader.fill();
    return Response.ok(response);
}
Also used : AttentionSetUtil.additionsOnly(com.google.gerrit.server.util.AttentionSetUtil.additionsOnly) AccountLoader(com.google.gerrit.server.account.AccountLoader) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) ImmutableSet(com.google.common.collect.ImmutableSet) RestReadView(com.google.gerrit.extensions.restapi.RestReadView) Inject(com.google.inject.Inject) Set(java.util.Set) Response(com.google.gerrit.extensions.restapi.Response) AttentionSetInfo(com.google.gerrit.extensions.common.AttentionSetInfo) ChangeResource(com.google.gerrit.server.change.ChangeResource) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) AttentionSetUtil(com.google.gerrit.server.util.AttentionSetUtil) Singleton(com.google.inject.Singleton) AccountLoader(com.google.gerrit.server.account.AccountLoader) AttentionSetInfo(com.google.gerrit.extensions.common.AttentionSetInfo)

Example 2 with AttentionSetInfo

use of com.google.gerrit.extensions.common.AttentionSetInfo in project gerrit by GerritCodeReview.

the class AttentionSetUtil method createAttentionSetInfo.

/**
 * Returns {@link AttentionSetInfo} from {@link AttentionSetUpdate} with {@link AccountInfo}
 * fields filled by {@code accountLoader}.
 */
public static AttentionSetInfo createAttentionSetInfo(AttentionSetUpdate attentionSetUpdate, AccountLoader accountLoader) {
    // Only one account is expected in attention set reason. If there are multiple, do not return
    // anything instead of failing the request.
    ImmutableSet<Account.Id> accountsInTemplate = AccountTemplateUtil.parseTemplates(attentionSetUpdate.reason());
    AccountInfo reasonAccount = accountsInTemplate.size() == 1 ? accountLoader.get(Iterables.getOnlyElement(accountsInTemplate)) : null;
    return new AttentionSetInfo(accountLoader.get(attentionSetUpdate.account()), attentionSetUpdate.timestamp(), attentionSetUpdate.reason(), reasonAccount);
}
Also used : AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AttentionSetInfo(com.google.gerrit.extensions.common.AttentionSetInfo)

Example 3 with AttentionSetInfo

use of com.google.gerrit.extensions.common.AttentionSetInfo in project gerrit by GerritCodeReview.

the class AttentionSetIT method addUserWithTemplateReason.

@Test
public void addUserWithTemplateReason() throws Exception {
    PushOneCommit.Result r = createChange();
    requestScopeOperations.setApiUser(user.id());
    String manualReason = "Added by " + AccountTemplateUtil.getAccountTemplate(user.id());
    int accountId = change(r).addToAttentionSet(new AttentionSetInput(admin.email(), manualReason))._accountId;
    assertThat(accountId).isEqualTo(admin.id().get());
    AttentionSetUpdate expectedAttentionSetUpdate = AttentionSetUpdate.createFromRead(fakeClock.now(), admin.id(), AttentionSetUpdate.Operation.ADD, manualReason);
    assertThat(r.getChange().attentionSet()).containsExactly(expectedAttentionSetUpdate);
    AttentionSetInfo attentionSetInfo = Iterables.getOnlyElement(change(r).get().attentionSet.values());
    assertThat(attentionSetInfo.reason).isEqualTo(manualReason);
    assertThat(attentionSetInfo.reasonAccount).isEqualTo(getAccountInfo(user.id()));
    assertThat(attentionSetInfo.account).isEqualTo(getAccountInfo(admin.id()));
    AttentionSetInfo getAttentionSetInfo = Iterables.getOnlyElement(getAttentionSet.apply(parseChangeResource(r.getChangeId())).value());
    assertThat(getAttentionSetInfo.reason).isEqualTo(manualReason);
    assertThat(getAttentionSetInfo.reasonAccount).isEqualTo(getAccountInfo(user.id()));
    assertThat(getAttentionSetInfo.account).isEqualTo(getAccountInfo(admin.id()));
}
Also used : AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AttentionSetInfo(com.google.gerrit.extensions.common.AttentionSetInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with AttentionSetInfo

use of com.google.gerrit.extensions.common.AttentionSetInfo in project gerrit by GerritCodeReview.

the class AttentionSetIT method addUserWithTemplateReasonMultipleAccounts.

@Test
public void addUserWithTemplateReasonMultipleAccounts() throws Exception {
    PushOneCommit.Result r = createChange();
    requestScopeOperations.setApiUser(user.id());
    String manualReason = String.format("Added by %s with user %s", AccountTemplateUtil.getAccountTemplate(user.id()), AccountTemplateUtil.getAccountTemplate(admin.id()));
    int accountId = change(r).addToAttentionSet(new AttentionSetInput(admin.email(), manualReason))._accountId;
    assertThat(accountId).isEqualTo(admin.id().get());
    AttentionSetUpdate expectedAttentionSetUpdate = AttentionSetUpdate.createFromRead(fakeClock.now(), admin.id(), AttentionSetUpdate.Operation.ADD, manualReason);
    assertThat(r.getChange().attentionSet()).containsExactly(expectedAttentionSetUpdate);
    AttentionSetInfo attentionSetInfo = Iterables.getOnlyElement(change(r).get().attentionSet.values());
    assertThat(attentionSetInfo.reason).isEqualTo(manualReason);
    assertThat(attentionSetInfo.reasonAccount).isNull();
    assertThat(attentionSetInfo.account).isEqualTo(getAccountInfo(admin.id()));
    AttentionSetInfo getAttentionSetInfo = Iterables.getOnlyElement(getAttentionSet.apply(parseChangeResource(r.getChangeId())).value());
    assertThat(getAttentionSetInfo.reason).isEqualTo(manualReason);
    assertThat(getAttentionSetInfo.reasonAccount).isNull();
    assertThat(getAttentionSetInfo.account).isEqualTo(getAccountInfo(admin.id()));
}
Also used : AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AttentionSetInfo(com.google.gerrit.extensions.common.AttentionSetInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with AttentionSetInfo

use of com.google.gerrit.extensions.common.AttentionSetInfo in project gerrit by GerritCodeReview.

the class AttentionSetIT method removeUser.

@Test
public void removeUser() throws Exception {
    PushOneCommit.Result r = createChange();
    // implictly adds the user to the attention set when adding as reviewer
    change(r).addReviewer(user.email());
    sender.clear();
    requestScopeOperations.setApiUser(user.id());
    fakeClock.advance(Duration.ofSeconds(42));
    change(r).attention(user.id().toString()).remove(new AttentionSetInput("removed"));
    AttentionSetUpdate expectedAttentionSetUpdate = AttentionSetUpdate.createFromRead(fakeClock.now(), user.id(), AttentionSetUpdate.Operation.REMOVE, "removed");
    assertThat(r.getChange().attentionSet()).containsExactly(expectedAttentionSetUpdate);
    // The removal also shows up in AttentionSetInfo.
    AttentionSetInfo attentionSetInfo = Iterables.getOnlyElement(change(r).get().removedFromAttentionSet.values());
    assertThat(attentionSetInfo.reason).isEqualTo("removed");
    assertThat(attentionSetInfo.account).isEqualTo(getAccountInfo(user.id()));
    // Second removal is ignored.
    fakeClock.advance(Duration.ofSeconds(42));
    change(r).attention(user.id().toString()).remove(new AttentionSetInput("removed again"));
    assertThat(r.getChange().attentionSet()).containsExactly(expectedAttentionSetUpdate);
    // Only one email since the second remove was ignored.
    String emailBody = Iterables.getOnlyElement(sender.getMessages()).body();
    assertThat(emailBody).contains(user.fullName() + " removed themselves from the attention set of this change.\n" + " The reason is: removed.");
}
Also used : AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AttentionSetInfo(com.google.gerrit.extensions.common.AttentionSetInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

AttentionSetInfo (com.google.gerrit.extensions.common.AttentionSetInfo)6 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)4 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)4 Test (org.junit.Test)4 AttentionSetUpdate (com.google.gerrit.entities.AttentionSetUpdate)3 AttentionSetInput (com.google.gerrit.extensions.api.changes.AttentionSetInput)3 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)1 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)1 Response (com.google.gerrit.extensions.restapi.Response)1 RestReadView (com.google.gerrit.extensions.restapi.RestReadView)1 AccountLoader (com.google.gerrit.server.account.AccountLoader)1 ChangeResource (com.google.gerrit.server.change.ChangeResource)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 AttentionSetUtil (com.google.gerrit.server.util.AttentionSetUtil)1 AttentionSetUtil.additionsOnly (com.google.gerrit.server.util.AttentionSetUtil.additionsOnly)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 Set (java.util.Set)1