From 9a6fdc2aeb4ff789f91da2d2c0fb76a7e2de3e78 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 7 Sep 2022 18:26:31 +0100 Subject: [PATCH] MDL-75517 report_participation: filter report by viewable roles only. --- report/participation/locallib.php | 8 +++++--- .../tests/behat/filter_participation.feature | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/report/participation/locallib.php b/report/participation/locallib.php index 8ab59b47a9b..df485c659f1 100644 --- a/report/participation/locallib.php +++ b/report/participation/locallib.php @@ -189,12 +189,14 @@ function report_participation_print_filter_form($course, $timefrom, $minlog, $ac $actionoptions = report_participation_get_action_options(); - // TODO: we need a new list of roles that are visible here. $context = context_course::instance($course->id); $roles = get_roles_used_in_context($context); + $rolesviewable = get_viewable_roles($context); + $guestrole = get_guest_role(); - $roles[$guestrole->id] = $guestrole; - $roleoptions = role_fix_names($roles, $context, ROLENAME_ALIAS, true); + $roleoptions = array_intersect_key($rolesviewable, $roles) + [ + $guestrole->id => role_get_name($guestrole, $context), + ]; $modinfo = get_fast_modinfo($course); diff --git a/report/participation/tests/behat/filter_participation.feature b/report/participation/tests/behat/filter_participation.feature index ff36a51c749..2d2027347fe 100644 --- a/report/participation/tests/behat/filter_participation.feature +++ b/report/participation/tests/behat/filter_participation.feature @@ -10,10 +10,12 @@ Feature: In a participation report, admin can filter student actions | Course 1 | C1 | 0 | 1 | And the following "users" exist: | username | firstname | lastname | email | + | manager1 | Manager | 1 | manager1@example.com | | teacher1 | Teacher | 1 | teacher1@example.com | | student1 | Student | 1 | student1@example.com | And the following "course enrolments" exist: | user | course | role | + | manager1 | C1 | manager | | teacher1 | C1 | editingteacher | | student1 | C1 | student | And the following "activity" exists: @@ -82,3 +84,21 @@ Feature: In a participation report, admin can filter student actions And I set the field "roleid" to "Student" And I press "Go" Then I should see "Yes (1)" + + @javascript + Scenario Outline: Filter participation report by viewable roles + Given I am on the "Course 1" course page logged in as "teacher1" + When I navigate to "Reports" in current page administration + And I click on "Course participation" "link" + # Teacher role cannot see Manager by default. + Then "Manager" "option" should not exist in the "Show only" "select" + And I set the following fields to these values: + | Activity module | Test book name | + | Show only | | + And I press "Go" + And I should see "" in the "reporttable" "table" + And I should not see "" in the "reporttable" "table" + Examples: + | role | uservisible | usernonvisible | + | Student | Student 1 | Teacher 1 | + | Teacher | Teacher 1 | Student 1 |