Merge "Add a defaultDisplayName server config"
This commit is contained in:
commit
4c0f07cb04
@ -121,6 +121,27 @@ If `NONE`, no users other than the current user are visible.
|
||||
+
|
||||
Default is `ALL`.
|
||||
|
||||
[[accounts.defaultDisplayName]]accounts.defaultDisplayName::
|
||||
+
|
||||
If a user account does not have a display name set, which is the normal
|
||||
case, then this configuration value chooses the strategy how to choose
|
||||
the display name. Note that this strategy is not applied by the backend.
|
||||
If the AccountInfo has the display name unset, then the client has to
|
||||
apply this strategy.
|
||||
+
|
||||
If `FULL_NAME`, then the (full) name of the user is chosen from
|
||||
link:rest-api-accounts.html#account-info[AccountInfo].
|
||||
+
|
||||
If `FIRST_NAME`, then the first word (i.e. everything until first
|
||||
whitespace character) of the (full) name of the user is chosen from
|
||||
link:rest-api-accounts.html#account-info[AccountInfo].
|
||||
+
|
||||
If `USERNAME`, then the username of the user is chosen from
|
||||
link:rest-api-accounts.html#account-info[AccountInfo]. If that is not
|
||||
set, then the (full) name will be used.
|
||||
+
|
||||
Default is `FULL_NAME`.
|
||||
|
||||
[[addreviewer]]
|
||||
=== Section addreviewer
|
||||
|
||||
|
@ -1419,10 +1419,13 @@ section.
|
||||
|
||||
[options="header",cols="1,6"]
|
||||
|=============================
|
||||
|Field Name |Description
|
||||
|`visibility` |
|
||||
|Field Name |Description
|
||||
|`visibility` |
|
||||
link:config-gerrit.html#accounts.visibility[Visibility setting for
|
||||
accounts].
|
||||
|`default_display_name`|The default strategy for choosing the display
|
||||
name in the UI, see also
|
||||
link:config-gerrit.html#accounts.defaultDisplayName[gerrit.config].
|
||||
|=============================
|
||||
|
||||
[[auth-info]]
|
||||
|
@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2020 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.extensions.common;
|
||||
|
||||
/**
|
||||
* Fallback rule for choosing a display name, if it is not explicitly set. This rule will not be
|
||||
* applied by the backend, but should be applied by the user interface.
|
||||
*/
|
||||
public enum AccountDefaultDisplayName {
|
||||
|
||||
/**
|
||||
* If the display name for an account is not set, then the (full) name will be used as the display
|
||||
* name in the user interface.
|
||||
*/
|
||||
FULL_NAME,
|
||||
|
||||
/**
|
||||
* If the display name for an account is not set, then the first name (i.e. full name until first
|
||||
* whitespace character) will be used as the display name in the user interface.
|
||||
*/
|
||||
FIRST_NAME,
|
||||
|
||||
/**
|
||||
* If the display name for an account is not set, then the username will be used as the display
|
||||
* name in the user interface. If the username is also not set, then the (full) name will be used.
|
||||
*/
|
||||
USERNAME
|
||||
}
|
@ -35,9 +35,11 @@ public class AccountInfo {
|
||||
|
||||
/**
|
||||
* The display name of the user. This allows users to control how their name is displayed in the
|
||||
* UI. It will likely be unset for most users. Host admins will just choose a default (full name,
|
||||
* user name, first name, ...) for all users, and this account property is just a way to opt out
|
||||
* of the host wide default strategy of choosing the display name.
|
||||
* UI. It will likely be unset for most users. This account property is just a way to opt out of
|
||||
* the host wide default strategy of choosing the display name, see
|
||||
* accounts.accountDefaultDisplayName in the server config. The default strategy is not applied by
|
||||
* the backend. The display name will just be left unset, and the client has to load and apply the
|
||||
* default strategy.
|
||||
*/
|
||||
public String displayName;
|
||||
|
||||
|
@ -22,4 +22,7 @@ package com.google.gerrit.extensions.common;
|
||||
public class AccountsInfo {
|
||||
/** The value of the {@code accounts.visibility} parameter in {@code gerrit.config}. */
|
||||
public AccountVisibility visibility;
|
||||
|
||||
/** The value of the {@code accounts.visibility} parameter in {@code gerrit.config}. */
|
||||
public AccountDefaultDisplayName defaultDisplayName;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import com.google.gerrit.extensions.api.changes.ActionVisitor;
|
||||
import com.google.gerrit.extensions.api.projects.CommentLinkInfo;
|
||||
import com.google.gerrit.extensions.auth.oauth.OAuthLoginProvider;
|
||||
import com.google.gerrit.extensions.auth.oauth.OAuthTokenEncrypter;
|
||||
import com.google.gerrit.extensions.common.AccountDefaultDisplayName;
|
||||
import com.google.gerrit.extensions.common.AccountVisibility;
|
||||
import com.google.gerrit.extensions.config.CapabilityDefinition;
|
||||
import com.google.gerrit.extensions.config.CloneCommand;
|
||||
@ -269,6 +270,9 @@ public class GerritGlobalModule extends FactoryModule {
|
||||
factory(InboundEmailRejectionSender.Factory.class);
|
||||
bind(PermissionCollection.Factory.class);
|
||||
bind(AccountVisibility.class).toProvider(AccountVisibilityProvider.class).in(SINGLETON);
|
||||
AccountDefaultDisplayName accountDefaultDisplayName =
|
||||
cfg.getEnum("accounts", null, "defaultDisplayName", AccountDefaultDisplayName.FULL_NAME);
|
||||
bind(AccountDefaultDisplayName.class).toInstance(accountDefaultDisplayName);
|
||||
factory(ProjectOwnerGroupsProvider.Factory.class);
|
||||
factory(SubmitRuleEvaluator.Factory.class);
|
||||
|
||||
|
@ -20,6 +20,7 @@ import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.data.ContributorAgreement;
|
||||
import com.google.gerrit.extensions.common.AccountDefaultDisplayName;
|
||||
import com.google.gerrit.extensions.common.AccountsInfo;
|
||||
import com.google.gerrit.extensions.common.AuthInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeConfigInfo;
|
||||
@ -74,6 +75,7 @@ import org.eclipse.jgit.lib.Config;
|
||||
public class GetServerInfo implements RestReadView<ConfigResource> {
|
||||
private final Config config;
|
||||
private final AccountVisibilityProvider accountVisibilityProvider;
|
||||
private final AccountDefaultDisplayName accountDefaultDisplayName;
|
||||
private final AuthConfig authConfig;
|
||||
private final Realm realm;
|
||||
private final PluginMapContext<DownloadScheme> downloadSchemes;
|
||||
@ -96,6 +98,7 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
||||
public GetServerInfo(
|
||||
@GerritServerConfig Config config,
|
||||
AccountVisibilityProvider accountVisibilityProvider,
|
||||
AccountDefaultDisplayName accountDefaultDisplayName,
|
||||
AuthConfig authConfig,
|
||||
Realm realm,
|
||||
PluginMapContext<DownloadScheme> downloadSchemes,
|
||||
@ -115,6 +118,7 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
||||
SitePaths sitePaths) {
|
||||
this.config = config;
|
||||
this.accountVisibilityProvider = accountVisibilityProvider;
|
||||
this.accountDefaultDisplayName = accountDefaultDisplayName;
|
||||
this.authConfig = authConfig;
|
||||
this.realm = realm;
|
||||
this.downloadSchemes = downloadSchemes;
|
||||
@ -156,6 +160,7 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
||||
private AccountsInfo getAccountsInfo() {
|
||||
AccountsInfo info = new AccountsInfo();
|
||||
info.visibility = accountVisibilityProvider.get();
|
||||
info.defaultDisplayName = accountDefaultDisplayName;
|
||||
return info;
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@ import com.google.gerrit.common.RawInputUtil;
|
||||
import com.google.gerrit.extensions.api.plugins.InstallPluginInput;
|
||||
import com.google.gerrit.extensions.client.AccountFieldName;
|
||||
import com.google.gerrit.extensions.client.AuthType;
|
||||
import com.google.gerrit.extensions.common.AccountDefaultDisplayName;
|
||||
import com.google.gerrit.extensions.common.AccountVisibility;
|
||||
import com.google.gerrit.extensions.common.ServerInfo;
|
||||
import com.google.gerrit.server.config.AllProjectsNameProvider;
|
||||
@ -41,6 +42,7 @@ public class ServerInfoIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
// accounts
|
||||
@GerritConfig(name = "accounts.visibility", value = "VISIBLE_GROUP")
|
||||
@GerritConfig(name = "accounts.defaultDisplayName", value = "FIRST_NAME")
|
||||
|
||||
// auth
|
||||
@GerritConfig(name = "auth.type", value = "HTTP")
|
||||
@ -82,6 +84,7 @@ public class ServerInfoIT extends AbstractDaemonTest {
|
||||
|
||||
// accounts
|
||||
assertThat(i.accounts.visibility).isEqualTo(AccountVisibility.VISIBLE_GROUP);
|
||||
assertThat(i.accounts.defaultDisplayName).isEqualTo(AccountDefaultDisplayName.FIRST_NAME);
|
||||
|
||||
// auth
|
||||
assertThat(i.auth.authType).isEqualTo(AuthType.HTTP);
|
||||
|
Loading…
Reference in New Issue
Block a user