Merge "AccountApi: Add methods to get and set GeneralPreferencesInfo"
This commit is contained in:
@@ -12,12 +12,12 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.account;
|
||||
package com.google.gerrit.acceptance.api.accounts;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo.DateFormat;
|
||||
@@ -34,6 +34,7 @@ import org.junit.Test;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
@NoHttpd
|
||||
public class GeneralPreferencesIT extends AbstractDaemonTest {
|
||||
private TestAccount user42;
|
||||
|
||||
@@ -43,21 +44,12 @@ public class GeneralPreferencesIT extends AbstractDaemonTest {
|
||||
user42 = accounts.create(name, name + "@example.com", "User 42");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDiffPreferencesOfNonExistingAccount_NotFound()
|
||||
throws Exception {
|
||||
RestResponse r = adminSession.get("/accounts/non-existing/preferences");
|
||||
r.assertNotFound();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAndSetPreferences() throws Exception {
|
||||
RestResponse r = adminSession.get("/accounts/" + user42.email
|
||||
+ "/preferences");
|
||||
r.assertOK();
|
||||
GeneralPreferencesInfo o = gApi.accounts()
|
||||
.id(user42.id.toString())
|
||||
.getPreferences();
|
||||
GeneralPreferencesInfo d = GeneralPreferencesInfo.defaults();
|
||||
GeneralPreferencesInfo o =
|
||||
newGson().fromJson(r.getReader(), GeneralPreferencesInfo.class);
|
||||
|
||||
assertThat(o.changesPerPage).isEqualTo(d.changesPerPage);
|
||||
assertThat(o.showSiteHeader).isEqualTo(d.showSiteHeader);
|
||||
@@ -102,9 +94,9 @@ public class GeneralPreferencesIT extends AbstractDaemonTest {
|
||||
i.urlAliases = new HashMap<>();
|
||||
i.urlAliases.put("foo", "bar");
|
||||
|
||||
r = adminSession.put("/accounts/" + user42.email + "/preferences", i);
|
||||
r.assertOK();
|
||||
o = newGson().fromJson(r.getReader(), GeneralPreferencesInfo.class);
|
||||
o = gApi.accounts()
|
||||
.id(user42.getId().toString())
|
||||
.setPreferences(i);
|
||||
|
||||
assertThat(o.changesPerPage).isEqualTo(i.changesPerPage);
|
||||
assertThat(o.showSiteHeader).isNull();
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.extensions.api.accounts;
|
||||
|
||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.GpgKeyInfo;
|
||||
import com.google.gerrit.extensions.restapi.NotImplementedException;
|
||||
@@ -26,6 +27,11 @@ public interface AccountApi {
|
||||
AccountInfo get() throws RestApiException;
|
||||
|
||||
String getAvatarUrl(int size) throws RestApiException;
|
||||
|
||||
GeneralPreferencesInfo getPreferences() throws RestApiException;
|
||||
GeneralPreferencesInfo setPreferences(GeneralPreferencesInfo in)
|
||||
throws RestApiException;
|
||||
|
||||
void starChange(String id) throws RestApiException;
|
||||
void unstarChange(String id) throws RestApiException;
|
||||
void addEmail(EmailInput input) throws RestApiException;
|
||||
@@ -50,6 +56,17 @@ public interface AccountApi {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralPreferencesInfo getPreferences() throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralPreferencesInfo setPreferences(GeneralPreferencesInfo in)
|
||||
throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void starChange(String id) throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.google.gerrit.common.errors.EmailException;
|
||||
import com.google.gerrit.extensions.api.accounts.AccountApi;
|
||||
import com.google.gerrit.extensions.api.accounts.EmailInput;
|
||||
import com.google.gerrit.extensions.api.accounts.GpgKeyApi;
|
||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.GpgKeyInfo;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
@@ -28,6 +29,8 @@ import com.google.gerrit.server.account.AccountLoader;
|
||||
import com.google.gerrit.server.account.AccountResource;
|
||||
import com.google.gerrit.server.account.CreateEmail;
|
||||
import com.google.gerrit.server.account.GetAvatar;
|
||||
import com.google.gerrit.server.account.GetPreferences;
|
||||
import com.google.gerrit.server.account.SetPreferences;
|
||||
import com.google.gerrit.server.account.StarredChanges;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.change.ChangesCollection;
|
||||
@@ -36,6 +39,9 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -48,6 +54,8 @@ public class AccountApiImpl implements AccountApi {
|
||||
private final ChangesCollection changes;
|
||||
private final AccountLoader.Factory accountLoaderFactory;
|
||||
private final Provider<GetAvatar> getAvatar;
|
||||
private final GetPreferences getPreferences;
|
||||
private final SetPreferences setPreferences;
|
||||
private final StarredChanges.Create starredChangesCreate;
|
||||
private final StarredChanges.Delete starredChangesDelete;
|
||||
private final CreateEmail.Factory createEmailFactory;
|
||||
@@ -57,6 +65,8 @@ public class AccountApiImpl implements AccountApi {
|
||||
AccountApiImpl(AccountLoader.Factory ailf,
|
||||
ChangesCollection changes,
|
||||
Provider<GetAvatar> getAvatar,
|
||||
GetPreferences getPreferences,
|
||||
SetPreferences setPreferences,
|
||||
StarredChanges.Create starredChangesCreate,
|
||||
StarredChanges.Delete starredChangesDelete,
|
||||
CreateEmail.Factory createEmailFactory,
|
||||
@@ -66,6 +76,8 @@ public class AccountApiImpl implements AccountApi {
|
||||
this.accountLoaderFactory = ailf;
|
||||
this.changes = changes;
|
||||
this.getAvatar = getAvatar;
|
||||
this.getPreferences = getPreferences;
|
||||
this.setPreferences = setPreferences;
|
||||
this.starredChangesCreate = starredChangesCreate;
|
||||
this.starredChangesDelete = starredChangesDelete;
|
||||
this.createEmailFactory = createEmailFactory;
|
||||
@@ -92,6 +104,21 @@ public class AccountApiImpl implements AccountApi {
|
||||
return myGetAvatar.apply(account).location();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralPreferencesInfo getPreferences() throws RestApiException {
|
||||
return getPreferences.apply(account);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneralPreferencesInfo setPreferences(GeneralPreferencesInfo in)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return setPreferences.apply(account, in);
|
||||
} catch (IOException | ConfigInvalidException e) {
|
||||
throw new RestApiException("Cannot set preferences", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void starChange(String id) throws RestApiException {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user