Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-60579

Impossible to have an invisible property on View that is persisted on save

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • core
    • None
    • Jenkins 2.214

      DescriptorVisibilityFilter is not used to filter properties that are displayed on the View edition.

      The same method View.getApplicablePropertyDescriptors() is used both to filter displayed properties on UI and to filter properties that are saved with the View.

      The only way to not show a property in UI is to use ViewPropertyDescriptor but then the property is not persisted and is removed when the users edit view and save it.

      @Extension
      public static final class DescriptorImpl extends ViewPropertyDescriptor {
      
          @Override
          public boolean isEnabledFor(View view) {
              return false;
          }
      }
      

      That means that it's not possible to have some hidden properties for View that are persisted.

      This method is used in jelly to filter properties:
      https://github.com/jenkinsci/jenkins/blob/d1502bffe8b5d530d31a4d697f064b79a5cab081/core/src/main/resources/hudson/model/View/configure.jelly#L55

      And it's also used in View to filter properties that are persisted:
      https://github.com/jenkinsci/jenkins/blob/d1502bffe8b5d530d31a4d697f064b79a5cab081/core/src/main/java/hudson/model/View.java#L1012

      I looked at Job configuration, a specific method based on DescriptorVisibilityFilter is used in jelly.
      https://github.com/jenkinsci/jenkins/blob/d1502bffe8b5d530d31a4d697f064b79a5cab081/core/src/main/resources/hudson/model/Job/configure.jelly#L51

      So this code should work for View when a plugin need to have an invisible property:

      @Extension
      public static final class DescriptorVisibilityFilterImpl extends DescriptorVisibilityFilter {
      
          @Override
          public boolean filter(Object context, Descriptor descriptor) {
              return false;
          }
      }

      I propose to add a new method in View to filter properties that use DescriptorVisibilityFilter to filter properties visible on UI and use it in View/configure.jelly.

      Rule test to reproduce the issue and the proposed correction are done in the PR: https://github.com/jenkinsci/jenkins/pull/4404

            ajard A. Jard
            ajard A. Jard
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: