use of com.google.gerrit.server.account.AccountLoader 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.server.account.AccountLoader 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.server.account.AccountLoader 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.server.account.AccountLoader in project gerrit by GerritCodeReview.
the class AccountApiImpl method get.
@Override
public com.google.gerrit.extensions.common.AccountInfo get() throws RestApiException {
AccountLoader accountLoader = accountLoaderFactory.create(true);
try {
AccountInfo ai = accountLoader.get(account.getUser().getAccountId());
accountLoader.fill();
return ai;
} catch (Exception e) {
throw asRestApiException("Cannot parse account", e);
}
}
use of com.google.gerrit.server.account.AccountLoader in project gerrit by GerritCodeReview.
the class DeleteChangeMessage method createUpdatedChangeMessageInfo.
private ChangeMessageInfo createUpdatedChangeMessageInfo(Change.Id cId, Project.NameKey project, int targetIdx) throws PermissionBackendException {
List<ChangeMessage> messages = changeMessagesUtil.byChange(notesFactory.createChecked(project, cId));
ChangeMessage updatedChangeMessage = messages.get(targetIdx);
AccountLoader accountLoader = accountLoaderFactory.create(true);
ChangeMessageInfo info = changeMessagesUtil.createChangeMessageInfoWithReplacedTemplates(updatedChangeMessage, accountLoader);
accountLoader.fill();
return info;
}
Aggregations