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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.models.RepositoryModel;
  25. import com.gitblit.models.UserModel;
  26. import com.gitblit.utils.ModelUtils;
  27. import com.gitblit.utils.StringUtils;
  28. /**
  29. * RootSubPage is a non-topbar navigable RootPage. It also has a page header.
  30. *
  31. * @author James Moger
  32. *
  33. */
  34. public abstract class RootSubPage extends RootPage {
  35. public RootSubPage() {
  36. super();
  37. createPageMapIfNeeded();
  38. }
  39. public RootSubPage(PageParameters params) {
  40. super(params);
  41. createPageMapIfNeeded();
  42. }
  43. protected boolean requiresPageMap() {
  44. return false;
  45. }
  46. protected void createPageMapIfNeeded() {
  47. if (requiresPageMap()) {
  48. // because Gitblit strives for page-statelessness
  49. // Wicket seems to get confused as to when it really should
  50. // generate a page map for complex pages. Conditionally ensure we
  51. // have a page map for complex AJAX pages like the EditNNN pages.
  52. Session.get().pageMapForName(null, true);
  53. setVersioned(true);
  54. }
  55. }
  56. @Override
  57. protected void setupPage(String pageName, String subName) {
  58. add(new Label("pageName", pageName));
  59. if (!StringUtils.isEmpty(subName)) {
  60. subName = "/ " + subName;
  61. }
  62. add(new Label("pageSubName", subName));
  63. super.setupPage("", pageName);
  64. }
  65. protected List<String> getAccessRestrictedRepositoryList(boolean includeWildcards, UserModel user) {
  66. // build list of access-restricted projects
  67. String lastProject = null;
  68. List<String> repos = new ArrayList<String>();
  69. if (includeWildcards) {
  70. // all repositories
  71. repos.add(".*");
  72. // all repositories excluding personal repositories
  73. if (ModelUtils.getUserRepoPrefix().length() == 1) {
  74. repos.add("[^" + ModelUtils.getUserRepoPrefix() + "].*");
  75. }
  76. }
  77. for (String repo : app().repositories().getRepositoryList()) {
  78. RepositoryModel repositoryModel = app().repositories().getRepositoryModel(repo);
  79. if (repositoryModel.accessRestriction.exceeds(AccessRestrictionType.NONE)
  80. && repositoryModel.authorizationControl.equals(AuthorizationControl.NAMED)) {
  81. if (user != null &&
  82. (repositoryModel.isOwner(user.username) || repositoryModel.isUsersPersonalRepository(user.username))) {
  83. // exclude Owner or personal repositories
  84. continue;
  85. }
  86. if (includeWildcards) {
  87. if (lastProject == null || !lastProject.equalsIgnoreCase(repositoryModel.projectPath)) {
  88. lastProject = repositoryModel.projectPath.toLowerCase();
  89. if (!StringUtils.isEmpty(repositoryModel.projectPath)) {
  90. // regex for all repositories within a project
  91. repos.add(repositoryModel.projectPath + "/.*");
  92. }
  93. }
  94. }
  95. repos.add(repo.toLowerCase());
  96. }
  97. }
  98. return repos;
  99. }
  100. }