You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RootSubPage.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.wicket.pages;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. import org.apache.wicket.PageParameters;
  20. import org.apache.wicket.Session;
  21. import org.apache.wicket.markup.html.basic.Label;
  22. import com.gitblit.Constants.AccessRestrictionType;
  23. import com.gitblit.Constants.AuthorizationControl;
  24. import com.gitblit.GitBlit;
  25. import com.gitblit.models.RepositoryModel;
  26. import com.gitblit.models.UserModel;
  27. import com.gitblit.utils.ModelUtils;
  28. import com.gitblit.utils.StringUtils;
  29. /**
  30. * RootSubPage is a non-topbar navigable RootPage. It also has a page header.
  31. *
  32. * @author James Moger
  33. *
  34. */
  35. public abstract class RootSubPage extends RootPage {
  36. public RootSubPage() {
  37. super();
  38. createPageMapIfNeeded();
  39. }
  40. public RootSubPage(PageParameters params) {
  41. super(params);
  42. createPageMapIfNeeded();
  43. }
  44. protected boolean requiresPageMap() {
  45. return false;
  46. }
  47. protected void createPageMapIfNeeded() {
  48. if (requiresPageMap()) {
  49. // because Gitblit strives for page-statelessness
  50. // Wicket seems to get confused as to when it really should
  51. // generate a page map for complex pages. Conditionally ensure we
  52. // have a page map for complex AJAX pages like the EditNNN pages.
  53. Session.get().pageMapForName(null, true);
  54. setVersioned(true);
  55. }
  56. }
  57. @Override
  58. protected void setupPage(String pageName, String subName) {
  59. add(new Label("pageName", pageName));
  60. if (!StringUtils.isEmpty(subName)) {
  61. subName = "/ " + subName;
  62. }
  63. add(new Label("pageSubName", subName));
  64. super.setupPage("", pageName);
  65. }
  66. protected List<String> getAccessRestrictedRepositoryList(boolean includeWildcards, UserModel user) {
  67. // build list of access-restricted projects
  68. String lastProject = null;
  69. List<String> repos = new ArrayList<String>();
  70. if (includeWildcards) {
  71. // all repositories
  72. repos.add(".*");
  73. // all repositories excluding personal repositories
  74. if (ModelUtils.getUserRepoPrefix().length() == 1) {
  75. repos.add("[^" + ModelUtils.getUserRepoPrefix() + "].*");
  76. }
  77. }
  78. for (String repo : GitBlit.self().getRepositoryList()) {
  79. RepositoryModel repositoryModel = GitBlit.self().getRepositoryModel(repo);
  80. if (repositoryModel.accessRestriction.exceeds(AccessRestrictionType.NONE)
  81. && repositoryModel.authorizationControl.equals(AuthorizationControl.NAMED)) {
  82. if (user != null &&
  83. (repositoryModel.isOwner(user.username) || repositoryModel.isUsersPersonalRepository(user.username))) {
  84. // exclude Owner or personal repositories
  85. continue;
  86. }
  87. if (includeWildcards) {
  88. if (lastProject == null || !lastProject.equalsIgnoreCase(repositoryModel.projectPath)) {
  89. lastProject = repositoryModel.projectPath.toLowerCase();
  90. if (!StringUtils.isEmpty(repositoryModel.projectPath)) {
  91. // regex for all repositories within a project
  92. repos.add(repositoryModel.projectPath + "/.*");
  93. }
  94. }
  95. }
  96. repos.add(repo.toLowerCase());
  97. }
  98. }
  99. return repos;
  100. }
  101. }