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

Users assigned context role via multiple components are counted multiple times

    XMLWordPrintable

    Details

      Description

      For system roles, where the users can be assigned from different sources, the count field is sometimes incorrect as it counts the same user multiple times.

      Following diff seemed to fix it here:

      accesslib.php

      diff --git a/lib/accesslib.php b/lib/accesslib.php
      index 45f07b4..5d3876e 100644
      --- a/lib/accesslib.php
      +++ b/lib/accesslib.php
      @@ -3371,7 +3371,7 @@ function get_assignable_roles(context $context, $rolenamedisplay = ROLENAME_ALIA
           $extrafields = '';
       
           if ($withusercounts) {
      -        $extrafields = ', (SELECT count(u.id)
      +        $extrafields = ', (SELECT count(DISTINCT u.id)
                                    FROM {role_assignments} cra JOIN {user} u ON cra.userid = u.id
                                   WHERE cra.roleid = r.id AND cra.contextid = :conid AND u.deleted = 0
                                 ) AS usercount';
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                pholden Paul Holden
                Reporter:
                pholden Paul Holden
                Peer reviewer:
                Luca Bösch
                Integrator:
                Eloy Lafuente (stronk7)
                Tester:
                CiBoT
                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:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  13/May/19

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 10 minutes
                  10m