]> source.dussan.org Git - gitblit.git/commitdiff
Include the username in the Gitblit repository url, if appropriate
authorJames Moger <james.moger@gitblit.com>
Sun, 8 Jan 2012 18:04:11 +0000 (13:04 -0500)
committerJames Moger <james.moger@gitblit.com>
Sun, 8 Jan 2012 18:04:11 +0000 (13:04 -0500)
src/com/gitblit/wicket/pages/BasePage.java
src/com/gitblit/wicket/pages/EmptyRepositoryPage.java
src/com/gitblit/wicket/pages/SummaryPage.java

index f98e8830a6d91ee61e5c73e217673b852215b468..80bff16781d731c7e0d6631a6981476cb6d1de83 100644 (file)
@@ -43,6 +43,7 @@ import com.gitblit.Constants.AccessRestrictionType;
 import com.gitblit.Constants.FederationStrategy;\r
 import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
+import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.WicketUtils;\r
@@ -166,6 +167,21 @@ public abstract class BasePage extends WebPage {
                HttpServletRequest req = servletWebRequest.getHttpServletRequest();\r
                return req.getServerName();\r
        }\r
+       \r
+       protected String getRepositoryUrl(RepositoryModel repository) {\r
+               StringBuilder sb = new StringBuilder();\r
+               sb.append(WicketUtils.getGitblitURL(getRequestCycle().getRequest()));\r
+               sb.append(Constants.GIT_PATH);\r
+               sb.append(repository.name);\r
+               \r
+               // inject username into repository url if authentication is required\r
+               if (repository.accessRestriction.exceeds(AccessRestrictionType.NONE)\r
+                               && GitBlitWebSession.get().isLoggedIn()) {\r
+                       String username = GitBlitWebSession.get().getUser().username;\r
+                       sb.insert(sb.indexOf("://") + 3, username + "@");\r
+               }\r
+               return sb.toString();\r
+       }\r
 \r
        public void warn(String message, Throwable t) {\r
                logger.warn(message, t);\r
index 50695b967f47f36c50f9d412629d45e1e0f89032..133cdac742870cd171a35d277a0352db97f66be5 100644 (file)
@@ -22,9 +22,10 @@ import java.util.List;
 import org.apache.wicket.PageParameters;\r
 import org.apache.wicket.markup.html.basic.Label;\r
 \r
-import com.gitblit.Constants;\r
 import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
+import com.gitblit.models.RepositoryModel;\r
+import com.gitblit.utils.ArrayUtils;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.panels.RepositoryUrlPanel;\r
 \r
@@ -34,22 +35,21 @@ public class EmptyRepositoryPage extends RootPage {
                super(params);\r
 \r
                String repositoryName = WicketUtils.getRepositoryName(params);\r
+               RepositoryModel repository = GitBlit.self().getRepositoryModel(repositoryName);\r
                setupPage(repositoryName, getString("gb.emptyRepository"));\r
 \r
                List<String> repositoryUrls = new ArrayList<String>();\r
 \r
                if (GitBlit.getBoolean(Keys.git.enableGitServlet, true)) {\r
-                       StringBuilder sb = new StringBuilder();\r
-                       sb.append(WicketUtils.getGitblitURL(getRequestCycle().getRequest()));\r
-                       sb.append(Constants.GIT_PATH);\r
-                       sb.append(repositoryName);\r
-                       repositoryUrls.add(sb.toString());\r
+                       // add the Gitblit repository url\r
+                       repositoryUrls.add(getRepositoryUrl(repository));\r
                }\r
                repositoryUrls.addAll(GitBlit.self().getOtherCloneUrls(repositoryName));\r
                \r
+               String primaryUrl = ArrayUtils.isEmpty(repositoryUrls) ? "" : repositoryUrls.get(0);\r
                add(new Label("repository", repositoryName));\r
-               add(new RepositoryUrlPanel("pushurl", repositoryUrls.get(0)));\r
+               add(new RepositoryUrlPanel("pushurl", primaryUrl));\r
                add(new Label("cloneSyntax", MessageFormat.format("git clone {0}", repositoryUrls.get(0))));\r
-               add(new Label("remoteSyntax", MessageFormat.format("git remote add gitblit {0}\ngit push gitblit master", repositoryUrls.get(0))));\r
+               add(new Label("remoteSyntax", MessageFormat.format("git remote add gitblit {0}\ngit push gitblit master", primaryUrl)));\r
        }\r
 }\r
index ed90a8490b018b1b069e9d6d2ce5b58db8a635cf..d928b06de7e546a024b7c328f2ca56610f5df549 100644 (file)
@@ -37,13 +37,13 @@ import org.wicketstuff.googlecharts.LineStyle;
 import org.wicketstuff.googlecharts.MarkerType;\r
 import org.wicketstuff.googlecharts.ShapeMarker;\r
 \r
-import com.gitblit.Constants;\r
-import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
+import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.models.Metric;\r
 import com.gitblit.models.PathModel;\r
 import com.gitblit.models.RepositoryModel;\r
+import com.gitblit.utils.ArrayUtils;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.utils.MarkdownUtils;\r
 import com.gitblit.utils.StringUtils;\r
@@ -116,17 +116,14 @@ public class SummaryPage extends RepositoryPage {
                        default:\r
                                add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));\r
                        }\r
-                       StringBuilder sb = new StringBuilder();\r
-                       sb.append(WicketUtils.getGitblitURL(getRequestCycle().getRequest()));\r
-                       sb.append(Constants.GIT_PATH);\r
-                       sb.append(repositoryName);\r
-                       repositoryUrls.add(sb.toString());\r
+                       // add the Gitblit repository url\r
+                       repositoryUrls.add(getRepositoryUrl(getRepositoryModel()));\r
                } else {\r
                        add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));\r
                }\r
                repositoryUrls.addAll(GitBlit.self().getOtherCloneUrls(repositoryName));\r
                \r
-               String primaryUrl = repositoryUrls.remove(0);\r
+               String primaryUrl = ArrayUtils.isEmpty(repositoryUrls) ? "" : repositoryUrls.remove(0);\r
                add(new RepositoryUrlPanel("repositoryCloneUrl", primaryUrl));\r
 \r
                add(new Label("otherUrls", StringUtils.flattenStrings(repositoryUrls, "<br/>"))\r