Skip to content

Commit

Permalink
Merge branch 'MDL-42189-403' of https://github.com/davewoloszyn/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_403_STABLE
  • Loading branch information
junpataleta committed Oct 26, 2023
2 parents d63fd03 + 82d1033 commit 4865c40
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
7 changes: 5 additions & 2 deletions grade/report/overview/lib.php
Expand Up @@ -69,14 +69,17 @@ class grade_report_overview extends grade_report {
* @param string $context
*/
public function __construct($userid, $gpr, $context) {
global $CFG, $COURSE, $DB;
global $CFG, $COURSE, $DB, $USER;
parent::__construct($COURSE->id, $gpr, $context);

// Get the user (for full name).
$this->user = $DB->get_record('user', array('id' => $userid));

// Set onlyactive flag to true if the user's viewing his/her report.
$onlyactive = ($this->user->id === $USER->id);

// Load the user's courses.
$this->courses = enrol_get_users_courses($this->user->id, false, 'id, shortname, showgrades');
$this->courses = enrol_get_users_courses($this->user->id, $onlyactive, 'id, shortname, showgrades');

$this->showrank = array();
$this->showrank['any'] = false;
Expand Down
31 changes: 31 additions & 0 deletions grade/report/overview/tests/behat/suspended.feature
@@ -0,0 +1,31 @@
@gradereport @gradereport_overview
Feature: Grade overview report should be hidden from suspended enrolments
While viewing the grade overview report
As a student
I should only see courses I am active in

Background:
Given the following "courses" exist:
| fullname | shortname |
| Active course | C1 |
| Suspended course | C2 |
And the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And the following "course enrolments" exist:
| user | course | role | status |
| student1 | C1 | student | 0 |
| student1 | C2 | student | 1 |

Scenario: Students should not see grades for courses with suspended enrolments
Given I am on the "Active course" "grades > Overview report > View" page logged in as "student1"
Then I should not see "Suspended course" in the "overview-grade" "table"
And I should see "Active course" in the "overview-grade" "table"

Scenario: Admins should see courses with suspended enrolments
Given I log in as "admin"
And I navigate to "Users > Accounts > Browse list of users" in site administration
And I follow "Student 1"
When I click on "Grades overview" "link"
Then I should see "Suspended course" in the "overview-grade" "table"
And I should see "Active course" in the "overview-grade" "table"

0 comments on commit 4865c40

Please sign in to comment.