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;
}
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);
}
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))));
}
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));
}
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;
}
Aggregations