MDL-72012 mod_h5pactivity: respect user access when getting report.

This commit is contained in:
Paul Holden 2022-01-17 21:15:38 +00:00 committed by Jun Pataleta
parent 5e3707417d
commit 0393514612

View File

@ -451,7 +451,9 @@ class manager {
* @return report|null available report (or null if no report available)
*/
public function get_report(int $userid = null, int $attemptid = null, $currentgroup = false): ?report {
global $USER;
global $USER, $CFG;
require_once("{$CFG->dirroot}/user/lib.php");
// If tracking is disabled, no reports are available.
if (!$this->instance->enabletracking) {
@ -470,6 +472,14 @@ class manager {
if ($this->can_view_all_attempts()) {
$user = core_user::get_user($userid);
// Ensure user can view the attempt of specific userid, respecting access checks.
if ($user && $user->id != $USER->id) {
$course = get_course($this->coursemodule->course);
if ($this->coursemodule->effectivegroupmode == SEPARATEGROUPS && !user_can_view_profile($user, $course)) {
return null;
}
}
} else if ($this->can_view_own_attempts()) {
$user = core_user::get_user($USER->id);
if ($userid && $user->id != $userid) {