From 23edf6052079ab63eece448893958d30ca8f623e Mon Sep 17 00:00:00 2001 From: Alexander Bias <alexander.bias@uni-ulm.de> Date: Tue, 19 Jul 2016 22:35:59 +0200 Subject: [PATCH] Adopt code changes in Moodle core auth_ldap, update README and version.php --- README.md | 4 +++- auth.php | 22 +++++++++++++++++++++- config.html | 29 +++++++++++++++++++++++++++++ version.php | 8 ++++---- 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c2ddd17..6023b18 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,14 @@ Moodle authentication method which provides all functionality of auth_ldap, but Requirements ------------ -This plugin requires Moodle 3.0+ +This plugin requires Moodle 3.1+ Changes ------- +* 2016-07-19 - Adopt code changes in Moodle core auth_ldap, adding the possibility to sync the "suspended" attribute +* 2016-07-19 - Check compatibility for Moodle 3.1, no functionality change * 2016-03-20 - Edit README to reflect the current naming of the User account syncronisation setting, no functionality change * 2016-02-10 - Change plugin version and release scheme to the scheme promoted by moodle.org, no functionality change * 2016-01-01 - Adopt code changes in Moodle core auth_ldap, including the new scheduled task feature. If you have used a LDAP syncronization cron job before, please use the LDAP syncronisation scheduled task from now on (for details, see "Configuring LDAP synchronization task" section below) diff --git a/auth.php b/auth.php index f26dd92..c54f531 100644 --- a/auth.php +++ b/auth.php @@ -45,9 +45,12 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { } /** - * Old syntax of class constructor for backward compatibility. + * Old syntax of class constructor. Deprecated in PHP7. + * + * @deprecated since Moodle 3.1 */ public function auth_plugin_ldap_syncplus() { + debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER); self::__construct(); } @@ -338,6 +341,9 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { } } } + if ($this->config->suspended_attribute && $this->config->sync_suspended) { + $updatekeys[] = 'suspended'; + } unset($all_keys); unset($key); } else { mtrace(get_string('noupdatestobedone', 'auth_ldap')); @@ -422,6 +428,12 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { // get_userinfo_asobj() might have replaced $user->username with the value // from the LDAP server (which can be mixed-case). Make sure it's lowercase $user->username = trim(core_text::strtolower($user->username)); + // It isn't possible to just rely on the configured suspension attribute since + // things like active directory use bit masks, other things using LDAP might + // do different stuff as well. + // + // The cast to int is a workaround for MDL-53959. + $user->suspended = (int)$this->is_user_suspended($user); if (empty($user->lang)) { $user->lang = $CFG->lang; } @@ -504,6 +516,12 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { if (!isset($config->user_attribute)) { $config->user_attribute = ''; } + if (!isset($config->suspended_attribute)) { + $config->suspended_attribute = ''; + } + if (!isset($config->sync_suspended)) { + $config->sync_suspended = false; + } if (!isset($config->search_sub)) { $config->search_sub = ''; } @@ -606,6 +624,8 @@ class auth_plugin_ldap_syncplus extends auth_plugin_ldap { set_config('contexts', $config->contexts, $this->pluginconfig); set_config('user_type', core_text::strtolower(trim($config->user_type)), $this->pluginconfig); set_config('user_attribute', core_text::strtolower(trim($config->user_attribute)), $this->pluginconfig); + set_config('suspended_attribute', core_text::strtolower(trim($config->suspended_attribute)), $this->pluginconfig); + set_config('sync_suspended', $config->sync_suspended, $this->pluginconfig); set_config('search_sub', $config->search_sub, $this->pluginconfig); set_config('opt_deref', $config->opt_deref, $this->pluginconfig); set_config('preventpassindb', $config->preventpassindb, $this->pluginconfig); diff --git a/config.html b/config.html index 6a52855..df3f782 100644 --- a/config.html +++ b/config.html @@ -22,6 +22,12 @@ if (!isset($config->user_type)) { if (!isset($config->user_attribute)) { $config->user_attribute = ''; } +if (!isset($config->suspended_attribute)) { + $config->suspended_attribute = ''; +} +if (!isset($config->sync_suspended)) { + $config->sync_suspended = ''; +} if (!isset($config->search_sub)) { $config->search_sub = ''; } @@ -311,6 +317,18 @@ if (!ldap_paged_results_supported($config->ldap_version)) { <?php print_string('auth_ldap_user_attribute', 'auth_ldap') ?> </td> </tr> +<tr valign="top" class="required"> + <td align="right"> + <label for="suspended_attribute"><?php print_string('auth_ldap_suspended_attribute_key', 'auth_ldap') ?></label> + </td> + <td> + <input name="suspended_attribute" id="suspended_attribute" type="text" size="30" value="<?php echo $config->suspended_attribute?>" /> + <?php if (isset($err['suspended_attribute'])) { echo $OUTPUT->error_text($err['suspended_attribute']); } ?> + </td> + <td> + <?php print_string('auth_ldap_suspended_attribute', 'auth_ldap') ?> + </td> +</tr> <tr valign="top" class="required"> <td align="right"> <label for="memberattribute"><?php print_string('auth_ldap_memberattribute_key', 'auth_ldap') ?></label> @@ -564,6 +582,17 @@ if (!ldap_paged_results_supported($config->ldap_version)) { <?php print_string('sync_script_createuser_enabled', 'auth_ldap_syncplus') ?> </td> </tr> +<tr valign="top"> + <td align="right"> + <label for="menusync_suspended"><?php print_string('auth_sync_suspended_key', 'auth') ?></label> + </td> + <td> + <?php echo html_writer::select($yesno, 'sync_suspended', $config->sync_suspended, false); ?> + </td> + <td> + <?php print_string('auth_sync_suspended', 'auth'); ?> + </td> +</tr> <tr> <td colspan="2"> <h4><?php print_string('auth_ntlmsso', 'auth_ldap') ?></h4> diff --git a/version.php b/version.php index c0fbc5b..c008fa1 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'auth_ldap_syncplus'; -$plugin->version = 2016032000; -$plugin->release = 'v3.0-r3'; -$plugin->requires = 2015111600; +$plugin->version = 2016071900; +$plugin->release = 'v3.1-r1'; +$plugin->requires = 2016052300; $plugin->maturity = MATURITY_STABLE; -$plugin->dependencies = array('auth_ldap' => 2015111600); +$plugin->dependencies = array('auth_ldap' => 2016052300); -- GitLab