Skip to content

Commit

Permalink
Merge branch 'MDL-58793-master-authcfgskip' of git://github.com/mudrd…
Browse files Browse the repository at this point in the history
…8mz/moodle
  • Loading branch information
danpoltawski committed May 8, 2017
2 parents 5da6b0f + 2b948c2 commit 1595500
Show file tree
Hide file tree
Showing 28 changed files with 81 additions and 17 deletions.
1 change: 1 addition & 0 deletions auth/cas/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function xmldb_auth_cas_upgrade($oldversion) {
if ($oldversion < 2017020700) {
// Convert info in config plugins from auth/cas to auth_cas.
upgrade_fix_config_auth_plugin_names('cas');
upgrade_fix_config_auth_plugin_defaults('cas');
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'cas');
}

Expand Down
2 changes: 1 addition & 1 deletion auth/cas/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
}

// Display locking / mapping of profile fields.
$authplugin = get_auth_plugin($this->name);
$authplugin = get_auth_plugin('cas');
$help = get_string('auth_ldapextrafields', 'auth_ldap');
$help .= get_string('auth_updatelocal_expl', 'auth');
$help .= get_string('auth_fieldlock_expl', 'auth');
Expand Down
1 change: 1 addition & 0 deletions auth/db/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function xmldb_auth_db_upgrade($oldversion) {
if ($oldversion < 2017032800) {
// Convert info in config plugins from auth/db to auth_db
upgrade_fix_config_auth_plugin_names('db');
upgrade_fix_config_auth_plugin_defaults('db');
upgrade_plugin_savepoint(true, 2017032800, 'auth', 'db');
}

Expand Down
2 changes: 1 addition & 1 deletion auth/db/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
new lang_string('auth_dbupdateusers_description', 'auth_db'), 0, $yesno));

// Display locking / mapping of profile fields.
$authplugin = get_auth_plugin($this->name);
$authplugin = get_auth_plugin('db');
display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields,
get_string('auth_dbextrafields', 'auth_db'),
true, true, $authplugin->get_custom_user_profile_fields());
Expand Down
1 change: 1 addition & 0 deletions auth/email/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function xmldb_auth_email_upgrade($oldversion) {
if ($oldversion < 2017020700) {
// Convert info in config plugins from auth/email to auth_email.
upgrade_fix_config_auth_plugin_names('email');
upgrade_fix_config_auth_plugin_defaults('email');
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'email');
}

Expand Down
2 changes: 1 addition & 1 deletion auth/email/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
new lang_string('auth_emailrecaptcha', 'auth_email'), 0, $options));

// Display locking / mapping of profile fields.
$authplugin = get_auth_plugin($this->name);
$authplugin = get_auth_plugin('email');
display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields,
get_string('auth_fieldlocks_help', 'auth'), false, false);
}
1 change: 1 addition & 0 deletions auth/fc/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function xmldb_auth_fc_upgrade($oldversion) {
if ($oldversion < 2017020700) {
// Convert info in config plugins from auth/fc to auth_fc.
upgrade_fix_config_auth_plugin_names('fc');
upgrade_fix_config_auth_plugin_defaults('fc');
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'fc');
}

Expand Down
2 changes: 1 addition & 1 deletion auth/fc/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
get_string('changepasswordhelp', 'auth'), '', PARAM_URL));

// Display locking / mapping of profile fields.
$authplugin = get_auth_plugin($this->name);
$authplugin = get_auth_plugin('fc');
display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields,
get_string('auth_fieldlocks_help', 'auth'), false, false);
}
1 change: 1 addition & 0 deletions auth/imap/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function xmldb_auth_imap_upgrade($oldversion) {
if ($oldversion < 2017020700) {
// Convert info in config plugins from auth/imap to auth_imap.
upgrade_fix_config_auth_plugin_names('imap');
upgrade_fix_config_auth_plugin_defaults('imap');
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'imap');
}

Expand Down
2 changes: 1 addition & 1 deletion auth/imap/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
get_string('changepasswordhelp', 'auth'), '', PARAM_URL));

// Display locking / mapping of profile fields.
$authplugin = get_auth_plugin($this->name);
$authplugin = get_auth_plugin('imap');
display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields,
get_string('auth_fieldlocks_help', 'auth'), false, false);

Expand Down
1 change: 1 addition & 0 deletions auth/ldap/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function xmldb_auth_ldap_upgrade($oldversion) {
if ($oldversion < 2017020700) {
// Convert info in config plugins from auth/ldap to auth_ldap.
upgrade_fix_config_auth_plugin_names('ldap');
upgrade_fix_config_auth_plugin_defaults('ldap');
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'ldap');
}

Expand Down
2 changes: 1 addition & 1 deletion auth/ldap/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@
}

// Display locking / mapping of profile fields.
$authplugin = get_auth_plugin($this->name);
$authplugin = get_auth_plugin('ldap');
$help = get_string('auth_ldapextrafields', 'auth_ldap');
$help .= get_string('auth_updatelocal_expl', 'auth');
$help .= get_string('auth_fieldlock_expl', 'auth');
Expand Down
1 change: 1 addition & 0 deletions auth/manual/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function xmldb_auth_manual_upgrade($oldversion) {
if ($oldversion < 2017020700) {
// Convert info in config plugins from auth/manual to auth_manual.
upgrade_fix_config_auth_plugin_names('manual');
upgrade_fix_config_auth_plugin_defaults('manual');
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'manual');
}

Expand Down
2 changes: 1 addition & 1 deletion auth/manual/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
new lang_string('expiration_warning_desc', 'auth_manual'), 0, $expirationwarningoptions));

// Display locking / mapping of profile fields.
$authplugin = get_auth_plugin($this->name);
$authplugin = get_auth_plugin('manual');
display_auth_lock_options($settings, $authplugin->authtype,
$authplugin->userfields, get_string('auth_fieldlocks_help', 'auth'), false, false);
}
1 change: 1 addition & 0 deletions auth/mnet/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function xmldb_auth_mnet_upgrade($oldversion) {
if ($oldversion < 2017020700) {
// Convert info in config plugins from auth/mnet to auth_mnet.
upgrade_fix_config_auth_plugin_names('mnet');
upgrade_fix_config_auth_plugin_defaults('mnet');
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'mnet');
}

Expand Down
1 change: 1 addition & 0 deletions auth/nntp/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function xmldb_auth_nntp_upgrade($oldversion) {
if ($oldversion < 2017020700) {
// Convert info in config plugins from auth/nntp to auth_nntp.
upgrade_fix_config_auth_plugin_names('nntp');
upgrade_fix_config_auth_plugin_defaults('nntp');
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'nntp');
}

Expand Down
2 changes: 1 addition & 1 deletion auth/nntp/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
get_string('changepasswordhelp', 'auth'), '', PARAM_URL));

// Display locking / mapping of profile fields.
$authplugin = get_auth_plugin($this->name);
$authplugin = get_auth_plugin('nntp');
display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields,
get_string('auth_fieldlocks_help', 'auth'), false, false);
}
1 change: 1 addition & 0 deletions auth/none/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function xmldb_auth_none_upgrade($oldversion) {
if ($oldversion < 2017020700) {
// Convert info in config plugins from auth/none to auth_none.
upgrade_fix_config_auth_plugin_names('none');
upgrade_fix_config_auth_plugin_defaults('none');
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'none');
}

Expand Down
2 changes: 1 addition & 1 deletion auth/none/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
new lang_string('auth_nonedescription', 'auth_none')));

// Display locking / mapping of profile fields.
$authplugin = get_auth_plugin($this->name);
$authplugin = get_auth_plugin('none');
display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields,
get_string('auth_fieldlocks_help', 'auth'), false, false);
}
2 changes: 1 addition & 1 deletion auth/oauth2/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
$warning = $OUTPUT->notification(get_string('createaccountswarning', 'auth_oauth2'), 'warning');
$settings->add(new admin_setting_heading('auth_oauth2/pluginname', '', $warning));

$authplugin = get_auth_plugin($this->name);
$authplugin = get_auth_plugin('oauth2');
display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields,
get_string('auth_fieldlocks_help', 'auth'), false, false);
}
1 change: 1 addition & 0 deletions auth/pam/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function xmldb_auth_pam_upgrade($oldversion) {
if ($oldversion < 2017020700) {
// Convert info in config plugins from auth/pam to auth_pam.
upgrade_fix_config_auth_plugin_names('pam');
upgrade_fix_config_auth_plugin_defaults('pam');
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'pam');
}

Expand Down
2 changes: 1 addition & 1 deletion auth/pam/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
new lang_string('auth_pamdescription', 'auth_pam')));

// Display locking / mapping of profile fields.
$authplugin = get_auth_plugin($this->name);
$authplugin = get_auth_plugin('pam');
display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields,
get_string('auth_fieldlocks_help', 'auth'), false, false);
}
1 change: 1 addition & 0 deletions auth/pop3/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function xmldb_auth_pop3_upgrade($oldversion) {
if ($oldversion < 2017020700) {
// Convert info in config plugins from auth/pop3 to auth_pop3.
upgrade_fix_config_auth_plugin_names('pop3');
upgrade_fix_config_auth_plugin_defaults('pop3');
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'pop3');
}

Expand Down
2 changes: 1 addition & 1 deletion auth/pop3/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
get_string('changepasswordhelp', 'auth'), '', PARAM_URL));

// Display locking / mapping of profile fields.
$authplugin = get_auth_plugin($this->name);
$authplugin = get_auth_plugin('pop3');
display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields,
get_string('auth_fieldlocks_help', 'auth'), false, false);
}
1 change: 1 addition & 0 deletions auth/shibboleth/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function xmldb_auth_shibboleth_upgrade($oldversion) {
if ($oldversion < 2017020700) {
// Convert info in config plugins from auth/shibboleth to auth_shibboleth.
upgrade_fix_config_auth_plugin_names('shibboleth');
upgrade_fix_config_auth_plugin_defaults('shibboleth');
upgrade_plugin_savepoint(true, 2017020700, 'auth', 'shibboleth');
}

Expand Down
2 changes: 1 addition & 1 deletion auth/shibboleth/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
get_string('changepasswordhelp', 'auth'), '', PARAM_URL));

// Display locking / mapping of profile fields.
$authplugin = get_auth_plugin($this->name);
$authplugin = get_auth_plugin('shibboleth');
display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields,
'', true, false, $authplugin->get_custom_user_profile_fields());

Expand Down
9 changes: 5 additions & 4 deletions auth/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ information provided here is intended especially for developers.

=== 3.3 ===

* Authentication plugins have been migrated to use the admin settings API.
Plugins should use a settings.php file to manage configurations rather than using the config.html files.
See how the helper function upgrade_fix_config_auth_plugin_names() can be used to convert the legacy settings to the
new ones.
* Authentication plugins have been migrated to use the admin settings API. Plugins should use a settings.php file to
manage configurations rather than using the old config.html files. See how the helper function
upgrade_fix_config_auth_plugin_names() can be used to convert the legacy settings to the new ones. Another helper
function upgrade_fix_config_auth_plugin_defaults() can be used to populate the settings with default values so that
they are not falsely reported as newly added ones.
* The function 'print_auth_lock_options' has been replaced by 'display_auth_lock_options' which uses the admin settings API.
See auth_manual as an exmple of how it can be used. More information can be found in MDL-12689.
* The list of supported identity providers (SSO IdP) returned by the 'loginpage_idp_list' method (used to render the
Expand Down
50 changes: 50 additions & 0 deletions lib/upgradelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2569,3 +2569,53 @@ function upgrade_fix_config_auth_plugin_names($plugin) {
unset_config($name, 'auth/'.$plugin);
}
}

/**
* Populate the auth plugin settings with defaults if needed.
*
* As a result of fixing the auth plugins config storage, many settings would
* be falsely reported as new ones by admin/upgradesettings.php. We do not want
* to confuse admins so we try to reduce the bewilderment by pre-populating the
* config_plugins table with default values. This should be done only for
* disabled auth methods. The enabled methods have their settings already
* stored, so reporting actual new settings for them is valid.
*
* @param string $plugin the auth plugin name such as 'cas', 'manual' or 'mnet'
*/
function upgrade_fix_config_auth_plugin_defaults($plugin) {
global $CFG;

$pluginman = core_plugin_manager::instance();
$enabled = $pluginman->get_enabled_plugins('auth');

if (isset($enabled[$plugin])) {
// Do not touch settings of enabled auth methods.
return;
}

// We can't directly use {@link core\plugininfo\auth::load_settings()} here
// because the plugins are not fully upgraded yet. Instead, we emulate what
// that method does. We fetch a temporary instance of the plugin's settings
// page to get access to the settings and their defaults. Note we are not
// adding that temporary instance into the admin tree. Yes, this is a hack.

$plugininfo = $pluginman->get_plugin_info('auth_'.$plugin);
$adminroot = admin_get_root();
$ADMIN = $adminroot;
$auth = $plugininfo;

$section = $plugininfo->get_settings_section_name();
$settingspath = $plugininfo->full_path('settings.php');

if (file_exists($settingspath)) {
$settings = new admin_settingpage($section, 'Emulated settings page for auth_'.$plugin, 'moodle/site:config');
include($settingspath);

if ($settings) {
// Consistently with what admin/cli/upgrade.php does, apply the default settings twice.
// I assume this is done for theoretical cases when a default value depends on an other.
admin_apply_default_settings($settings, false);
admin_apply_default_settings($settings, false);
}
}
}

0 comments on commit 1595500

Please sign in to comment.