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

Users assigned context role via multiple components are counted multiple times

XMLWordPrintable

      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';
      

            pholden Paul Holden
            pholden Paul Holden
            Luca Bösch Luca Bösch
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            CiBoT CiBoT
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

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

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.