MDL-49651 mod_forum: Respect course visibility in cron
authorMathew <mathewm@hotmail.co.nz>
Mon, 10 Dec 2018 03:04:10 +0000 (11:04 +0800)
committerMathew <mathewm@hotmail.co.nz>
Mon, 24 Dec 2018 01:11:15 +0000 (09:11 +0800)
This checks the courses' current visibility and the users permissions.
If they have the permission to view the course when it is hidden they'll get messages.

We already have checks for the users enrolled & subscription status.

mod/forum/lib.php

index aaf91fb..81bf60d 100644 (file)
@@ -657,6 +657,12 @@ function forum_cron() {
                     }
                 }
 
                     }
                 }
 
+                $coursecontext = context_course::instance($course->id);
+                if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext, $userto->id)) {
+                    // The course is hidden and the user does not have access to it.
+                    continue;
+                }
+
                 // Don't send email if the forum is Q&A and the user has not posted.
                 // Initial topics are still mailed.
                 if ($forum->type == 'qanda' && !forum_get_user_posted_time($discussion->id, $userto->id) && $pid != $discussion->firstpost) {
                 // Don't send email if the forum is Q&A and the user has not posted.
                 // Initial topics are still mailed.
                 if ($forum->type == 'qanda' && !forum_get_user_posted_time($discussion->id, $userto->id) && $pid != $discussion->firstpost) {