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
*/\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
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
* @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