| | |
| | | settings.getBoolean(Keys.web.showHttpServletUrls, true)) { |
| | | AccessPermission permission = user.getRepositoryPermission(repository).permission; |
| | | if (permission.exceeds(AccessPermission.NONE)) { |
| | | Transport transport = Transport.fromString(request.getScheme()); |
| | | String repoUrl = getRepositoryUrl(request, username, repository); |
| | | Transport transport = Transport.fromUrl(repoUrl); |
| | | if (permission.atLeast(AccessPermission.PUSH) && !acceptsPush(transport)) { |
| | | // downgrade the repo permission for this transport |
| | | // because it is not an acceptable PUSH transport |
| | | permission = AccessPermission.CLONE; |
| | | } |
| | | list.add(new RepositoryUrl(getRepositoryUrl(request, username, repository), permission)); |
| | | list.add(new RepositoryUrl(repoUrl, permission)); |
| | | } |
| | | } |
| | | |
| | |
| | | // add all other urls |
| | | // {0} = repository |
| | | // {1} = username |
| | | boolean advertisePermsForOther = settings.getBoolean(Keys.web.advertiseAccessPermissionForOtherUrls, false); |
| | | for (String url : settings.getStrings(Keys.web.otherUrls)) { |
| | | String externalUrl = null; |
| | | |
| | | if (url.contains("{1}")) { |
| | | // external url requires username, only add url IF we have one |
| | | if (!StringUtils.isEmpty(username)) { |
| | | list.add(new RepositoryUrl(MessageFormat.format(url, repository.name, username), null)); |
| | | if (StringUtils.isEmpty(username)) { |
| | | continue; |
| | | } else { |
| | | externalUrl = MessageFormat.format(url, repository.name, username); |
| | | } |
| | | } else { |
| | | // external url does not require username |
| | | list.add(new RepositoryUrl(MessageFormat.format(url, repository.name), null)); |
| | | // external url does not require username, just do repo name formatting |
| | | externalUrl = MessageFormat.format(url, repository.name); |
| | | } |
| | | |
| | | AccessPermission permission = null; |
| | | if (advertisePermsForOther) { |
| | | permission = user.getRepositoryPermission(repository).permission; |
| | | if (permission.exceeds(AccessPermission.NONE)) { |
| | | Transport transport = Transport.fromUrl(externalUrl); |
| | | if (permission.atLeast(AccessPermission.PUSH) && !acceptsPush(transport)) { |
| | | // downgrade the repo permission for this transport |
| | | // because it is not an acceptable PUSH transport |
| | | permission = AccessPermission.CLONE; |
| | | } |
| | | } |
| | | } |
| | | list.add(new RepositoryUrl(externalUrl, permission)); |
| | | } |
| | | |
| | | // sort transports by highest permission and then by transport security |
| | |
| | | |
| | | @Override |
| | | public int compare(RepositoryUrl o1, RepositoryUrl o2) { |
| | | if (!o1.isExternal() && o2.isExternal()) { |
| | | // prefer Gitblit over external |
| | | if (o1.hasPermission() && !o2.hasPermission()) { |
| | | // prefer known permission items over unknown |
| | | return -1; |
| | | } else if (o1.isExternal() && !o2.isExternal()) { |
| | | // prefer Gitblit over external |
| | | } else if (!o1.hasPermission() && o2.hasPermission()) { |
| | | // prefer known permission items over unknown |
| | | return 1; |
| | | } else if (o1.isExternal() && o2.isExternal()) { |
| | | } else if (!o1.hasPermission() && !o2.hasPermission()) { |
| | | // sort by Transport ordinal |
| | | return o1.transport.compareTo(o2.transport); |
| | | } else if (o1.permission.exceeds(o2.permission)) { |