Merge branch 'MDL-27156_file_cap' of git://github.com/andyjdavis/moodle
This commit is contained in:
@@ -453,7 +453,7 @@ class gradingform_rubric_controller extends gradingform_controller {
|
||||
global $CFG;
|
||||
return array(
|
||||
'maxfiles' => -1,
|
||||
'maxbytes' => get_max_upload_file_size($CFG->maxbytes),
|
||||
'maxbytes' => get_user_max_upload_file_size($context, $CFG->maxbytes),
|
||||
'context' => $context,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -120,6 +120,7 @@ $string['course:changeshortname'] = 'Change course short name';
|
||||
$string['course:changesummary'] = 'Change course summary';
|
||||
$string['course:enrolconfig'] = 'Configure enrol instances in courses';
|
||||
$string['course:enrolreview'] = 'Review course enrolments';
|
||||
$string['course:ignorefilesizelimits'] = 'Use files larger than any file size restrictions';
|
||||
$string['course:manageactivities'] = 'Manage activities';
|
||||
$string['course:managefiles'] = 'Manage files';
|
||||
$string['course:managegrades'] = 'Manage grades';
|
||||
|
||||
@@ -854,6 +854,14 @@ $capabilities = array(
|
||||
)
|
||||
),
|
||||
|
||||
'moodle/course:ignorefilesizelimits' => array(
|
||||
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_COURSE,
|
||||
'archetypes' => array(
|
||||
)
|
||||
),
|
||||
|
||||
'moodle/course:manageactivities' => array(
|
||||
|
||||
'riskbitmask' => RISK_XSS,
|
||||
|
||||
@@ -69,7 +69,7 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
}
|
||||
}
|
||||
if (!empty($options['maxbytes'])) {
|
||||
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
|
||||
$this->_options['maxbytes'] = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $options['maxbytes']);
|
||||
}
|
||||
if (empty($options['return_types'])) {
|
||||
$this->_options['return_types'] = (FILE_INTERNAL | FILE_REFERENCE);
|
||||
@@ -129,8 +129,8 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
|
||||
* @param int $maxbytes file size
|
||||
*/
|
||||
function setMaxbytes($maxbytes) {
|
||||
global $CFG;
|
||||
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $maxbytes);
|
||||
global $CFG, $PAGE;
|
||||
$this->_options['maxbytes'] = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $maxbytes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -354,7 +354,7 @@ class form_filemanager implements renderable {
|
||||
if (!empty($this->options->maxbytes) && $this->options->maxbytes > 0) {
|
||||
$maxbytes = $this->options->maxbytes;
|
||||
}
|
||||
$this->options->maxbytes = get_max_upload_file_size($CFG->maxbytes, $coursebytes, $maxbytes);
|
||||
$this->options->maxbytes = get_user_max_upload_file_size($context, $CFG->maxbytes, $coursebytes, $maxbytes);
|
||||
|
||||
// building file picker options
|
||||
$params = new stdClass();
|
||||
|
||||
@@ -79,7 +79,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
|
||||
if (!empty($PAGE->course)) {
|
||||
$coursemaxbytes = $PAGE->course->maxbytes;
|
||||
}
|
||||
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $coursemaxbytes, $fpmaxbytes);
|
||||
$this->_options['maxbytes'] = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $coursemaxbytes, $fpmaxbytes);
|
||||
$this->_type = 'filepicker';
|
||||
parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
|
||||
}
|
||||
|
||||
@@ -5841,6 +5841,32 @@ function get_max_upload_file_size($sitebytes=0, $coursebytes=0, $modulebytes=0)
|
||||
return $minimumsize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum size for uploading files for the current user
|
||||
*
|
||||
* This function takes in account @see:get_max_upload_file_size() the user's capabilities
|
||||
*
|
||||
* @param context $context The context in which to check user capabilities
|
||||
* @param int $sizebytes Set maximum size
|
||||
* @param int $coursebytes Current course $course->maxbytes (in bytes)
|
||||
* @param int $modulebytes Current module ->maxbytes (in bytes)
|
||||
* @param stdClass The user
|
||||
* @return int The maximum size for uploading files.
|
||||
*/
|
||||
function get_user_max_upload_file_size($context, $sitebytes=0, $coursebytes=0, $modulebytes=0, $user=null) {
|
||||
global $USER;
|
||||
|
||||
if (empty($user)) {
|
||||
$user = $USER;
|
||||
}
|
||||
|
||||
if (has_capability('moodle/course:ignorefilesizelimits', $context, $user)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return get_max_upload_file_size($sitebytes, $coursebytes, $modulebytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of possible sizes in local language
|
||||
*
|
||||
|
||||
@@ -2114,7 +2114,7 @@ abstract class lesson_page extends lesson_base {
|
||||
$context = $PAGE->context;
|
||||
}
|
||||
if ($maxbytes === null) {
|
||||
$maxbytes =get_max_upload_file_size();
|
||||
$maxbytes = get_user_max_upload_file_size($context);
|
||||
}
|
||||
$properties = file_postupdate_standard_editor($properties, 'contents', array('noclean'=>true, 'maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$maxbytes), $context, 'mod_lesson', 'page_contents', $properties->id);
|
||||
$DB->update_record("lesson_pages", $properties);
|
||||
|
||||
@@ -93,7 +93,8 @@ if ($repository = $DB->get_record_sql($sql, array($repo_id))) {
|
||||
}
|
||||
}
|
||||
|
||||
$moodle_maxbytes = get_max_upload_file_size();
|
||||
$context = context::instance_by_id($contextid);
|
||||
$moodle_maxbytes = get_user_max_upload_file_size($context);
|
||||
// to prevent maxbytes greater than moodle maxbytes setting
|
||||
if ($maxbytes == 0 || $maxbytes>=$moodle_maxbytes) {
|
||||
$maxbytes = $moodle_maxbytes;
|
||||
|
||||
@@ -82,7 +82,7 @@ if (!$repository = $DB->get_record_sql($sql, array($repo_id))) {
|
||||
// Check permissions
|
||||
repository::check_capability($contextid, $repository);
|
||||
|
||||
$moodle_maxbytes = get_max_upload_file_size();
|
||||
$moodle_maxbytes = get_user_max_upload_file_size($context);
|
||||
// to prevent maxbytes greater than moodle maxbytes setting
|
||||
if ($maxbytes == 0 || $maxbytes>=$moodle_maxbytes) {
|
||||
$maxbytes = $moodle_maxbytes;
|
||||
|
||||
Reference in New Issue
Block a user