Commit bd50524c authored by Gregor Anzelj's avatar Gregor Anzelj Committed by Robert Lyon

Automatically generate "Institution name" field (Bug #1394812)

Change-Id: I1bd65328134a57757bf788839fef06715a984310
behatnotneeded
Signed-off-by: default avatarGregor Anzelj <gregor.anzelj@gmail.com>
parent ffc3f7db
......@@ -261,17 +261,6 @@ if ($institution || $add) {
safe_require('artefact', 'internal');
$elements = array(
'name' => array(
'type' => 'text',
'title' => get_string('institutionname', 'admin'),
'rules' => array(
'required' => true,
'maxlength' => 255,
'regex' => '/^[a-zA-Z]+$/'
),
'ignore' => !$add,
'help' => true,
),
'add' => array(
'type' => 'hidden',
'value' => true,
......@@ -290,7 +279,7 @@ if ($institution || $add) {
),
'displayname' => array(
'type' => 'text',
'title' => get_string('institutiondisplayname', 'admin'),
'title' => get_string('institutionname', 'admin'),
'defaultvalue' => $data->displayname,
'rules' => array(
'required' => true,
......@@ -664,12 +653,26 @@ EOF;
exit;
}
// Generate random lower-case alpha-only institution name.
function generate_institution_name() {
$i = substr(str_shuffle("abcdefghijklmnopqrstuvwxyz"), 0, 6);
if ($institution = get_record('institution', 'name', $i)) {
// try again
generate_institution_name();
}
else {
return $i;
}
}
function institution_validate(Pieform $form, $values) {
global $USER;
global $USER, $institution, $add;
if (!empty($values['name']) && !$form->get_error('name') && record_exists('institution', 'name', $values['name'])) {
$form->set_error('name', get_string('institutionnamealreadytaken', 'admin'));
// Automatically generate institution name when adding new institution
if ($add) {
$institution = generate_institution_name();
}
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']) {
$form->set_error('defaultquota', get_string('maxquotatoolow', 'artefact.file'));
......@@ -722,7 +725,7 @@ function institution_submit(Pieform $form, $values) {
// Update the basic institution record...
if ($add) {
$newinstitution = new Institution();
$newinstitution->initialise($values['name'], $values['displayname']);
$newinstitution->initialise($institution, $values['displayname']);
$institution = $newinstitution->name;
}
else {
......
......@@ -14,8 +14,7 @@ Scenario: Creating an Institution assigning users and changing their passwords
And I follow "Institution"
And I press "Add institution"
And I fill in the following:
| Institution name | institutionone |
| Institution display name | institution One |
| Institution name | Institution One |
And I press "Submit"
# Creating user 1
And I follow "Users"
......@@ -26,7 +25,7 @@ Scenario: Creating an Institution assigning users and changing their passwords
| email | bob@example.com |
| username | bob |
| password | mahara1 |
And I select "institution One" from "Institution"
And I select "Institution One" from "Institution"
And I check "Institution administrator"
And I press "Create user"
# Creating user 2
......@@ -38,7 +37,7 @@ Scenario: Creating an Institution assigning users and changing their passwords
| email | jen@example.com |
| username | jen |
| password | mahara1 |
And I select "institution One" from "Institution"
And I select "Institution One" from "Institution"
And I press "Create user"
# Log out as user admin
And I follow "Logout"
......
......@@ -14,8 +14,7 @@ Scenario: Creating an institution (selenium test)
And I follow "Institutions"
And I press "Add institution"
And I fill in the following:
| Institution name | institutionone |
| Institution display name | institution One |
| Institution name | Institution One |
And I press "Submit"
# Verifying the institution has been created
Then I should see "Institution added successfully"
......
......@@ -11,7 +11,6 @@ Scenario: Turning switches on and off on Edit Institution page (Bug 1431569)
# Checking the default settings are correct
And the following fields match these values:
| Institution name * | |
| Institution display name * | |
| Registration allowed | 0 |
| Confirm registration | 1 |
| Drop-down navigation | 0 |
......@@ -20,8 +19,7 @@ Scenario: Turning switches on and off on Edit Institution page (Bug 1431569)
| Maximum user accounts allowed | |
# Turning the switches on and off
And I set the following fields to these values:
| Institution display name * | The Avenger |
| Institution display name * | Team Awesome |
| Institution name * | Team Awesome |
| Registration allowed | 1 |
| Confirm registration | 0 |
| Drop-down navigation | 1 |
......
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