From: James Moger Date: Sun, 8 Jan 2012 18:04:11 +0000 (-0500) Subject: Include the username in the Gitblit repository url, if appropriate X-Git-Tag: v0.8.0~11 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e21181a6e65a96108a85e9eecca5f04e348760a0;p=gitblit.git Include the username in the Gitblit repository url, if appropriate --- diff --git a/src/com/gitblit/wicket/pages/BasePage.java b/src/com/gitblit/wicket/pages/BasePage.java index f98e8830..80bff167 100644 --- a/src/com/gitblit/wicket/pages/BasePage.java +++ b/src/com/gitblit/wicket/pages/BasePage.java @@ -43,6 +43,7 @@ import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.Constants.FederationStrategy; import com.gitblit.GitBlit; import com.gitblit.Keys; +import com.gitblit.models.RepositoryModel; import com.gitblit.models.UserModel; import com.gitblit.wicket.GitBlitWebSession; import com.gitblit.wicket.WicketUtils; @@ -166,6 +167,21 @@ public abstract class BasePage extends WebPage { HttpServletRequest req = servletWebRequest.getHttpServletRequest(); return req.getServerName(); } + + protected String getRepositoryUrl(RepositoryModel repository) { + StringBuilder sb = new StringBuilder(); + sb.append(WicketUtils.getGitblitURL(getRequestCycle().getRequest())); + sb.append(Constants.GIT_PATH); + sb.append(repository.name); + + // inject username into repository url if authentication is required + if (repository.accessRestriction.exceeds(AccessRestrictionType.NONE) + && GitBlitWebSession.get().isLoggedIn()) { + String username = GitBlitWebSession.get().getUser().username; + sb.insert(sb.indexOf("://") + 3, username + "@"); + } + return sb.toString(); + } public void warn(String message, Throwable t) { logger.warn(message, t); diff --git a/src/com/gitblit/wicket/pages/EmptyRepositoryPage.java b/src/com/gitblit/wicket/pages/EmptyRepositoryPage.java index 50695b96..133cdac7 100644 --- a/src/com/gitblit/wicket/pages/EmptyRepositoryPage.java +++ b/src/com/gitblit/wicket/pages/EmptyRepositoryPage.java @@ -22,9 +22,10 @@ import java.util.List; import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.basic.Label; -import com.gitblit.Constants; import com.gitblit.GitBlit; import com.gitblit.Keys; +import com.gitblit.models.RepositoryModel; +import com.gitblit.utils.ArrayUtils; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.panels.RepositoryUrlPanel; @@ -34,22 +35,21 @@ public class EmptyRepositoryPage extends RootPage { super(params); String repositoryName = WicketUtils.getRepositoryName(params); + RepositoryModel repository = GitBlit.self().getRepositoryModel(repositoryName); setupPage(repositoryName, getString("gb.emptyRepository")); List repositoryUrls = new ArrayList(); if (GitBlit.getBoolean(Keys.git.enableGitServlet, true)) { - StringBuilder sb = new StringBuilder(); - sb.append(WicketUtils.getGitblitURL(getRequestCycle().getRequest())); - sb.append(Constants.GIT_PATH); - sb.append(repositoryName); - repositoryUrls.add(sb.toString()); + // add the Gitblit repository url + repositoryUrls.add(getRepositoryUrl(repository)); } repositoryUrls.addAll(GitBlit.self().getOtherCloneUrls(repositoryName)); + String primaryUrl = ArrayUtils.isEmpty(repositoryUrls) ? "" : repositoryUrls.get(0); add(new Label("repository", repositoryName)); - add(new RepositoryUrlPanel("pushurl", repositoryUrls.get(0))); + add(new RepositoryUrlPanel("pushurl", primaryUrl)); add(new Label("cloneSyntax", MessageFormat.format("git clone {0}", repositoryUrls.get(0)))); - add(new Label("remoteSyntax", MessageFormat.format("git remote add gitblit {0}\ngit push gitblit master", repositoryUrls.get(0)))); + add(new Label("remoteSyntax", MessageFormat.format("git remote add gitblit {0}\ngit push gitblit master", primaryUrl))); } } diff --git a/src/com/gitblit/wicket/pages/SummaryPage.java b/src/com/gitblit/wicket/pages/SummaryPage.java index ed90a849..d928b06d 100644 --- a/src/com/gitblit/wicket/pages/SummaryPage.java +++ b/src/com/gitblit/wicket/pages/SummaryPage.java @@ -37,13 +37,13 @@ import org.wicketstuff.googlecharts.LineStyle; import org.wicketstuff.googlecharts.MarkerType; import org.wicketstuff.googlecharts.ShapeMarker; -import com.gitblit.Constants; -import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.GitBlit; import com.gitblit.Keys; +import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.models.Metric; import com.gitblit.models.PathModel; import com.gitblit.models.RepositoryModel; +import com.gitblit.utils.ArrayUtils; import com.gitblit.utils.JGitUtils; import com.gitblit.utils.MarkdownUtils; import com.gitblit.utils.StringUtils; @@ -116,17 +116,14 @@ public class SummaryPage extends RepositoryPage { default: add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false)); } - StringBuilder sb = new StringBuilder(); - sb.append(WicketUtils.getGitblitURL(getRequestCycle().getRequest())); - sb.append(Constants.GIT_PATH); - sb.append(repositoryName); - repositoryUrls.add(sb.toString()); + // add the Gitblit repository url + repositoryUrls.add(getRepositoryUrl(getRepositoryModel())); } else { add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false)); } repositoryUrls.addAll(GitBlit.self().getOtherCloneUrls(repositoryName)); - String primaryUrl = repositoryUrls.remove(0); + String primaryUrl = ArrayUtils.isEmpty(repositoryUrls) ? "" : repositoryUrls.remove(0); add(new RepositoryUrlPanel("repositoryCloneUrl", primaryUrl)); add(new Label("otherUrls", StringUtils.flattenStrings(repositoryUrls, "
"))