use of com.google.gerrit.exceptions.NoSuchGroupException in project gerrit by GerritCodeReview.
the class AccountManager method addGroupMember.
private void addGroupMember(AccountGroup.UUID groupUuid, IdentifiedUser user) throws IOException, ConfigInvalidException, AccountException {
// The user initiated this request by logging in. -> Attribute all modifications to that user.
GroupsUpdate groupsUpdate = groupsUpdateFactory.create(user);
GroupDelta groupDelta = GroupDelta.builder().setMemberModification(memberIds -> Sets.union(memberIds, ImmutableSet.of(user.getAccountId()))).build();
try {
groupsUpdate.updateGroup(groupUuid, groupDelta);
} catch (NoSuchGroupException e) {
throw new AccountException(String.format("Group %s not found", groupUuid), e);
}
}
use of com.google.gerrit.exceptions.NoSuchGroupException in project gerrit by GerritCodeReview.
the class AddMembers method addMembers.
public void addMembers(AccountGroup.UUID groupUuid, Set<Account.Id> newMemberIds) throws IOException, NoSuchGroupException, ConfigInvalidException {
GroupDelta groupDelta = GroupDelta.builder().setMemberModification(memberIds -> Sets.union(memberIds, newMemberIds)).build();
groupsUpdateProvider.get().updateGroup(groupUuid, groupDelta);
}
use of com.google.gerrit.exceptions.NoSuchGroupException in project gerrit by GerritCodeReview.
the class AddMembers method apply.
@Override
public Response<List<AccountInfo>> apply(GroupResource resource, Input input) throws AuthException, NotInternalGroupException, UnprocessableEntityException, IOException, ConfigInvalidException, ResourceNotFoundException, PermissionBackendException {
GroupDescription.Internal internalGroup = resource.asInternalGroup().orElseThrow(NotInternalGroupException::new);
input = Input.init(input);
GroupControl control = resource.getControl();
if (!control.canAddMember()) {
throw new AuthException("Cannot add members to group " + internalGroup.getName());
}
Set<Account.Id> newMemberIds = new LinkedHashSet<>();
for (String nameOrEmailOrId : input.members) {
Account a = findAccount(nameOrEmailOrId);
if (!a.isActive()) {
throw new UnprocessableEntityException(String.format("Account Inactive: %s", nameOrEmailOrId));
}
newMemberIds.add(a.id());
}
AccountGroup.UUID groupUuid = internalGroup.getGroupUUID();
try {
addMembers(groupUuid, newMemberIds);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
}
return Response.ok(toAccountInfoList(newMemberIds));
}
use of com.google.gerrit.exceptions.NoSuchGroupException in project gerrit by GerritCodeReview.
the class DeleteSubgroups method removeSubgroups.
private void removeSubgroups(AccountGroup.UUID parentGroupUuid, Set<AccountGroup.UUID> removedSubgroupUuids) throws NoSuchGroupException, IOException, ConfigInvalidException {
GroupDelta groupDelta = GroupDelta.builder().setSubgroupModification(subgroupUuids -> Sets.difference(subgroupUuids, removedSubgroupUuids)).build();
groupsUpdateProvider.get().updateGroup(parentGroupUuid, groupDelta);
}
use of com.google.gerrit.exceptions.NoSuchGroupException 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);
}
Aggregations