Search in sources :

Example 16 with NoSuchGroupException

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();
}
Also used : AuthException(com.google.gerrit.extensions.restapi.AuthException) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException) GroupDescription(com.google.gerrit.entities.GroupDescription) GroupControl(com.google.gerrit.server.account.GroupControl) AccountGroup(com.google.gerrit.entities.AccountGroup) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) HashSet(java.util.HashSet)

Example 17 with NoSuchGroupException

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);
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) SubgroupResource(com.google.gerrit.server.group.SubgroupResource) GroupResource(com.google.gerrit.server.group.GroupResource) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException) IdString(com.google.gerrit.extensions.restapi.IdString) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) GroupResolver(com.google.gerrit.server.group.GroupResolver) Inject(com.google.inject.Inject) Response(com.google.gerrit.extensions.restapi.Response) DefaultInput(com.google.gerrit.extensions.restapi.DefaultInput) ArrayList(java.util.ArrayList) RestModifyView(com.google.gerrit.extensions.restapi.RestModifyView) GroupsUpdate(com.google.gerrit.server.group.db.GroupsUpdate) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) ImmutableList(com.google.common.collect.ImmutableList) GroupDescription(com.google.gerrit.entities.GroupDescription) RestCollectionCreateView(com.google.gerrit.extensions.restapi.RestCollectionCreateView) AuthException(com.google.gerrit.extensions.restapi.AuthException) LinkedHashSet(java.util.LinkedHashSet) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupControl(com.google.gerrit.server.account.GroupControl) Set(java.util.Set) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) Provider(com.google.inject.Provider) List(java.util.List) UserInitiated(com.google.gerrit.server.UserInitiated) GroupDelta(com.google.gerrit.server.group.db.GroupDelta) Input(com.google.gerrit.server.restapi.group.AddSubgroups.Input) Singleton(com.google.inject.Singleton) GroupDelta(com.google.gerrit.server.group.db.GroupDelta)

Example 18 with NoSuchGroupException

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);
}
Also used : UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) AccountGroup(com.google.gerrit.entities.AccountGroup) ContributorAgreement(com.google.gerrit.entities.ContributorAgreement) AuthException(com.google.gerrit.extensions.restapi.AuthException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AccountState(com.google.gerrit.server.account.AccountState) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException)

Example 19 with NoSuchGroupException

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));
}
Also used : GroupDescription(com.google.gerrit.entities.GroupDescription) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupDelta(com.google.gerrit.server.group.db.GroupDelta) AuthException(com.google.gerrit.extensions.restapi.AuthException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException)

Example 20 with NoSuchGroupException

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);
}
Also used : GroupDescription(com.google.gerrit.entities.GroupDescription) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupDelta(com.google.gerrit.server.group.db.GroupDelta) DescriptionInput(com.google.gerrit.extensions.common.DescriptionInput) AuthException(com.google.gerrit.extensions.restapi.AuthException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException)

Aggregations

NoSuchGroupException (com.google.gerrit.exceptions.NoSuchGroupException)26 AccountGroup (com.google.gerrit.entities.AccountGroup)22 GroupDescription (com.google.gerrit.entities.GroupDescription)13 AuthException (com.google.gerrit.extensions.restapi.AuthException)12 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)12 GroupControl (com.google.gerrit.server.account.GroupControl)12 GroupDelta (com.google.gerrit.server.group.db.GroupDelta)12 Account (com.google.gerrit.entities.Account)10 ArrayList (java.util.ArrayList)10 Inject (com.google.inject.Inject)9 IOException (java.io.IOException)9 Singleton (com.google.inject.Singleton)8 Sets (com.google.common.collect.Sets)7 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)7 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)7 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)6 IdString (com.google.gerrit.extensions.restapi.IdString)6 Response (com.google.gerrit.extensions.restapi.Response)6 GroupResource (com.google.gerrit.server.group.GroupResource)6 GroupsUpdate (com.google.gerrit.server.group.db.GroupsUpdate)6