Skip to content

Commit

Permalink
Merge branch 'wip-MDL-52100-33' of git://github.com/abgreeve/moodle i…
Browse files Browse the repository at this point in the history
…nto MOODLE_33_STABLE
  • Loading branch information
David Monllao committed Dec 18, 2017
2 parents ccd3ab3 + 304b80c commit 847250b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/filelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea

$newhashes = array();
$filecount = 0;
$context = context::instance_by_id($contextid, MUST_EXIST);
foreach ($draftfiles as $file) {
if (!$options['subdirs'] && $file->get_filepath() !== '/') {
continue;
Expand All @@ -856,8 +857,11 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea
continue;
}
if (!$file->is_directory()) {
if ($options['maxbytes'] and $options['maxbytes'] < $file->get_filesize()) {
// oversized file - should not get here at all
// Check to see if this file was uploaded by someone who can ignore the file size limits.
$fileusermaxbytes = get_user_max_upload_file_size($context, $options['maxbytes'], 0, 0, $file->get_userid());
if ($fileusermaxbytes != USER_CAN_IGNORE_FILE_SIZE_LIMITS
&& ($options['maxbytes'] and $options['maxbytes'] < $file->get_filesize())) {
// Oversized file.
continue;
}
if ($options['maxfiles'] != -1 and $options['maxfiles'] <= $filecount) {
Expand Down
5 changes: 3 additions & 2 deletions lib/tests/filelib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,6 @@ public function test_file_rewrite_pluginfile_urls() {
public static function create_draft_file($filedata = array()) {
global $USER;

self::setAdminUser();
$fs = get_file_storage();

$filerecord = array(
Expand Down Expand Up @@ -1185,7 +1184,9 @@ public function test_file_merge_files_from_draft_area_into_filearea_max_file_byt
global $USER;

$this->resetAfterTest(true);
$this->setAdminUser();
// The admin has no restriction for max file uploads, so use a normal user.
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
$fs = get_file_storage();

$file = self::create_draft_file();
Expand Down

0 comments on commit 847250b

Please sign in to comment.