Search in sources :

Example 6 with GroupDelta

use of com.google.gerrit.server.group.db.GroupDelta in project gerrit by GerritCodeReview.

the class GroupsUpdateIT method groupRenameIsRetriedWhenFailedDueToConcurrentNameModification.

@Test
public void groupRenameIsRetriedWhenFailedDueToConcurrentNameModification() throws Exception {
    createGroup("users", "users-UUID");
    GroupDelta groupDelta = GroupDelta.builder().setName(AccountGroup.nameKey("contributors")).setMemberModification(new CreateAnotherGroupOnceAsSideEffectOfMemberModification("verifiers")).build();
    updateGroup(AccountGroup.uuid("users-UUID"), groupDelta);
    Stream<String> allGroupNames = getAllGroupNames();
    assertThat(allGroupNames).containsAtLeast("contributors", "verifiers");
}
Also used : GroupDelta(com.google.gerrit.server.group.db.GroupDelta) Test(org.junit.Test)

Example 7 with GroupDelta

use of com.google.gerrit.server.group.db.GroupDelta in project gerrit by GerritCodeReview.

the class DeleteMembers method removeGroupMembers.

private void removeGroupMembers(AccountGroup.UUID groupUuid, Set<Account.Id> accountIds) throws IOException, NoSuchGroupException, ConfigInvalidException {
    GroupDelta groupDelta = GroupDelta.builder().setMemberModification(memberIds -> Sets.difference(memberIds, accountIds)).build();
    groupsUpdateProvider.get().updateGroup(groupUuid, groupDelta);
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) 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) Inject(com.google.inject.Inject) Response(com.google.gerrit.extensions.restapi.Response) MemberResource(com.google.gerrit.server.group.MemberResource) RestModifyView(com.google.gerrit.extensions.restapi.RestModifyView) GroupsUpdate(com.google.gerrit.server.group.db.GroupsUpdate) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) GroupDescription(com.google.gerrit.entities.GroupDescription) AuthException(com.google.gerrit.extensions.restapi.AuthException) 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) 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) Singleton(com.google.inject.Singleton) GroupDelta(com.google.gerrit.server.group.db.GroupDelta)

Example 8 with GroupDelta

use of com.google.gerrit.server.group.db.GroupDelta in project gerrit by GerritCodeReview.

the class SchemaCreatorImpl method createBatchUsersGroup.

private void createBatchUsersGroup(Sequences seqs, Repository allUsersRepo, GroupReference groupReference, AccountGroup.UUID adminsGroupUuid) throws IOException, ConfigInvalidException {
    InternalGroupCreation groupCreation = getGroupCreation(seqs, groupReference);
    GroupDelta groupDelta = GroupDelta.builder().setDescription("Users who perform batch actions on Gerrit").setOwnerGroupUUID(adminsGroupUuid).build();
    createGroup(allUsersRepo, groupCreation, groupDelta);
}
Also used : GroupDelta(com.google.gerrit.server.group.db.GroupDelta) InternalGroupCreation(com.google.gerrit.server.group.db.InternalGroupCreation)

Example 9 with GroupDelta

use of com.google.gerrit.server.group.db.GroupDelta 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 10 with GroupDelta

use of com.google.gerrit.server.group.db.GroupDelta 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)

Aggregations

GroupDelta (com.google.gerrit.server.group.db.GroupDelta)20 AccountGroup (com.google.gerrit.entities.AccountGroup)12 NoSuchGroupException (com.google.gerrit.exceptions.NoSuchGroupException)12 GroupDescription (com.google.gerrit.entities.GroupDescription)8 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)8 Sets (com.google.common.collect.Sets)7 AuthException (com.google.gerrit.extensions.restapi.AuthException)7 GroupsUpdate (com.google.gerrit.server.group.db.GroupsUpdate)7 Inject (com.google.inject.Inject)7 Provider (com.google.inject.Provider)7 Singleton (com.google.inject.Singleton)7 IOException (java.io.IOException)7 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)7 Set (java.util.Set)6 Account (com.google.gerrit.entities.Account)5 Response (com.google.gerrit.extensions.restapi.Response)5 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)5 UserInitiated (com.google.gerrit.server.UserInitiated)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5