Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-27156 repository: Added a new capability so that select users can…

… bypass file size restrictions
  • Loading branch information...
commit 8ac95c279cb1be2bf41683a42146e9cdd6054cfd 1 parent f8dfdb5
@andyjdavis andyjdavis authored
View
1  lang/en/role.php
@@ -120,6 +120,7 @@
$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';
View
8 lib/db/access.php
@@ -854,6 +854,14 @@
)
),
+ 'moodle/course:ignorefilesizelimits' => array(
+
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'archetypes' => array(
+ )
+ ),
+
'moodle/course:manageactivities' => array(
'riskbitmask' => RISK_XSS,
View
26 lib/moodlelib.php
@@ -5842,6 +5842,32 @@ function get_max_upload_file_size($sitebytes=0, $coursebytes=0, $modulebytes=0)
}
/**
+ * Returns the maximum size for uploading files for the current user
+ *
+ * This function calls @see:get_max_upload_file_size() then considers 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
*
* Related to {@link get_max_upload_file_size()} - this function returns an
View
3  repository/filepicker.php
@@ -93,7 +93,8 @@
}
}
-$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;
View
2  repository/repository_ajax.php
@@ -82,7 +82,7 @@
// 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;
Please sign in to comment.
Something went wrong with that request. Please try again.