Commit cc8c6d0d authored by Hugh Davenport's avatar Hugh Davenport

Add institutional override for user quotas

Also add in default quota for each institution

Change-Id: Ibfdd5a10990e9c6a936b9ad5921f734df1f5c805
Signed-off-by: default avatarHugh Davenport <hugh@catalyst.net.nz>
parent 41e92d90
......@@ -137,6 +137,16 @@ if (!$USER->get('admin')) {
unset ($elements['authinstance']['defaultvalue']);
}
if (!($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride'))) {
$elements['quota'] = array(
'type' => 'text',
'disabled' => true,
'title' => get_string('filequota', 'admin'),
'description' => get_string('filequotadescription', 'admin'),
'value' => display_size(get_config_plugin('artefact', 'file', 'defaultquota')),
);
}
$form = pieform(array(
'name' => 'adduser',
'autofocus' => false,
......
......@@ -110,13 +110,24 @@ $elements['expiry'] = array(
'maxyear' => $currentdate['year'] + 20,
'defaultvalue' => $user->expiry
);
$elements['quota'] = array(
'type' => 'bytes',
'title' => get_string('filequota','admin'),
'description' => get_string('filequotadescription','admin'),
'rules' => array('integer' => true),
'defaultvalue' => $user->quota,
);
if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) {
$elements['quota'] = array(
'type' => 'bytes',
'title' => get_string('filequota','admin'),
'description' => get_string('filequotadescription','admin'),
'rules' => array('integer' => true),
'defaultvalue' => $user->quota,
);
}
else {
$elements['quota'] = array(
'type' => 'text',
'disabled' => true,
'title' => get_string('filequota', 'admin'),
'description' => get_string('filequotadescription', 'admin'),
'value' => display_size($user->quota),
);
}
$authinstances = auth_get_auth_instances();
if (count($authinstances) > 1) {
......
......@@ -290,6 +290,22 @@ if ($institution || $add) {
'options' => $themeoptions,
'help' => true,
);
if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) {
$elements['defaultquota'] = array(
'type' => 'bytes',
'title' => get_string('defaultquota', 'artefact.file'),
'description' => get_string('defaultinstitutionquotadescription', 'admin'),
'defaultvalue' => !empty($data->defaultquota) ? $data->defaultquota : get_config_plugin('artefact', 'file', 'defaultquota'),
);
}
else {
$elements['defaultquota'] = array(
'type' => 'text',
'title' => get_string('defaultquota', 'artefact.file'),
'value' => display_size(!empty($data->defaultquota) ? $data->defaultquota : get_config_plugin('artefact', 'file', 'defaultquota')),
'disabled' => true,
);
}
if ($USER->get('admin')) {
$elements['maxuseraccounts'] = array(
'type' => 'text',
......@@ -403,6 +419,9 @@ function institution_validate(Pieform $form, $values) {
if (!empty($values['name']) && !$form->get_error('name') && record_exists('institution', 'name', $values['name'])) {
$form->set_error('name', get_string('institutionnamealreadytaken', 'admin'));
}
if (get_config_plugin('artefact', 'file', 'maxquotaenabled') && get_config_plugin('artefact', 'file', 'maxquota') < $values['defaultquota']) {
$form->set_error('defaultquota', get_string('maxquotatoolow', 'artefact.file'));
}
}
function institution_submit(Pieform $form, $values) {
......@@ -427,6 +446,10 @@ function institution_submit(Pieform $form, $values) {
$newinstitution->registerallowed = ($values['registerallowed']) ? 1 : 0;
}
$newinstitution->theme = (empty($values['theme']) || $values['theme'] == 'sitedefault') ? null : $values['theme'];
if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) {
$newinstitution->defaultquota = $values['defaultquota'];
}
if ($institution != 'mahara') {
$newinstitution->defaultmembershipperiod = ($values['defaultmembershipperiod']) ? intval($values['defaultmembershipperiod']) : null;
if ($USER->get('admin')) {
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2011 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2011 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('JSON', 1);
define('INSTITUTIONALADMIN', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform/elements/bytes.php');
$instid = param_integer('instid');
$disabled = param_boolean('disabled', false);
$definst = get_field('auth_instance', 'id', 'institution', 'mahara');
if (!$USER->is_institutional_admin($instid)) {
$data = array('data' => null, 'error' => true, 'message' => 'You are not an administrator for this institution');
json_reply($data);
return;
}
if ($definst && $instid == $definst) {
$quota = get_config_plugin('artefact', 'file', 'defaultquota');
}
else {
$record = get_record_sql('SELECT i.* from {institution} i JOIN {auth_instance} ai ON (i.name = ai.institution) WHERE ai.id = ?', array($instid));
$quota = $record->defaultquota;
if (!$quota) {
$quota = get_config_plugin('artefact', 'file', 'defaultquota');
}
}
$data = array(
'data' => ($disabled ? display_size($quota) : pieform_element_bytes_get_bytes_from_bytes($quota)),
'error' => false,
'message' => null,
);
json_reply($data);
......@@ -112,6 +112,13 @@ $form = array(
'name' => 'uploadcsv',
'elements' => array(
'authinstance' => $authinstanceelement,
'quota' => array(
'type' => 'bytes',
'title' => get_string('filequota', 'admin'),
'description' => get_string('filequotadescription', 'admin'),
'rules' => array('integer' => true, 'minvalue' => 0),
'defaultvalue' => get_config_plugin('artefact', 'file', 'defaultquota'),
),
'file' => array(
'type' => 'file',
'title' => get_string('csvfile', 'admin'),
......@@ -139,6 +146,16 @@ $form = array(
)
);
if (!($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride'))) {
$form['elements']['quota'] = array(
'type' => 'text',
'disabled' => true,
'title' => get_string('filequota', 'admin'),
'description' => get_string('filequotadescription', 'admin'),
'value' => display_size(get_config_plugin('artefact', 'file', 'defaultquota')),
);
}
/**
* The CSV file is parsed here so validation errors can be returned to the
* user. The data from a successful parsing is stored in the <var>$CVSDATA</var>
......@@ -160,6 +177,12 @@ function uploadcsv_validate(Pieform $form, $values) {
return;
}
$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)));
}
require_once('csvfile.php');
$authinstance = (int) $values['authinstance'];
......@@ -296,6 +319,7 @@ function uploadcsv_submit(Pieform $form, $values) {
$user->lastname = $record[$formatkeylookup['lastname']];
$user->password = $record[$formatkeylookup['password']];
$user->email = $record[$formatkeylookup['email']];
$user->quota = $values['quota'];
if (isset($formatkeylookup['studentid'])) {
$user->studentid = $record[$formatkeylookup['studentid']];
......@@ -408,7 +432,7 @@ else {
$form = pieform($form);
$smarty = smarty();
$smarty = smarty(array('adminuploadcsv'));
$smarty->assign('uploadcsvpagedescription', $uploadcsvpagedescription);
$smarty->assign('uploadcsvform', $form);
$smarty->assign('PAGEHEADING', TITLE);
......
......@@ -51,6 +51,8 @@ $string['Date'] = 'Date';
$string['defaultagreement'] = 'Default Agreement';
$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['institutionoverride'] = 'Institution Quota';
$string['institutionoverridedescription'] = 'You can allow institution administrators to set user file quotas and have default quotas for each institution.';
$string['maxquotaenabled'] = 'Enforce a site-wide maximum quota';
$string['maxquota'] = 'Maximum Quota';
$string['maxquotatoolow'] = 'The maximum quota cannot be lower than the default quota.';
......
......@@ -1110,6 +1110,23 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
'collapsible' => true
);
$override = get_config_plugin('artefact', 'file', 'institutionaloverride');
$elements['overridefieldset'] = array(
'type' => 'fieldset',
'legend' => get_string('institutionoverride', 'artefact.file'),
'elements' => array(
'institutionaloverridedescription' => array(
'value' => '<tr><td colspan="2">' . get_string('institutionoverridedescription', 'artefact.file') . '</td></tr>',
),
'institutionaloverride' => array(
'title' => get_string('institutionoverride', 'artefact.file'),
'type' => 'checkbox',
'defaultvalue' => $override,
),
),
'collapsible' => true,
);
$maxquota = get_config_plugin('artefact', 'file', 'maxquota');
$maxquotaenabled = get_config_plugin('artefact', 'file', 'maxquotaenabled');
if (empty($maxquota)) {
......@@ -1248,6 +1265,7 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
public static function save_config_options($values) {
global $USER;
set_config_plugin('artefact', 'file', 'defaultquota', $values['defaultquota']);
set_config_plugin('artefact', 'file', 'institutionaloverride', $values['institutionaloverride']);
set_config_plugin('artefact', 'file', 'maxquota', $values['maxquota']);
set_config_plugin('artefact', 'file', 'maxquotaenabled', $values['maxquotaenabled']);
set_config_plugin('artefact', 'file', 'profileiconwidth', $values['profileiconwidth']);
......
......@@ -34,6 +34,25 @@ function move_step(i) {
}
}
function change_quota(i) {
var quota = document.getElementById('adduser_quota');
var quotaUnits = document.getElementById('adduser_quota_units');
var params = {};
params.instid = i.value;
if (quotaUnits == null) {
params.disabled = true;
}
sendjsonrequest('quota.json.php', params, 'POST', function(data) {
if (quotaUnits == null) {
quota.value = data.data;
}
else {
quota.value = data.data.number;
quotaUnits.value = data.data.units;
}
});
}
addLoadEvent(function() {
var step1_spans = getElementsByTagAndClassName('span', 'requiredmarker', 'step1');
var step1_inputs = getElementsByTagAndClassName('input', 'required', 'step1');
......@@ -86,5 +105,14 @@ addLoadEvent(function() {
connect(i, 'onfocus', partial(move_step, i));
connect(i, 'onclick', partial(move_step, i));
});
select = document.getElementById('adduser_authinstance');
if (select != null) {
connect(select, 'onchange', partial(change_quota, select));
}
else {
select = document.getElementsByName('authinstance')[0];
}
change_quota(select);
});
/**
* Support file for the uploadcsv admin page in Mahara
* @source: http://gitorious.org/mahara/mahara
*
* @licstart
* Copyright (C) 2010 Catalyst IT Ltd
*
* The JavaScript code in this page is free software: you can
* redistribute it and/or modify it under the terms of the GNU
* General Public License (GNU GPL) as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version. The code is distributed WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
*
* As additional permission under GNU GPL version 3 section 7, you
* may distribute non-source (e.g., minimized or compacted) forms of
* that code without the copy of the GNU GPL normally required by
* section 4, provided you include this license notice and a URL
* through which recipients can access the Corresponding Source.
* @licend
*/
function change_quota(i) {
var quota = document.getElementById('uploadcsv_quota');
var quotaUnits = document.getElementById('uploadcsv_quota_units');
var params = {};
params.instid = i.value;
if (quotaUnits == null) {
params.disabled = true;
}
sendjsonrequest('quota.json.php', params, 'POST', function(data) {
if (quotaUnits == null) {
quota.value = data.data;
}
else {
quota.value = data.data.number;
quotaUnits.value = data.data.units;
}
});
}
addLoadEvent(function() {
select = document.getElementById('uploadcsv_authinstance');
if (select != null) {
connect(select, 'onchange', partial(change_quota, select));
}
else {
select = document.getElementsByName('authinstance')[0];
}
change_quota(select);
});
......@@ -669,6 +669,8 @@ $string['noinstitutionsdescription'] = 'If you would like to associate users wit
$string['Lockedfields'] = 'Locked fields';
$string['disabledlockedfieldhelp'] = 'Note: Disabled check boxes are for profile fields which are locked in the institution settings for "%s". These profile fields are locked at the site level and cannot be unlocked here.';
$string['defaultinstitutionquotadescription'] = 'You can set the amount of disk space new users in this institution will have as their quota. Existing users quotas for this institution will not be changed.';
// Suspend Institutions
$string['errorwhileunsuspending'] = 'An error occured while trying to unsuspend';
$string['institutionsuspended'] = 'Institution suspended';
......
......@@ -46,6 +46,7 @@
<FIELD NAME="expirymailsent" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0"/>
<FIELD NAME="suspended" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0"/>
<FIELD NAME="priority" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="1"/>
<FIELD NAME="defaultquota" TYPE="int" LENGTH="10" NOTNULL="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="name" />
......
......@@ -2336,5 +2336,12 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2011053100) {
$table = new XMLDBTable('institution');
$field = new XMLDBField('defaultquota');
$field->setAttributes(XMLDB_TYPE_INTEGER, 10);
add_field($table, $field);
}
return $status;
}
......@@ -28,7 +28,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2011052600;
$config->version = 2011053100;
$config->release = '1.5.0dev';
$config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';
......
......@@ -46,7 +46,7 @@ echo $form_tag;
<td class="filler">&raquo;</td>
<td class="step step2">
<table>
<?php foreach(array('username', 'password', 'staff', 'admin', 'quota', 'authinstance', 'institutionadmin') as $field) { ?>
<?php foreach(array('username', 'password', 'staff', 'admin', 'authinstance', 'quota', 'institutionadmin') as $field) { ?>
<tr>
<th><?php echo $elements[$field]['labelhtml']; ?></th>
<td><?php echo $elements[$field]['html']; ?></td>
......
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