MDL-60058 assign: stop teacher from seeing due date event on dashboard

Thanks to Damyon Wiese for the patch.
This commit is contained in:
Ryan Wyllie 2017-10-11 06:26:16 +00:00
parent 028fa14436
commit 7ec6d873e1
3 changed files with 25 additions and 13 deletions

View File

@ -1886,6 +1886,14 @@ function mod_assign_core_calendar_provide_event_action(calendar_event $event,
return null;
}
$participant = $assign->get_participant($USER->id);
if (!$participant) {
// If the user is not a participant in the assignment then they have
// no action to take. This will filter out the events for teachers.
return null;
}
// The user has not yet submitted anything. Show the addsubmission link.
$name = get_string('addsubmission', 'assign');
$url = new \moodle_url('/mod/assign/view.php', [

View File

@ -2036,9 +2036,13 @@ class assign {
* @return null|stdClass user record
*/
public function get_participant($userid) {
global $DB;
global $DB, $USER;
$participant = $DB->get_record('user', array('id' => $userid));
if ($userid == $USER->id) {
$participant = clone ($USER);
} else {
$participant = $DB->get_record('user', array('id' => $userid));
}
if (!$participant) {
return null;
}
@ -5719,11 +5723,15 @@ class assign {
return false;
}
if ($userid == $graderid &&
$this->submissions_open($userid) &&
has_capability('mod/assign:submit', $this->context, $graderid)) {
// User can edit their own submission.
return true;
if ($userid == $graderid) {
if ($this->submissions_open($userid) &&
has_capability('mod/assign:submit', $this->context, $graderid)) {
// User can edit their own submission.
return true;
} else {
// We need to return here because editothersubmission should never apply to a users own submission.
return false;
}
}
if (!has_capability('mod/assign:editothersubmission', $this->context, $graderid)) {

View File

@ -486,12 +486,8 @@ class mod_assign_lib_testcase extends mod_assign_base_testcase {
// Decorate action event.
$actionevent = mod_assign_core_calendar_provide_event_action($event, $factory);
// Confirm the event was decorated.
$this->assertInstanceOf('\core_calendar\local\event\value_objects\action', $actionevent);
$this->assertEquals(get_string('addsubmission', 'assign'), $actionevent->get_name());
$this->assertInstanceOf('moodle_url', $actionevent->get_url());
$this->assertEquals(1, $actionevent->get_item_count());
$this->assertFalse($actionevent->is_actionable());
// The teacher should not have an action for a due date event.
$this->assertNull($actionevent);
}
public function test_assign_core_calendar_provide_event_action_duedate_as_student() {