AccountApi: Add methods to get and set DiffPreferencesInfo
Change-Id: I139d2c784052d92d3f0c84044a5a361e1bbf061d
This commit is contained in:
@@ -12,34 +12,26 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// 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 static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
import com.google.gerrit.acceptance.RestResponse;
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
|
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
|
||||||
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
|
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
|
||||||
import com.google.gerrit.extensions.client.Theme;
|
import com.google.gerrit.extensions.client.Theme;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@NoHttpd
|
||||||
public class DiffPreferencesIT extends AbstractDaemonTest {
|
public class DiffPreferencesIT extends AbstractDaemonTest {
|
||||||
@Test
|
|
||||||
public void getDiffPreferencesOfNonExistingAccount_NotFound()
|
|
||||||
throws Exception {
|
|
||||||
adminSession.get("/accounts/non-existing/preferences.diff")
|
|
||||||
.assertNotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDiffPreferences() throws Exception {
|
public void getDiffPreferences() throws Exception {
|
||||||
RestResponse r = adminSession.get("/accounts/" + admin.email
|
|
||||||
+ "/preferences.diff");
|
|
||||||
r.assertOK();
|
|
||||||
DiffPreferencesInfo d = DiffPreferencesInfo.defaults();
|
DiffPreferencesInfo d = DiffPreferencesInfo.defaults();
|
||||||
DiffPreferencesInfo o =
|
DiffPreferencesInfo o = gApi.accounts()
|
||||||
newGson().fromJson(r.getReader(), DiffPreferencesInfo.class);
|
.id(admin.getId().toString())
|
||||||
|
.getDiffPreferences();
|
||||||
|
|
||||||
assertThat(o.context).isEqualTo(d.context);
|
assertThat(o.context).isEqualTo(d.context);
|
||||||
assertThat(o.tabSize).isEqualTo(d.tabSize);
|
assertThat(o.tabSize).isEqualTo(d.tabSize);
|
||||||
@@ -93,11 +85,9 @@ public class DiffPreferencesIT extends AbstractDaemonTest {
|
|||||||
i.hideEmptyPane ^= true;
|
i.hideEmptyPane ^= true;
|
||||||
i.matchBrackets ^= true;
|
i.matchBrackets ^= true;
|
||||||
|
|
||||||
RestResponse r = adminSession.put("/accounts/" + admin.email
|
DiffPreferencesInfo o = gApi.accounts()
|
||||||
+ "/preferences.diff", i);
|
.id(admin.getId().toString())
|
||||||
r.assertOK();
|
.setDiffPreferences(i);
|
||||||
DiffPreferencesInfo o = newGson().fromJson(r.getReader(),
|
|
||||||
DiffPreferencesInfo.class);
|
|
||||||
|
|
||||||
assertThat(o.context).isEqualTo(i.context);
|
assertThat(o.context).isEqualTo(i.context);
|
||||||
assertThat(o.tabSize).isEqualTo(i.tabSize);
|
assertThat(o.tabSize).isEqualTo(i.tabSize);
|
||||||
@@ -125,10 +115,9 @@ public class DiffPreferencesIT extends AbstractDaemonTest {
|
|||||||
// Partially fill input record
|
// Partially fill input record
|
||||||
i = new DiffPreferencesInfo();
|
i = new DiffPreferencesInfo();
|
||||||
i.tabSize = 42;
|
i.tabSize = 42;
|
||||||
r = adminSession.put("/accounts/" + admin.email
|
DiffPreferencesInfo a = gApi.accounts()
|
||||||
+ "/preferences.diff", i);
|
.id(admin.getId().toString())
|
||||||
DiffPreferencesInfo a = newGson().fromJson(r.getReader(),
|
.setDiffPreferences(i);
|
||||||
DiffPreferencesInfo.class);
|
|
||||||
|
|
||||||
assertThat(a.context).isEqualTo(o.context);
|
assertThat(a.context).isEqualTo(o.context);
|
||||||
assertThat(a.tabSize).isEqualTo(42);
|
assertThat(a.tabSize).isEqualTo(42);
|
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
package com.google.gerrit.extensions.api.accounts;
|
package com.google.gerrit.extensions.api.accounts;
|
||||||
|
|
||||||
|
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
|
||||||
import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
||||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||||
import com.google.gerrit.extensions.common.AccountInfo;
|
import com.google.gerrit.extensions.common.AccountInfo;
|
||||||
@@ -33,6 +34,10 @@ public interface AccountApi {
|
|||||||
GeneralPreferencesInfo setPreferences(GeneralPreferencesInfo in)
|
GeneralPreferencesInfo setPreferences(GeneralPreferencesInfo in)
|
||||||
throws RestApiException;
|
throws RestApiException;
|
||||||
|
|
||||||
|
DiffPreferencesInfo getDiffPreferences() throws RestApiException;
|
||||||
|
DiffPreferencesInfo setDiffPreferences(DiffPreferencesInfo in)
|
||||||
|
throws RestApiException;
|
||||||
|
|
||||||
EditPreferencesInfo getEditPreferences() throws RestApiException;
|
EditPreferencesInfo getEditPreferences() throws RestApiException;
|
||||||
EditPreferencesInfo setEditPreferences(EditPreferencesInfo in)
|
EditPreferencesInfo setEditPreferences(EditPreferencesInfo in)
|
||||||
throws RestApiException;
|
throws RestApiException;
|
||||||
@@ -72,6 +77,17 @@ public interface AccountApi {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DiffPreferencesInfo getDiffPreferences() throws RestApiException {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DiffPreferencesInfo setDiffPreferences(DiffPreferencesInfo in)
|
||||||
|
throws RestApiException {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EditPreferencesInfo getEditPreferences() throws RestApiException {
|
public EditPreferencesInfo getEditPreferences() throws RestApiException {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
@@ -28,7 +28,6 @@ import com.google.gerrit.server.config.AllUsersName;
|
|||||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||||
import com.google.gerrit.server.git.MetaDataUpdate;
|
import com.google.gerrit.server.git.MetaDataUpdate;
|
||||||
import com.google.gerrit.server.git.UserConfigSections;
|
import com.google.gerrit.server.git.UserConfigSections;
|
||||||
import com.google.gwtorm.server.OrmException;
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
@@ -60,7 +59,7 @@ public class SetDiffPreferences implements
|
|||||||
@Override
|
@Override
|
||||||
public DiffPreferencesInfo apply(AccountResource rsrc, DiffPreferencesInfo in)
|
public DiffPreferencesInfo apply(AccountResource rsrc, DiffPreferencesInfo in)
|
||||||
throws AuthException, BadRequestException, ConfigInvalidException,
|
throws AuthException, BadRequestException, ConfigInvalidException,
|
||||||
RepositoryNotFoundException, IOException, OrmException {
|
RepositoryNotFoundException, IOException {
|
||||||
if (self.get() != rsrc.getUser()
|
if (self.get() != rsrc.getUser()
|
||||||
&& !self.get().getCapabilities().canModifyAccount()) {
|
&& !self.get().getCapabilities().canModifyAccount()) {
|
||||||
throw new AuthException("requires Modify Account capability");
|
throw new AuthException("requires Modify Account capability");
|
||||||
|
@@ -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.AccountApi;
|
||||||
import com.google.gerrit.extensions.api.accounts.EmailInput;
|
import com.google.gerrit.extensions.api.accounts.EmailInput;
|
||||||
import com.google.gerrit.extensions.api.accounts.GpgKeyApi;
|
import com.google.gerrit.extensions.api.accounts.GpgKeyApi;
|
||||||
|
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
|
||||||
import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
||||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||||
import com.google.gerrit.extensions.common.AccountInfo;
|
import com.google.gerrit.extensions.common.AccountInfo;
|
||||||
@@ -30,8 +31,10 @@ import com.google.gerrit.server.account.AccountLoader;
|
|||||||
import com.google.gerrit.server.account.AccountResource;
|
import com.google.gerrit.server.account.AccountResource;
|
||||||
import com.google.gerrit.server.account.CreateEmail;
|
import com.google.gerrit.server.account.CreateEmail;
|
||||||
import com.google.gerrit.server.account.GetAvatar;
|
import com.google.gerrit.server.account.GetAvatar;
|
||||||
|
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.GetPreferences;
|
import com.google.gerrit.server.account.GetPreferences;
|
||||||
|
import com.google.gerrit.server.account.SetDiffPreferences;
|
||||||
import com.google.gerrit.server.account.SetEditPreferences;
|
import com.google.gerrit.server.account.SetEditPreferences;
|
||||||
import com.google.gerrit.server.account.SetPreferences;
|
import com.google.gerrit.server.account.SetPreferences;
|
||||||
import com.google.gerrit.server.account.StarredChanges;
|
import com.google.gerrit.server.account.StarredChanges;
|
||||||
@@ -59,6 +62,8 @@ public class AccountApiImpl implements AccountApi {
|
|||||||
private final Provider<GetAvatar> getAvatar;
|
private final Provider<GetAvatar> getAvatar;
|
||||||
private final GetPreferences getPreferences;
|
private final GetPreferences getPreferences;
|
||||||
private final SetPreferences setPreferences;
|
private final SetPreferences setPreferences;
|
||||||
|
private final GetDiffPreferences getDiffPreferences;
|
||||||
|
private final SetDiffPreferences setDiffPreferences;
|
||||||
private final GetEditPreferences getEditPreferences;
|
private final GetEditPreferences getEditPreferences;
|
||||||
private final SetEditPreferences setEditPreferences;
|
private final SetEditPreferences setEditPreferences;
|
||||||
private final StarredChanges.Create starredChangesCreate;
|
private final StarredChanges.Create starredChangesCreate;
|
||||||
@@ -72,6 +77,8 @@ public class AccountApiImpl implements AccountApi {
|
|||||||
Provider<GetAvatar> getAvatar,
|
Provider<GetAvatar> getAvatar,
|
||||||
GetPreferences getPreferences,
|
GetPreferences getPreferences,
|
||||||
SetPreferences setPreferences,
|
SetPreferences setPreferences,
|
||||||
|
GetDiffPreferences getDiffPreferences,
|
||||||
|
SetDiffPreferences setDiffPreferences,
|
||||||
GetEditPreferences getEditPreferences,
|
GetEditPreferences getEditPreferences,
|
||||||
SetEditPreferences setEditPreferences,
|
SetEditPreferences setEditPreferences,
|
||||||
StarredChanges.Create starredChangesCreate,
|
StarredChanges.Create starredChangesCreate,
|
||||||
@@ -85,6 +92,8 @@ public class AccountApiImpl implements AccountApi {
|
|||||||
this.getAvatar = getAvatar;
|
this.getAvatar = getAvatar;
|
||||||
this.getPreferences = getPreferences;
|
this.getPreferences = getPreferences;
|
||||||
this.setPreferences = setPreferences;
|
this.setPreferences = setPreferences;
|
||||||
|
this.getDiffPreferences = getDiffPreferences;
|
||||||
|
this.setDiffPreferences = setDiffPreferences;
|
||||||
this.getEditPreferences = getEditPreferences;
|
this.getEditPreferences = getEditPreferences;
|
||||||
this.setEditPreferences = setEditPreferences;
|
this.setEditPreferences = setEditPreferences;
|
||||||
this.starredChangesCreate = starredChangesCreate;
|
this.starredChangesCreate = starredChangesCreate;
|
||||||
@@ -128,6 +137,25 @@ public class AccountApiImpl implements AccountApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DiffPreferencesInfo getDiffPreferences() throws RestApiException {
|
||||||
|
try {
|
||||||
|
return getDiffPreferences.apply(account);
|
||||||
|
} catch (IOException | ConfigInvalidException e) {
|
||||||
|
throw new RestApiException("Cannot query diff preferences", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DiffPreferencesInfo setDiffPreferences(DiffPreferencesInfo in)
|
||||||
|
throws RestApiException {
|
||||||
|
try {
|
||||||
|
return setDiffPreferences.apply(account, in);
|
||||||
|
} catch (IOException | ConfigInvalidException e) {
|
||||||
|
throw new RestApiException("Cannot set diff preferences", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EditPreferencesInfo getEditPreferences() throws RestApiException {
|
public EditPreferencesInfo getEditPreferences() throws RestApiException {
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user