Commit ffbade6d authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge "Bug 1855344: Allow institution shortname to contain numbers"

parents a7fc2a3a 612e261a
......@@ -16,7 +16,7 @@ define('JSON', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$contentname = param_alpha('contentname');
$institution = param_alpha('institution', null);
$institution = param_alphanum('institution', null);
if (empty($institution)) {
$institution = 'mahara';
}
......
......@@ -760,6 +760,21 @@ EOF;
function institution_validate(Pieform $form, $values) {
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 (get_config_plugin('artefact', 'file', 'maxquotaenabled') && get_config_plugin('artefact', 'file', 'maxquota') < $values['defaultquota']) {
......
......@@ -18,7 +18,7 @@ safe_require('artefact', 'blog');
$blogs = (object) array(
'offset' => param_integer('offset', 0),
'limit' => param_integer('limit', 10),
'institution' => param_alpha('institution', null),
'institution' => param_alphanum('institution', null),
'group' => param_integer('group', null),
);
......
......@@ -19,7 +19,7 @@ $folderid = param_integer('folder', 0);
$viewid = param_integer('view', 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
......
......@@ -35,7 +35,7 @@ if ($group = param_integer('group', null)) {
$values = array($group);
$params['group'] = $group;
}
else if ($institution = param_alpha('institution', null)) {
else if ($institution = param_alphanum('institution', null)) {
if ($institution == 'mahara') {
define('ADMIN', 1);
define('MENUITEM', 'configsite');
......
......@@ -35,7 +35,7 @@ if ($group = param_integer('group', null)) {
$values = array($group);
$params['group'] = $group;
}
else if ($institution = param_alpha('institution', null)) {
else if ($institution = param_alphanum('institution', null)) {
if ($institution == 'mahara') {
define('ADMIN', 1);
define('MENUITEM', 'configsite');
......
......@@ -19,7 +19,7 @@ if (!is_logged_in()) {
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')) {
throw new AccessDeniedException(get_string('notinstitutionmember', 'error'));
......
......@@ -19,7 +19,7 @@ $offset = param_integer('offset', 0);
$limit = param_integer('limit', 12);
$setlimit = param_boolean('setlimit', false);
$groupid = param_integer('group', null);
$institution = param_alpha('institution', null);
$institution = param_alphanum('institution', null);
$orderby = param_alphanum('orderby', null);
if (!empty($groupid)) {
......
......@@ -982,6 +982,7 @@ $string['institutiondeletedsuccessfully'] = 'Institution deleted successfully';
$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['institutionname'] = 'Institution name';
$string['institutionnameinvalid'] = 'Institution name is invalid';
$string['institutionshortname'] = 'Institution short name';
$string['institutionnamealreadytaken'] = 'This institution name is already taken.';
$string['institutiondisplayname'] = 'Institution display name';
......
......@@ -1155,14 +1155,11 @@ function institution_generate_name($displayname) {
$basename = mb_substr($displayname, 0, 255);
$basename = iconv('UTF-8', 'ASCII//TRANSLIT', $displayname);
$basename = strtolower($basename);
$basename = preg_replace('/[^a-z]/', '', $basename);
if (strlen($basename) < 2) {
$basename = 'inst' . $basename;
$basename = preg_replace('/[^a-z0-9]/', '', $basename);
$basename = substr($basename, 0, 255);
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
// that makes it unique
$finalname = $basename;
......
......@@ -5661,7 +5661,8 @@ function get_institutions_to_associate() {
// This does not apply for site admins
foreach ($USER->institutions as $inst) {
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() {
$records = get_records_array('institution');
foreach ($records as $inst) {
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');
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'institution.php');
$institution = param_alpha('institution', false);
$institution = param_alphanum('institution', false);
if ($institution == 'mahara') {
redirect('/admin/site/shareviews.php');
......
......@@ -20,7 +20,7 @@ require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('libroot') . 'view.php');
require_once(get_config('libroot') . 'institution.php');
$institution = param_alpha('institution', false);
$institution = param_alphanum('institution', false);
$offset = param_integer('offset', 0);
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