Search in sources :

Example 11 with GroupDelta

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

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

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

the class SchemaCreatorImpl method createAdminsGroup.

private void createAdminsGroup(Sequences seqs, Repository allUsersRepo, GroupReference groupReference) throws IOException, ConfigInvalidException {
    InternalGroupCreation groupCreation = getGroupCreation(seqs, groupReference);
    GroupDelta groupDelta = GroupDelta.builder().setDescription("Gerrit Site Administrators").build();
    createGroup(allUsersRepo, groupCreation, groupDelta);
}
Also used : GroupDelta(com.google.gerrit.server.group.db.GroupDelta) InternalGroupCreation(com.google.gerrit.server.group.db.InternalGroupCreation)

Example 14 with GroupDelta

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

the class GroupsUpdateIT method createGroup.

private void createGroup(String groupName, String groupUuid) throws Exception {
    InternalGroupCreation groupCreation = getGroupCreation(groupName, groupUuid);
    GroupDelta groupDelta = GroupDelta.builder().build();
    createGroup(groupCreation, groupDelta);
}
Also used : GroupDelta(com.google.gerrit.server.group.db.GroupDelta) InternalGroupCreation(com.google.gerrit.server.group.db.InternalGroupCreation)

Example 15 with GroupDelta

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

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