Search in sources :

Example 1 with GroupInput

use of com.google.gerrit.extensions.api.groups.GroupInput in project gerrit by GerritCodeReview.

the class AbstractDaemonTest method createGroup.

protected String createGroup(String name, String owner) throws Exception {
    name = name(name);
    GroupInput in = new GroupInput();
    in.name = name;
    in.ownerId = owner;
    gApi.groups().create(in);
    return name;
}
Also used : GroupInput(com.google.gerrit.extensions.api.groups.GroupInput)

Example 2 with GroupInput

use of com.google.gerrit.extensions.api.groups.GroupInput in project gerrit by GerritCodeReview.

the class GroupsImpl method create.

@Override
public GroupApi create(String name) throws RestApiException {
    GroupInput in = new GroupInput();
    in.name = name;
    return create(in);
}
Also used : GroupInput(com.google.gerrit.extensions.api.groups.GroupInput)

Example 3 with GroupInput

use of com.google.gerrit.extensions.api.groups.GroupInput in project gerrit by GerritCodeReview.

the class CreateGroup method apply.

@Override
public Response<GroupInfo> apply(TopLevelResource resource, IdString id, GroupInput input) throws AuthException, BadRequestException, UnprocessableEntityException, ResourceConflictException, IOException, ConfigInvalidException, ResourceNotFoundException, PermissionBackendException {
    String name = id.get();
    if (input == null) {
        input = new GroupInput();
    }
    if (input.name != null && !name.equals(input.name)) {
        throw new BadRequestException("name must match URL");
    }
    AccountGroup.UUID ownerUuid = owner(input);
    CreateGroupArgs args = new CreateGroupArgs();
    args.setGroupName(name);
    args.uuid = Strings.isNullOrEmpty(input.uuid) ? null : AccountGroup.UUID.parse(input.uuid);
    if (args.uuid != null) {
        if (!args.uuid.isInternalGroup()) {
            throw new BadRequestException(String.format("invalid group UUID '%s'", args.uuid.get()));
        }
        if (groupCache.get(args.uuid).isPresent()) {
            throw new ResourceConflictException(String.format("group with UUID '%s' already exists", args.uuid.get()));
        }
    }
    args.groupDescription = Strings.emptyToNull(input.description);
    args.visibleToAll = MoreObjects.firstNonNull(input.visibleToAll, defaultVisibleToAll);
    args.ownerGroupUuid = ownerUuid;
    if (input.members != null && !input.members.isEmpty()) {
        List<Account.Id> members = new ArrayList<>();
        for (String nameOrEmailOrId : input.members) {
            Account a = addMembers.findAccount(nameOrEmailOrId);
            if (!a.isActive()) {
                throw new UnprocessableEntityException(String.format("Account Inactive: %s", nameOrEmailOrId));
            }
            members.add(a.id());
        }
        args.initialMembers = members;
    } else {
        args.initialMembers = ownerUuid == null ? Collections.singleton(self.get().getAccountId()) : Collections.emptySet();
    }
    try {
        groupCreationValidationListeners.runEach(l -> l.validateNewGroup(args), ValidationException.class);
    } catch (ValidationException e) {
        throw new ResourceConflictException(e.getMessage(), e);
    }
    return Response.created(json.format(new InternalGroupDescription(createGroup(args))));
}
Also used : GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) Account(com.google.gerrit.entities.Account) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) InternalGroupDescription(com.google.gerrit.server.group.InternalGroupDescription) ValidationException(com.google.gerrit.server.validators.ValidationException) ArrayList(java.util.ArrayList) IdString(com.google.gerrit.extensions.restapi.IdString) CreateGroupArgs(com.google.gerrit.server.account.CreateGroupArgs) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) AccountGroup(com.google.gerrit.entities.AccountGroup) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException)

Example 4 with GroupInput

use of com.google.gerrit.extensions.api.groups.GroupInput in project gerrit by GerritCodeReview.

the class AbstractPushForReview method pushForMasterWithCcGroup.

@Test
public void pushForMasterWithCcGroup() throws Exception {
    TestAccount user2 = accountCreator.user2();
    String group = name("group");
    GroupInput gin = new GroupInput();
    gin.name = group;
    gin.members = ImmutableList.of(user.username(), user2.username());
    // TODO(dborowitz): Shouldn't be necessary; see ReviewerModifier.
    gin.visibleToAll = true;
    gApi.groups().create(gin);
    PushOneCommit.Result r = pushTo("refs/for/master%cc=" + group);
    r.assertOkStatus();
    r.assertChange(Change.Status.NEW, null, ImmutableList.of(), ImmutableList.of(user, user2));
}
Also used : GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with GroupInput

use of com.google.gerrit.extensions.api.groups.GroupInput in project gerrit by GerritCodeReview.

the class GroupOperationsImplTest method createArbitraryGroupInput.

private GroupInput createArbitraryGroupInput() {
    GroupInput groupInput = new GroupInput();
    groupInput.name = name("verifiers-" + uniqueGroupNameIndex++);
    return groupInput;
}
Also used : GroupInput(com.google.gerrit.extensions.api.groups.GroupInput)

Aggregations

GroupInput (com.google.gerrit.extensions.api.groups.GroupInput)27 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)13 Test (org.junit.Test)13 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)9 GroupAssert.assertGroupInfo (com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo)6 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)5 TestAccount (com.google.gerrit.acceptance.TestAccount)5 AccountGroup (com.google.gerrit.entities.AccountGroup)5 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)4 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4 Account (com.google.gerrit.entities.Account)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Iterables (com.google.common.collect.Iterables)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 ExtensionRegistry (com.google.gerrit.acceptance.ExtensionRegistry)2 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)2 NoHttpd (com.google.gerrit.acceptance.NoHttpd)2 ProjectOperations (com.google.gerrit.acceptance.testsuite.project.ProjectOperations)2