From ec92334c18aa1f9beee6752fe15469d14425dcd9 Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Thu, 5 Apr 2018 01:15:47 +1000 Subject: [PATCH] MDL-58768 mod_assign: Add $user param to assign::can_grade --- mod/assign/locallib.php | 5 +++-- mod/assign/tests/locallib_test.php | 5 +++++ mod/assign/upgrade.txt | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index dd24fc97795..9ae6cd0d7d9 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -3306,11 +3306,12 @@ class assign { /** * Does this user have grade permission for this assignment? * + * @param int|stdClass $user The object or id of the user who will do the editing (default to current user). * @return bool */ - public function can_grade() { + public function can_grade($user = null) { // Permissions check. - if (!has_capability('mod/assign:grade', $this->context)) { + if (!has_capability('mod/assign:grade', $this->context, $user)) { return false; } diff --git a/mod/assign/tests/locallib_test.php b/mod/assign/tests/locallib_test.php index 882f9cc546a..659ae737664 100644 --- a/mod/assign/tests/locallib_test.php +++ b/mod/assign/tests/locallib_test.php @@ -1720,6 +1720,11 @@ class mod_assign_locallib_testcase extends advanced_testcase { $this->setUser($teacher); $this->assertEquals(true, $assign->can_grade()); + // Test the viewgrades capability for other users. + $this->setUser(); + $this->assertTrue($assign->can_grade($teacher->id)); + $this->assertFalse($assign->can_grade($student->id)); + // Test the viewgrades capability - without mod/assign:grade. $this->setUser($student); diff --git a/mod/assign/upgrade.txt b/mod/assign/upgrade.txt index e6cef2135bb..aa0b6af782f 100644 --- a/mod/assign/upgrade.txt +++ b/mod/assign/upgrade.txt @@ -1,5 +1,8 @@ This files describes API changes in the assign code. +=== 3.4.5 === +* The function can_grade() now has optional $user parameter. + === 3.4 === * assign::add_attempt requires that set_most_recent_team_submission() be called if attempting to use this function with a team submission.