From 6ce5b797cca2f8b3c32c10d93bcf5535fa7394b7 Mon Sep 17 00:00:00 2001 From: mindless Date: Sun, 27 Jun 2010 18:31:50 +0000 Subject: [PATCH] [FIXED HUDSON-6832] Hide some sidepanel links that should not be shown in user-private views. Use it="${app}" for Manage Hudson and New Job links, so these check the proper permission. Replaced !it.isDefault() check with new ViewGroup.canDelete API call.. Hudson ViewGroup uses isDefault() for this method; MyViewsProperty checks views.size() > 1 so link is hidden when there is only one user-private view. Used !=false in jelly for backward compatibility (if a plugin implements ViewGroup but does not have canDelete, null!=false will result in true). git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@32319 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/model/Hudson.java | 8 ++++++-- core/src/main/java/hudson/model/MyViewsProperty.java | 12 ++++++++---- core/src/main/java/hudson/model/TreeView.java | 7 +++++-- core/src/main/java/hudson/model/ViewGroup.java | 11 ++++++++--- .../main/resources/hudson/model/Messages.properties | 1 + .../main/resources/hudson/model/View/sidepanel.jelly | 7 +++---- 6 files changed, 31 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java index 446f142a08..e171aa16ba 100644 --- a/core/src/main/java/hudson/model/Hudson.java +++ b/core/src/main/java/hudson/model/Hudson.java @@ -1280,9 +1280,13 @@ public final class Hudson extends Node implements ItemGroup, Stapl save(); } + public boolean canDelete(View view) { + return !view.isDefault(); // Cannot delete primary view + } + public synchronized void deleteView(View view) throws IOException { - if(views.size()<=1) - throw new IllegalStateException(); + if (views.size() <= 1) + throw new IllegalStateException("Cannot delete last view"); views.remove(view); save(); } diff --git a/core/src/main/java/hudson/model/MyViewsProperty.java b/core/src/main/java/hudson/model/MyViewsProperty.java index 8539fb00f1..195d4b0691 100644 --- a/core/src/main/java/hudson/model/MyViewsProperty.java +++ b/core/src/main/java/hudson/model/MyViewsProperty.java @@ -1,7 +1,7 @@ /* * The MIT License * - * Copyright (c) 2004-2009, Sun Microsystems, Inc., Tom Huybrechts + * Copyright (c) 2004-2010, Sun Microsystems, Inc., Tom Huybrechts * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -113,9 +113,13 @@ public class MyViewsProperty extends UserProperty implements ViewGroup, Action { return null; } + public boolean canDelete(View view) { + return views.size() > 1; // Cannot delete last view + } + public void deleteView(View view) throws IOException { if (views.size() <= 1) { - throw new IllegalStateException(); + throw new IllegalStateException("Cannot delete last view"); } views.remove(view); if (view.getViewName().equals(primaryViewName)) { @@ -194,7 +198,7 @@ public class MyViewsProperty extends UserProperty implements ViewGroup, Action { ///// Action methods ///// public String getDisplayName() { - return "My Views"; + return Messages.MyViewsProperty_DisplayName(); } public String getIconFileName() { @@ -210,7 +214,7 @@ public class MyViewsProperty extends UserProperty implements ViewGroup, Action { @Override public String getDisplayName() { - return "My Views"; + return Messages.MyViewsProperty_DisplayName(); } @Override diff --git a/core/src/main/java/hudson/model/TreeView.java b/core/src/main/java/hudson/model/TreeView.java index 625719ab87..a950965840 100644 --- a/core/src/main/java/hudson/model/TreeView.java +++ b/core/src/main/java/hudson/model/TreeView.java @@ -1,7 +1,7 @@ /* * The MIT License * - * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi + * Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -39,7 +39,6 @@ import java.util.List; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.CopyOnWriteArrayList; -import java.text.ParseException; /** * @@ -125,6 +124,10 @@ public class TreeView extends View implements ViewGroup { protected void submit(StaplerRequest req) throws IOException, ServletException, FormException { } + public boolean canDelete(View view) { + return true; + } + public void deleteView(View view) throws IOException { views.remove(view); } diff --git a/core/src/main/java/hudson/model/ViewGroup.java b/core/src/main/java/hudson/model/ViewGroup.java index 76c83b8985..45f2d76fcb 100644 --- a/core/src/main/java/hudson/model/ViewGroup.java +++ b/core/src/main/java/hudson/model/ViewGroup.java @@ -1,7 +1,8 @@ /* * The MIT License * - * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Tom Huybrechts + * Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi, + * Tom Huybrechts, Alan Harder * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -31,12 +32,16 @@ import java.util.Collection; /** * Container of {@link View}s. * - *

STILL EXPERIMENTAL: DO NOT IMPLEMENT

- * * @author Kohsuke Kawaguchi * @since 1.269 */ public interface ViewGroup extends Saveable, ModelObject, AccessControlled { + /** + * Determine whether a view may be deleted. + * @since 1.365 + */ + boolean canDelete(View view); + /** * Deletes a view in this group. */ diff --git a/core/src/main/resources/hudson/model/Messages.properties b/core/src/main/resources/hudson/model/Messages.properties index e4174105b9..9afa3e3b89 100644 --- a/core/src/main/resources/hudson/model/Messages.properties +++ b/core/src/main/resources/hudson/model/Messages.properties @@ -267,6 +267,7 @@ Cause.RemoteCause.ShortDescriptionWithNote=Started by remote host {0} with note: ProxyView.NoSuchViewExists=Global view {0} does not exist ProxyView.DisplayName=Include a global view +MyViewsProperty.DisplayName=My Views MyViewsProperty.GlobalAction.DisplayName=My Views MyViewsProperty.ViewExistsCheck.NotExist=A view with name {0} does not exist MyViewsProperty.ViewExistsCheck.AlreadyExists=A view with name {0} already exists diff --git a/core/src/main/resources/hudson/model/View/sidepanel.jelly b/core/src/main/resources/hudson/model/View/sidepanel.jelly index 7af552f977..76e5c092e1 100644 --- a/core/src/main/resources/hudson/model/View/sidepanel.jelly +++ b/core/src/main/resources/hudson/model/View/sidepanel.jelly @@ -35,8 +35,8 @@ THE SOFTWARE. - - + + @@ -50,8 +50,7 @@ THE SOFTWARE. - - + -- GitLab