Permalink
Browse files

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

… bypass file size restrictions
  • Loading branch information...
andyjdavis committed Mar 27, 2012
1 parent f8dfdb5 commit 8ac95c279cb1be2bf41683a42146e9cdd6054cfd
Showing with 38 additions and 2 deletions.
  1. +1 −0 lang/en/role.php
  2. +8 −0 lib/db/access.php
  3. +26 −0 lib/moodlelib.php
  4. +2 −1 repository/filepicker.php
  5. +1 −1 repository/repository_ajax.php
View
@@ -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
@@ -854,6 +854,14 @@
)
),
+ 'moodle/course:ignorefilesizelimits' => array(
+
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'archetypes' => array(
+ )
+ ),
+
'moodle/course:manageactivities' => array(
'riskbitmask' => RISK_XSS,
View
@@ -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 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
*
@@ -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;
@@ -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;

0 comments on commit 8ac95c2

Please sign in to comment.