Moodle
  1. Moodle
  2. MDL-26951

Cannot change archetype on existing role to None

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0.2
    • Fix Version/s: 2.0.3
    • Component/s: Roles / Access
    • Labels:
      None
    • Environment:
      Linux x86 64-bit, Apache 2.2.13, php 5.2.10, MySQL 5.0.91-community, Moodle 2.02+ build 20110309
    • Database:
      MySQL
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE
    • Rank:
      16954

      Description

      In Site Administration -> Users -> Permissions -> Define Roles, changing the archetype on a role to None does not work and does not show any errors.

      Steps to reproduce:
      0. Login to Moodle as site administrator.
      1. Navigate to Site Administration -> Users -> Permissions -> Define Roles.
      2. Click the Edit button for a role, or view a role and then click the edit button on the page. To test safely, you may want to duplicate an existing role. In your choice, choose a role that has an Archetype, i.e. Student.
      3. In the select field for Role Archetype, choose "None".
      4. Click Save changes.
      5. View the role you just saved.

      What is expected:
      After performing these steps, you should see in step 5 that the Archetype on the role is "None".

      What actually happens:
      In step 5, the Archetype on the role has not been changed and is still the old value.

      More details:
      From my analysis, the bug lies in /admin/roles/lib.php, class define_role_table_advanced, function read_submitted_permissions, in the section where it is reading the input data for the Archetype select field.
      In my build it starts at line 629. Snippet:

      629 // Legacy type.
      630 $archetype = optional_param('archetype', null, PARAM_RAW);
      631 if ($archetype) {
      632 $archetypes = get_role_archetypes();
      633 if (isset($archetypes[$archetype]))

      { 634 $this->role->archetype = $archetype; 635 }

      else

      { 636 $this->role->archetype = ''; 637 }

      638 }

      Now, the value for Archetype when it is None is ''. The way this is written, it understands '' as both the input was not sent to the server (which occurs when the edit form is first shown, pre-submission), as well as when the input is sent to the server and it is "None". In other words, when you submit "None", it thinks you have skipped on submitting an optional parameter, and does not write None.

      Based on your logic for checking whether the submitted Archetype is in the list of valid Archetypes, the bug fix would be that to submit "None", submit an invalid archetype name, even "none" itself, just not '' and not a valid archetype name. Then it will know that the parameter was submitted, but because it will not find it in the valid archetype list, it will end up assigning it to '', the value that has to end up in the database.

      Workaround:
      This bug only affects the interface. I was able to change the Archetype attribute of the desired role to an empty string in the mdl_role table manually, and viewing the role in Moodle showed that it was archetype 'none'.

      Implications beyond this case:
      Any form in Moodle that accepts the value '' for an optional parameter, where the '' can both mean it was submitted as a "None" choice as well as not submitted at all, potentially has this same bug!

        Issue Links

          Activity

          Hide
          Petr Škoda added a comment -

          This issue will be fixed int he next weekly build, thanks for the report!

          Petr

          Show
          Petr Škoda added a comment - This issue will be fixed int he next weekly build, thanks for the report! Petr

            People

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

              Dates

              • Created:
                Updated:
                Resolved: