Merge changes I6974d505,I3685381f
* changes: Allow change GroupJson options in CreateGroup CreateGroup: add members to GroupInput
This commit is contained in:
@@ -1314,10 +1314,12 @@ If set, must match the group name in the URL.
|
||||
|`visible_to_all`|optional|
|
||||
Whether the group is visible to all registered users. +
|
||||
`false` if not set.
|
||||
|`owner_id`|optional|The URL encoded ID of the owner group. +
|
||||
|`owner_id` |optional|The URL encoded ID of the owner group. +
|
||||
This can be a group UUID, a legacy numeric group ID or a unique group
|
||||
name. +
|
||||
If not set, the new group will be self-owned.
|
||||
|`members` |optional|The initial members in a list of +
|
||||
link:#account-id[account ids].
|
||||
|===========================
|
||||
|
||||
[[group-options-info]]
|
||||
|
@@ -14,9 +14,12 @@
|
||||
|
||||
package com.google.gerrit.extensions.api.groups;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupInput {
|
||||
public String name;
|
||||
public String description;
|
||||
public Boolean visibleToAll;
|
||||
public String ownerId;
|
||||
public List<String> members;
|
||||
}
|
||||
|
@@ -125,11 +125,11 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
|
||||
GroupControl control = resource.getControl();
|
||||
|
||||
Set<Account.Id> newMemberIds = new HashSet<>();
|
||||
for (String nameOrEmail : input.members) {
|
||||
Account a = findAccount(nameOrEmail);
|
||||
for (String nameOrEmailOrId : input.members) {
|
||||
Account a = findAccount(nameOrEmailOrId);
|
||||
if (!a.isActive()) {
|
||||
throw new UnprocessableEntityException(String.format(
|
||||
"Account Inactive: %s", nameOrEmail));
|
||||
"Account Inactive: %s", nameOrEmailOrId));
|
||||
}
|
||||
|
||||
if (!control.canAddMember()) {
|
||||
@@ -142,10 +142,10 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
|
||||
return toAccountInfoList(newMemberIds);
|
||||
}
|
||||
|
||||
private Account findAccount(String nameOrEmail) throws AuthException,
|
||||
Account findAccount(String nameOrEmailOrId) throws AuthException,
|
||||
UnprocessableEntityException, OrmException, IOException {
|
||||
try {
|
||||
return accounts.parse(nameOrEmail).getAccount();
|
||||
return accounts.parse(nameOrEmailOrId).getAccount();
|
||||
} catch (UnprocessableEntityException e) {
|
||||
// might be because the account does not exist or because the account is
|
||||
// not visible
|
||||
@@ -153,9 +153,9 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
|
||||
case HTTP_LDAP:
|
||||
case CLIENT_SSL_CERT_LDAP:
|
||||
case LDAP:
|
||||
if (accountResolver.find(db.get(), nameOrEmail) == null) {
|
||||
if (accountResolver.find(db.get(), nameOrEmailOrId) == null) {
|
||||
// account does not exist, try to create it
|
||||
Account a = createAccountByLdap(nameOrEmail);
|
||||
Account a = createAccountByLdap(nameOrEmailOrId);
|
||||
if (a != null) {
|
||||
return a;
|
||||
}
|
||||
|
@@ -21,8 +21,10 @@ import com.google.gerrit.common.data.GroupDescription;
|
||||
import com.google.gerrit.common.data.GroupDescriptions;
|
||||
import com.google.gerrit.extensions.annotations.RequiresCapability;
|
||||
import com.google.gerrit.extensions.api.groups.GroupInput;
|
||||
import com.google.gerrit.extensions.client.ListGroupsOption;
|
||||
import com.google.gerrit.extensions.common.GroupInfo;
|
||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
@@ -51,6 +53,8 @@ import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -96,9 +100,19 @@ public class CreateGroup implements RestModifyView<TopLevelResource, GroupInput>
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public CreateGroup addOption(ListGroupsOption o) {
|
||||
json.addOption(o);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CreateGroup addOptions(Collection<ListGroupsOption> o) {
|
||||
json.addOptions(o);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupInfo apply(TopLevelResource resource, GroupInput input)
|
||||
throws BadRequestException, UnprocessableEntityException,
|
||||
throws AuthException, BadRequestException, UnprocessableEntityException,
|
||||
ResourceConflictException, OrmException, IOException {
|
||||
if (input == null) {
|
||||
input = new GroupInput();
|
||||
@@ -114,9 +128,22 @@ public class CreateGroup implements RestModifyView<TopLevelResource, GroupInput>
|
||||
args.visibleToAll = MoreObjects.firstNonNull(input.visibleToAll,
|
||||
defaultVisibleToAll);
|
||||
args.ownerGroupId = ownerId;
|
||||
args.initialMembers = ownerId == null
|
||||
? Collections.singleton(self.get().getAccountId())
|
||||
: Collections.<Account.Id> emptySet();
|
||||
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.getId());
|
||||
}
|
||||
args.initialMembers = members;
|
||||
} else {
|
||||
args.initialMembers = ownerId == null
|
||||
? Collections.singleton(self.get().getAccountId())
|
||||
: Collections.<Account.Id> emptySet();
|
||||
}
|
||||
|
||||
for (GroupCreationValidationListener l : groupCreationValidationListeners) {
|
||||
try {
|
||||
|
Reference in New Issue
Block a user