use of com.google.gerrit.server.account.GroupControl 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.server.account.GroupControl in project gerrit by GerritCodeReview.
the class DeleteMembers method apply.
@Override
public Response<?> apply(GroupResource resource, Input input) throws AuthException, NotInternalGroupException, UnprocessableEntityException, IOException, ConfigInvalidException, ResourceNotFoundException {
GroupDescription.Internal internalGroup = resource.asInternalGroup().orElseThrow(NotInternalGroupException::new);
input = Input.init(input);
final GroupControl control = resource.getControl();
if (!control.canRemoveMember()) {
throw new AuthException("Cannot delete members from group " + internalGroup.getName());
}
Set<Account.Id> membersToRemove = new HashSet<>();
for (String nameOrEmail : input.members) {
if (Strings.isNullOrEmpty(nameOrEmail)) {
continue;
}
membersToRemove.add(accountResolver.resolve(nameOrEmail).asUnique().account().id());
}
AccountGroup.UUID groupUuid = internalGroup.getGroupUUID();
try {
removeGroupMembers(groupUuid, membersToRemove);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
}
return Response.none();
}
use of com.google.gerrit.server.account.GroupControl in project gerrit by GerritCodeReview.
the class GroupsCollection method parse.
@Override
public GroupResource parse(TopLevelResource parent, IdString id) throws AuthException, ResourceNotFoundException {
final CurrentUser user = self.get();
if (user instanceof AnonymousUser) {
throw new AuthException("Authentication required");
} else if (!(user.isIdentifiedUser() || user.isInternalUser())) {
throw new ResourceNotFoundException(id);
}
GroupDescription.Basic group = groupResolver.parseId(id.get());
if (group == null) {
throw new ResourceNotFoundException(id.get());
}
GroupControl ctl = groupControlFactory.controlFor(group);
if (!ctl.isVisible()) {
throw new ResourceNotFoundException(id);
}
return new GroupResource(ctl);
}
use of com.google.gerrit.server.account.GroupControl in project gerrit by GerritCodeReview.
the class ListMembers method getIndirectMemberIds.
private Set<Account.Id> getIndirectMemberIds(GroupDescription.Internal group, HashSet<AccountGroup.UUID> seenGroups) {
Set<Account.Id> indirectMembers = new HashSet<>();
Set<AccountGroup.UUID> subgroupMembersToLoad = new HashSet<>();
for (AccountGroup.UUID subgroupUuid : group.getSubgroups()) {
if (!seenGroups.contains(subgroupUuid)) {
seenGroups.add(subgroupUuid);
subgroupMembersToLoad.add(subgroupUuid);
}
}
groupCache.get(subgroupMembersToLoad).values().stream().map(InternalGroupDescription::new).forEach(subgroup -> {
GroupControl subgroupControl = groupControlFactory.controlFor(subgroup);
indirectMembers.addAll(getTransitiveMemberIds(subgroup, subgroupControl, seenGroups));
});
return indirectMembers;
}
Aggregations