MDL-66178 user: filter course participants for users with no roles.

This commit is contained in:
Paul Holden 2019-07-30 07:55:50 +01:00
parent 414eca8923
commit 90ce66a9ce
3 changed files with 27 additions and 4 deletions

View File

@ -1293,7 +1293,7 @@ function user_get_tagged_users($tag, $exclusivemode = false, $fromctx = 0, $ctx
* @param int $courseid The course id
* @param int $groupid The groupid, 0 means all groups and USERSWITHOUTGROUP no group
* @param int $accesssince The time since last access, 0 means any time
* @param int $roleid The role id, 0 means all roles
* @param int $roleid The role id, 0 means all roles and -1 no roles
* @param int $enrolid The enrolment id, 0 means all enrolment methods will be returned.
* @param int $statusid The user enrolment status, -1 means all enrolments regardless of the status will be returned, if allowed.
* @param string|array $search The search that was performed, empty means perform no search
@ -1367,8 +1367,14 @@ function user_get_participants_sql($courseid, $groupid = 0, $accesssince = 0, $r
list($relatedctxsql, $relatedctxparams) = $DB->get_in_or_equal($context->get_parent_context_ids(true),
SQL_PARAMS_NAMED, 'relatedctx');
$wheres[] = "u.id IN (SELECT userid FROM {role_assignments} WHERE roleid = :roleid AND contextid $relatedctxsql)";
$params = array_merge($params, array('roleid' => $roleid), $relatedctxparams);
// Get users without any role.
if ($roleid == -1) {
$wheres[] = "u.id NOT IN (SELECT userid FROM {role_assignments} WHERE contextid $relatedctxsql)";
$params = array_merge($params, $relatedctxparams);
} else {
$wheres[] = "u.id IN (SELECT userid FROM {role_assignments} WHERE roleid = :roleid AND contextid $relatedctxsql)";
$params = array_merge($params, array('roleid' => $roleid), $relatedctxparams);
}
}
if (!empty($search)) {

View File

@ -135,7 +135,7 @@ class core_user_renderer extends plugin_renderer_base {
}
$criteria = get_string('role');
$roleoptions = [];
$roleoptions = $this->format_filter_option(USER_FILTER_ROLE, $criteria, -1, get_string('noroles', 'role'));
foreach ($roles as $id => $role) {
$roleoptions += $this->format_filter_option(USER_FILTER_ROLE, $criteria, $id, $role);
}

View File

@ -98,6 +98,23 @@ Feature: Course participants can be filtered
| Group: Group A | Student 1 | Student 2 | | Student 3 | XX-IGNORE-XX |
| Group: Group B | Student 2 | | | Student 1 | Student 3 |
@javascript
Scenario: Filter users who have no role in a course
Given I log in as "teacher1"
And I am on "Course 1" course homepage
And I navigate to course participants
And I click on "Student 1's role assignments" "link"
And I click on ".form-autocomplete-selection [aria-selected=true]" "css_element"
And I press key "27" in the field "Student 1's role assignments"
And I click on "Save changes" "link"
When I open the autocomplete suggestions list
And I click on "Role: No roles" item in the autocomplete list
Then I should see "Student 1" in the "participants" "table"
And I should not see "Student 2" in the "participants" "table"
And I should not see "Student 3" in the "participants" "table"
And I should not see "Student 4" in the "participants" "table"
And I should not see "Teacher 1" in the "participants" "table"
@javascript
Scenario: Multiple filters applied
Given I log in as "teacher1"