For clone commands rely on scheme URLs from the server
Do not construct clone commands on client-side, but rely on the scheme URLs that are retrieved from the server. Change-Id: I7077ce0dcf21941d44ec69e4aecf7adb94bbeebe Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
parent
d0bde8e151
commit
f94d06bc25
gerrit-common/src/main/java/com/google/gerrit/common/data
gerrit-gwtui/src/main/java/com/google/gerrit/client
gerrit-httpd/src/main/java/com/google/gerrit/httpd
@ -35,7 +35,6 @@ public class GerritConfig implements Cloneable {
|
|||||||
protected GitwebConfig gitweb;
|
protected GitwebConfig gitweb;
|
||||||
protected AuthType authType;
|
protected AuthType authType;
|
||||||
protected String gitDaemonUrl;
|
protected String gitDaemonUrl;
|
||||||
protected String gitHttpUrl;
|
|
||||||
protected String sshdAddress;
|
protected String sshdAddress;
|
||||||
protected String editFullNameUrl;
|
protected String editFullNameUrl;
|
||||||
protected Set<Account.FieldName> editableAccountFields;
|
protected Set<Account.FieldName> editableAccountFields;
|
||||||
@ -152,17 +151,6 @@ public class GerritConfig implements Cloneable {
|
|||||||
gitDaemonUrl = url;
|
gitDaemonUrl = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGitHttpUrl() {
|
|
||||||
return gitHttpUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGitHttpUrl(String url) {
|
|
||||||
if (url != null && !url.endsWith("/")) {
|
|
||||||
url += "/";
|
|
||||||
}
|
|
||||||
gitHttpUrl = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSshdAddress() {
|
public String getSshdAddress() {
|
||||||
return sshdAddress;
|
return sshdAddress;
|
||||||
}
|
}
|
||||||
|
@ -44,10 +44,6 @@ public class AuthInfo extends JavaScriptObject {
|
|||||||
return authType() == AuthType.CLIENT_SSL_CERT_LDAP;
|
return authType() == AuthType.CLIENT_SSL_CERT_LDAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isCustomExtension() {
|
|
||||||
return authType() == AuthType.CUSTOM_EXTENSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final boolean canEdit(Account.FieldName f) {
|
public final boolean canEdit(Account.FieldName f) {
|
||||||
return editableAccountFields().contains(f);
|
return editableAccountFields().contains(f);
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,12 @@
|
|||||||
package com.google.gerrit.client.download;
|
package com.google.gerrit.client.download;
|
||||||
|
|
||||||
import com.google.gerrit.client.Gerrit;
|
import com.google.gerrit.client.Gerrit;
|
||||||
|
import com.google.gerrit.client.config.DownloadInfo.DownloadSchemeInfo;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
|
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
|
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
|
||||||
import com.google.gwt.aria.client.Roles;
|
import com.google.gwt.aria.client.Roles;
|
||||||
import com.google.gwt.core.client.GWT;
|
|
||||||
import com.google.gwt.event.dom.client.ClickEvent;
|
import com.google.gwt.event.dom.client.ClickEvent;
|
||||||
import com.google.gwt.event.dom.client.ClickHandler;
|
import com.google.gwt.event.dom.client.ClickHandler;
|
||||||
import com.google.gwt.user.client.Window;
|
|
||||||
import com.google.gwt.user.client.ui.Anchor;
|
import com.google.gwt.user.client.ui.Anchor;
|
||||||
import com.google.gwt.user.client.ui.Widget;
|
import com.google.gwt.user.client.ui.Widget;
|
||||||
import com.google.gwtjsonrpc.common.AsyncCallback;
|
import com.google.gwtjsonrpc.common.AsyncCallback;
|
||||||
@ -29,166 +28,79 @@ import com.google.gwtjsonrpc.common.VoidResult;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class DownloadUrlLink extends Anchor implements ClickHandler {
|
public class DownloadUrlLink extends Anchor implements ClickHandler {
|
||||||
public static class AnonGitLink extends DownloadUrlLink {
|
private enum KnownScheme {
|
||||||
public AnonGitLink(String project) {
|
ANON_GIT(DownloadScheme.ANON_GIT, "git", Util.M.anonymousDownload("Git")),
|
||||||
super(DownloadScheme.ANON_GIT, Util.M.anonymousDownload("Git"), project);
|
ANON_HTTP(DownloadScheme.ANON_HTTP, "anonymous http", Util.M.anonymousDownload("HTTP")),
|
||||||
|
SSH(DownloadScheme.SSH, "ssh", "SSH"),
|
||||||
|
HTTP(DownloadScheme.HTTP, "http", "HTTP");
|
||||||
|
|
||||||
|
public final DownloadScheme downloadScheme;
|
||||||
|
public final String name;
|
||||||
|
public final String text;
|
||||||
|
|
||||||
|
private KnownScheme(DownloadScheme downloadScheme, String name, String text) {
|
||||||
|
this.downloadScheme = downloadScheme;
|
||||||
|
this.name = name;
|
||||||
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
static KnownScheme get(String name) {
|
||||||
public String getUrlData() {
|
for (KnownScheme s : values()) {
|
||||||
StringBuilder r = new StringBuilder();
|
if (s.name.equals(name)) {
|
||||||
r.append(Gerrit.getConfig().getGitDaemonUrl());
|
return s;
|
||||||
r.append(projectName);
|
|
||||||
return r.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class AnonHttpLink extends DownloadUrlLink {
|
|
||||||
public AnonHttpLink(String project) {
|
|
||||||
super(DownloadScheme.ANON_HTTP, Util.M.anonymousDownload("HTTP"), project);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUrlData() {
|
|
||||||
StringBuilder r = new StringBuilder();
|
|
||||||
if (Gerrit.getConfig().getGitHttpUrl() != null) {
|
|
||||||
r.append(Gerrit.getConfig().getGitHttpUrl());
|
|
||||||
} else {
|
|
||||||
r.append(hostPageUrl);
|
|
||||||
}
|
|
||||||
r.append(projectName);
|
|
||||||
return r.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class SshLink extends DownloadUrlLink {
|
|
||||||
public SshLink(String project) {
|
|
||||||
super(DownloadScheme.SSH, "SSH", project);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUrlData() {
|
|
||||||
String sshAddr = Gerrit.getConfig().getSshdAddress();
|
|
||||||
final StringBuilder r = new StringBuilder();
|
|
||||||
r.append("ssh://");
|
|
||||||
r.append(Gerrit.getUserAccount().getUserName());
|
|
||||||
r.append("@");
|
|
||||||
if (sshAddr.startsWith("*:") || "".equals(sshAddr)) {
|
|
||||||
r.append(Window.Location.getHostName());
|
|
||||||
}
|
|
||||||
if (sshAddr.startsWith("*")) {
|
|
||||||
sshAddr = sshAddr.substring(1);
|
|
||||||
}
|
|
||||||
r.append(sshAddr);
|
|
||||||
r.append("/");
|
|
||||||
r.append(projectName);
|
|
||||||
return r.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class HttpLink extends DownloadUrlLink {
|
|
||||||
protected boolean anonymous;
|
|
||||||
|
|
||||||
public HttpLink(String project, boolean anonymous) {
|
|
||||||
super(DownloadScheme.HTTP, "HTTP", project);
|
|
||||||
this.anonymous = anonymous;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUrlData() {
|
|
||||||
final StringBuilder r = new StringBuilder();
|
|
||||||
if (Gerrit.getConfig().getGitHttpUrl() != null
|
|
||||||
&& (anonymous || siteReliesOnHttp())) {
|
|
||||||
r.append(Gerrit.getConfig().getGitHttpUrl());
|
|
||||||
} else {
|
|
||||||
String base = hostPageUrl;
|
|
||||||
int p = base.indexOf("://");
|
|
||||||
int s = base.indexOf('/', p + 3);
|
|
||||||
if (s < 0) {
|
|
||||||
s = base.length();
|
|
||||||
}
|
}
|
||||||
String host = base.substring(p + 3, s);
|
|
||||||
if (host.contains("@")) {
|
|
||||||
host = host.substring(host.indexOf('@') + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
r.append(base.substring(0, p + 3));
|
|
||||||
r.append(Gerrit.getUserAccount().getUserName());
|
|
||||||
r.append('@');
|
|
||||||
r.append(host);
|
|
||||||
r.append(base.substring(s));
|
|
||||||
}
|
}
|
||||||
r.append(projectName);
|
return null;
|
||||||
return r.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean siteReliesOnHttp() {
|
|
||||||
return Gerrit.getConfig().getGitHttpUrl() != null
|
|
||||||
&& Gerrit.info().auth().isCustomExtension()
|
|
||||||
&& !Gerrit.getConfig().siteHasUsernames();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<DownloadUrlLink> createDownloadUrlLinks(String project,
|
public static List<DownloadUrlLink> createDownloadUrlLinks(String project,
|
||||||
boolean allowAnonymous) {
|
boolean allowAnonymous) {
|
||||||
List<DownloadUrlLink> urls = new ArrayList<>();
|
List<DownloadUrlLink> urls = new ArrayList<>();
|
||||||
Set<String> allowedSchemes = Gerrit.info().download().schemes();
|
for (String s : Gerrit.info().download().schemes()) {
|
||||||
|
DownloadSchemeInfo scheme = Gerrit.info().download().scheme(s);
|
||||||
|
if (scheme.isAuthRequired() && !allowAnonymous) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (allowAnonymous
|
KnownScheme knownScheme = KnownScheme.get(s);
|
||||||
&& Gerrit.getConfig().getGitDaemonUrl() != null
|
if (knownScheme != null) {
|
||||||
&& allowedSchemes.contains("git")) {
|
urls.add(new DownloadUrlLink(knownScheme.downloadScheme,
|
||||||
urls.add(new DownloadUrlLink.AnonGitLink(project));
|
knownScheme.text, scheme.getUrl(project)));
|
||||||
}
|
} else {
|
||||||
|
urls.add(new DownloadUrlLink(s, scheme.getUrl(project)));
|
||||||
if (allowAnonymous
|
}
|
||||||
&& allowedSchemes.contains("anonymous http")) {
|
|
||||||
urls.add(new DownloadUrlLink.AnonHttpLink(project));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Gerrit.getConfig().getSshdAddress() != null
|
|
||||||
&& hasUserName()
|
|
||||||
&& allowedSchemes.contains("ssh")) {
|
|
||||||
urls.add(new DownloadUrlLink.SshLink(project));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((hasUserName() || siteReliesOnHttp())
|
|
||||||
&& allowedSchemes.contains("http")) {
|
|
||||||
urls.add(new DownloadUrlLink.HttpLink(project, allowAnonymous));
|
|
||||||
}
|
}
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasUserName() {
|
private final DownloadScheme urlType;
|
||||||
return Gerrit.isSignedIn()
|
private final String urlData;
|
||||||
&& Gerrit.getUserAccount().getUserName() != null
|
|
||||||
&& Gerrit.getUserAccount().getUserName().length() > 0;
|
public DownloadUrlLink(String text, String urlData) {
|
||||||
|
this(null, text, urlData);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DownloadScheme urlType;
|
public DownloadUrlLink(DownloadScheme urlType, String text, String urlData) {
|
||||||
protected String projectName;
|
|
||||||
protected String urlData;
|
|
||||||
protected String hostPageUrl = GWT.getHostPageBaseURL();
|
|
||||||
|
|
||||||
public DownloadUrlLink(DownloadScheme urlType, String text, String project) {
|
|
||||||
super(text);
|
super(text);
|
||||||
setStyleName(Gerrit.RESOURCES.css().downloadLink());
|
setStyleName(Gerrit.RESOURCES.css().downloadLink());
|
||||||
Roles.getTabRole().set(getElement());
|
Roles.getTabRole().set(getElement());
|
||||||
addClickHandler(this);
|
addClickHandler(this);
|
||||||
|
|
||||||
if (!hostPageUrl.endsWith("/")) {
|
|
||||||
hostPageUrl += "/";
|
|
||||||
}
|
|
||||||
this.urlType = urlType;
|
this.urlType = urlType;
|
||||||
this.projectName = project;
|
this.urlData = urlData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUrlData() {
|
public String getUrlData() {
|
||||||
return urlData;
|
return urlData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DownloadScheme getUrlType() {
|
||||||
|
return urlType;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(ClickEvent event) {
|
public void onClick(ClickEvent event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@ -196,7 +108,7 @@ public class DownloadUrlLink extends Anchor implements ClickHandler {
|
|||||||
|
|
||||||
select();
|
select();
|
||||||
|
|
||||||
if (Gerrit.isSignedIn()) {
|
if (Gerrit.isSignedIn() && urlType != null) {
|
||||||
// If the user is signed-in, remember this choice for future panels.
|
// If the user is signed-in, remember this choice for future panels.
|
||||||
//
|
//
|
||||||
AccountGeneralPreferences pref =
|
AccountGeneralPreferences pref =
|
||||||
|
@ -44,7 +44,7 @@ public class DownloadUrlPanel extends FlowPanel {
|
|||||||
if (first == null) {
|
if (first == null) {
|
||||||
first = d;
|
first = d;
|
||||||
}
|
}
|
||||||
if (d.urlType == urlType) {
|
if (d.getUrlType() == urlType) {
|
||||||
d.select();
|
d.select();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,6 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
|||||||
}
|
}
|
||||||
config.setSwitchAccountUrl(cfg.getString("auth", null, "switchAccountUrl"));
|
config.setSwitchAccountUrl(cfg.getString("auth", null, "switchAccountUrl"));
|
||||||
config.setGitDaemonUrl(cfg.getString("gerrit", null, "canonicalgiturl"));
|
config.setGitDaemonUrl(cfg.getString("gerrit", null, "canonicalgiturl"));
|
||||||
config.setGitHttpUrl(cfg.getString("gerrit", null, "gitHttpUrl"));
|
|
||||||
config.setAuthType(authConfig.getAuthType());
|
config.setAuthType(authConfig.getAuthType());
|
||||||
config.setDocumentationAvailable(servletContext
|
config.setDocumentationAvailable(servletContext
|
||||||
.getResource("/Documentation/index.html") != null);
|
.getResource("/Documentation/index.html") != null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user