Commit 77cfd878 authored by Andrew Robert Nicols's avatar Andrew Robert Nicols
Browse files

Allow specification of a site-wide maximum quota (Closes: #628736).


Signed-off-by: default avatarAndrew Robert Nicols <andrew.nicols@luns.net.uk>
parent 8435ce3b
...@@ -162,6 +162,15 @@ $siteform = pieform(array( ...@@ -162,6 +162,15 @@ $siteform = pieform(array(
'elements' => $elements, 'elements' => $elements,
)); ));
function edituser_site_validate(Pieform $form, $values) {
global $USER, $SESSION;
$maxquotaenabled = get_config_plugin('artefact', 'file', 'maxquotaenabled');
$maxquota = get_config_plugin('artefact', 'file', 'maxquota');
if ($maxquotaenabled && $values['quota'] > $maxquota) {
$form->set_error('quota', get_string('maxquotaexceededform', 'artefact.file', display_size($maxquota)));
$SESSION->add_error_msg(get_string('maxquotaexceeded', 'artefact.file', display_size($maxquota)));
}
}
function edituser_site_submit(Pieform $form, $values) { function edituser_site_submit(Pieform $form, $values) {
if (!$user = get_record('usr', 'id', $values['id'])) { if (!$user = get_record('usr', 'id', $values['id'])) {
......
...@@ -51,6 +51,12 @@ $string['Date'] = 'Date'; ...@@ -51,6 +51,12 @@ $string['Date'] = 'Date';
$string['defaultagreement'] = 'Default Agreement'; $string['defaultagreement'] = 'Default Agreement';
$string['defaultquota'] = 'Default Quota'; $string['defaultquota'] = 'Default Quota';
$string['defaultquotadescription'] = 'You can set the amount of disk space that new users will have as their quota here. Existing user quotas will not be changed.'; $string['defaultquotadescription'] = 'You can set the amount of disk space that new users will have as their quota here. Existing user quotas will not be changed.';
$string['maxquotaenabled'] = 'Enforce a site-wide maximum quota';
$string['maxquota'] = 'Maximum Quota';
$string['maxquotatoolow'] = 'The maximum quota cannot be lower than the default quota.';
$string['maxquotaexceeded'] = 'You specified a quota above the maximum available setting for this site (%s). Try specifying a lower value or contact the site administrator to have them increase the maximum quota.';
$string['maxquotaexceededform'] = 'Please specify a file quota of less than %s.';
$string['maxquotadescription'] = 'You can set the maximum quota that an administrator can give to a user. Existing user quotas will not be affected.';
$string['deletefile?'] = 'Are you sure you want to delete this file?'; $string['deletefile?'] = 'Are you sure you want to delete this file?';
$string['deletefolder?'] = 'Are you sure you want to delete this folder?'; $string['deletefolder?'] = 'Are you sure you want to delete this folder?';
$string['Description'] = 'Description'; $string['Description'] = 'Description';
......
...@@ -1060,6 +1060,32 @@ class ArtefactTypeFile extends ArtefactTypeFileBase { ...@@ -1060,6 +1060,32 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
'collapsible' => true 'collapsible' => true
); );
$maxquota = get_config_plugin('artefact', 'file', 'maxquota');
$maxquotaenabled = get_config_plugin('artefact', 'file', 'maxquotaenabled');
if (empty($maxquota)) {
$maxquota = 1024 * 1024 * 1024;
}
$elements['maxquota'] = array(
'type' => 'fieldset',
'legend' => get_string('maxquota', 'artefact.file'),
'elements' => array(
'maxquotadescription' => array(
'value' => '<tr><td colspan="2">' . get_string('maxquotadescription', 'artefact.file') . '</td></tr>'
),
'maxquotaenabled' => array(
'title' => get_string('maxquotaenabled', 'artefact.file'),
'type' => 'checkbox',
'defaultvalue' => $maxquotaenabled,
),
'maxquota' => array(
'title' => get_string('maxquota', 'artefact.file'),
'type' => 'bytes',
'defaultvalue' => $maxquota,
),
),
'collapsible' => true
);
// Require user agreement before uploading files // Require user agreement before uploading files
// Rework this when/if we provide translatable agreements // Rework this when/if we provide translatable agreements
$uploadagreement = get_config_plugin('artefact', 'file', 'uploadagreement'); $uploadagreement = get_config_plugin('artefact', 'file', 'uploadagreement');
...@@ -1138,9 +1164,18 @@ class ArtefactTypeFile extends ArtefactTypeFileBase { ...@@ -1138,9 +1164,18 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
); );
} }
public static function validate_config_options($form, $values) {
global $USER;
if ($values['maxquota'] < $values['defaultquota']) {
$form->set_error('maxquota', get_string('maxquotatoolow', 'artefact.file'));
}
}
public static function save_config_options($values) { public static function save_config_options($values) {
global $USER; global $USER;
set_config_plugin('artefact', 'file', 'defaultquota', $values['defaultquota']); set_config_plugin('artefact', 'file', 'defaultquota', $values['defaultquota']);
set_config_plugin('artefact', 'file', 'maxquota', $values['maxquota']);
set_config_plugin('artefact', 'file', 'maxquotaenabled', $values['maxquotaenabled']);
set_config_plugin('artefact', 'file', 'profileiconwidth', $values['profileiconwidth']); set_config_plugin('artefact', 'file', 'profileiconwidth', $values['profileiconwidth']);
set_config_plugin('artefact', 'file', 'profileiconheight', $values['profileiconheight']); set_config_plugin('artefact', 'file', 'profileiconheight', $values['profileiconheight']);
set_config_plugin('artefact', 'file', 'uploadagreement', $values['uploadagreement']); set_config_plugin('artefact', 'file', 'uploadagreement', $values['uploadagreement']);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment