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

Cannot clear lists of allowed roles when editing a role

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Development in progress
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.4.5, 3.4.6, 3.4.7, 3.5.2, 3.5.3, 3.5.4, 3.6, 3.6.1, 3.6.2
    • Fix Version/s: None
    • Component/s: Roles / Access
    • Labels:
    • Testing Instructions:
      Hide
      1. Log in as admin
      2. Go to Site administration -> Users -> Permissions
      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 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
    • Pull from Repository:
    • Pull 3.5 Branch:
    • Pull 3.6 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

            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:

                Time Tracking

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 30 minutes
                1h 30m