From 3ef28dc52857286c855dd1690d5d297e0f205525 Mon Sep 17 00:00:00 2001 From: Felipe Carasso Date: Mon, 8 Jul 2019 17:02:51 -0400 Subject: [PATCH 1/4] fix(ISSUE-21): updates config to use settings api --- .gitignore | 1 + config.html | 55 ------------------------------------------------ db/upgrade.php | 15 +++++++++++++ settings.php | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ version.php | 4 ++-- 5 files changed, 75 insertions(+), 57 deletions(-) create mode 100644 .gitignore delete mode 100644 config.html create mode 100644 db/upgrade.php create mode 100644 settings.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d1b811b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.sql diff --git a/config.html b/config.html deleted file mode 100644 index 71a9efc..0000000 --- a/config.html +++ /dev/null @@ -1,55 +0,0 @@ - -recaptcha)) { - $config->recaptcha = false; - } - - $yesno = array( get_string('no'), get_string('yes') ); - - if (!isset($config->notif_strategy) || !is_numeric($config->notif_strategy) || $config->notif_strategy < -2) { - $config->notif_strategy = -1; - } -?> - - - - - - - - - - - - - - - - -authtype, $user_fields, get_string('auth_fieldlocks_help', 'auth'), false, false); - -?> -
-

-
recaptcha, false); - ?>
get_string("auth_emailadminnotif_strategy_first", "auth_emailadmin"), - '-2' => get_string("auth_emailadminnotif_strategy_all", "auth_emailadmin") - ); - $admins = get_admins(); - foreach ($admins as $admin) { - $options[$admin->id] = $admin->username; - } - - echo html_writer::select($options, 'notif_strategy', $config->notif_strategy); - ?>
diff --git a/db/upgrade.php b/db/upgrade.php new file mode 100644 index 0000000..e6937f0 --- /dev/null +++ b/db/upgrade.php @@ -0,0 +1,15 @@ +. + +/** + * Admin settings and defaults. Heavily based on auth/email/settings.php. + * + * @package auth_emailadmin + * @copyright 2019 Felipe Carasso + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +if ($ADMIN->fulltree) { + + // Introductory explanation. + $settings->add(new admin_setting_heading('auth_emailadmin/pluginname', '', + new lang_string('auth_emailadmindescription', 'auth_emailadmin'))); + + $options = array( + new lang_string('no'), + new lang_string('yes'), + ); + + $settings->add(new admin_setting_configselect('auth_emailadmin/recaptcha', + new lang_string('auth_emailadminrecaptcha_key', 'auth_emailadmin'), + new lang_string('auth_emailadminrecaptcha', 'auth_emailadmin'), 0, $options)); + $options = array('-1' => get_string("auth_emailadminnotif_strategy_first", "auth_emailadmin"), + '-2' => get_string("auth_emailadminnotif_strategy_all", "auth_emailadmin") + ); + $admins = get_admins(); + foreach ($admins as $admin) { + $options[$admin->id] = $admin->username; + } + + $settings->add(new admin_setting_configselect('auth_emailadmin/notif_strategy', + new lang_string('auth_emailadminnotif_strategy_key', 'auth_emailadmin'), + new lang_string('auth_emailadminnotif_strategy', 'auth_emailadmin'), -1, $options)); + + // Display locking / mapping of profile fields. + $authplugin = get_auth_plugin('email'); + display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields, + get_string('auth_fieldlocks_help', 'auth'), false, false); +} diff --git a/version.php b/version.php index cfe3d2d..2e6b3d0 100644 --- a/version.php +++ b/version.php @@ -26,8 +26,8 @@ defined('MOODLE_INTERNAL') || die; -$plugin->version = 2019070400; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2019070800; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2015051101; // Requires this Moodle version. $plugin->component = 'auth_emailadmin'; // Full name of the plugin (used for diagnostics). $plugin->maturity = MATURITY_STABLE; -$plugin->release = '1.4.2'; +$plugin->release = '1.4.3'; From ee577a2ade18c56407a73f15f8377b91774c2fb4 Mon Sep 17 00:00:00 2001 From: Felipe Carasso Date: Mon, 8 Jul 2019 22:03:03 -0400 Subject: [PATCH 2/4] fix(ISSUE-17): repairs lock user fields, db update --- auth.php | 1 + db/upgrade.php | 2 ++ settings.php | 2 +- version.php | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/auth.php b/auth.php index 0bb4a1e..375611c 100644 --- a/auth.php +++ b/auth.php @@ -42,6 +42,7 @@ class auth_plugin_emailadmin extends auth_plugin_base { */ public function __construct() { $this->authtype = 'emailadmin'; + $this->config = get_config('auth_'.$this->authtype); } /* Backward compatible constructor. */ diff --git a/db/upgrade.php b/db/upgrade.php index e6937f0..5c78612 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -12,4 +12,6 @@ function xmldb_auth_emailadmin_upgrade($oldversion) { upgrade_fix_config_auth_plugin_defaults('emailadmin'); upgrade_plugin_savepoint(true, 2019070800, 'auth', 'emailadmin'); } + + return true; } diff --git a/settings.php b/settings.php index ec33bd5..c64ea81 100644 --- a/settings.php +++ b/settings.php @@ -51,7 +51,7 @@ new lang_string('auth_emailadminnotif_strategy', 'auth_emailadmin'), -1, $options)); // Display locking / mapping of profile fields. - $authplugin = get_auth_plugin('email'); + $authplugin = get_auth_plugin('emailadmin'); display_auth_lock_options($settings, $authplugin->authtype, $authplugin->userfields, get_string('auth_fieldlocks_help', 'auth'), false, false); } diff --git a/version.php b/version.php index 2e6b3d0..1807e5a 100644 --- a/version.php +++ b/version.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die; -$plugin->version = 2019070800; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2019070801; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2015051101; // Requires this Moodle version. $plugin->component = 'auth_emailadmin'; // Full name of the plugin (used for diagnostics). $plugin->maturity = MATURITY_STABLE; From 2f2971ab1bdafa6a6a757d155235bf9577511592 Mon Sep 17 00:00:00 2001 From: Felipe Carasso Date: Mon, 8 Jul 2019 23:26:35 -0400 Subject: [PATCH 3/4] fix(ISSUE-25): makes use of lib function to gather profile fields --- auth.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/auth.php b/auth.php index 375611c..9cb163c 100644 --- a/auth.php +++ b/auth.php @@ -390,11 +390,9 @@ public function list_custom_fields($user) { global $CFG, $DB; $result = ''; - if ($fields = $DB->get_records('user_info_field')) { - foreach ($fields as $field) { - $fieldobj = new profile_field_base($field->id, $user->id); - $result .= format_string($fieldobj->field->name.':') . ' ' . $fieldobj->display_data() . PHP_EOL; - } + $fields = profile_get_user_fields_with_data($user->id); + foreach ($fields as $field) { + $result .= format_string($field->field->shortname.':') . ' ' . $field->display_data() . PHP_EOL; } return $result; From 2b357bc920f1101a3a3cd2259d7a8814414a5c27 Mon Sep 17 00:00:00 2001 From: Felipe Carasso Date: Tue, 9 Jul 2019 04:02:44 -0400 Subject: [PATCH 4/4] feat(ISSUE-18): adds support for notifying users with profile update capability --- auth.php | 16 +++++++++++----- lang/en/auth_emailadmin.php | 1 + settings.php | 5 +++-- version.php | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/auth.php b/auth.php index 9cb163c..5cd7980 100644 --- a/auth.php +++ b/auth.php @@ -29,6 +29,7 @@ } require_once($CFG->libdir.'/authlib.php'); +require_once($CFG->libdir.'/accesslib.php'); require_once($CFG->dirroot.'/user/profile/lib.php'); require_once('classes/message.class.php'); @@ -272,7 +273,7 @@ public function is_captcha_enabled() { */ public function send_confirmation_email_support($user) { global $CFG; - $config = get_config('auth/emailadmin'); + $config = $this->config; $site = get_site(); $supportuser = core_user::get_support_user(); @@ -305,15 +306,20 @@ public function send_confirmation_email_support($user) { // Directly email rather than using the messaging system to ensure its not routed to a popup or jabber. $admins = get_admins(); - $return = false; - $admin_found = false; - // Send message to fist admin (main) only. Remove "break" for all admins. if (!isset($config->notif_strategy)) { $config->notif_strategy = -1; } - $config->notif_strategy = intval($config->notif_strategy); + + if ($config->notif_strategy == -3 || $config->notif_strategy >= 0) { + $admins = array_merge($admins, get_users_by_capability(context_system::instance(), 'moodle/user:update')); + } + + $return = false; + $admin_found = false; + + // Send message to fist admin (main) only. Remove "break" for all admins. $send_list = array(); foreach ($admins as $admin) { error_log(print_r( $config->notif_strategy . ":" . $admin->id, true )); diff --git a/lang/en/auth_emailadmin.php b/lang/en/auth_emailadmin.php index 8cc2e49..e012a18 100644 --- a/lang/en/auth_emailadmin.php +++ b/lang/en/auth_emailadmin.php @@ -101,5 +101,6 @@ $string['auth_emailadminnotif_strategy'] = 'Defines the strategy to send the registration notifications. Available options are "first" admin user, "all" admin users or one specific admin user.'; $string['auth_emailadminnotif_strategy_first'] = 'First admin user'; $string['auth_emailadminnotif_strategy_all'] = 'All admin users'; +$string['auth_emailadminnotif_strategy_allupdate'] = 'All admins and users with user update capability'; $string['pluginname'] = 'Email-based self-registration with admin confirmation'; diff --git a/settings.php b/settings.php index c64ea81..a4bf072 100644 --- a/settings.php +++ b/settings.php @@ -39,9 +39,10 @@ new lang_string('auth_emailadminrecaptcha_key', 'auth_emailadmin'), new lang_string('auth_emailadminrecaptcha', 'auth_emailadmin'), 0, $options)); $options = array('-1' => get_string("auth_emailadminnotif_strategy_first", "auth_emailadmin"), - '-2' => get_string("auth_emailadminnotif_strategy_all", "auth_emailadmin") + '-2' => get_string("auth_emailadminnotif_strategy_all", "auth_emailadmin"), + '-3' => get_string("auth_emailadminnotif_strategy_allupdate", "auth_emailadmin") ); - $admins = get_admins(); + $admins = array_merge(get_admins(), get_users_by_capability(context_system::instance(), 'moodle/user:update')); foreach ($admins as $admin) { $options[$admin->id] = $admin->username; } diff --git a/version.php b/version.php index 1807e5a..9492ae8 100644 --- a/version.php +++ b/version.php @@ -26,7 +26,7 @@ defined('MOODLE_INTERNAL') || die; -$plugin->version = 2019070801; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2019070802; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2015051101; // Requires this Moodle version. $plugin->component = 'auth_emailadmin'; // Full name of the plugin (used for diagnostics). $plugin->maturity = MATURITY_STABLE;