]> source.dussan.org Git - gitblit.git/commitdiff
Improve ticket propose instructions based on primary repository url
authorJames Moger <james.moger@gitblit.com>
Wed, 2 Apr 2014 15:45:14 +0000 (11:45 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 10 Apr 2014 23:01:30 +0000 (19:01 -0400)
src/main/java/com/gitblit/wicket/GitBlitWebApp.properties
src/main/java/com/gitblit/wicket/pages/TicketPage.java

index 2ab023ff04ecb0db80429a7a2361ae73bf628150..aeb2d9ef85be3d84345420cfcdea0af680dd595d 100644 (file)
@@ -670,3 +670,5 @@ gb.repositoryDoesNotAcceptPatchsets = This repository does not accept patchsets.
 gb.serverDoesNotAcceptPatchsets = This server does not accept patchsets.
 gb.ticketIsClosed = This ticket is closed.
 gb.mergeToDescription = default integration branch for merging ticket patchsets
+gb.anonymousCanNotPropose = Anonymous users can not propose patchsets.
+gb.youDoNotHaveClonePermission = You are not permitted to clone this repository.
\ No newline at end of file
index 8571b088a0cdcc0bea11469523ee4061b155a892..e4bb41fd9998101d99e8145d33c31e4225681d7f 100644 (file)
@@ -54,7 +54,6 @@ import org.eclipse.jgit.lib.PersonIdent;
 import org.eclipse.jgit.lib.Ref;\r
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
-import org.eclipse.jgit.transport.URIish;\r
 \r
 import com.gitblit.Constants;\r
 import com.gitblit.Constants.AccessPermission;\r
@@ -734,16 +733,17 @@ public class TicketPage extends TicketBasePage {
                 */\r
                if (currentPatchset == null) {\r
                        // no patchset available\r
-                       String repoUrl = getRepositoryUrl(user, repository);\r
-                       if (ticket.isOpen() && app().tickets().isAcceptingNewPatchsets(repository) && !StringUtils.isEmpty(repoUrl)) {\r
+                       RepositoryUrl repoUrl = getRepositoryUrl(user, repository);\r
+                       boolean canPropose = repoUrl != null && repoUrl.permission.atLeast(AccessPermission.CLONE) && !UserModel.ANONYMOUS.equals(user);\r
+                       if (ticket.isOpen() && app().tickets().isAcceptingNewPatchsets(repository) && canPropose) {\r
                                // ticket & repo will accept a proposal patchset\r
                                // show the instructions for proposing a patchset\r
                                Fragment changeIdFrag = new Fragment("patchset", "proposeFragment", this);\r
                                changeIdFrag.add(new Label("proposeInstructions", MarkdownUtils.transformMarkdown(getString("gb.proposeInstructions"))).setEscapeModelStrings(false));\r
                                changeIdFrag.add(new Label("ptWorkflow", MessageFormat.format(getString("gb.proposeWith"), "Barnum")));\r
-                               changeIdFrag.add(new Label("ptWorkflowSteps", getProposeWorkflow("propose_pt.md", repoUrl, ticket.number)).setEscapeModelStrings(false));\r
+                               changeIdFrag.add(new Label("ptWorkflowSteps", getProposeWorkflow("propose_pt.md", repoUrl.url, ticket.number)).setEscapeModelStrings(false));\r
                                changeIdFrag.add(new Label("gitWorkflow", MessageFormat.format(getString("gb.proposeWith"), "Git")));\r
-                               changeIdFrag.add(new Label("gitWorkflowSteps", getProposeWorkflow("propose_git.md", repoUrl, ticket.number)).setEscapeModelStrings(false));\r
+                               changeIdFrag.add(new Label("gitWorkflowSteps", getProposeWorkflow("propose_git.md", repoUrl.url, ticket.number)).setEscapeModelStrings(false));\r
                                add(changeIdFrag);\r
                        } else {\r
                                // explain why you can't propose a patchset\r
@@ -757,6 +757,12 @@ public class TicketPage extends TicketBasePage {
                                        reason = getString("gb.repositoryIsFrozen");\r
                                } else if (!repository.acceptNewPatchsets) {\r
                                        reason = getString("gb.repositoryDoesNotAcceptPatchsets");\r
+                               } else if (!canPropose) {\r
+                                       if (UserModel.ANONYMOUS.equals(user)) {\r
+                                               reason = getString("gb.anonymousCanNotPropose");\r
+                                       } else {\r
+                                               reason = getString("gb.youDoNotHaveClonePermission");\r
+                                       }\r
                                } else {\r
                                        reason = getString("gb.serverDoesNotAcceptPatchsets");\r
                                }\r
@@ -1476,19 +1482,14 @@ public class TicketPage extends TicketBasePage {
         * @param repository\r
         * @return the primary repository url\r
         */\r
-       protected String getRepositoryUrl(UserModel user, RepositoryModel repository) {\r
+       protected RepositoryUrl getRepositoryUrl(UserModel user, RepositoryModel repository) {\r
                HttpServletRequest req = ((WebRequest) getRequest()).getHttpServletRequest();\r
                List<RepositoryUrl> urls = app().gitblit().getRepositoryUrls(req, user, repository);\r
                if (ArrayUtils.isEmpty(urls)) {\r
                        return null;\r
                }\r
-               String primaryurl = urls.get(0).url;\r
-               String url = primaryurl;\r
-               try {\r
-                       url = new URIish(primaryurl).setUser(null).toString();\r
-               } catch (Exception e) {\r
-               }\r
-               return url;\r
+               RepositoryUrl primary = urls.get(0);\r
+               return primary;\r
        }\r
 \r
        /**\r