summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Martin <paul@paulsputer.com>2016-03-27 17:05:38 +0100
committerPaul Martin <paul@paulsputer.com>2016-03-27 17:09:16 +0100
commit795ce2765773156da868720303a6b2638d14820b (patch)
treed20f4aab7b49721a3390db4a413f6449ed138259 /src
parent713d27789bc0b5d82b607fed20e5f16ad9216898 (diff)
downloadgitblit-795ce2765773156da868720303a6b2638d14820b.tar.gz
gitblit-795ce2765773156da868720303a6b2638d14820b.zip
Friendly URL for EditFile Page #974
+ Prevent Edit of old doc version
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/gitblit/utils/JGitUtils.java17
-rw-r--r--src/main/java/com/gitblit/wicket/GitBlitWebApp.java2
-rw-r--r--src/main/java/com/gitblit/wicket/GitBlitWebApp.properties7
-rw-r--r--src/main/java/com/gitblit/wicket/pages/EditFilePage.html4
-rw-r--r--src/main/java/com/gitblit/wicket/pages/EditFilePage.java20
5 files changed, 37 insertions, 13 deletions
diff --git a/src/main/java/com/gitblit/utils/JGitUtils.java b/src/main/java/com/gitblit/utils/JGitUtils.java
index 3aaad6d7..90d40020 100644
--- a/src/main/java/com/gitblit/utils/JGitUtils.java
+++ b/src/main/java/com/gitblit/utils/JGitUtils.java
@@ -2727,5 +2727,22 @@ public class JGitUtils {
}
return success;
}
+
+ /**
+ * Returns true if the commit identified by commitId is at the tip of it's branch.
+ *
+ * @param repository
+ * @param commitId
+ * @return true if the given commit is the tip
+ */
+ public static boolean isTip(Repository repository, String commitId) {
+ try {
+ RefModel tip = getBranch(repository, commitId);
+ return (tip != null);
+ } catch (Exception e) {
+ LOGGER.error("Failed to determine isTip", e);
+ }
+ return false;
+ }
}
diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java
index 296c2544..c10d8873 100644
--- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java
+++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java
@@ -59,6 +59,7 @@ import com.gitblit.wicket.pages.CommitPage;
import com.gitblit.wicket.pages.ComparePage;
import com.gitblit.wicket.pages.DocPage;
import com.gitblit.wicket.pages.DocsPage;
+import com.gitblit.wicket.pages.EditFilePage;
import com.gitblit.wicket.pages.EditMilestonePage;
import com.gitblit.wicket.pages.EditRepositoryPage;
import com.gitblit.wicket.pages.EditTicketPage;
@@ -230,6 +231,7 @@ public class GitBlitWebApp extends WebApplication implements GitblitWicketApp {
// setup the markup document urls
mount("/docs", DocsPage.class, "r", "h");
mount("/doc", DocPage.class, "r", "h", "f");
+ mount("/editfile", EditFilePage.class, "r", "h", "f");
// federation urls
mount("/proposal", ReviewProposalPage.class, "t");
diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
index 36c416e7..f425615c 100644
--- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
+++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
@@ -770,4 +770,9 @@ gb.filestore = filestore
gb.filestoreStats = Filestore contains {0} files with a total size of {1}. ({2} remaining)
gb.statusChangedOn = status changed on
gb.statusChangedBy = status changed by
-gb.filestoreHelp = How to use the Filestore? \ No newline at end of file
+gb.filestoreHelp = How to use the Filestore?
+gb.editFile = edit file
+gb.continueEditing = Continue Editing
+gb.commitChanges = Commit Changes
+gb.fileNotMergeable = Unable to commit {0}. This file can not be automatically merged.
+gb.fileCommitted = Successfully committed {0}. \ No newline at end of file
diff --git a/src/main/java/com/gitblit/wicket/pages/EditFilePage.html b/src/main/java/com/gitblit/wicket/pages/EditFilePage.html
index 602149b7..d6b6eee3 100644
--- a/src/main/java/com/gitblit/wicket/pages/EditFilePage.html
+++ b/src/main/java/com/gitblit/wicket/pages/EditFilePage.html
@@ -34,8 +34,8 @@
<textarea style="width:100%; resize:none" wicket:id="commitMessage"></textarea>
</div>
<div class="modal-footer">
- <a href="#" data-dismiss="modal" class="btn">Continue editing</a>
- <a href="#" onclick="commitChanges()" class="btn btn-primary">Commit changes</a>
+ <a href="#" data-dismiss="modal" class="btn"><wicket:message key="gb.continueEditing"></wicket:message></a>
+ <a href="#" onclick="commitChanges()" class="btn btn-primary"><wicket:message key="gb.commitChanges"></wicket:message></a>
</div>
</div>
</form>
diff --git a/src/main/java/com/gitblit/wicket/pages/EditFilePage.java b/src/main/java/com/gitblit/wicket/pages/EditFilePage.java
index 378f2a35..00375373 100644
--- a/src/main/java/com/gitblit/wicket/pages/EditFilePage.java
+++ b/src/main/java/com/gitblit/wicket/pages/EditFilePage.java
@@ -17,6 +17,7 @@ package com.gitblit.wicket.pages;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -51,7 +52,7 @@ import com.gitblit.wicket.MarkupProcessor;
import com.gitblit.wicket.MarkupProcessor.MarkupDocument;
import com.gitblit.wicket.WicketUtils;
-@CacheControl(LastModified.BOOT)
+@CacheControl(LastModified.REPOSITORY)
public class EditFilePage extends RepositoryPage {
public EditFilePage(final PageParameters params) {
@@ -96,9 +97,9 @@ public class EditFilePage extends RepositoryPage {
Fragment fragment;
String displayedCommitId = commit.getId().getName();
MarkupDocument markupDoc = processor.parse(repositoryName, displayedCommitId, documentPath, markupText);
- logger.info("Loading Edit File page: " + displayedCommitId);
+ logger.trace("Loading Edit File page: " + displayedCommitId);
- if (currentUser.canEdit(getRepositoryModel())) {
+ if (currentUser.canEdit(getRepositoryModel()) && JGitUtils.isTip(getRepository(), objectId.toString())) {
final Model<String> documentContent = new Model<String>(markupDoc.markup);
final Model<String> commitMessage = new Model<String>("Document update");
@@ -112,7 +113,6 @@ public class EditFilePage extends RepositoryPage {
@Override
protected void onSubmit() {
-
final Repository repository = getRepository();
final String document = documentContent.getObject();
final String message = commitMessage.getObject();
@@ -125,7 +125,7 @@ public class EditFilePage extends RepositoryPage {
try {
ObjectId docAtLoad = getRepository().resolve(commitIdAtLoad.getObject());
- logger.info("Commiting Edit File page: " + commitIdAtLoad.getObject());
+ logger.trace("Commiting Edit File page: " + commitIdAtLoad.getObject());
DirCache index = DirCache.newInCore();
DirCacheBuilder builder = index.builder();
@@ -156,12 +156,12 @@ public class EditFilePage extends RepositoryPage {
}
if (success == false) {
- EditFilePage.this.error("Unable to commit document " + path, false);
+ getSession().error(MessageFormat.format(getString("gb.fileNotMergeable"),path));
return;
}
+ getSession().info(MessageFormat.format(getString("gb.fileCommitted"),path));
setResponsePage(EditFilePage.class, params);
- return;
}
};
@@ -197,12 +197,12 @@ public class EditFilePage extends RepositoryPage {
fragment.add(new ExternalLink("rawLink", rawUrl));
add(fragment);
-
+
}
@Override
protected String getPageName() {
- return getString("gb.docs");
+ return getString("gb.editFile");
}
@Override
@@ -212,7 +212,7 @@ public class EditFilePage extends RepositoryPage {
@Override
protected Class<? extends BasePage> getRepoNavPageClass() {
- return DocsPage.class;
+ return EditFilePage.class;
}