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

lib/accesslib.php/count_role_users function give wrong results

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: 1.7.4, 1.8.2
    • Fix Version/s: 1.8.5, 1.9
    • Component/s: Roles / Access
    • Labels:
      None
    • Environment:
      any
    • Affected Branches:
      MOODLE_17_STABLE, MOODLE_18_STABLE
    • Fixed Branches:
      MOODLE_18_STABLE, MOODLE_19_STABLE

      Description

      When assigning roles to a course the script /admin/roles/assign.php first give a quick summary of roles and the
      current number of users having these roles.

      Unfortunately the numbers are wrong , and do not match what is seen when getting role's details, since the called API function lib/accesslib.php/count_role_users do not filter out deleted users, i.e. users having the flag deleted set ...

      current SQL is :

      $SQL = "SELECT count
      FROM {$CFG->prefix}role_assignments r
      WHERE (r.contextid = $context->id $parentcontexts)
      AND r.roleid = $roleid";

      where it should be :

      $SQL = "SELECT count
      FROM {$CFG->prefix}role_assignments r,{$CFG->prefix}user u
      WHERE (r.contextid = $context->id $parentcontexts)
      AND r.roleid = $roleid
      AND r.userid=u.id
      AND not u.deleted";

      According to phpxref , this function is called only from admin/roles/assign.php, so this patch should be without other consequences.

      Cheers.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                poltawski Dan Poltawski
                Reporter:
                ppollet Patrick Pollet
                Participants:
                Component watchers:
                Amaia Anabitarte, Carlos Escobedo, Sara Arjona (@sarjona), Víctor Déniz Falcón
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  3/Mar/08