MDL-60058 assign: stop teacher from seeing due date event on dashboard
authorRyan Wyllie <ryan@moodle.com>
Wed, 11 Oct 2017 06:26:16 +0000 (06:26 +0000)
committerRyan Wyllie <ryan@moodle.com>
Fri, 13 Oct 2017 06:38:03 +0000 (06:38 +0000)
Thanks to Damyon Wiese for the patch.

mod/assign/lib.php
mod/assign/locallib.php
mod/assign/tests/lib_test.php

index aa623c8..9c6c2c1 100644 (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', [
index 4f84e77..9eb7a77 100644 (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)) {
index 976d182..79c924c 100644 (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() {