diff --git a/grade/report/overview/lib.php b/grade/report/overview/lib.php index f051293b73e..03b1f97b3a9 100644 --- a/grade/report/overview/lib.php +++ b/grade/report/overview/lib.php @@ -80,14 +80,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; diff --git a/grade/report/overview/tests/behat/suspended.feature b/grade/report/overview/tests/behat/suspended.feature new file mode 100644 index 00000000000..551aa737e57 --- /dev/null +++ b/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"