Merge "Support getting account details in extension API"
This commit is contained in:
@@ -19,6 +19,7 @@ import com.google.gerrit.extensions.client.DiffPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.ProjectWatchInfo;
|
||||
import com.google.gerrit.extensions.common.AccountDetailInfo;
|
||||
import com.google.gerrit.extensions.common.AccountExternalIdInfo;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.AgreementInfo;
|
||||
@@ -36,6 +37,8 @@ import java.util.SortedSet;
|
||||
public interface AccountApi {
|
||||
AccountInfo get() throws RestApiException;
|
||||
|
||||
AccountDetailInfo detail() throws RestApiException;
|
||||
|
||||
boolean getActive() throws RestApiException;
|
||||
|
||||
void setActive(boolean active) throws RestApiException;
|
||||
@@ -116,6 +119,11 @@ public interface AccountApi {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountDetailInfo detail() throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getActive() throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright (C) 2018 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class AccountDetailInfo extends AccountInfo {
|
||||
public Timestamp registeredOn;
|
||||
public Boolean inactive;
|
||||
|
||||
public AccountDetailInfo(Integer id) {
|
||||
super(id);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import com.google.gerrit.extensions.client.DiffPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.ProjectWatchInfo;
|
||||
import com.google.gerrit.extensions.common.AccountDetailInfo;
|
||||
import com.google.gerrit.extensions.common.AccountExternalIdInfo;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.AgreementInfo;
|
||||
@@ -57,6 +58,7 @@ import com.google.gerrit.server.restapi.account.DeleteWatchedProjects;
|
||||
import com.google.gerrit.server.restapi.account.GetActive;
|
||||
import com.google.gerrit.server.restapi.account.GetAgreements;
|
||||
import com.google.gerrit.server.restapi.account.GetAvatar;
|
||||
import com.google.gerrit.server.restapi.account.GetDetail;
|
||||
import com.google.gerrit.server.restapi.account.GetDiffPreferences;
|
||||
import com.google.gerrit.server.restapi.account.GetEditPreferences;
|
||||
import com.google.gerrit.server.restapi.account.GetEmails;
|
||||
@@ -92,6 +94,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
private final AccountResource account;
|
||||
private final ChangesCollection changes;
|
||||
private final AccountLoader.Factory accountLoaderFactory;
|
||||
private final GetDetail getDetail;
|
||||
private final GetAvatar getAvatar;
|
||||
private final GetPreferences getPreferences;
|
||||
private final SetPreferences setPreferences;
|
||||
@@ -131,6 +134,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
AccountApiImpl(
|
||||
AccountLoader.Factory ailf,
|
||||
ChangesCollection changes,
|
||||
GetDetail getDetail,
|
||||
GetAvatar getAvatar,
|
||||
GetPreferences getPreferences,
|
||||
SetPreferences setPreferences,
|
||||
@@ -169,6 +173,7 @@ public class AccountApiImpl implements AccountApi {
|
||||
this.account = account;
|
||||
this.accountLoaderFactory = ailf;
|
||||
this.changes = changes;
|
||||
this.getDetail = getDetail;
|
||||
this.getAvatar = getAvatar;
|
||||
this.getPreferences = getPreferences;
|
||||
this.setPreferences = setPreferences;
|
||||
@@ -217,6 +222,15 @@ public class AccountApiImpl implements AccountApi {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountDetailInfo detail() throws RestApiException {
|
||||
try {
|
||||
return getDetail.apply(account);
|
||||
} catch (Exception e) {
|
||||
throw asRestApiException("Cannot get detail", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getActive() throws RestApiException {
|
||||
Response<String> result = getActive.apply(account);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.restapi.account;
|
||||
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.AccountDetailInfo;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.account.AccountDirectory.FillOptions;
|
||||
@@ -23,7 +23,6 @@ import com.google.gerrit.server.account.InternalAccountDirectory;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
|
||||
@@ -46,13 +45,4 @@ public class GetDetail implements RestReadView<AccountResource> {
|
||||
directory.fillAccountInfo(Collections.singleton(info), EnumSet.allOf(FillOptions.class));
|
||||
return info;
|
||||
}
|
||||
|
||||
public static class AccountDetailInfo extends AccountInfo {
|
||||
public Timestamp registeredOn;
|
||||
public Boolean inactive;
|
||||
|
||||
public AccountDetailInfo(Integer id) {
|
||||
super(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ import com.google.gerrit.extensions.api.config.ConsistencyCheckInfo;
|
||||
import com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo;
|
||||
import com.google.gerrit.extensions.api.config.ConsistencyCheckInput;
|
||||
import com.google.gerrit.extensions.api.config.ConsistencyCheckInput.CheckAccountsInput;
|
||||
import com.google.gerrit.extensions.common.AccountDetailInfo;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.EmailInfo;
|
||||
@@ -818,6 +819,32 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
accountIndexedCounter.assertNoReindex();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDetail() throws Exception {
|
||||
String email = "preferred@example.com";
|
||||
String name = "Foo";
|
||||
String username = name("foo");
|
||||
TestAccount foo = accountCreator.create(username, email, name);
|
||||
String secondaryEmail = "secondary@example.com";
|
||||
EmailInput input = newEmailInput(secondaryEmail);
|
||||
gApi.accounts().id(foo.id.get()).addEmail(input);
|
||||
|
||||
String status = "OOO";
|
||||
gApi.accounts().id(foo.id.get()).setStatus(status);
|
||||
|
||||
setApiUser(foo);
|
||||
AccountDetailInfo detail = gApi.accounts().id(foo.id.get()).detail();
|
||||
assertThat(detail._accountId).isEqualTo(foo.id.get());
|
||||
assertThat(detail.name).isEqualTo(name);
|
||||
assertThat(detail.username).isEqualTo(username);
|
||||
assertThat(detail.email).isEqualTo(email);
|
||||
assertThat(detail.secondaryEmails).containsExactly(secondaryEmail);
|
||||
assertThat(detail.status).isEqualTo(status);
|
||||
assertThat(detail.registeredOn).isEqualTo(getAccount(foo.getId()).getRegisteredOn());
|
||||
assertThat(detail.inactive).isNull();
|
||||
assertThat(detail._moreAccounts).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getOwnEmails() throws Exception {
|
||||
String email = "preferred@example.com";
|
||||
|
||||
@@ -19,8 +19,8 @@ import static com.google.gerrit.acceptance.rest.account.AccountAssert.assertAcco
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.extensions.common.AccountDetailInfo;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.restapi.account.GetDetail.AccountDetailInfo;
|
||||
import org.junit.Test;
|
||||
|
||||
public class GetAccountDetailIT extends AbstractDaemonTest {
|
||||
|
||||
Reference in New Issue
Block a user