Commit 612e261a authored by Robert Lyon's avatar Robert Lyon

Bug 1855344: Allow institution shortname to contain numbers

And allow it to be min 1 character in length

behatnotneeded

Change-Id: I7dbea5929f47a42865377da2260e30f037802a73
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent b56e0750
...@@ -16,7 +16,7 @@ define('JSON', 1); ...@@ -16,7 +16,7 @@ define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php'); require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$contentname = param_alpha('contentname'); $contentname = param_alpha('contentname');
$institution = param_alpha('institution', null); $institution = param_alphanum('institution', null);
if (empty($institution)) { if (empty($institution)) {
$institution = 'mahara'; $institution = 'mahara';
} }
......
...@@ -760,6 +760,21 @@ EOF; ...@@ -760,6 +760,21 @@ EOF;
function institution_validate(Pieform $form, $values) { function institution_validate(Pieform $form, $values) {
global $USER, $institution, $add; global $USER, $institution, $add;
if ($add) {
try {
$check = institution_generate_name($values['displayname']);
}
catch (ParamOutOfRangeException $e) {
$form->set_error('displayname', get_string('institutionnameinvalid', 'admin'));
}
}
else {
$check = strtolower($values['displayname']);
$check = preg_replace('/[^a-z0-9]/', '', $check);
if (strlen($check) < 1 || $check === '0') {
$form->set_error('displayname', get_string('institutionnameinvalid', 'admin'));
}
}
if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) { if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) {
if (get_config_plugin('artefact', 'file', 'maxquotaenabled') && get_config_plugin('artefact', 'file', 'maxquota') < $values['defaultquota']) { if (get_config_plugin('artefact', 'file', 'maxquotaenabled') && get_config_plugin('artefact', 'file', 'maxquota') < $values['defaultquota']) {
......
...@@ -18,7 +18,7 @@ safe_require('artefact', 'blog'); ...@@ -18,7 +18,7 @@ safe_require('artefact', 'blog');
$blogs = (object) array( $blogs = (object) array(
'offset' => param_integer('offset', 0), 'offset' => param_integer('offset', 0),
'limit' => param_integer('limit', 10), 'limit' => param_integer('limit', 10),
'institution' => param_alpha('institution', null), 'institution' => param_alphanum('institution', null),
'group' => param_integer('group', null), 'group' => param_integer('group', null),
); );
......
...@@ -19,7 +19,7 @@ $folderid = param_integer('folder', 0); ...@@ -19,7 +19,7 @@ $folderid = param_integer('folder', 0);
$viewid = param_integer('view', 0); $viewid = param_integer('view', 0);
$groupid = param_integer('group', 0); $groupid = param_integer('group', 0);
$institution = param_alpha('institution', 0); $institution = param_alphanum('institution', 0);
/* /*
* Function to check if the specified artefact should be downloadable * Function to check if the specified artefact should be downloadable
......
...@@ -35,7 +35,7 @@ if ($group = param_integer('group', null)) { ...@@ -35,7 +35,7 @@ if ($group = param_integer('group', null)) {
$values = array($group); $values = array($group);
$params['group'] = $group; $params['group'] = $group;
} }
else if ($institution = param_alpha('institution', null)) { else if ($institution = param_alphanum('institution', null)) {
if ($institution == 'mahara') { if ($institution == 'mahara') {
define('ADMIN', 1); define('ADMIN', 1);
define('MENUITEM', 'configsite'); define('MENUITEM', 'configsite');
......
...@@ -35,7 +35,7 @@ if ($group = param_integer('group', null)) { ...@@ -35,7 +35,7 @@ if ($group = param_integer('group', null)) {
$values = array($group); $values = array($group);
$params['group'] = $group; $params['group'] = $group;
} }
else if ($institution = param_alpha('institution', null)) { else if ($institution = param_alphanum('institution', null)) {
if ($institution == 'mahara') { if ($institution == 'mahara') {
define('ADMIN', 1); define('ADMIN', 1);
define('MENUITEM', 'configsite'); define('MENUITEM', 'configsite');
......
...@@ -19,7 +19,7 @@ if (!is_logged_in()) { ...@@ -19,7 +19,7 @@ if (!is_logged_in()) {
throw new AccessDeniedException(); throw new AccessDeniedException();
} }
$inst = param_alpha('institution'); $inst = param_alphanum('institution');
if (is_isolated() && !in_array($inst, array_keys($USER->get('institutions'))) && !$USER->get('admin')) { if (is_isolated() && !in_array($inst, array_keys($USER->get('institutions'))) && !$USER->get('admin')) {
throw new AccessDeniedException(get_string('notinstitutionmember', 'error')); throw new AccessDeniedException(get_string('notinstitutionmember', 'error'));
......
...@@ -19,7 +19,7 @@ $offset = param_integer('offset', 0); ...@@ -19,7 +19,7 @@ $offset = param_integer('offset', 0);
$limit = param_integer('limit', 12); $limit = param_integer('limit', 12);
$setlimit = param_boolean('setlimit', false); $setlimit = param_boolean('setlimit', false);
$groupid = param_integer('group', null); $groupid = param_integer('group', null);
$institution = param_alpha('institution', null); $institution = param_alphanum('institution', null);
$orderby = param_alphanum('orderby', null); $orderby = param_alphanum('orderby', null);
if (!empty($groupid)) { if (!empty($groupid)) {
......
...@@ -982,6 +982,7 @@ $string['institutiondeletedsuccessfully'] = 'Institution deleted successfully'; ...@@ -982,6 +982,7 @@ $string['institutiondeletedsuccessfully'] = 'Institution deleted successfully';
$string['noauthpluginforinstitution'] = 'Your site administrator has not configured an authentication plugin for this institution.'; $string['noauthpluginforinstitution'] = 'Your site administrator has not configured an authentication plugin for this institution.';
$string['adminnoauthpluginforinstitution'] = 'Please configure an authentication plugin for this institution.'; $string['adminnoauthpluginforinstitution'] = 'Please configure an authentication plugin for this institution.';
$string['institutionname'] = 'Institution name'; $string['institutionname'] = 'Institution name';
$string['institutionnameinvalid'] = 'Institution name is invalid';
$string['institutionshortname'] = 'Institution short name'; $string['institutionshortname'] = 'Institution short name';
$string['institutionnamealreadytaken'] = 'This institution name is already taken.'; $string['institutionnamealreadytaken'] = 'This institution name is already taken.';
$string['institutiondisplayname'] = 'Institution display name'; $string['institutiondisplayname'] = 'Institution display name';
......
...@@ -1155,14 +1155,11 @@ function institution_generate_name($displayname) { ...@@ -1155,14 +1155,11 @@ function institution_generate_name($displayname) {
$basename = mb_substr($displayname, 0, 255); $basename = mb_substr($displayname, 0, 255);
$basename = iconv('UTF-8', 'ASCII//TRANSLIT', $displayname); $basename = iconv('UTF-8', 'ASCII//TRANSLIT', $displayname);
$basename = strtolower($basename); $basename = strtolower($basename);
$basename = preg_replace('/[^a-z]/', '', $basename); $basename = preg_replace('/[^a-z0-9]/', '', $basename);
if (strlen($basename) < 2) { $basename = substr($basename, 0, 255);
$basename = 'inst' . $basename; if (strlen($basename) < 1 || $basename === '0') {
throw new ParamOutOfRangeException(get_string('institutionnameinvalid', 'admin'));
} }
else {
$basename = substr($basename, 0, 255);
}
// Make sure the name is unique. If it is not, add a suffix and see if // Make sure the name is unique. If it is not, add a suffix and see if
// that makes it unique // that makes it unique
$finalname = $basename; $finalname = $basename;
......
...@@ -5661,7 +5661,8 @@ function get_institutions_to_associate() { ...@@ -5661,7 +5661,8 @@ function get_institutions_to_associate() {
// This does not apply for site admins // This does not apply for site admins
foreach ($USER->institutions as $inst) { foreach ($USER->institutions as $inst) {
if (empty($inst->suspended)) { if (empty($inst->suspended)) {
$institutions = array_merge($institutions, array($inst->institution => $inst->displayname)); // use + to perserve numerical keys
$institutions = $institutions + array($inst->institution => $inst->displayname);
} }
} }
} }
...@@ -5670,7 +5671,8 @@ function get_institutions_to_associate() { ...@@ -5670,7 +5671,8 @@ function get_institutions_to_associate() {
$records = get_records_array('institution'); $records = get_records_array('institution');
foreach ($records as $inst) { foreach ($records as $inst) {
if (empty($inst->suspended)) { if (empty($inst->suspended)) {
$institutions = array_merge($institutions, array($inst->name => $inst->displayname)); // use + to perserve numerical keys
$institutions = $institutions + array($inst->name => $inst->displayname);
} }
} }
} }
......
...@@ -17,7 +17,7 @@ require(dirname(dirname(__FILE__)) . '/init.php'); ...@@ -17,7 +17,7 @@ require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('libroot') . 'view.php'); require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'institution.php'); require_once(get_config('libroot') . 'institution.php');
$institution = param_alpha('institution', false); $institution = param_alphanum('institution', false);
if ($institution == 'mahara') { if ($institution == 'mahara') {
redirect('/admin/site/shareviews.php'); redirect('/admin/site/shareviews.php');
......
...@@ -20,7 +20,7 @@ require(dirname(dirname(__FILE__)) . '/init.php'); ...@@ -20,7 +20,7 @@ require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('libroot') . 'view.php'); require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'institution.php'); require_once(get_config('libroot') . 'institution.php');
$institution = param_alpha('institution', false); $institution = param_alphanum('institution', false);
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
if ($institution == 'mahara') { if ($institution == 'mahara') {
......
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