Search in sources :

Example 11 with NoSuchGroupException

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);
    }
}
Also used : ExternalIdKeyFactory(com.google.gerrit.server.account.externalids.ExternalIdKeyFactory) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException) GlobalCapability(com.google.gerrit.common.data.GlobalCapability) ProjectCache(com.google.gerrit.server.project.ProjectCache) Inject(com.google.inject.Inject) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) GroupsUpdate(com.google.gerrit.server.group.db.GroupsUpdate) Strings(com.google.common.base.Strings) Config(org.eclipse.jgit.lib.Config) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) SCHEME_USERNAME(com.google.gerrit.server.account.externalids.ExternalId.SCHEME_USERNAME) ExternalIdFactory(com.google.gerrit.server.account.externalids.ExternalIdFactory) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) NoSuchUserException(com.google.gerrit.server.auth.NoSuchUserException) AccountGroup(com.google.gerrit.entities.AccountGroup) ImmutableSet(com.google.common.collect.ImmutableSet) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) Sequences(com.google.gerrit.server.notedb.Sequences) SshKeyCache(com.google.gerrit.server.ssh.SshKeyCache) AccessSection(com.google.gerrit.entities.AccessSection) StorageException(com.google.gerrit.exceptions.StorageException) Collection(java.util.Collection) Permission(com.google.gerrit.entities.Permission) Account(com.google.gerrit.entities.Account) Set(java.util.Set) AccountFieldName(com.google.gerrit.extensions.client.AccountFieldName) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) ExternalIds(com.google.gerrit.server.account.externalids.ExternalIds) Objects(java.util.Objects) Consumer(java.util.function.Consumer) Provider(com.google.inject.Provider) List(java.util.List) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ServerInitiated(com.google.gerrit.server.ServerInitiated) Optional(java.util.Optional) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) VisibleForTesting(com.google.common.annotations.VisibleForTesting) DuplicateExternalIdKeyException(com.google.gerrit.server.account.externalids.DuplicateExternalIdKeyException) GroupDelta(com.google.gerrit.server.group.db.GroupDelta) FluentLogger(com.google.common.flogger.FluentLogger) Singleton(com.google.inject.Singleton) GroupDelta(com.google.gerrit.server.group.db.GroupDelta) GroupsUpdate(com.google.gerrit.server.group.db.GroupsUpdate) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException)

Example 12 with NoSuchGroupException

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);
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) AuthType(com.google.gerrit.extensions.client.AuthType) AccountCache(com.google.gerrit.server.account.AccountCache) AccountLoader(com.google.gerrit.server.account.AccountLoader) 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) Inject(com.google.inject.Inject) Response(com.google.gerrit.extensions.restapi.Response) DefaultInput(com.google.gerrit.extensions.restapi.DefaultInput) MemberResource(com.google.gerrit.server.group.MemberResource) 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) GroupDescription(com.google.gerrit.entities.GroupDescription) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) RestCollectionCreateView(com.google.gerrit.extensions.restapi.RestCollectionCreateView) AuthException(com.google.gerrit.extensions.restapi.AuthException) UnresolvableAccountException(com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) LinkedHashSet(java.util.LinkedHashSet) AccountGroup(com.google.gerrit.entities.AccountGroup) Input(com.google.gerrit.server.restapi.group.AddMembers.Input) GroupControl(com.google.gerrit.server.account.GroupControl) AccountResolver(com.google.gerrit.server.account.AccountResolver) Account(com.google.gerrit.entities.Account) Set(java.util.Set) IOException(java.io.IOException) AccountException(com.google.gerrit.server.account.AccountException) Sets(com.google.common.collect.Sets) Provider(com.google.inject.Provider) List(java.util.List) UserInitiated(com.google.gerrit.server.UserInitiated) AuthRequest(com.google.gerrit.server.account.AuthRequest) Optional(java.util.Optional) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) AuthConfig(com.google.gerrit.server.config.AuthConfig) GroupDelta(com.google.gerrit.server.group.db.GroupDelta) AccountState(com.google.gerrit.server.account.AccountState) AccountManager(com.google.gerrit.server.account.AccountManager) Singleton(com.google.inject.Singleton) GroupDelta(com.google.gerrit.server.group.db.GroupDelta)

Example 13 with NoSuchGroupException

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));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Account(com.google.gerrit.entities.Account) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) AuthException(com.google.gerrit.extensions.restapi.AuthException) IdString(com.google.gerrit.extensions.restapi.IdString) 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) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 14 with NoSuchGroupException

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);
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) SubgroupResource(com.google.gerrit.server.group.SubgroupResource) GroupResource(com.google.gerrit.server.group.GroupResource) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) NoSuchGroupException(com.google.gerrit.exceptions.NoSuchGroupException) 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) RestModifyView(com.google.gerrit.extensions.restapi.RestModifyView) GroupsUpdate(com.google.gerrit.server.group.db.GroupsUpdate) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) GroupDescription(com.google.gerrit.entities.GroupDescription) AuthException(com.google.gerrit.extensions.restapi.AuthException) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupControl(com.google.gerrit.server.account.GroupControl) Set(java.util.Set) IOException(java.io.IOException) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) Sets(com.google.common.collect.Sets) Provider(com.google.inject.Provider) 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 15 with NoSuchGroupException

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) ArrayList(java.util.ArrayList) AuthException(com.google.gerrit.extensions.restapi.AuthException) IdString(com.google.gerrit.extensions.restapi.IdString) 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)

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