Commit 2693c939 authored by Robert Lyon's avatar Robert Lyon
Browse files

'Add users by csv' to ignore non-essential mandatory fields (Bug #1322387)



Sometimes you just don't have all the data when you are adding users via
csv but you have enough to create a user. So will remove the checking
of mandatory fields - to be in line with 'Add user' page.

Change-Id: I2e2758e6cc82483f0c4c7899fd1bab049c052b8f
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent e10fefd4
......@@ -24,37 +24,10 @@ raise_memory_limit("512M");
ini_set('auto_detect_line_endings', 1);
$FORMAT = array();
$ALLOWEDKEYS = array(
'username',
'remoteuser',
'password',
'email',
'firstname',
'lastname',
'preferredname',
'studentid',
'introduction',
'officialwebsite',
'personalwebsite',
'blogaddress',
'address',
'town',
'city',
'country',
'homenumber',
'businessnumber',
'mobilenumber',
'faxnumber',
'icqnumber',
'msnnumber',
'aimscreenname',
'yahoochat',
'skypeusername',
'jabberusername',
'occupation',
'industry',
'authinstance'
);
$specialcases = array('username', 'password', 'remoteuser', 'authinstance');
$ALLOWEDKEYS = array_keys(ArtefactTypeProfile::get_all_fields());
$ALLOWEDKEYS = array_merge($ALLOWEDKEYS, $specialcases);
$UPDATES = array(); // During validation, remember which users already exist
$INSTITUTIONNAME = array(); // Mapping from institution id to display name
......@@ -212,17 +185,12 @@ function uploadcsv_validate(Pieform $form, $values) {
// Now we know all of the field names are valid, we need to make
// sure that the required fields are included
$mandatoryfields = array(
'username',
'username', 'email', 'firstname', 'lastname'
);
if (!$values['updateusers']) {
$mandatoryfields[] = 'password';
}
$mandatoryfields = array_merge($mandatoryfields, array_keys(ArtefactTypeProfile::get_mandatory_fields()));
if ($lockedprofilefields = get_column('institution_locked_profile_field', 'profilefield', 'name', $institution)) {
$mandatoryfields = array_merge($mandatoryfields, $lockedprofilefields);
}
$csvusers->set('mandatoryfields', $mandatoryfields);
$csvdata = $csvusers->get_data();
......@@ -602,9 +570,7 @@ function uploadcsv_submit(Pieform $form, $values) {
// Get a list of all profile fields, to inform the user on what fields they can
// put in their file.
$fields = "<ul class=fieldslist>\n";
$fieldlist = array_keys(ArtefactTypeProfile::get_all_fields());
$fieldlist[]= 'remoteuser'; // is a special case
foreach ($fieldlist as $type) {
foreach ($ALLOWEDKEYS as $type) {
if ($type == 'firstname' || $type == 'lastname' || $type == 'email') {
continue;
}
......@@ -612,19 +578,7 @@ foreach ($fieldlist as $type) {
}
$fields .= "<div class=cl></div></ul>\n";
if ($USER->get('admin')) {
$uploadcsvpagedescription = get_string('uploadcsvpagedescription2', 'admin',
get_config('wwwroot') . 'admin/extensions/pluginconfig.php?plugintype=artefact&pluginname=internal&type=profile',
get_config('wwwroot') . 'admin/users/institutions.php',
$fields
);
}
else {
$uploadcsvpagedescription = get_string('uploadcsvpagedescription2institutionaladmin', 'admin',
get_config('wwwroot') . 'admin/users/institutions.php',
$fields
);
}
$uploadcsvpagedescription = get_string('uploadcsvpagedescription3', 'admin', $fields);
$form = pieform($form);
......
......@@ -572,24 +572,13 @@ $string['uploadcsverrorduplicateremoteuser'] = 'Line %s of the file specifies a
$string['uploadcsverrorremoteusertaken'] = 'Line %s of the file specifies a remote username "%s" that is already taken by the user "%s".';
$string['uploadcsverrorusernotininstitution'] = 'Error on line %s: The user "%s" is not a member of the institution %s.';
$string['uploadcsverroruserinaninstitution'] = 'Error on line %s: The user "%s" is a member of the following institutions: %s. You cannot update this user\'s authentication method to "No Institution".';
$string['uploadcsvpagedescription2'] = '<p>You may use this facility to upload new users via a <acronym title="Comma Separated Values">CSV</acronym> file.</p>
$string['uploadcsvpagedescription3'] = '<p>You may use this facility to upload new users via a <acronym title="Comma Separated Values">CSV</acronym> file.</p>
<p>The first row of your CSV file should specify the format of your CSV data. For example, it should look like this:</p>
<pre>username,password,email,firstname,lastname,studentid</pre>
<p>This row must include the <tt>username</tt>, <tt>password</tt>, <tt>email</tt>, <tt>firstname</tt> and <tt>lastname</tt> fields. It must also include fields that you have made mandatory for all users to fill out and any fields locked for the institution you are uploading the users for. You can <a href="%s">configure the mandatory fields</a> for all institutions or <a href="%s">configure the locked fields for each institution</a>.</p>
<p>Your CSV file may include any other profile fields as you require. The full list of fields is:</p>
%s';
$string['uploadcsvpagedescription2institutionaladmin'] = '<p>You may use this facility to upload new users via a <acronym title="Comma Separated Values">CSV</acronym> file.</p>
<p>The first row of your CSV file should specify the format of your CSV data. For example, it should look like this:</p>
<pre>username,password,email,firstname,lastname,studentid</pre>
<p>This row must include the <tt>username</tt>, <tt>password</tt>, <tt>email</tt>, <tt>firstname</tt> and <tt>lastname</tt> fields. It must also include any fields that the site administrator has made mandatory and any fields that are locked for your institution. You can <a href="%s">configure the locked fields</a> for the institution(s) you manage.</p>
<p>This row must include the <tt>username</tt>, <tt>password</tt>, <tt>email</tt>, <tt>firstname</tt> and <tt>lastname</tt> fields.</p>
<p>Your CSV file may include any other profile fields as you require. The full list of fields is:</p>
......
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