From a428cf4ac88e2e674f4267a620d7338a3491a5cc Mon Sep 17 00:00:00 2001 From: Jake Dallimore Date: Fri, 11 Nov 2016 17:18:07 +0800 Subject: [PATCH] MDL-56870 lib: block access to deleted module in require_login --- lang/en/error.php | 1 + lib/moodlelib.php | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lang/en/error.php b/lang/en/error.php index fe57dd31f3b..f7c5ac85b60 100644 --- a/lang/en/error.php +++ b/lang/en/error.php @@ -22,6 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['activityisscheduledfordeletion'] = 'Activity deletion in progress...'; $string['authnotexisting'] = 'The autorization plugin doesn\'t exist'; $string['backupcontainexternal'] = 'This backup file contains external Moodle Network Hosts that are not configured locally'; $string['backuptablefail'] = 'Backup tables could NOT be set up successfully!'; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index ecff98b1245..c5ff6df8eee 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2517,6 +2517,7 @@ function get_login_url() { * @return mixed Void, exit, and die depending on path * @throws coding_exception * @throws require_login_exception + * @throws moodle_exception */ function require_login($courseorid = null, $autologinguest = true, $cm = null, $setwantsurltome = true, $preventredirect = false) { global $CFG, $SESSION, $USER, $PAGE, $SITE, $DB, $OUTPUT; @@ -2684,8 +2685,8 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $ // Make sure the USER has a sesskey set up. Used for CSRF protection. sesskey(); - // Do not bother admins with any formalities. - if (is_siteadmin()) { + // Do not bother admins with any formalities, except for activities pending deletion. + if (is_siteadmin() && !($cm && $cm->deletioninprogress)) { // Set the global $COURSE. if ($cm) { $PAGE->set_cm($cm, $course); @@ -2873,6 +2874,15 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $ } } + // Check whether the activity has been scheduled for deletion. If so, then deny access, even for admins. + if ($cm && $cm->deletioninprogress) { + if ($preventredirect) { + throw new moodle_exception('activityisscheduledfordeletion'); + } + require_once($CFG->dirroot . '/course/lib.php'); + redirect(course_get_url($course), get_string('activityisscheduledfordeletion', 'error')); + } + // Check visibility of activity to current user; includes visible flag, conditional availability, etc. if ($cm && !$cm->uservisible) { if ($preventredirect) {