SetEditPreferences: Return info from REST handler
This is needed to harmonize the API across different user preferences: * diff * edit * general Change-Id: I8126fc217a442c551fba1fcfcecdb6c07d1b2d64
This commit is contained in:
@@ -1402,11 +1402,28 @@ link:#edit-preferences-info[EditPreferencesInfo] entity.
|
||||
}
|
||||
----
|
||||
|
||||
The response is "`204 No Content`"
|
||||
As result the new edit preferences of the user are returned as a
|
||||
link:#edit-preferences-info[EditPreferencesInfo] entity.
|
||||
|
||||
.Response
|
||||
----
|
||||
HTTP/1.1 204 No Content
|
||||
HTTP/1.1 200 OK
|
||||
Content-Disposition: attachment
|
||||
Content-Type: application/json;charset=UTF-8
|
||||
|
||||
)]}'
|
||||
{
|
||||
"theme": "ECLIPSE",
|
||||
"key_map_type": "VIM",
|
||||
"tab_size": 4,
|
||||
"line_length": 80,
|
||||
"cursor_blink_rate": 530,
|
||||
"hide_top_menu": true,
|
||||
"show_whitespace_errors": true,
|
||||
"hide_line_numbers": true,
|
||||
"match_brackets": true,
|
||||
"auto_close_brackets": true
|
||||
}
|
||||
----
|
||||
|
||||
[[get-starred-changes]]
|
||||
|
||||
@@ -59,20 +59,18 @@ public class EditPreferencesIT extends AbstractDaemonTest {
|
||||
out.theme = Theme.TWILIGHT;
|
||||
out.keyMapType = KeyMapType.EMACS;
|
||||
|
||||
adminSession.put(endPoint, out).assertNoContent();
|
||||
|
||||
r = adminSession.get(endPoint);
|
||||
r = adminSession.put(endPoint, out);
|
||||
r.assertOK();
|
||||
|
||||
EditPreferencesInfo info = getEditPrefInfo(r);
|
||||
assertEditPreferences(info, out);
|
||||
|
||||
// Partially filled input record
|
||||
EditPreferencesInfo in = new EditPreferencesInfo();
|
||||
in.tabSize = 42;
|
||||
adminSession.put(endPoint, in).assertNoContent();
|
||||
|
||||
r = adminSession.get(endPoint);
|
||||
r = adminSession.put(endPoint, in);
|
||||
r.assertOK();
|
||||
|
||||
info = getEditPrefInfo(r);
|
||||
out.tabSize = in.tabSize;
|
||||
assertEditPreferences(info, out);
|
||||
|
||||
@@ -45,7 +45,7 @@ public class AccountApi {
|
||||
|
||||
/** Put the account edit preferences */
|
||||
public static void putEditPreferences(EditPreferences in,
|
||||
AsyncCallback<VoidResult> cb) {
|
||||
AsyncCallback<EditPreferences> cb) {
|
||||
self().view("preferences.edit").put(in, cb);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public class EditPreferences extends JavaScriptObject {
|
||||
return p;
|
||||
}
|
||||
|
||||
public final void copyTo(EditPreferencesInfo p) {
|
||||
public final EditPreferencesInfo copyTo(EditPreferencesInfo p) {
|
||||
p.tabSize = tabSize();
|
||||
p.lineLength = lineLength();
|
||||
p.cursorBlinkRate = cursorBlinkRate();
|
||||
@@ -50,6 +50,7 @@ public class EditPreferences extends JavaScriptObject {
|
||||
p.autoCloseBrackets = autoCloseBrackets();
|
||||
p.theme = theme();
|
||||
p.keyMapType = keyMapType();
|
||||
return p;
|
||||
}
|
||||
|
||||
public final void theme(Theme i) {
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
package com.google.gerrit.client.editor;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.VoidResult;
|
||||
import com.google.gerrit.client.account.AccountApi;
|
||||
import com.google.gerrit.client.account.EditPreferences;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.ui.NpIntTextBox;
|
||||
import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.KeyMapType;
|
||||
import com.google.gerrit.extensions.client.Theme;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
@@ -235,10 +235,11 @@ public class EditPreferencesBox extends Composite {
|
||||
|
||||
@UiHandler("save")
|
||||
void onSave(@SuppressWarnings("unused") ClickEvent e) {
|
||||
AccountApi.putEditPreferences(prefs, new GerritCallback<VoidResult>() {
|
||||
AccountApi.putEditPreferences(prefs,
|
||||
new GerritCallback<EditPreferences>() {
|
||||
@Override
|
||||
public void onSuccess(VoidResult n) {
|
||||
prefs.copyTo(Gerrit.getEditPreferences());
|
||||
public void onSuccess(EditPreferences p) {
|
||||
Gerrit.setEditPreferences(p.copyTo(new EditPreferencesInfo()));
|
||||
}
|
||||
});
|
||||
close();
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
package com.google.gerrit.server.account;
|
||||
|
||||
import static com.google.gerrit.server.account.GetEditPreferences.readFromGit;
|
||||
import static com.google.gerrit.server.config.ConfigUtil.loadSection;
|
||||
import static com.google.gerrit.server.config.ConfigUtil.storeSection;
|
||||
|
||||
import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
@@ -58,7 +58,7 @@ public class SetEditPreferences implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response<?> apply(AccountResource rsrc, EditPreferencesInfo in)
|
||||
public EditPreferencesInfo apply(AccountResource rsrc, EditPreferencesInfo in)
|
||||
throws AuthException, BadRequestException, RepositoryNotFoundException,
|
||||
IOException, ConfigInvalidException {
|
||||
if (self.get() != rsrc.getUser()
|
||||
@@ -73,6 +73,7 @@ public class SetEditPreferences implements
|
||||
Account.Id accountId = rsrc.getUser().getAccountId();
|
||||
|
||||
VersionedAccountPreferences prefs;
|
||||
EditPreferencesInfo out = new EditPreferencesInfo();
|
||||
try (MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName)) {
|
||||
prefs = VersionedAccountPreferences.forUser(accountId);
|
||||
prefs.load(md);
|
||||
@@ -80,8 +81,10 @@ public class SetEditPreferences implements
|
||||
readFromGit(accountId, gitMgr, allUsersName, in),
|
||||
EditPreferencesInfo.defaults());
|
||||
prefs.commit(md);
|
||||
out = loadSection(prefs.getConfig(), UserConfigSections.EDIT, null, out,
|
||||
EditPreferencesInfo.defaults(), null);
|
||||
}
|
||||
|
||||
return Response.none();
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user