Skip to content

Commit

Permalink
MDL-75517 report_participation: filter report by viewable roles only.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden authored and ilyatregubov committed Mar 8, 2023
1 parent 493205b commit f0a557b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions report/participation/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
20 changes: 20 additions & 0 deletions report/participation/tests/behat/filter_participation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 | <role> |
And I press "Go"
And I should see "<uservisible>" in the "reporttable" "table"
And I should not see "<usernonvisible>" in the "reporttable" "table"
Examples:
| role | uservisible | usernonvisible |
| Student | Student 1 | Teacher 1 |
| Teacher | Teacher 1 | Student 1 |

0 comments on commit f0a557b

Please sign in to comment.