]> source.dussan.org Git - gitblit.git/commitdiff
Friendly URL for EditFile Page #974 1022/head
authorPaul Martin <paul@paulsputer.com>
Sun, 27 Mar 2016 16:05:38 +0000 (17:05 +0100)
committerPaul Martin <paul@paulsputer.com>
Sun, 27 Mar 2016 16:09:16 +0000 (17:09 +0100)
+ Prevent Edit of old doc version

src/main/java/com/gitblit/utils/JGitUtils.java
src/main/java/com/gitblit/wicket/GitBlitWebApp.java
src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
src/main/java/com/gitblit/wicket/pages/EditFilePage.html
src/main/java/com/gitblit/wicket/pages/EditFilePage.java

index 3aaad6d731a671bfdd116758cbc44c245cd667b5..90d40020484eff9de8e6954ec3fe723be214c7c7 100644 (file)
@@ -2727,5 +2727,22 @@ public class JGitUtils {
                }\r
                return success;\r
        }\r
+       \r
+       /**\r
+        * Returns true if the commit identified by commitId is at the tip of it's branch.\r
+        *\r
+        * @param repository\r
+        * @param commitId\r
+        * @return true if the given commit is the tip\r
+        */\r
+       public static boolean isTip(Repository repository, String commitId) {\r
+               try {\r
+                       RefModel tip = getBranch(repository, commitId);\r
+                       return (tip != null);   \r
+               } catch (Exception e) {\r
+                       LOGGER.error("Failed to determine isTip", e);\r
+               }\r
+               return false;\r
+       }\r
 \r
 }\r
index 296c2544742b197163d9a1e1c778f1c08adbc6de..c10d88732214831dc732a61b3ba7267b863a5d70 100644 (file)
@@ -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");
index 36c416e7aa065c4cfea8a58a37368ffc8fd258b0..f425615ccd9372a8a40d7f4d86b1958f0020b42b 100644 (file)
@@ -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
index 602149b7fc7d77bf74d349be85a30c9c80007426..d6b6eee3e7c8ebec4c6786aa4e213765eed02a8e 100644 (file)
@@ -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>
index 378f2a355da29b92ac1d63eeb84e9f718ca06b55..003753731a0b2108805eabaef4bf5897cef383bb 100644 (file)
@@ -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;
        }