use of com.google.gerrit.exceptions.NoSuchGroupException 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.exceptions.NoSuchGroupException in project gerrit by GerritCodeReview.
the class AddSubgroups method addSubgroups.
private void addSubgroups(AccountGroup.UUID parentGroupUuid, Set<AccountGroup.UUID> newSubgroupUuids) throws NoSuchGroupException, IOException, ConfigInvalidException {
GroupDelta groupDelta = GroupDelta.builder().setSubgroupModification(subgroupUuids -> Sets.union(subgroupUuids, newSubgroupUuids)).build();
groupsUpdateProvider.get().updateGroup(parentGroupUuid, groupDelta);
}
use of com.google.gerrit.exceptions.NoSuchGroupException in project gerrit by GerritCodeReview.
the class PutAgreement method apply.
@Override
public Response<String> apply(AccountResource resource, AgreementInput input) throws IOException, RestApiException, ConfigInvalidException {
if (!agreementsEnabled) {
throw new MethodNotAllowedException("contributor agreements disabled");
}
if (!self.get().hasSameAccountId(resource.getUser())) {
throw new AuthException("not allowed to enter contributor agreement");
}
String agreementName = Strings.nullToEmpty(input.name);
ContributorAgreement ca = projectCache.getAllProjects().getConfig().getContributorAgreements().get(agreementName);
if (ca == null) {
throw new UnprocessableEntityException("contributor agreement not found");
}
if (ca.getAutoVerify() == null) {
throw new BadRequestException("cannot enter a non-autoVerify agreement");
}
AccountGroup.UUID uuid = ca.getAutoVerify().getUUID();
if (uuid == null) {
throw new ResourceConflictException("autoverify group uuid not found");
}
AccountState accountState = self.get().state();
try {
addMembers.addMembers(uuid, ImmutableSet.of(accountState.account().id()));
} catch (NoSuchGroupException e) {
throw new ResourceConflictException("autoverify group not found", e);
}
agreementSignup.fire(accountState, agreementName);
return Response.ok(agreementName);
}
use of com.google.gerrit.exceptions.NoSuchGroupException in project gerrit by GerritCodeReview.
the class PutOwner method apply.
@Override
public Response<GroupInfo> apply(GroupResource resource, OwnerInput input) throws ResourceNotFoundException, NotInternalGroupException, AuthException, BadRequestException, UnprocessableEntityException, IOException, ConfigInvalidException, PermissionBackendException {
GroupDescription.Internal internalGroup = resource.asInternalGroup().orElseThrow(NotInternalGroupException::new);
if (!resource.getControl().isOwner()) {
throw new AuthException("Not group owner");
}
if (input == null || Strings.isNullOrEmpty(input.owner)) {
throw new BadRequestException("owner is required");
}
GroupDescription.Basic owner = groupResolver.parse(input.owner);
if (!internalGroup.getOwnerGroupUUID().equals(owner.getGroupUUID())) {
AccountGroup.UUID groupUuid = internalGroup.getGroupUUID();
GroupDelta groupDelta = GroupDelta.builder().setOwnerGroupUUID(owner.getGroupUUID()).build();
try {
groupsUpdateProvider.get().updateGroup(groupUuid, groupDelta);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
}
}
return Response.ok(json.format(owner));
}
use of com.google.gerrit.exceptions.NoSuchGroupException in project gerrit by GerritCodeReview.
the class PutDescription method apply.
@Override
public Response<String> apply(GroupResource resource, DescriptionInput input) throws AuthException, NotInternalGroupException, ResourceNotFoundException, IOException, ConfigInvalidException {
if (input == null) {
// Delete would set description to null.
input = new DescriptionInput();
}
GroupDescription.Internal internalGroup = resource.asInternalGroup().orElseThrow(NotInternalGroupException::new);
if (!resource.getControl().isOwner()) {
throw new AuthException("Not group owner");
}
String currentDescription = Strings.nullToEmpty(internalGroup.getDescription());
String newDescription = Strings.nullToEmpty(input.description);
if (!Objects.equals(currentDescription, newDescription)) {
AccountGroup.UUID groupUuid = internalGroup.getGroupUUID();
GroupDelta groupDelta = GroupDelta.builder().setDescription(newDescription).build();
try {
groupsUpdateProvider.get().updateGroup(groupUuid, groupDelta);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
}
}
return Strings.isNullOrEmpty(input.description) ? Response.none() : Response.ok(input.description);
}
Aggregations