Commit d00eaf37 authored by Aaron Wells's avatar Aaron Wells
Browse files

lib/user.php: new institutional users should have license set to "institution default"

Bug #1162134. Previously we were storing the "institution default"
value as "-" in the database. I've changed this to saving a constant,
LICENSE_INSTITUTION_DEFAULT, which is defined as "(institution default)".

Change-Id: I05337d9e8b1b547f12e4658b8d78fcbe1b5b2ea4
parent 542b506b
......@@ -3192,5 +3192,10 @@ function xmldb_core_upgrade($oldversion=0) {
install_licenses_default();
}
if ($oldversion < 2013032202) {
require_once(get_config('libroot').'license.php');
set_field('usr_account_preference', 'value', LICENSE_INSTITUTION_DEFAULT, 'field', 'licensedefault', 'value', '-');
}
return $status;
}
......@@ -29,6 +29,8 @@
defined('INTERNAL') || die();
require_once(get_config('libroot') . 'license.php');
class Institution {
const UNINITIALIZED = 0;
......@@ -486,6 +488,9 @@ class Institution {
)
);
// If the user's license default is set to "institution default", remove the pref
delete_records('usr_account_preference', 'usr', $user->id, 'field', 'licensedefault', 'value', LICENSE_INSTITUTION_DEFAULT);
delete_records('usr_institution', 'usr', $user->id, 'institution', $this->name);
handle_event('updateuser', $user->id);
db_commit();
......
......@@ -26,10 +26,13 @@
defined('INTERNAL') || die();
define('LICENSE_INSTITUTION_DEFAULT', '(institution default)');
/**
* Given an artefact object, return the first of the two pieform elements.
*
* @param object The artefact
* @param object $artefact The artefact
* @param boolean $always_allow_none True to indicate that it should definitely include "allow none"; otherwise the function decides
* @return array A pieform element (license field).
*/
function license_form_el_basic($artefact, $always_allow_none=false) {
......@@ -44,24 +47,34 @@ function license_form_el_basic($artefact, $always_allow_none=false) {
$options[$l->name] = $l->displayname;
}
// Determine whether to include the "none selected" option in the list of licenses
$include_noneselected = false;
// If it was passed in as a param, then we will include "none selected"
if ($always_allow_none) {
$options[''] = '';
$include_noneselected = true;
}
$institution = $USER->get('institutions');
if ($institution) {
$institution = array_shift($institution);
// If the user's institution is not set to "license mandatory", then we will include "none selected"
if (empty($institution->licensemandatory)) {
$options[''] = '';
$include_noneselected = true;
}
}
else {
$options[''] = '';
// If the user has no institution, then we will include "none selected"
$include_noneselected = true;
}
if ($include_noneselected) {
$options[''] = get_string('licensenone');
}
if (empty($artefact)) {
// Find the correct default license.
$license = $USER->get_account_preference('licensedefault');
if ($license === NULL or $license === '-') {
// If the user is set to "institution default"
if ($license == LICENSE_INSTITUTION_DEFAULT) {
if ($institution and isset($institution->licensedefault)) {
$license = $institution->licensedefault;
}
......@@ -69,7 +82,8 @@ function license_form_el_basic($artefact, $always_allow_none=false) {
$license = '';
}
}
if (!isset($options[$license]) and !get_config('licenseallowcustom')) {
if (!isset($options[$license]) && !get_config('licenseallowcustom')) {
// Note: this won't happen normally, but it can happen for instance
// if the site admin removes a license which is the default for the
// user's institution.
......@@ -87,9 +101,6 @@ function license_form_el_basic($artefact, $always_allow_none=false) {
}
}
if (isset($options[''])) {
$options[''] = get_string('licensenone');
}
$res = array(
'defaultvalue' => $license,
'type' => 'select',
......
......@@ -218,6 +218,7 @@ function expected_account_preferences() {
'theme' => '',
'resizeonuploaduserdefault' => 1,
'devicedetection' => 1,
'licensedefault' => '',
);
}
......@@ -248,10 +249,10 @@ function general_account_prefs_form_elements($prefs) {
$elements['licensedefault'] = license_form_el_basic(null);
$elements['licensedefault']['title'] = get_string('licensedefault','account');
if ($USER->get('institutions')) {
$elements['licensedefault']['options']['-'] = get_string('licensedefaultinherit','account');
$elements['licensedefault']['options'][LICENSE_INSTITUTION_DEFAULT] = get_string('licensedefaultinherit','account');
}
$elements['licensedefault']['description'] = get_string('licensedefaultdescription','account');
if (isset($prefs->licensedefault) && $prefs->licensedefault != '') {
if (isset($prefs->licensedefault)) {
$elements['licensedefault']['defaultvalue'] = $prefs->licensedefault;
}
}
......@@ -2115,7 +2116,7 @@ function addfriend_submit(Pieform $form, $values) {
*
* @param object $user stdclass or User object for the usr table
* @param array $profile profile field/values to set
* @param string $institution Institution the user should joined to
* @param string|object $institution Institution the user should joined to (name or Institution object)
* @param stdclass $remoteauth authinstance record for a remote authinstance
* @param string $remotename username on the remote site
* @param array $accountprefs user account preferences to set
......@@ -2168,6 +2169,7 @@ function create_user($user, $profile=array(), $institution=null, $remoteauth=nul
if ($institution->name != 'mahara') {
$institution->addUserAsMember($user); // uses $user->newuser
}
$accountprefs['licensedefault'] = LICENSE_INSTITUTION_DEFAULT;
}
if (!empty($remoteauth)) {
......
......@@ -30,7 +30,7 @@ defined('INTERNAL') || die();
$config = new StdClass;
// See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2013032201;
$config->version = 2013032202;
$config->release = '1.7rc2dev';
$config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';
......
Supports Markdown
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