From faa5d173cc59bf2b47893ea87a425177d6c3ea6e 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 | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 55f734cbbec..67b3f57c1f6 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -3316,11 +3316,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 80ec0cd2a04..d4b17e9a7b8 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 d32481c41b9..dbcd9fd04f8 100644 --- a/mod/assign/upgrade.txt +++ b/mod/assign/upgrade.txt @@ -4,6 +4,7 @@ This files describes API changes in the assign code. * The mod_assign_base_testcase unit test base class has been deprecated. It encouraged poor unit test design and led to significant performance issues with unit tests. See MDL-55609 for further information. +* The function can_grade() now has optional $user parameter. === 3.5 === * Functions assign:get_assign_grading_summary_renderable, assign:can_view_submission, assign:count_submissions_with_status,