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