MDL-58768 mod_assign: Add $user param to assign::can_grade

This commit is contained in:
Shamim Rezaie
2018-07-31 15:45:36 +10:00
parent 856d6bcaf7
commit ec92334c18
3 changed files with 11 additions and 2 deletions
+3 -2
View File
@@ -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;
}
+5
View File
@@ -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);
+3
View File
@@ -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.