From 8daefa09d99774639a355c0dfa2b989fa1007f5f Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Thu, 11 Oct 2012 17:11:18 -0400
Subject: [PATCH] Created static repository close functions for unit testing and fixed Windows sharing violations
---
src/com/gitblit/wicket/pages/RepositoryPage.java | 39 +++++++++++++--------------------------
1 files changed, 13 insertions(+), 26 deletions(-)
diff --git a/src/com/gitblit/wicket/pages/RepositoryPage.java b/src/com/gitblit/wicket/pages/RepositoryPage.java
index 8ca2b33..b7cade6 100644
--- a/src/com/gitblit/wicket/pages/RepositoryPage.java
+++ b/src/com/gitblit/wicket/pages/RepositoryPage.java
@@ -28,12 +28,10 @@
import org.apache.wicket.Component;
import org.apache.wicket.PageParameters;
-import org.apache.wicket.RedirectException;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.ExternalLink;
-import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
@@ -62,7 +60,6 @@
import com.gitblit.wicket.PageRegistration.OtherPageLink;
import com.gitblit.wicket.SessionlessForm;
import com.gitblit.wicket.WicketUtils;
-import com.gitblit.wicket.panels.BasePanel.JavascriptEventConfirmation;
import com.gitblit.wicket.panels.LinkPanel;
import com.gitblit.wicket.panels.NavigationPanel;
import com.gitblit.wicket.panels.RefsPanel;
@@ -171,6 +168,10 @@
}
return pages;
}
+
+ protected boolean allowForkControls() {
+ return true;
+ }
@Override
protected void setupPage(String repositoryName, String pageName) {
@@ -195,6 +196,9 @@
add(new Label("pageName", pageName).setRenderBodyOnly(true));
UserModel user = GitBlitWebSession.get().getUser();
+ if (user == null) {
+ user = UserModel.ANONYMOUS;
+ }
// indicate origin repository
RepositoryModel model = getRepositoryModel();
@@ -205,7 +209,7 @@
if (origin == null) {
// no origin repository
add(new Label("originRepository").setVisible(false));
- } else if (!user.canViewRepository(origin)) {
+ } else if (!user.canView(origin)) {
// show origin repository without link
Fragment forkFrag = new Fragment("originRepository", "originFragment", this);
forkFrag.add(new Label("originRepository", StringUtils.stripDotGit(model.originRepository)));
@@ -230,7 +234,7 @@
}
// fork controls
- if (user == null) {
+ if (!allowForkControls() || user == null || !user.isAuthenticated) {
// must be logged-in to fork, hide all fork controls
add(new ExternalLink("forkLink", "").setVisible(false));
add(new ExternalLink("myForkLink", "").setVisible(false));
@@ -238,13 +242,13 @@
} else {
String fork = GitBlit.self().getFork(user.username, model.name);
boolean hasFork = fork != null;
- boolean canFork = user.canForkRepository(model);
+ boolean canFork = user.canFork(model);
if (hasFork || !canFork) {
// user not allowed to fork or fork already exists or repo forbids forking
add(new ExternalLink("forkLink", "").setVisible(false));
- if (user.canFork && !model.allowForks) {
+ if (user.canFork() && !model.allowForks) {
// show forks prohibited indicator
Fragment wc = new Fragment("forksProhibitedIndicator", "forksProhibitedFragment", this);
Label lbl = new Label("forksProhibited", getString("gb.forksProhibited"));
@@ -268,25 +272,8 @@
// can fork and we do not have one
add(new Label("forksProhibitedIndicator").setVisible(false));
add(new ExternalLink("myForkLink", "").setVisible(false));
- Link<Void> forkLink = new Link<Void>("forkLink") {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public void onClick() {
- UserModel user = GitBlitWebSession.get().getUser();
- RepositoryModel model = getRepositoryModel();
- String asFork = MessageFormat.format("~{0}/{1}.git", user.username, StringUtils.stripDotGit(StringUtils.getLastPathElement(model.name)));
- if (GitBlit.self().fork(model, GitBlitWebSession.get().getUser())) {
- throw new RedirectException(SummaryPage.class, WicketUtils.newRepositoryParameter(asFork));
- } else {
- error(MessageFormat.format(getString("gb.repositoryForkFailed"), model));
- }
- }
- };
- forkLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(
- getString("gb.forkRepository"), getRepositoryModel())));
- add(forkLink);
+ String url = getRequestCycle().urlFor(ForkPage.class, WicketUtils.newRepositoryParameter(model.name)).toString();
+ add(new ExternalLink("forkLink", url));
}
}
--
Gitblit v1.9.1