Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-82214

Some admin settings reset to empty when read-only and the page it is on is saved

XMLWordPrintable

    • MOODLE_403_STABLE, MOODLE_404_STABLE
    • MOODLE_403_STABLE, MOODLE_404_STABLE
    • mdl-82214-m403
    • mdl-82214-m404
    • mdl-82214
    • Hide

      Editable settings work

      Setup

      • You are logged in as a Site administrator (for example admin)

      Steps

      1. Navigate to Site administration > Users > Permissions > User policies
      2. Check the Auto-login guests setting
      3. Set some options in Hide user fields
      4. Set some options in Show user identity
      5. Press Save changes
      6. Verify that Auto-login guests setting is checked
      7. Verify that the options you selected in Hide user fields and Show user identity have been saved
      8. Un-check the Auto-login guests setting
      9. Un-select all options in Hide user fields
      10. Un-select all options in Show user identity
      11. Press Save changes
      12. Verify that Auto-login guests setting is un-checked
      13. Verify that no options in Hide user fields and Show user identity are selected

      Read only test

      Setup

      1. You have applied mdl-82214-test.patch for main and 4.4 and mdl-82214-test_403.patchto your Moodle code base

      Steps

      1. On the command line in the root Moodle directory run: php mdl-82214.php
      2. Login as a Site administrator (for example admin)
      3. Navigate to Site administration > Server > System paths
      4. Verify that the Completed setting is checked
      5. Verify that the Readonly Multi-checkbox and Readonly Multi-select options have items selected
      6. Press Save changes
      7. Verify that the Completed, Readonly Multi-checkbox and Readonly Multi-select settings are unchanged.
      Show
      Editable settings work Setup You are logged in as a Site administrator (for example admin) Steps Navigate to Site administration > Users > Permissions > User policies Check the Auto-login guests setting Set some options in Hide user fields Set some options in Show user identity Press Save changes Verify that Auto-login guests setting is checked Verify that the options you selected in Hide user fields and Show user identity have been saved Un-check the Auto-login guests setting Un-select all options in Hide user fields Un-select all options in Show user identity Press Save changes Verify that Auto-login guests setting is un-checked Verify that no options in Hide user fields and Show user identity are selected Read only test Setup You have applied mdl-82214-test.patch for main and 4.4 and mdl-82214-test_403.patch to your Moodle code base Steps On the command line in the root Moodle directory run: php mdl-82214.php Login as a Site administrator (for example admin) Navigate to Site administration > Server > System paths Verify that the Completed setting is checked Verify that the Readonly Multi-checkbox and Readonly Multi-select options have items selected Press Save changes Verify that the Completed , Readonly Multi-checkbox and Readonly Multi-select settings are unchanged.

      If you have a checkbox admin setting that is set to be read only and set to have a value of yes when you save the screen it is updated to the no state.

      This appears to be happening because of[ the hidden input that is configured to no|https://github.com/moodle/moodle/blob/main/admin/templates/setting_configcheckbox.mustache#L41], when the checkbox is set to be disabled it is not submitted as part of the form.

      This means that the hidden field is submitted which causes the setting to be changed.

      I think that to fix this the hidden input should only be output if the setting is not read only.

      I found this bug while trying to implement a setting that could not be changed via the admin UI, but which I wanted to display to the users, i.e. something like:

      class admin_setting_completed extends \admin_setting_configcheckbox {
          /**
           * Constructor for the setting.
           *
           * @param $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins.
           */
          public function __construct($name) {
              $visiblename = 'Completed';
              $description = 'This setting should not change if code else where has set it to "1"';
              parent::__construct($name, $visiblename, $description, null);
          }
       
          /**
           * This setting is not configurable via the UI.
           */
          public function is_readonly(): bool {
              return true;
          }
      }
      

      In my plugin I can workaround this by making my control by making it use it's own template

      I have created a patch that will allow you to observe this in action, it adds a config element to the System paths settings page

      mdl-82214.patch

      Replication steps

      1. Apply the patch to the main branch
      2. From the root Moodle directory run php mdl-82214.php to set the setting to the yes value
      3. Login to Moodle as the admin
      4. Navigate to Site Administration > Server > System paths
      5. Observe the read only Completed checkbox at the bottom of the page is checked
      6. Press Save changes
      7. Observe that the read only Completed checkbox is is now not checked

      There is also now a patch that demonstrated the same issue with multipcheckbox and multiselect settings.

      mdl-82214-test.patch

            nmagill Neill Magill
            nmagill Neill Magill
            Raquel Ortega Raquel Ortega
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 5 hours, 4 minutes
                5h 4m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.