Merge "Gerrit Client: Use REST API to get server info"

This commit is contained in:
Edwin Kempin
2015-05-20 12:28:19 +00:00
committed by Gerrit Code Review
18 changed files with 216 additions and 89 deletions

View File

@@ -18,7 +18,6 @@ import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Account.FieldName;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gerrit.reviewdb.client.Project;
import java.util.List;
import java.util.Set;
@@ -35,15 +34,12 @@ public class GerritConfig implements Cloneable {
protected boolean httpPasswordSettingsEnabled = true;
protected GitwebConfig gitweb;
protected boolean useContributorAgreements;
protected boolean useContactInfo;
protected AuthType authType;
protected Set<DownloadScheme> downloadSchemes;
protected String gitDaemonUrl;
protected String gitHttpUrl;
protected String sshdAddress;
protected String editFullNameUrl;
protected Project.NameKey wildProject;
protected Set<Account.FieldName> editableAccountFields;
protected boolean documentationAvailable;
protected String anonymousCowardName;
@@ -135,10 +131,6 @@ public class GerritConfig implements Cloneable {
httpPasswordUrl = url;
}
public AuthType getAuthType() {
return authType;
}
public void setAuthType(final AuthType t) {
authType = t;
}
@@ -159,22 +151,6 @@ public class GerritConfig implements Cloneable {
gitweb = w;
}
public boolean isUseContributorAgreements() {
return useContributorAgreements;
}
public void setUseContributorAgreements(final boolean r) {
useContributorAgreements = r;
}
public boolean isUseContactInfo() {
return useContactInfo;
}
public void setUseContactInfo(final boolean r) {
useContactInfo = r;
}
public String getGitDaemonUrl() {
return gitDaemonUrl;
}
@@ -205,22 +181,6 @@ public class GerritConfig implements Cloneable {
sshdAddress = addr;
}
public Project.NameKey getWildProject() {
return wildProject;
}
public void setWildProject(final Project.NameKey wp) {
wildProject = wp;
}
public boolean canEdit(final Account.FieldName f) {
return editableAccountFields.contains(f);
}
public Set<Account.FieldName> getEditableAccountFields() {
return editableAccountFields;
}
public void setEditableAccountFields(final Set<Account.FieldName> af) {
editableAccountFields = af;
}
@@ -250,9 +210,9 @@ public class GerritConfig implements Cloneable {
}
public boolean siteHasUsernames() {
if (getAuthType() == AuthType.CUSTOM_EXTENSION
if (authType == AuthType.CUSTOM_EXTENSION
&& getHttpPasswordUrl() != null
&& !canEdit(FieldName.USER_NAME)) {
&& !editableAccountFields.contains(FieldName.USER_NAME)) {
return false;
}
return true;

View File

@@ -695,7 +695,7 @@ public class Dispatcher {
}
if (matchExact(SETTINGS_AGREEMENTS, token)
&& Gerrit.getConfig().isUseContributorAgreements()) {
&& Gerrit.info().auth().useContributorAgreements()) {
return new MyAgreementsScreen();
}

View File

@@ -28,6 +28,7 @@ import com.google.gerrit.client.api.PluginLoader;
import com.google.gerrit.client.changes.ChangeConstants;
import com.google.gerrit.client.changes.ChangeListScreen;
import com.google.gerrit.client.config.ConfigServerApi;
import com.google.gerrit.client.config.ServerInfo;
import com.google.gerrit.client.extensions.TopMenu;
import com.google.gerrit.client.extensions.TopMenuItem;
import com.google.gerrit.client.extensions.TopMenuList;
@@ -49,7 +50,6 @@ import com.google.gerrit.extensions.client.GerritTopMenu;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gwt.aria.client.Roles;
import com.google.gwt.core.client.EntryPoint;
@@ -106,6 +106,7 @@ public class Gerrit implements EntryPoint {
private static String myHost;
private static GerritConfig myConfig;
private static ServerInfo myServerInfo;
private static HostPageData.Theme myTheme;
private static Account myAccount;
private static String defaultScreenToken;
@@ -288,6 +289,11 @@ public class Gerrit implements EntryPoint {
return myConfig;
}
/** Get the public configuration data used by this Gerrit instance. */
public static ServerInfo info() {
return myServerInfo;
}
public static GitwebLink getGitwebLink() {
GitwebConfig gw = getConfig().getGitwebLink();
return gw != null && gw.type != null ? new GitwebLink(gw) : null;
@@ -426,8 +432,16 @@ public class Gerrit implements EntryPoint {
initHostname();
Window.setTitle(M.windowTitle1(myHost));
final HostPageDataService hpd = GWT.create(HostPageDataService.class);
hpd.load(new GerritCallback<HostPageData>() {
RpcStatus.INSTANCE = new RpcStatus();
CallbackGroup cbg = new CallbackGroup();
ConfigServerApi.serverInfo(cbg.add(new GerritCallback<ServerInfo>() {
@Override
public void onSuccess(ServerInfo info) {
myServerInfo = info;
}
}));
HostPageDataService hpd = GWT.create(HostPageDataService.class);
hpd.load(cbg.addFinal(new GerritCallback<HostPageData>() {
@Override
public void onSuccess(final HostPageData result) {
Document.get().getElementById("gerrit_hostpagedata").removeFromParent();
@@ -444,7 +458,7 @@ public class Gerrit implements EntryPoint {
}
onModuleLoad2(result);
}
});
}));
}
private static void initHostname() {
@@ -538,7 +552,6 @@ public class Gerrit implements EntryPoint {
};
gBody.add(body);
RpcStatus.INSTANCE = new RpcStatus();
JsonUtil.addRpcStartHandler(RpcStatus.INSTANCE);
JsonUtil.addRpcCompleteHandler(RpcStatus.INSTANCE);
JsonUtil.setDefaultXsrfManager(new XsrfManager() {
@@ -705,9 +718,9 @@ public class Gerrit implements EntryPoint {
}
if (signedIn) {
whoAmI(cfg.getAuthType() != AuthType.CLIENT_SSL_CERT_LDAP);
whoAmI(!info().auth().isClientSslCertLdap());
} else {
switch (cfg.getAuthType()) {
switch (info().auth().authType()) {
case CLIENT_SSL_CERT_LDAP:
break;

View File

@@ -16,7 +16,6 @@ package com.google.gerrit.client;
import com.google.gerrit.client.account.AccountInfo;
import com.google.gerrit.client.ui.InlineHyperlink;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.AnchorElement;
import com.google.gwt.dom.client.Element;
@@ -53,8 +52,8 @@ public class UserPopupPanel extends PluginSafePopupPanel {
if (showSettingsLink) {
if (Gerrit.getConfig().getSwitchAccountUrl() != null) {
switchAccount.setHref(Gerrit.getConfig().getSwitchAccountUrl());
} else if (Gerrit.getConfig().getAuthType() == AuthType.DEVELOPMENT_BECOME_ANY_ACCOUNT
|| Gerrit.getConfig().getAuthType() == AuthType.OPENID) {
} else if (Gerrit.info().auth().isDev()
|| Gerrit.info().auth().isOpenId()) {
switchAccount.setHref(Gerrit.selfRedirect("/login/"));
} else {
switchAccount.removeFromParent();

View File

@@ -65,7 +65,7 @@ class ContactPanelFull extends ContactPanelShort {
hasContact.setStyleName(Gerrit.RESOURCES.css().accountContactOnFile());
hasContact.setVisible(false);
if (Gerrit.getConfig().isUseContactInfo()) {
if (Gerrit.info().hasContactStore()) {
body.add(privhtml);
body.add(hasContact);
body.add(infoSecure);
@@ -116,7 +116,7 @@ class ContactPanelFull extends ContactPanelShort {
@Override
ContactInformation toContactInformation() {
final ContactInformation info;
if (Gerrit.getConfig().isUseContactInfo()) {
if (Gerrit.info().hasContactStore()) {
info = new ContactInformation();
info.setAddress(addressTxt.getText());
info.setCountry(countryTxt.getText());

View File

@@ -23,7 +23,6 @@ import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Account.FieldName;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gerrit.reviewdb.client.ContactInformation;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.event.dom.client.ChangeEvent;
@@ -101,7 +100,7 @@ class ContactPanelShort extends Composite {
}
int row = 0;
if (!Gerrit.getConfig().canEdit(FieldName.USER_NAME)
if (!Gerrit.info().auth().canEdit(FieldName.USER_NAME)
&& Gerrit.getConfig().siteHasUsernames()) {
infoPlainText.resizeRows(infoPlainText.getRowCount() + 1);
row(infoPlainText, row++, Util.C.userName(), new UsernameField());
@@ -168,11 +167,11 @@ class ContactPanelShort extends Composite {
}
private boolean canEditFullName() {
return Gerrit.getConfig().canEdit(Account.FieldName.FULL_NAME);
return Gerrit.info().auth().canEdit(Account.FieldName.FULL_NAME);
}
private boolean canRegisterNewEmail() {
return Gerrit.getConfig().canEdit(Account.FieldName.REGISTER_NEW_EMAIL);
return Gerrit.info().auth().canEdit(Account.FieldName.REGISTER_NEW_EMAIL);
}
void hideSaveButton() {
@@ -275,7 +274,7 @@ class ContactPanelShort extends Composite {
@Override
public void onSuccess(EmailInfo result) {
box.hide();
if (Gerrit.getConfig().getAuthType() == AuthType.DEVELOPMENT_BECOME_ANY_ACCOUNT) {
if (Gerrit.info().auth().isDev()) {
currentEmail = addr;
if (emailPick.getItemCount() == 0) {
final Account me = Gerrit.getUserAccount();
@@ -325,7 +324,7 @@ class ContactPanelShort extends Composite {
buttons.add(register);
buttons.add(cancel);
if (Gerrit.getConfig().getAuthType() != AuthType.DEVELOPMENT_BECOME_ANY_ACCOUNT) {
if (!Gerrit.info().auth().isDev()) {
body.add(new HTML(Util.C.descRegisterNewEmail()));
}
body.add(inEmail);

View File

@@ -21,7 +21,6 @@ import com.google.gerrit.client.rpc.ScreenLoadCallback;
import com.google.gerrit.client.ui.FancyFlexTable;
import com.google.gerrit.common.auth.openid.OpenIdUrls;
import com.google.gerrit.reviewdb.client.AccountExternalId;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
@@ -59,8 +58,8 @@ public class MyIdentitiesScreen extends SettingsScreen {
});
add(deleteIdentity);
if (Gerrit.getConfig().getAuthType() == AuthType.OPENID
|| Gerrit.getConfig().getAuthType() == AuthType.OAUTH) {
if (Gerrit.info().auth().isOpenId()
|| Gerrit.info().auth().isOAuth()) {
Button linkIdentity = new Button(Util.C.buttonLinkIdentity());
linkIdentity.addClickHandler(new ClickHandler() {
@Override

View File

@@ -70,7 +70,7 @@ public class RegisterScreen extends AccountScreen {
formBody.add(contactGroup);
if (Gerrit.getUserAccount().getUserName() == null
&& Gerrit.getConfig().canEdit(FieldName.USER_NAME)) {
&& Gerrit.info().auth().canEdit(FieldName.USER_NAME)) {
final FlowPanel fp = new FlowPanel();
fp.setStyleName(Gerrit.RESOURCES.css().registerScreenSection());
fp.add(new SmallHeading(Util.C.welcomeUsernameHeading()));
@@ -116,7 +116,7 @@ public class RegisterScreen extends AccountScreen {
final FlowPanel choices = new FlowPanel();
choices.setStyleName(Gerrit.RESOURCES.css().registerScreenNextLinks());
if (Gerrit.getConfig().isUseContributorAgreements()) {
if (Gerrit.info().auth().useContributorAgreements()) {
final FlowPanel agreementGroup = new FlowPanel();
agreementGroup.setStyleName(Gerrit.RESOURCES.css().registerScreenSection());
agreementGroup.add(new SmallHeading(Util.C.welcomeAgreementHeading()));

View File

@@ -34,7 +34,7 @@ public abstract class SettingsScreen extends MenuScreen {
}
link(Util.C.tabWebIdentities(), PageLinks.SETTINGS_WEBIDENT);
link(Util.C.tabMyGroups(), PageLinks.SETTINGS_MYGROUPS);
if (Gerrit.getConfig().isUseContributorAgreements()) {
if (Gerrit.info().auth().useContributorAgreements()) {
link(Util.C.tabAgreements(), PageLinks.SETTINGS_AGREEMENTS);
}
}

View File

@@ -86,7 +86,7 @@ class UsernameField extends Composite {
}
private boolean canEditUserName() {
return Gerrit.getConfig().canEdit(Account.FieldName.USER_NAME);
return Gerrit.info().auth().canEdit(Account.FieldName.USER_NAME);
}
private void confirmSetUserName() {

View File

@@ -250,8 +250,7 @@ public class AccessSectionEditor extends Composite implements
if (value.getPermission(permissionName) != null) {
return;
}
if (Gerrit.getConfig().getWildProject()
.equals(projectAccess.getProjectName())
if (Gerrit.info().gerrit().isAllProjects(projectAccess.getProjectName())
&& !Permission.canBeOnAllProjects(value.getName(), permissionName)) {
return;
}

View File

@@ -264,7 +264,7 @@ public class ProjectInfoScreen extends ProjectScreen {
grid.addHeader(new SmallHeading(Util.C.headingAgreements()));
contributorAgreements = newInheritedBooleanBox();
if (Gerrit.getConfig().isUseContributorAgreements()) {
if (Gerrit.info().auth().useContributorAgreements()) {
saveEnabler.listenTo(contributorAgreements);
grid.add(Util.C.useContributorAgreements(), contributorAgreements);
}
@@ -310,7 +310,7 @@ public class ProjectInfoScreen extends ProjectScreen {
}
}
if (inheritedIndex >= 0) {
if (getProjectKey().equals(Gerrit.getConfig().getWildProject())) {
if (Gerrit.info().gerrit().isAllProjects(getProjectKey())) {
if (box.getSelectedIndex() == inheritedIndex) {
for (int i = 0; i < box.getItemCount(); i++) {
if (box.getValue(i).equals(InheritableBoolean.FALSE.name())) {

View File

@@ -0,0 +1,82 @@
// Copyright (C) 2015 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.client.config;
import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import java.util.ArrayList;
import java.util.List;
public class AuthInfo extends JavaScriptObject {
public final AuthType authType() {
return AuthType.valueOf(authTypeRaw());
}
public final boolean isOpenId() {
return authType() == AuthType.OPENID;
}
public final boolean isOAuth() {
return authType() == AuthType.OAUTH;
}
public final boolean isDev() {
return authType() == AuthType.DEVELOPMENT_BECOME_ANY_ACCOUNT;
}
public final boolean isClientSslCertLdap() {
return authType() == AuthType.CLIENT_SSL_CERT_LDAP;
}
public final boolean isCustomExtension() {
return authType() == AuthType.CUSTOM_EXTENSION;
}
public final boolean canEdit(Account.FieldName f) {
return editableAccountFields().contains(f);
}
public final List<Account.FieldName> editableAccountFields() {
List<Account.FieldName> fields = new ArrayList<>();
for (AccountFieldNameInfo f : Natives.asList(_editableAccountFields())) {
fields.add(f.get());
}
return fields;
}
public final native boolean useContributorAgreements()
/*-{ return this.use_contributor_agreements || false; }-*/;
private final native String authTypeRaw() /*-{ return this.auth_type; }-*/;
private final native JsArray<AccountFieldNameInfo> _editableAccountFields()
/*-{ return this.editable_account_fields; }-*/;
protected AuthInfo() {
}
private static class AccountFieldNameInfo extends JavaScriptObject {
final Account.FieldName get() {
return Account.FieldName.valueOf(getRaw());
}
private final native String getRaw() /*-{ return this; }-*/;
protected AccountFieldNameInfo() {
}
}
}

View File

@@ -37,4 +37,8 @@ public class ConfigServerApi {
public static void defaultPreferences(AsyncCallback<Preferences> cb) {
new RestApi("/config/server/preferences").get(cb);
}
public static void serverInfo(AsyncCallback<ServerInfo> cb) {
new RestApi("/config/server/info").get(cb);
}
}

View File

@@ -0,0 +1,42 @@
// Copyright (C) 2015 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.client.config;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gwt.core.client.JavaScriptObject;
public class GerritInfo extends JavaScriptObject {
public final Project.NameKey allProjectsNameKey() {
return new Project.NameKey(allProjects());
}
public final boolean isAllProjects(Project.NameKey p) {
return allProjectsNameKey().equals(p);
}
public final Project.NameKey allUsersNameKey() {
return new Project.NameKey(allUsers());
}
public final boolean isAllUsers(Project.NameKey p) {
return allUsersNameKey().equals(p);
}
public final native String allProjects() /*-{ return this.all_projects; }-*/;
public final native String allUsers() /*-{ return this.all_users; }-*/;
protected GerritInfo() {
}
}

View File

@@ -0,0 +1,37 @@
// Copyright (C) 2015 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.client.config;
import com.google.gwt.core.client.JavaScriptObject;
public class ServerInfo extends JavaScriptObject {
public final native AuthInfo auth() /*-{ return this.auth; }-*/;
public final native ContactStoreInfo contactStore() /*-{ return this.contact_store; }-*/;
public final native GerritInfo gerrit() /*-{ return this.gerrit; }-*/;
public final boolean hasContactStore() {
return contactStore() != null;
}
protected ServerInfo() {
}
public static class ContactStoreInfo extends JavaScriptObject {
public final native String url() /*-{ return this.url; }-*/;
protected ContactStoreInfo() {
}
}
}

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.client.download;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gwt.aria.client.Roles;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
@@ -129,7 +128,7 @@ public class DownloadUrlLink extends Anchor implements ClickHandler {
public static boolean siteReliesOnHttp() {
return Gerrit.getConfig().getGitHttpUrl() != null
&& Gerrit.getConfig().getAuthType() == AuthType.CUSTOM_EXTENSION
&& Gerrit.info().auth().isCustomExtension()
&& !Gerrit.getConfig().siteHasUsernames();
}

View File

@@ -24,13 +24,11 @@ import com.google.gerrit.common.data.GitwebConfig;
import com.google.gerrit.server.account.Realm;
import com.google.gerrit.server.change.ArchiveFormat;
import com.google.gerrit.server.change.GetArchive;
import com.google.gerrit.server.config.AllProjectsName;
import com.google.gerrit.server.config.AnonymousCowardName;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gerrit.server.config.ConfigUtil;
import com.google.gerrit.server.config.DownloadConfig;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.contact.ContactStore;
import com.google.gerrit.server.ssh.SshInfo;
import com.google.inject.Inject;
import com.google.inject.Provider;
@@ -50,20 +48,21 @@ class GerritConfigProvider implements Provider<GerritConfig> {
private final DownloadConfig downloadConfig;
private final GetArchive.AllowedFormats archiveFormats;
private final GitWebConfig gitWebConfig;
private final AllProjectsName wildProject;
private final SshInfo sshInfo;
private final ContactStore contactStore;
private final ServletContext servletContext;
private final String anonymousCowardName;
@Inject
GerritConfigProvider(final Realm r, @GerritServerConfig final Config gsc,
final AuthConfig ac, final GitWebConfig gwc, final AllProjectsName wp,
final SshInfo si, final ContactStore cs,
final ServletContext sc, final DownloadConfig dc,
final GetArchive.AllowedFormats af,
@AnonymousCowardName final String acn) {
GerritConfigProvider(Realm r,
@GerritServerConfig Config gsc,
AuthConfig ac,
GitWebConfig gwc,
SshInfo si,
ServletContext sc,
DownloadConfig dc,
GetArchive.AllowedFormats af,
@AnonymousCowardName String acn) {
realm = r;
cfg = gsc;
authConfig = ac;
@@ -71,8 +70,6 @@ class GerritConfigProvider implements Provider<GerritConfig> {
archiveFormats = af;
gitWebConfig = gwc;
sshInfo = si;
wildProject = wp;
contactStore = cs;
servletContext = sc;
anonymousCowardName = acn;
}
@@ -109,13 +106,10 @@ class GerritConfigProvider implements Provider<GerritConfig> {
break;
}
config.setSwitchAccountUrl(cfg.getString("auth", null, "switchAccountUrl"));
config.setUseContributorAgreements(authConfig.isUseContributorAgreements());
config.setGitDaemonUrl(cfg.getString("gerrit", null, "canonicalgiturl"));
config.setGitHttpUrl(cfg.getString("gerrit", null, "gitHttpUrl"));
config.setUseContactInfo(contactStore != null && contactStore.isEnabled());
config.setDownloadSchemes(downloadConfig.getDownloadSchemes());
config.setAuthType(authConfig.getAuthType());
config.setWildProject(wildProject);
config.setDocumentationAvailable(servletContext
.getResource("/Documentation/index.html") != null);
config.setAnonymousCowardName(anonymousCowardName);