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

Cannot clear lists of allowed roles when editing a role

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      1. Log in as admin
      2. Go to Site administration -> Users -> Permissions -> Define roles
      3. Edit one of the existing roles
      4. Select at least one value for all 'Allow role ****' multiple selects.
        • Fields are: Allow role assignments, Allow role overrides, Allow role switches and Allow role to view.
      5. Save changes
      6. Edit the same existing role again.
      7. Unselect all values in all  'Allow role ****' multiple selects.
      8. Save changes
      9. Edit the same existing role.
      10. Make sure changes were saved and the  'Allow role ****' multiple selects are empty.
      Show
      Log in as admin Go to Site administration -> Users -> Permissions -> Define roles Edit one of the existing roles Select at least one value for all 'Allow role ****' multiple selects. Fields are : Allow role assignments, Allow role overrides, Allow role switches and Allow role to view. Save changes Edit the same existing role again. Unselect all values in all  'Allow role ****' multiple selects. Save changes Edit the same existing role. Make sure changes were saved and the  'Allow role ****' multiple selects are empty.
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_34_STABLE, MOODLE_35_STABLE, MOODLE_36_STABLE
    • Fixed Branches:
      MOODLE_37_STABLE, MOODLE_38_STABLE
    • Pull 3.7 Branch:
    • Pull 3.8 Branch:
    • Pull Master Branch:

      Description

      If an existing role has one or more allowed roles selected, clearing the list is ignored when saved and the list of allowed roles remains unchanged.

      The issue is caused by this code in define_role_table_advanced.php:

       // Allowed roles.
       $allow = optional_param_array('allowassign', null, PARAM_INT);
       if (!is_null($allow)) {
        $this->allowassign = $allow;
       }
       $allow = optional_param_array('allowoverride', null, PARAM_INT);
       if (!is_null($allow)) {
        $this->allowoverride = $allow;
       }
       $allow = optional_param_array('allowswitch', null, PARAM_INT);
       if (!is_null($allow)) {
        $this->allowswitch = $allow;
       }
       $allow = optional_param_array('allowview', null, PARAM_INT);
       if (!is_null($allow)) {
        $this->allowview = $allow;
       }
      

      Changing it to the following resolves the issue:

       // Allowed roles.
       $allow = optional_param_array('allowassign', null, PARAM_INT);
       if (!is_null($allow)) {
        $this->allowassign = $allow;
       } else {
        $this->allowassign = array();
       }
       $allow = optional_param_array('allowoverride', null, PARAM_INT);
       if (!is_null($allow)) {
        $this->allowoverride = $allow;
       } else {
        $this->allowoverride = array();
       }
       $allow = optional_param_array('allowswitch', null, PARAM_INT);
       if (!is_null($allow)) {
        $this->allowswitch = $allow;
       } else {
        $this->allowswitch = array();
       }
       $allow = optional_param_array('allowview', null, PARAM_INT);
       if (!is_null($allow)) {
        $this->allowview = $allow;
       } else {
        $this->allowview = array();
       }
       

      Steps to reproduce:

      • Log in as admin
      • Go to Site administration -> Users -> Permissions
      • Edit one of the existing roles
      • Select at least one value for all 'Allow role ****' multiple selects.
      • Save changes
      • Edit the same existing role again.
      • Unselect all values in all  'Allow role ****' multiple selects.
      • Save changes
      • Go to edit the same existing role. The  'Allow role ****' multiple selects are not empty. Changes were not saved.

        Attachments

          Activity

            People

            Assignee:
            marina Marina Glancy
            Reporter:
            svickers Stephen Vickers
            Peer reviewer:
            Paul Holden
            Integrator:
            Andrew Nicols
            Tester:
            Janelle Barcega
            Participants:
            Component watchers:
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              13/Jan/20

                Time Tracking

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 hours, 12 minutes
                3h 12m