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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Component/s: core
    • Labels:
      None
    • Similar Issues:
    • Released As:
      Jenkins 2.214

      Description

      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

        Attachments

          Activity

          Hide
          oleg_nenashev Oleg Nenashev added a comment -

          A. Jard if you would like ti get it backported to LTS, please mark it as an LTS candidate

          Show
          oleg_nenashev Oleg Nenashev added a comment - A. Jard if you would like ti get it backported to LTS, please mark it as an LTS candidate

            People

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

              Dates

              Created:
              Updated:
              Resolved: