/hudson-core/src/main/java/hudson/model/MyView.java

http://github.com/hudson/hudson · Java · 109 lines · 61 code · 13 blank · 35 comment · 2 complexity · 2e040ba2509a17230456310aae749737 MD5 · raw file

  1. /*
  2. * The MIT License
  3. *
  4. * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe, Tom Huybrechts
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. package hudson.model;
  25. import java.io.IOException;
  26. import java.util.ArrayList;
  27. import java.util.Collection;
  28. import java.util.Collections;
  29. import java.util.List;
  30. import javax.servlet.ServletException;
  31. import org.kohsuke.stapler.StaplerRequest;
  32. import org.kohsuke.stapler.StaplerResponse;
  33. import org.kohsuke.stapler.DataBoundConstructor;
  34. import hudson.model.Descriptor.FormException;
  35. import hudson.Extension;
  36. /**
  37. * {@link View} that only contains projects for which the current user has access to.
  38. *
  39. * @since 1.220
  40. * @author Tom Huybrechts
  41. */
  42. public class MyView extends View {
  43. @DataBoundConstructor
  44. public MyView(String name) {
  45. super(name);
  46. }
  47. public MyView(String name, ViewGroup owner) {
  48. this(name);
  49. this.owner = owner;
  50. }
  51. @Override
  52. public boolean contains(TopLevelItem item) {
  53. return item.hasPermission(Job.CONFIGURE);
  54. }
  55. @Override
  56. public Item doCreateItem(StaplerRequest req, StaplerResponse rsp)
  57. throws IOException, ServletException {
  58. return Hudson.getInstance().doCreateItem(req, rsp);
  59. }
  60. @Override
  61. public Collection<TopLevelItem> getItems() {
  62. List<TopLevelItem> items = new ArrayList<TopLevelItem>();
  63. for (TopLevelItem item : Hudson.getInstance().getItems()) {
  64. if (item.hasPermission(Job.CONFIGURE)) {
  65. items.add(item);
  66. }
  67. }
  68. return Collections.unmodifiableList(items);
  69. }
  70. @Override
  71. public String getPostConstructLandingPage() {
  72. return ""; // there's no configuration page
  73. }
  74. @Override
  75. public void onJobRenamed(Item item, String oldName, String newName) {
  76. // noop
  77. }
  78. @Override
  79. protected void submit(StaplerRequest req) throws IOException, ServletException, FormException {
  80. // noop
  81. }
  82. @Extension
  83. public static final class DescriptorImpl extends ViewDescriptor {
  84. /**
  85. * If the security is not enabled, there's no point in having
  86. * this type of views.
  87. */
  88. @Override
  89. public boolean isInstantiable() {
  90. return Hudson.getInstance().isUseSecurity();
  91. }
  92. public String getDisplayName() {
  93. return Messages.MyView_DisplayName();
  94. }
  95. }
  96. }