From 6ed86eca7a9677c0e114841c7ceaf1926cb6a442 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 20 Dec 2019 13:30:40 +1300 Subject: [PATCH] MDL-63734 adminlib: Hide password when defined in config.php This will hide the password on admin_setting_configpasswordunmask fields when it is already defined in config.php --- .../setting_configpasswordunmask.mustache | 18 +++++++++++++++++- lib/adminlib.php | 16 ++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/admin/templates/setting_configpasswordunmask.mustache b/admin/templates/setting_configpasswordunmask.mustache index 8cb2d661ae49a..7092e820a65d1 100644 --- a/admin/templates/setting_configpasswordunmask.mustache +++ b/admin/templates/setting_configpasswordunmask.mustache @@ -24,15 +24,30 @@ * size - form element size * value - form element value * id - element id + * forced - has value been defined in config.php Example context (json): { "name": "test", "id": "test0", "size": "8", - "value": "secret" + "value": "secret", + "forced": false } }} +{{#forced}} +
+ +
+{{/forced}} +{{^forced}}
@@ -61,3 +76,4 @@ require(['core_form/passwordunmask'], function(PasswordUnmask) { new PasswordUnmask("{{ id }}"); }); {{/js}} +{{/forced}} diff --git a/lib/adminlib.php b/lib/adminlib.php index 1f731a46f6eb0..1b1aaf188f13f 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -2641,13 +2641,25 @@ protected function add_to_config_log($name, $oldvalue, $value) { * @return string Rendered HTML */ public function output_html($data, $query='') { - global $OUTPUT; + global $OUTPUT, $CFG; + $forced = false; + if (empty($this->plugin)) { + if (array_key_exists($this->name, $CFG->config_php_settings)) { + $forced = true; + } + } else { + if (array_key_exists($this->plugin, $CFG->forced_plugin_settings) + and array_key_exists($this->name, $CFG->forced_plugin_settings[$this->plugin])) { + $forced = true; + } + } $context = (object) [ 'id' => $this->get_id(), 'name' => $this->get_full_name(), 'size' => $this->size, - 'value' => $data, + 'value' => $forced ? null : $data, 'forceltr' => $this->get_force_ltr(), + 'forced' => $forced ]; $element = $OUTPUT->render_from_template('core_admin/setting_configpasswordunmask', $context); return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', null, $query);