diff options
author | James Moger <james.moger@gitblit.com> | 2013-05-02 21:37:58 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2013-05-02 21:37:58 -0400 |
commit | 264ba908941414ea5e750524b2472f7ad0670563 (patch) | |
tree | 4476371a9478a9f78661c1b89ccef4ada11aaadd /src/main/java/com/gitblit/wicket/pages/BasePage.java | |
parent | 19352c18bd27ea61b9466110c1be874079f60b63 (diff) | |
download | gitblit-264ba908941414ea5e750524b2472f7ad0670563.tar.gz gitblit-264ba908941414ea5e750524b2472f7ad0670563.zip |
Improved the repository url panel and show git daemon url, appropriately
This will probably be refined some more to merge the http/https and git urls
into a single url panel.
Diffstat (limited to 'src/main/java/com/gitblit/wicket/pages/BasePage.java')
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/BasePage.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/main/java/com/gitblit/wicket/pages/BasePage.java b/src/main/java/com/gitblit/wicket/pages/BasePage.java index bb7d8c9e..b2dcce3f 100644 --- a/src/main/java/com/gitblit/wicket/pages/BasePage.java +++ b/src/main/java/com/gitblit/wicket/pages/BasePage.java @@ -32,6 +32,7 @@ import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest;
import org.apache.wicket.Application;
+import org.apache.wicket.Component;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.PageParameters;
import org.apache.wicket.RedirectToUrlException;
@@ -44,6 +45,7 @@ import org.apache.wicket.markup.html.link.ExternalLink; import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.protocol.http.RequestUtils;
+import org.apache.wicket.protocol.http.WebRequest;
import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -63,6 +65,7 @@ import com.gitblit.utils.StringUtils; import com.gitblit.utils.TimeUtils;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.WicketUtils;
+import com.gitblit.wicket.panels.DetailedRepositoryUrlPanel;
import com.gitblit.wicket.panels.LinkPanel;
public abstract class BasePage extends SessionPage {
@@ -270,6 +273,45 @@ public abstract class BasePage extends SessionPage { return sb.toString();
}
+ protected Component createGitDaemonUrlPanel(String wicketId, UserModel user, RepositoryModel repository) {
+ int gitDaemonPort = GitBlit.getInteger(Keys.git.daemonPort, 0);
+ if (gitDaemonPort > 0 && user.canClone(repository)) {
+ String servername = ((WebRequest) getRequest()).getHttpServletRequest().getServerName();
+ String gitDaemonUrl;
+ if (gitDaemonPort == 9418) {
+ // standard port
+ gitDaemonUrl = MessageFormat.format("git://{0}/{1}", servername, repository.name);
+ } else {
+ // non-standard port
+ gitDaemonUrl = MessageFormat.format("git://{0}:{1,number,0}/{2}", servername, gitDaemonPort, repository.name);
+ }
+
+ AccessPermission gitDaemonPermission = user.getRepositoryPermission(repository).permission;;
+ if (gitDaemonPermission.atLeast(AccessPermission.CLONE)) {
+ if (repository.accessRestriction.atLeast(AccessRestrictionType.CLONE)) {
+ // can not authenticate clone via anonymous git protocol
+ gitDaemonPermission = AccessPermission.NONE;
+ } else if (repository.accessRestriction.atLeast(AccessRestrictionType.PUSH)) {
+ // can not authenticate push via anonymous git protocol
+ gitDaemonPermission = AccessPermission.CLONE;
+ } else {
+ // normal user permission
+ }
+ }
+
+ if (AccessPermission.NONE.equals(gitDaemonPermission)) {
+ // repository prohibits all anonymous access
+ return new Label(wicketId).setVisible(false);
+ } else {
+ // repository allows some form of anonymous access
+ return new DetailedRepositoryUrlPanel(wicketId, getLocalizer(), this, repository.name, gitDaemonUrl, gitDaemonPermission);
+ }
+ } else {
+ // git daemon is not running
+ return new Label(wicketId).setVisible(false);
+ }
+ }
+
protected List<ProjectModel> getProjectModels() {
final UserModel user = GitBlitWebSession.get().getUser();
List<ProjectModel> projects = GitBlit.self().getProjectModels(user, true);
|