use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.
the class TestSubmitRule method newSubmitRuleInfo.
private static TestSubmitRuleInfo newSubmitRuleInfo(SubmitRecord r, AccountLoader accounts) {
TestSubmitRuleInfo info = new TestSubmitRuleInfo();
info.status = r.status.name();
info.errorMessage = r.errorMessage;
if (r.labels != null) {
for (SubmitRecord.Label n : r.labels) {
AccountInfo who = n.appliedBy != null ? accounts.get(n.appliedBy) : new AccountInfo(null);
label(info, n, who);
}
}
return info;
}
use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.
the class AddMembers method toAccountInfoList.
private List<AccountInfo> toAccountInfoList(Set<Account.Id> accountIds) throws PermissionBackendException {
List<AccountInfo> result = new ArrayList<>();
AccountLoader loader = infoFactory.create(true);
for (Account.Id accId : accountIds) {
result.add(loader.get(accId));
}
loader.fill();
return result;
}
use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.
the class GetAuditLog method apply.
@Override
public Response<List<? extends GroupAuditEventInfo>> apply(GroupResource rsrc) throws AuthException, NotInternalGroupException, IOException, ConfigInvalidException, PermissionBackendException {
GroupDescription.Internal group = rsrc.asInternalGroup().orElseThrow(NotInternalGroupException::new);
if (!rsrc.getControl().isOwner()) {
throw new AuthException("Not group owner");
}
AccountLoader accountLoader = accountLoaderFactory.create(true);
List<GroupAuditEventInfo> auditEvents = new ArrayList<>();
try (Repository allUsersRepo = repoManager.openRepository(allUsers)) {
for (AccountGroupMemberAudit auditEvent : groups.getMembersAudit(allUsersRepo, group.getGroupUUID())) {
AccountInfo member = accountLoader.get(auditEvent.memberId());
auditEvents.add(GroupAuditEventInfo.createAddUserEvent(accountLoader.get(auditEvent.addedBy()), auditEvent.addedOn(), member));
if (!auditEvent.isActive()) {
auditEvents.add(GroupAuditEventInfo.createRemoveUserEvent(accountLoader.get(auditEvent.removedBy().orElse(null)), auditEvent.removedOn().orElse(null), member));
}
}
List<AccountGroupByIdAudit> subGroupsAudit = groups.getSubgroupsAudit(allUsersRepo, group.getGroupUUID());
Map<AccountGroup.UUID, InternalGroup> groups = groupCache.get(subGroupsAudit.stream().map(a -> a.includeUuid()).collect(toImmutableList()));
for (AccountGroupByIdAudit auditEvent : subGroupsAudit) {
AccountGroup.UUID includedGroupUUID = auditEvent.includeUuid();
InternalGroup includedGroup = groups.get(includedGroupUUID);
GroupInfo member;
if (includedGroup != null) {
member = groupJson.format(new InternalGroupDescription(includedGroup));
} else {
member = new GroupInfo();
member.id = Url.encode(includedGroupUUID.get());
GroupDescription.Basic groupDescription = groupBackend.get(includedGroupUUID);
if (groupDescription != null) {
member.name = groupDescription.getName();
}
}
auditEvents.add(GroupAuditEventInfo.createAddGroupEvent(accountLoader.get(auditEvent.addedBy()), auditEvent.addedOn(), member));
if (!auditEvent.isActive()) {
auditEvents.add(GroupAuditEventInfo.createRemoveGroupEvent(accountLoader.get(auditEvent.removedBy().orElse(null)), auditEvent.removedOn().orElse(null), member));
}
}
}
accountLoader.fill();
// sort by date and then reverse so that the newest audit event comes first
auditEvents.sort(comparing((GroupAuditEventInfo a) -> a.date).reversed());
return Response.ok(auditEvents);
}
use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.
the class GetMember method apply.
@Override
public Response<AccountInfo> apply(MemberResource rsrc) throws PermissionBackendException {
AccountLoader loader = infoFactory.create(true);
AccountInfo info = loader.get(rsrc.getMember().getAccountId());
loader.fill();
return Response.ok(info);
}
use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.
the class PostReviewIT method votingMakesCallerReviewer.
@Test
public void votingMakesCallerReviewer() throws Exception {
// Admin owns the change
PushOneCommit.Result r = createChange();
// User adds themselves and changes state
requestScopeOperations.setApiUser(user.id());
ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 1);
gApi.changes().id(r.getChangeId()).current().review(input);
Map<ReviewerState, Collection<AccountInfo>> reviewers = gApi.changes().id(r.getChangeId()).get().reviewers;
assertThat(reviewers).hasSize(1);
AccountInfo reviewer = Iterables.getOnlyElement(reviewers.get(ReviewerState.REVIEWER));
assertThat(reviewer._accountId).isEqualTo(user.id().get());
}
Aggregations