From ef1b8d05f6ed849a3c8cbbab86e06fe476aa10d6 Mon Sep 17 00:00:00 2001 From: raortegar Date: Wed, 26 Mar 2025 09:49:38 +0100 Subject: [PATCH] MDL-84009 tool_mfa: Additional factor instances support --- admin/tool/mfa/action.php | 11 +++++++++ .../local/factor/object_factor_base.php | 24 +++++++++++++++++++ admin/tool/mfa/lang/en/tool_mfa.php | 1 + 3 files changed, 36 insertions(+) diff --git a/admin/tool/mfa/action.php b/admin/tool/mfa/action.php index 060d1ae6c54..9dc9eb333cc 100644 --- a/admin/tool/mfa/action.php +++ b/admin/tool/mfa/action.php @@ -169,6 +169,17 @@ switch ($action) { echo $OUTPUT->heading(get_string('managefactor', 'factor_' . $factorobject->name)); echo $OUTPUT->active_factors($factor); echo $OUTPUT->single_button($returnurl, get_string('back')); + + // Displays a setup additional button in case it is needed. + if ($factorobject->show_additional_setup_button()) { + echo $OUTPUT->single_button( + url: new \moodle_url('action.php', ['action' => 'setup', 'factor' => $factor]), + label: $factorobject->get_additional_setup_string(), + method: 'post', + options: ['type' => 'primary'], + ); + } + // JS for modal confirming replace and revoke actions. $PAGE->requires->js_call_amd('tool_mfa/confirmation_modal', 'init', [$context->id]); diff --git a/admin/tool/mfa/classes/local/factor/object_factor_base.php b/admin/tool/mfa/classes/local/factor/object_factor_base.php index d60ff420488..b1fb205889a 100644 --- a/admin/tool/mfa/classes/local/factor/object_factor_base.php +++ b/admin/tool/mfa/classes/local/factor/object_factor_base.php @@ -421,6 +421,18 @@ abstract class object_factor_base implements object_factor { return $this->has_setup(); } + /** + * Returns true if a button should be shown to add factors of the same kind on the preferences page. + * For example, give user's the ability to set up multiple security keys. + * + * Override in child class if necessary. + * + * @return bool + */ + public function show_additional_setup_button(): bool { + return false; + } + /** * Returns true if a factor requires input from the user to verify. * @@ -578,6 +590,18 @@ abstract class object_factor_base implements object_factor { return get_string('setupfactor', 'tool_mfa'); } + /** + * Gets the string for additional setup button on preferences page. + * If the user has the ability to set up multiple security keys. + * + * Override in child class if necessary. + * + * @return string + */ + public function get_additional_setup_string(): string { + return get_string('setupfactorbuttonadditional', 'tool_mfa'); + } + /** * Gets the string for manage button on preferences page. * diff --git a/admin/tool/mfa/lang/en/tool_mfa.php b/admin/tool/mfa/lang/en/tool_mfa.php index 9ff23fb2165..606329f82f3 100644 --- a/admin/tool/mfa/lang/en/tool_mfa.php +++ b/admin/tool/mfa/lang/en/tool_mfa.php @@ -151,6 +151,7 @@ $string['settings:redir_exclusions_help'] = 'Each new line is a relative URL fro $string['settings:weight'] = 'Factor weight'; $string['settings:weight_help'] = 'The weight of this factor if passed. A user needs at least 100 points to log in.'; $string['setupfactor'] = 'Set up factor'; +$string['setupfactorbuttonadditional'] = 'Add additional factor'; $string['setuprequired'] = 'User setup'; $string['state:fail'] = 'Fail'; $string['state:locked'] = 'Locked';