Add support to retrieve the account diff preferences via REST
The diff preferences of a user can now be retrieved by GET on '/accounts/*/preferences.diff'. Change-Id: Ica4014496b8ced4d0d0f34804a8dc4efcdd694a1
This commit is contained in:
@@ -257,6 +257,41 @@ The response redirects to the URL of the avatar image.
|
||||
Location: https://profiles/avatar/john_doe.jpeg?s=20x20
|
||||
----
|
||||
|
||||
[[get-diff-preferences]]
|
||||
Get Diff Preferences
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
[verse]
|
||||
'GET /accounts/link:#account-id[\{account-id\}]/preferences.diff'
|
||||
|
||||
Retrieves the diff preferences of a user.
|
||||
|
||||
.Request
|
||||
----
|
||||
GET /a/accounts/self/preferences.diff HTTP/1.0
|
||||
----
|
||||
|
||||
As result the diff preferences of the user are returned as a
|
||||
link:#diff-preferences-info[DiffPreferencesInfo] entity.
|
||||
|
||||
.Response
|
||||
----
|
||||
HTTP/1.1 200 OK
|
||||
Content-Disposition: attachment
|
||||
Content-Type: application/json;charset=UTF-8
|
||||
|
||||
)]}'
|
||||
{
|
||||
"context": 10,
|
||||
"ignore_whitespace": "IGNORE_ALL_SPACE",
|
||||
"intraline_difference": true,
|
||||
"line_length": 100,
|
||||
"show_tabs": true,
|
||||
"show_whitespace_errors": true,
|
||||
"syntax_highlighting": true,
|
||||
"tab_size": 8
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
[[ids]]
|
||||
IDs
|
||||
@@ -349,6 +384,52 @@ link:access-control.html#capability_startReplication[Start Replication]
|
||||
capability.
|
||||
|=================================
|
||||
|
||||
[[diff-preferences-info]]
|
||||
DiffPreferencesInfo
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
The `DiffPreferencesInfo` entity contains information about the diff
|
||||
preferences of a user.
|
||||
|
||||
[options="header",width="50%",cols="1,^1,5"]
|
||||
|=====================================
|
||||
|Field Name ||Description
|
||||
|`context` ||
|
||||
The number of lines of context when viewing a patch.
|
||||
|`expand_all_comments` |not set if `false`|
|
||||
Whether all inline comments should be automatically expanded.
|
||||
|`ignore_whitespace` ||
|
||||
Whether whitespace changes should be ignored and if yes, which
|
||||
whitespace changes should be ignored. +
|
||||
Allowed values are `IGNORE_NONE`, `IGNORE_SPACE_AT_EOL`,
|
||||
`IGNORE_SPACE_CHANGE`, `IGNORE_ALL_SPACE`.
|
||||
|`intraline_difference` |not set if `false`|
|
||||
Whether intraline differences should be highlighted.
|
||||
|`line_length` ||
|
||||
Number of characters that should be displayed in one line.
|
||||
|`manual_review` |not set if `false`|
|
||||
Whether the 'Reviewed' flag should not be set automatically on a patch
|
||||
when it is viewed.
|
||||
|`retain_header` |not set if `false`|
|
||||
Whether the header that is displayed above the patch (that either shows
|
||||
the commit message, the diff preferences, the patch sets or the files)
|
||||
should be retained on file switch.
|
||||
|`show_line_endings` |not set if `false`|
|
||||
Whether Windows EOL/Cr-Lf should be displayed as '\r' in a dotted-line
|
||||
box.
|
||||
|`show_tabs` |not set if `false`|
|
||||
Whether tabs should be shown.
|
||||
|`show_whitespace_errors`|not set if `false`|
|
||||
Whether whitespace errors should be shown.
|
||||
|`skip_deleted` |not set if `false`|
|
||||
Whether deleted files should be skipped on file switch.
|
||||
|`skip_uncommented` |not set if `false`|
|
||||
Whether uncommented files should be skipped on file switch.
|
||||
|`syntax_highlighting` |not set if `false`|
|
||||
Whether syntax highlighting should be enabled.
|
||||
|`tab_size` ||
|
||||
Number of spaces that should be used to display one tab.
|
||||
|=====================================
|
||||
|
||||
[[query-limit-info]]
|
||||
QueryLimitInfo
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
// Copyright (C) 2013 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.server.account;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
|
||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
public class GetDiffPreferences implements RestReadView<AccountResource> {
|
||||
|
||||
private final Provider<CurrentUser> self;
|
||||
|
||||
@Inject
|
||||
GetDiffPreferences(Provider<CurrentUser> self) {
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiffPreferencesInfo apply(AccountResource rsrc) throws AuthException {
|
||||
if (self.get() != rsrc.getUser()
|
||||
&& !self.get().getCapabilities().canAdministrateServer()) {
|
||||
throw new AuthException("restricted to administrator");
|
||||
}
|
||||
return DiffPreferencesInfo.parse(rsrc.getUser().getAccountDiffPreference());
|
||||
}
|
||||
|
||||
static class DiffPreferencesInfo {
|
||||
static DiffPreferencesInfo parse(AccountDiffPreference p) {
|
||||
DiffPreferencesInfo info = new DiffPreferencesInfo();
|
||||
info.context = p.getContext();
|
||||
info.expandAllComments = p.isExpandAllComments() ? true : null;
|
||||
info.ignoreWhitespace = p.getIgnoreWhitespace();
|
||||
info.intralineDifference = p.isIntralineDifference() ? true : null;
|
||||
info.lineLength = p.getLineLength();
|
||||
info.manualReview = p.isManualReview() ? true : null;
|
||||
info.retainHeader = p.isRetainHeader() ? true : null;
|
||||
info.showLineEndings = p.isShowLineEndings() ? true : null;
|
||||
info.showTabs = p.isShowTabs() ? true : null;
|
||||
info.showWhitespaceErrors = p.isShowWhitespaceErrors() ? true : null;
|
||||
info.skipDeleted = p.isSkipDeleted() ? true : null;
|
||||
info.skipUncommented = p.isSkipUncommented() ? true : null;
|
||||
info.syntaxHighlighting = p.isSyntaxHighlighting() ? true : null;
|
||||
info.tabSize = p.getTabSize();
|
||||
return info;
|
||||
}
|
||||
|
||||
short context;
|
||||
Boolean expandAllComments;
|
||||
Whitespace ignoreWhitespace;
|
||||
Boolean intralineDifference;
|
||||
int lineLength;
|
||||
Boolean manualReview;
|
||||
Boolean retainHeader;
|
||||
Boolean showLineEndings;
|
||||
Boolean showTabs;
|
||||
Boolean showWhitespaceErrors;
|
||||
Boolean skipDeleted;
|
||||
Boolean skipUncommented;
|
||||
Boolean syntaxHighlighting;
|
||||
int tabSize;
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ public class Module extends RestApiModule {
|
||||
get(ACCOUNT_KIND, "avatar").to(GetAvatar.class);
|
||||
child(ACCOUNT_KIND, "capabilities").to(Capabilities.class);
|
||||
get(ACCOUNT_KIND, "groups").to(GetGroups.class);
|
||||
get(ACCOUNT_KIND, "preferences.diff").to(GetDiffPreferences.class);
|
||||
get(CAPABILITY_KIND).to(GetCapabilities.CheckOne.class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user