From bc8da017b595b4847bddc010e67ff9e9cb27dd01 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Mon, 18 Jun 2012 11:33:28 +0700 Subject: [PATCH] MDL-27156 repositories: altered filepicker.php so that users with the ability to ignore course file size restrictions are not incorrectly restricted --- lib/form/filepicker.php | 5 ++++- lib/moodlelib.php | 12 ++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/form/filepicker.php b/lib/form/filepicker.php index bcee75d22a8..a27f0151bb2 100644 --- a/lib/form/filepicker.php +++ b/lib/form/filepicker.php @@ -207,7 +207,10 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input { $usercontext = get_context_instance(CONTEXT_USER, $USER->id); if ($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id DESC', false)) { $file = array_shift($files); - if ($this->_options['maxbytes'] and $file->get_filesize() > $this->_options['maxbytes']) { + if ($this->_options['maxbytes'] + and $this->_options['maxbytes'] !== USER_CAN_IGNORE_FILE_SIZE_LIMITS + and $file->get_filesize() > $this->_options['maxbytes']) { + // bad luck, somebody tries to sneak in oversized file $file->delete(); } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 6978a424b7c..a2f63098cd8 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -473,6 +473,11 @@ define('HUB_MOODLEORGHUBURL', "http://hub.moodle.org"); */ define('MOODLE_OFFICIAL_MOBILE_SERVICE', 'moodle_mobile_app'); +/** + * Indicates the user has the capabilities required to ignore activity and course file size restrictions + */ +define('USER_CAN_IGNORE_FILE_SIZE_LIMITS', -1); + /// PARAMETER HANDLING //////////////////////////////////////////////////// /** @@ -5860,10 +5865,9 @@ function get_user_max_upload_file_size($context, $sitebytes=0, $coursebytes=0, $ $user = $USER; } - // Temp. commenting this until MDL-27156 fixes it! - // if (has_capability('moodle/course:ignorefilesizelimits', $context, $user)) { - // return -1; - // } + if (has_capability('moodle/course:ignorefilesizelimits', $context, $user)) { + return USER_CAN_IGNORE_FILE_SIZE_LIMITS; + } return get_max_upload_file_size($sitebytes, $coursebytes, $modulebytes); }