diff options
author | Paul Martin <paul@paulsputer.com> | 2016-03-14 22:50:03 +0000 |
---|---|---|
committer | Paul Martin <paul@paulsputer.com> | 2016-03-27 17:09:16 +0100 |
commit | 713d27789bc0b5d82b607fed20e5f16ad9216898 (patch) | |
tree | 719334b6266873cc0c70b2aeae76624ef37f1a2f | |
parent | e8b565ab9d15cbcfae26f6edb59b3dea0652ddb1 (diff) | |
download | gitblit-713d27789bc0b5d82b607fed20e5f16ad9216898.tar.gz gitblit-713d27789bc0b5d82b607fed20e5f16ad9216898.zip |
Disable edit links in read only mode #974
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/DocPage.java | 9 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/DocsPage.java | 17 |
2 files changed, 21 insertions, 5 deletions
diff --git a/src/main/java/com/gitblit/wicket/pages/DocPage.java b/src/main/java/com/gitblit/wicket/pages/DocPage.java index fe05ada2..5d711343 100644 --- a/src/main/java/com/gitblit/wicket/pages/DocPage.java +++ b/src/main/java/com/gitblit/wicket/pages/DocPage.java @@ -25,11 +25,13 @@ import org.apache.wicket.markup.html.panel.Fragment; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
+import com.gitblit.models.UserModel;
import com.gitblit.servlet.RawServlet;
import com.gitblit.utils.BugtraqProcessor;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.CacheControl;
+import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.MarkupProcessor;
import com.gitblit.wicket.MarkupProcessor.MarkupDocument;
@@ -44,7 +46,9 @@ public class DocPage extends RepositoryPage { final String path = WicketUtils.getPath(params).replace("%2f", "/").replace("%2F", "/");
MarkupProcessor processor = new MarkupProcessor(app().settings(), app().xssFilter());
-
+ UserModel currentUser = (GitBlitWebSession.get().getUser() != null) ? GitBlitWebSession.get().getUser() : UserModel.ANONYMOUS;
+ final boolean userCanEdit = currentUser.canEdit(getRepositoryModel());
+
Repository r = getRepository();
RevCommit commit = JGitUtils.getCommit(r, objectId);
String [] encodings = getEncodings();
@@ -86,7 +90,8 @@ public class DocPage extends RepositoryPage { // document page links
fragment.add(new BookmarkablePageLink<Void>("editLink", EditFilePage.class,
- WicketUtils.newPathParameter(repositoryName, objectId, documentPath)));
+ WicketUtils.newPathParameter(repositoryName, objectId, documentPath))
+ .setEnabled(userCanEdit));
fragment.add(new BookmarkablePageLink<Void>("blameLink", BlamePage.class,
WicketUtils.newPathParameter(repositoryName, objectId, documentPath)));
fragment.add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
diff --git a/src/main/java/com/gitblit/wicket/pages/DocsPage.java b/src/main/java/com/gitblit/wicket/pages/DocsPage.java index 93016920..52443862 100644 --- a/src/main/java/com/gitblit/wicket/pages/DocsPage.java +++ b/src/main/java/com/gitblit/wicket/pages/DocsPage.java @@ -27,15 +27,19 @@ import org.apache.wicket.markup.html.panel.Fragment; import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
+import org.apache.wicket.model.StringResourceModel;
+import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import com.gitblit.models.PathModel;
+import com.gitblit.models.UserModel;
import com.gitblit.servlet.RawServlet;
import com.gitblit.utils.ByteFormat;
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.CacheControl;
+import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.CacheControl.LastModified;
import com.gitblit.wicket.MarkupProcessor;
import com.gitblit.wicket.MarkupProcessor.MarkupDocument;
@@ -54,6 +58,9 @@ public class DocsPage extends RepositoryPage { MarkupProcessor processor = new MarkupProcessor(app().settings(), app().xssFilter());
Repository r = getRepository();
+ UserModel currentUser = (GitBlitWebSession.get().getUser() != null) ? GitBlitWebSession.get().getUser() : UserModel.ANONYMOUS;
+ final boolean userCanEdit = currentUser.canEdit(getRepositoryModel());
+
RevCommit head = JGitUtils.getCommit(r, objectId);
final String commitId = getBestCommitId(head);
@@ -102,9 +109,12 @@ public class DocsPage extends RepositoryPage { @Override
public void populateItem(final Item<MarkupDocument> item) {
MarkupDocument doc = item.getModelObject();
- // document page links
+
item.add(new BookmarkablePageLink<Void>("editLink", EditFilePage.class,
- WicketUtils.newPathParameter(repositoryName, commitId, doc.documentPath)));
+ WicketUtils.newPathParameter(repositoryName, commitId, doc.documentPath))
+ .setEnabled(userCanEdit));
+
+ // document page links
item.add(new BookmarkablePageLink<Void>("blameLink", BlamePage.class,
WicketUtils.newPathParameter(repositoryName, commitId, doc.documentPath)));
item.add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
@@ -151,7 +161,8 @@ public class DocsPage extends RepositoryPage { item.add(new BookmarkablePageLink<Void>("view", DocPage.class, WicketUtils
.newPathParameter(repositoryName, commitId, entry.path)));
item.add(new BookmarkablePageLink<Void>("edit", EditFilePage.class, WicketUtils
- .newPathParameter(repositoryName, commitId, entry.path)));
+ .newPathParameter(repositoryName, commitId, entry.path))
+ .setEnabled(userCanEdit));
String rawUrl = RawServlet.asLink(getContextUrl(), repositoryName, commitId, entry.path);
item.add(new ExternalLink("raw", rawUrl));
item.add(new BookmarkablePageLink<Void>("blame", BlamePage.class, WicketUtils
|