From 6d18f136ae88ec97e351a723df570816a959ec68 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 12 Jan 2022 11:07:34 +0000 Subject: [PATCH] MDL-72772 gradereport_overview: account for users with parent roles. --- course/user.php | 4 +++- grade/report/overview/lib.php | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/course/user.php b/course/user.php index 17477f5b1b6..ee187c67b2f 100644 --- a/course/user.php +++ b/course/user.php @@ -193,7 +193,9 @@ switch ($mode) { require_once $CFG->dirroot.'/grade/report/'.$CFG->grade_profilereport.'/lib.php'; // User must be able to view this grade report. - require_capability('gradereport/' . $CFG->grade_profilereport .':view', $coursecontext); + if (!$viewasuser) { + require_capability('gradereport/' . $CFG->grade_profilereport . ':view', $coursecontext); + } $functionname = 'grade_report_'.$CFG->grade_profilereport.'_profilereport'; if (function_exists($functionname)) { diff --git a/grade/report/overview/lib.php b/grade/report/overview/lib.php index d1528b228bd..b20c5e3de60 100644 --- a/grade/report/overview/lib.php +++ b/grade/report/overview/lib.php @@ -272,6 +272,12 @@ class grade_report_overview extends grade_report { if ($this->courses) { $coursesdata = $this->setup_courses_data($studentcoursesonly); + // Check whether current user can view all grades of this user - parent most probably. + $viewasuser = $this->course->showgrades && has_any_capability([ + 'moodle/grade:viewall', + 'moodle/user:viewuseractivitiesreport', + ], context_user::instance($this->user->id)); + foreach ($coursesdata as $coursedata) { $course = $coursedata['course']; @@ -282,13 +288,15 @@ class grade_report_overview extends grade_report { $coursenamelink = format_string(get_course_display_name_for_list($course), true, ['context' => $coursecontext]); // Link to the course grade report pages (performing same capability checks as the pages themselves). - if ($activitylink && has_capability('gradereport/' . $CFG->grade_profilereport .':view', $coursecontext)) { + if ($activitylink && + (has_capability('gradereport/' . $CFG->grade_profilereport .':view', $coursecontext) || $viewasuser)) { + $coursenamelink = html_writer::link(new moodle_url('/course/user.php', [ 'mode' => 'grade', 'id' => $course->id, 'user' => $this->user->id, ]), $coursenamelink); - } else if (!$activitylink && has_capability('gradereport/user:view', $coursecontext)) { + } else if (!$activitylink && (has_capability('gradereport/user:view', $coursecontext) || $viewasuser)) { $coursenamelink = html_writer::link(new moodle_url('/grade/report/user/index.php', [ 'id' => $course->id, 'userid' => $this->user->id,