use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.
the class ListGroups method suggestGroups.
private List<GroupInfo> suggestGroups() throws OrmException, BadRequestException {
if (conflictingSuggestParameters()) {
throw new BadRequestException("You should only have no more than one --project and -n with --suggest");
}
List<GroupReference> groupRefs = Lists.newArrayList(Iterables.limit(groupBackend.suggest(suggest, Iterables.getFirst(projects, null)), limit <= 0 ? 10 : Math.min(limit, 10)));
List<GroupInfo> groupInfos = Lists.newArrayListWithCapacity(groupRefs.size());
for (final GroupReference ref : groupRefs) {
GroupDescription.Basic desc = groupBackend.get(ref.getUUID());
if (desc != null) {
groupInfos.add(json.addOptions(options).format(desc));
}
}
return groupInfos;
}
use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.
the class Schema_150_to_151_Test method createGroup.
private AccountGroup.Id createGroup(String name) throws Exception {
GroupInput groupInput = new GroupInput();
groupInput.name = name;
GroupInfo groupInfo = createGroupFactory.create(name).apply(TopLevelResource.INSTANCE, groupInput);
return new Id(groupInfo.groupId);
}
use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.
the class GetGroups method apply.
@Override
public List<GroupInfo> apply(AccountResource resource) throws OrmException {
IdentifiedUser user = resource.getUser();
Account.Id userId = user.getAccountId();
List<GroupInfo> groups = new ArrayList<>();
for (AccountGroup.UUID uuid : user.getEffectiveGroups().getKnownGroups()) {
GroupControl ctl;
try {
ctl = groupControlFactory.controlFor(uuid);
} catch (NoSuchGroupException e) {
continue;
}
if (ctl.isVisible() && ctl.canSeeMember(userId)) {
groups.add(json.format(ctl.getGroup()));
}
}
return groups;
}
use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.
the class AddSubgroups method apply.
@Override
public Response<List<GroupInfo>> apply(GroupResource resource, Input input) throws NotInternalGroupException, AuthException, UnprocessableEntityException, ResourceNotFoundException, IOException, ConfigInvalidException, PermissionBackendException {
GroupDescription.Internal group = resource.asInternalGroup().orElseThrow(NotInternalGroupException::new);
input = Input.init(input);
GroupControl control = resource.getControl();
if (!control.canAddGroup()) {
throw new AuthException(String.format("Cannot add groups to group %s", group.getName()));
}
List<GroupInfo> result = new ArrayList<>();
Set<AccountGroup.UUID> subgroupUuids = new LinkedHashSet<>();
for (String subgroupIdentifier : input.groups) {
GroupDescription.Basic subgroup = groupResolver.parse(subgroupIdentifier);
subgroupUuids.add(subgroup.getGroupUUID());
result.add(json.format(subgroup));
}
AccountGroup.UUID groupUuid = group.getGroupUUID();
try {
addSubgroups(groupUuid, subgroupUuids);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
}
return Response.ok(result);
}
use of com.google.gerrit.extensions.common.GroupInfo 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);
}
Aggregations