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
|
.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]]
|
[[get-starred-changes]]
|
||||||
|
|||||||
@@ -59,20 +59,18 @@ public class EditPreferencesIT extends AbstractDaemonTest {
|
|||||||
out.theme = Theme.TWILIGHT;
|
out.theme = Theme.TWILIGHT;
|
||||||
out.keyMapType = KeyMapType.EMACS;
|
out.keyMapType = KeyMapType.EMACS;
|
||||||
|
|
||||||
adminSession.put(endPoint, out).assertNoContent();
|
r = adminSession.put(endPoint, out);
|
||||||
|
|
||||||
r = adminSession.get(endPoint);
|
|
||||||
r.assertOK();
|
r.assertOK();
|
||||||
|
|
||||||
EditPreferencesInfo info = getEditPrefInfo(r);
|
EditPreferencesInfo info = getEditPrefInfo(r);
|
||||||
assertEditPreferences(info, out);
|
assertEditPreferences(info, out);
|
||||||
|
|
||||||
// Partially filled input record
|
// Partially filled input record
|
||||||
EditPreferencesInfo in = new EditPreferencesInfo();
|
EditPreferencesInfo in = new EditPreferencesInfo();
|
||||||
in.tabSize = 42;
|
in.tabSize = 42;
|
||||||
adminSession.put(endPoint, in).assertNoContent();
|
r = adminSession.put(endPoint, in);
|
||||||
|
|
||||||
r = adminSession.get(endPoint);
|
|
||||||
r.assertOK();
|
r.assertOK();
|
||||||
|
|
||||||
info = getEditPrefInfo(r);
|
info = getEditPrefInfo(r);
|
||||||
out.tabSize = in.tabSize;
|
out.tabSize = in.tabSize;
|
||||||
assertEditPreferences(info, out);
|
assertEditPreferences(info, out);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class AccountApi {
|
|||||||
|
|
||||||
/** Put the account edit preferences */
|
/** Put the account edit preferences */
|
||||||
public static void putEditPreferences(EditPreferences in,
|
public static void putEditPreferences(EditPreferences in,
|
||||||
AsyncCallback<VoidResult> cb) {
|
AsyncCallback<EditPreferences> cb) {
|
||||||
self().view("preferences.edit").put(in, cb);
|
self().view("preferences.edit").put(in, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class EditPreferences extends JavaScriptObject {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void copyTo(EditPreferencesInfo p) {
|
public final EditPreferencesInfo copyTo(EditPreferencesInfo p) {
|
||||||
p.tabSize = tabSize();
|
p.tabSize = tabSize();
|
||||||
p.lineLength = lineLength();
|
p.lineLength = lineLength();
|
||||||
p.cursorBlinkRate = cursorBlinkRate();
|
p.cursorBlinkRate = cursorBlinkRate();
|
||||||
@@ -50,6 +50,7 @@ public class EditPreferences extends JavaScriptObject {
|
|||||||
p.autoCloseBrackets = autoCloseBrackets();
|
p.autoCloseBrackets = autoCloseBrackets();
|
||||||
p.theme = theme();
|
p.theme = theme();
|
||||||
p.keyMapType = keyMapType();
|
p.keyMapType = keyMapType();
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void theme(Theme i) {
|
public final void theme(Theme i) {
|
||||||
|
|||||||
@@ -15,11 +15,11 @@
|
|||||||
package com.google.gerrit.client.editor;
|
package com.google.gerrit.client.editor;
|
||||||
|
|
||||||
import com.google.gerrit.client.Gerrit;
|
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.AccountApi;
|
||||||
import com.google.gerrit.client.account.EditPreferences;
|
import com.google.gerrit.client.account.EditPreferences;
|
||||||
import com.google.gerrit.client.rpc.GerritCallback;
|
import com.google.gerrit.client.rpc.GerritCallback;
|
||||||
import com.google.gerrit.client.ui.NpIntTextBox;
|
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.KeyMapType;
|
||||||
import com.google.gerrit.extensions.client.Theme;
|
import com.google.gerrit.extensions.client.Theme;
|
||||||
import com.google.gwt.core.client.GWT;
|
import com.google.gwt.core.client.GWT;
|
||||||
@@ -235,12 +235,13 @@ public class EditPreferencesBox extends Composite {
|
|||||||
|
|
||||||
@UiHandler("save")
|
@UiHandler("save")
|
||||||
void onSave(@SuppressWarnings("unused") ClickEvent e) {
|
void onSave(@SuppressWarnings("unused") ClickEvent e) {
|
||||||
AccountApi.putEditPreferences(prefs, new GerritCallback<VoidResult>() {
|
AccountApi.putEditPreferences(prefs,
|
||||||
@Override
|
new GerritCallback<EditPreferences>() {
|
||||||
public void onSuccess(VoidResult n) {
|
@Override
|
||||||
prefs.copyTo(Gerrit.getEditPreferences());
|
public void onSuccess(EditPreferences p) {
|
||||||
}
|
Gerrit.setEditPreferences(p.copyTo(new EditPreferencesInfo()));
|
||||||
});
|
}
|
||||||
|
});
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,12 +15,12 @@
|
|||||||
package com.google.gerrit.server.account;
|
package com.google.gerrit.server.account;
|
||||||
|
|
||||||
import static com.google.gerrit.server.account.GetEditPreferences.readFromGit;
|
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 static com.google.gerrit.server.config.ConfigUtil.storeSection;
|
||||||
|
|
||||||
import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
||||||
import com.google.gerrit.extensions.restapi.AuthException;
|
import com.google.gerrit.extensions.restapi.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
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.extensions.restapi.RestModifyView;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
@@ -58,7 +58,7 @@ public class SetEditPreferences implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response<?> apply(AccountResource rsrc, EditPreferencesInfo in)
|
public EditPreferencesInfo apply(AccountResource rsrc, EditPreferencesInfo in)
|
||||||
throws AuthException, BadRequestException, RepositoryNotFoundException,
|
throws AuthException, BadRequestException, RepositoryNotFoundException,
|
||||||
IOException, ConfigInvalidException {
|
IOException, ConfigInvalidException {
|
||||||
if (self.get() != rsrc.getUser()
|
if (self.get() != rsrc.getUser()
|
||||||
@@ -73,6 +73,7 @@ public class SetEditPreferences implements
|
|||||||
Account.Id accountId = rsrc.getUser().getAccountId();
|
Account.Id accountId = rsrc.getUser().getAccountId();
|
||||||
|
|
||||||
VersionedAccountPreferences prefs;
|
VersionedAccountPreferences prefs;
|
||||||
|
EditPreferencesInfo out = new EditPreferencesInfo();
|
||||||
try (MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName)) {
|
try (MetaDataUpdate md = metaDataUpdateFactory.get().create(allUsersName)) {
|
||||||
prefs = VersionedAccountPreferences.forUser(accountId);
|
prefs = VersionedAccountPreferences.forUser(accountId);
|
||||||
prefs.load(md);
|
prefs.load(md);
|
||||||
@@ -80,8 +81,10 @@ public class SetEditPreferences implements
|
|||||||
readFromGit(accountId, gitMgr, allUsersName, in),
|
readFromGit(accountId, gitMgr, allUsersName, in),
|
||||||
EditPreferencesInfo.defaults());
|
EditPreferencesInfo.defaults());
|
||||||
prefs.commit(md);
|
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