Merge "AccountApi: Add getGroups method"
This commit is contained in:
@@ -1134,6 +1134,12 @@ public abstract class AbstractDaemonTest {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String createAccount(String name, String group) throws Exception {
|
||||||
|
name = name(name);
|
||||||
|
accountCreator.create(name, group);
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
protected RevCommit getHead(Repository repo, String name) throws Exception {
|
protected RevCommit getHead(Repository repo, String name) throws Exception {
|
||||||
try (RevWalk rw = new RevWalk(repo)) {
|
try (RevWalk rw = new RevWalk(repo)) {
|
||||||
Ref r = repo.exactRef(name);
|
Ref r = repo.exactRef(name);
|
||||||
|
@@ -31,6 +31,7 @@ import static com.google.gerrit.server.account.externalids.ExternalId.SCHEME_GPG
|
|||||||
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
|
import static com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS;
|
||||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
import static java.util.stream.Collectors.toSet;
|
import static java.util.stream.Collectors.toSet;
|
||||||
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
|
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
@@ -1313,6 +1314,26 @@ public class AccountIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void groups() throws Exception {
|
||||||
|
assertGroups(
|
||||||
|
admin.username, ImmutableList.of("Anonymous Users", "Registered Users", "Administrators"));
|
||||||
|
|
||||||
|
//TODO: update when test user is fixed to be included in "Anonymous Users" and
|
||||||
|
// "Registered Users" groups
|
||||||
|
assertGroups(user.username, ImmutableList.of());
|
||||||
|
|
||||||
|
String group = createGroup("group");
|
||||||
|
String newUser = createAccount("user1", group);
|
||||||
|
assertGroups(newUser, ImmutableList.of(group));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertGroups(String user, List<String> expected) throws Exception {
|
||||||
|
List<String> actual =
|
||||||
|
gApi.accounts().id(user).getGroups().stream().map(g -> g.name).collect(toList());
|
||||||
|
assertThat(actual).containsExactlyElementsIn(expected);
|
||||||
|
}
|
||||||
|
|
||||||
private void assertSequenceNumbers(List<SshKeyInfo> sshKeys) {
|
private void assertSequenceNumbers(List<SshKeyInfo> sshKeys) {
|
||||||
int seq = 1;
|
int seq = 1;
|
||||||
for (SshKeyInfo key : sshKeys) {
|
for (SshKeyInfo key : sshKeys) {
|
||||||
|
@@ -687,12 +687,6 @@ public class GroupsIT extends AbstractDaemonTest {
|
|||||||
return groupCache.get(new AccountGroup.NameKey(name));
|
return groupCache.get(new AccountGroup.NameKey(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String createAccount(String name, String group) throws Exception {
|
|
||||||
name = name(name);
|
|
||||||
accountCreator.create(name, group);
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setCreatedOnToNull(AccountGroup.UUID groupUuid) throws Exception {
|
private void setCreatedOnToNull(AccountGroup.UUID groupUuid) throws Exception {
|
||||||
groupsUpdateProvider.get().updateGroup(db, groupUuid, group -> group.setCreatedOn(null));
|
groupsUpdateProvider.get().updateGroup(db, groupUuid, group -> group.setCreatedOn(null));
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,7 @@ import com.google.gerrit.extensions.common.AgreementInfo;
|
|||||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||||
import com.google.gerrit.extensions.common.EmailInfo;
|
import com.google.gerrit.extensions.common.EmailInfo;
|
||||||
import com.google.gerrit.extensions.common.GpgKeyInfo;
|
import com.google.gerrit.extensions.common.GpgKeyInfo;
|
||||||
|
import com.google.gerrit.extensions.common.GroupInfo;
|
||||||
import com.google.gerrit.extensions.common.SshKeyInfo;
|
import com.google.gerrit.extensions.common.SshKeyInfo;
|
||||||
import com.google.gerrit.extensions.restapi.NotImplementedException;
|
import com.google.gerrit.extensions.restapi.NotImplementedException;
|
||||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||||
@@ -69,6 +70,8 @@ public interface AccountApi {
|
|||||||
|
|
||||||
List<ChangeInfo> getStarredChanges() throws RestApiException;
|
List<ChangeInfo> getStarredChanges() throws RestApiException;
|
||||||
|
|
||||||
|
List<GroupInfo> getGroups() throws RestApiException;
|
||||||
|
|
||||||
List<EmailInfo> getEmails() throws RestApiException;
|
List<EmailInfo> getEmails() throws RestApiException;
|
||||||
|
|
||||||
void addEmail(EmailInput input) throws RestApiException;
|
void addEmail(EmailInput input) throws RestApiException;
|
||||||
@@ -196,6 +199,11 @@ public interface AccountApi {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GroupInfo> getGroups() throws RestApiException {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<EmailInfo> getEmails() throws RestApiException {
|
public List<EmailInfo> getEmails() throws RestApiException {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
@@ -33,6 +33,7 @@ import com.google.gerrit.extensions.common.AgreementInput;
|
|||||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||||
import com.google.gerrit.extensions.common.EmailInfo;
|
import com.google.gerrit.extensions.common.EmailInfo;
|
||||||
import com.google.gerrit.extensions.common.GpgKeyInfo;
|
import com.google.gerrit.extensions.common.GpgKeyInfo;
|
||||||
|
import com.google.gerrit.extensions.common.GroupInfo;
|
||||||
import com.google.gerrit.extensions.common.SshKeyInfo;
|
import com.google.gerrit.extensions.common.SshKeyInfo;
|
||||||
import com.google.gerrit.extensions.restapi.IdString;
|
import com.google.gerrit.extensions.restapi.IdString;
|
||||||
import com.google.gerrit.extensions.restapi.Response;
|
import com.google.gerrit.extensions.restapi.Response;
|
||||||
@@ -54,6 +55,7 @@ import com.google.gerrit.server.account.GetDiffPreferences;
|
|||||||
import com.google.gerrit.server.account.GetEditPreferences;
|
import com.google.gerrit.server.account.GetEditPreferences;
|
||||||
import com.google.gerrit.server.account.GetEmails;
|
import com.google.gerrit.server.account.GetEmails;
|
||||||
import com.google.gerrit.server.account.GetExternalIds;
|
import com.google.gerrit.server.account.GetExternalIds;
|
||||||
|
import com.google.gerrit.server.account.GetGroups;
|
||||||
import com.google.gerrit.server.account.GetPreferences;
|
import com.google.gerrit.server.account.GetPreferences;
|
||||||
import com.google.gerrit.server.account.GetSshKeys;
|
import com.google.gerrit.server.account.GetSshKeys;
|
||||||
import com.google.gerrit.server.account.GetWatchedProjects;
|
import com.google.gerrit.server.account.GetWatchedProjects;
|
||||||
@@ -70,6 +72,7 @@ import com.google.gerrit.server.account.StarredChanges;
|
|||||||
import com.google.gerrit.server.account.Stars;
|
import com.google.gerrit.server.account.Stars;
|
||||||
import com.google.gerrit.server.change.ChangeResource;
|
import com.google.gerrit.server.change.ChangeResource;
|
||||||
import com.google.gerrit.server.change.ChangesCollection;
|
import com.google.gerrit.server.change.ChangesCollection;
|
||||||
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
import com.google.inject.assistedinject.Assisted;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -116,6 +119,7 @@ public class AccountApiImpl implements AccountApi {
|
|||||||
private final GetExternalIds getExternalIds;
|
private final GetExternalIds getExternalIds;
|
||||||
private final DeleteExternalIds deleteExternalIds;
|
private final DeleteExternalIds deleteExternalIds;
|
||||||
private final PutStatus putStatus;
|
private final PutStatus putStatus;
|
||||||
|
private final GetGroups getGroups;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
AccountApiImpl(
|
AccountApiImpl(
|
||||||
@@ -153,6 +157,7 @@ public class AccountApiImpl implements AccountApi {
|
|||||||
GetExternalIds getExternalIds,
|
GetExternalIds getExternalIds,
|
||||||
DeleteExternalIds deleteExternalIds,
|
DeleteExternalIds deleteExternalIds,
|
||||||
PutStatus putStatus,
|
PutStatus putStatus,
|
||||||
|
GetGroups getGroups,
|
||||||
@Assisted AccountResource account) {
|
@Assisted AccountResource account) {
|
||||||
this.account = account;
|
this.account = account;
|
||||||
this.accountLoaderFactory = ailf;
|
this.accountLoaderFactory = ailf;
|
||||||
@@ -189,6 +194,7 @@ public class AccountApiImpl implements AccountApi {
|
|||||||
this.getExternalIds = getExternalIds;
|
this.getExternalIds = getExternalIds;
|
||||||
this.deleteExternalIds = deleteExternalIds;
|
this.deleteExternalIds = deleteExternalIds;
|
||||||
this.putStatus = putStatus;
|
this.putStatus = putStatus;
|
||||||
|
this.getGroups = getGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -362,6 +368,15 @@ public class AccountApiImpl implements AccountApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<GroupInfo> getGroups() throws RestApiException {
|
||||||
|
try {
|
||||||
|
return getGroups.apply(account);
|
||||||
|
} catch (OrmException e) {
|
||||||
|
throw asRestApiException("Cannot get groups", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<EmailInfo> getEmails() {
|
public List<EmailInfo> getEmails() {
|
||||||
return getEmails.apply(account);
|
return getEmails.apply(account);
|
||||||
|
Reference in New Issue
Block a user