From 1f66c92a1a09f16e38c19316e9d8362245862654 Mon Sep 17 00:00:00 2001 From: Michael Hawkins Date: Thu, 26 Sep 2024 14:27:25 +0800 Subject: [PATCH 1/2] MDL-82939 core_sms: Add class to the SMS table This makes it possible to reference in behat table steps. --- sms/classes/table/sms_gateway_table.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sms/classes/table/sms_gateway_table.php b/sms/classes/table/sms_gateway_table.php index d3f94340cca..d063482ce9b 100644 --- a/sms/classes/table/sms_gateway_table.php +++ b/sms/classes/table/sms_gateway_table.php @@ -49,6 +49,8 @@ class sms_gateway_table extends flexible_table implements dynamic_table { $this->setup_column_configuration(); $this->set_filterset(new sms_gateway_table_filterset()); $this->setup(); + $tableclasses = $this->attributes['class'] . ' ' . $this->get_table_id(); + $this->set_attribute('class', $tableclasses); } #[\Override] From c7810fd7ce3213a15d6061734b11923c91dc0c29 Mon Sep 17 00:00:00 2001 From: Michael Hawkins Date: Thu, 26 Sep 2024 03:09:11 +0800 Subject: [PATCH 2/2] MDL-82939 core_sms: Update lang strings Also fixed a bug where the gateways page didnt render the correct title. --- .../sms/tests/behat/factor_sms_setup.feature | 2 +- .../behat/factor_sms_setup_gateway.feature | 8 ++--- lang/en/sms.php | 18 +++++------ sms/classes/form/sms_gateway_form.php | 2 -- sms/configure.php | 32 ++++++++++--------- sms/sms_gateways.php | 17 ++++++---- sms/templates/sms_gateways.mustache | 3 ++ sms/tests/behat/list_sms_gateways.feature | 15 +++++---- 8 files changed, 52 insertions(+), 45 deletions(-) diff --git a/admin/tool/mfa/factor/sms/tests/behat/factor_sms_setup.feature b/admin/tool/mfa/factor/sms/tests/behat/factor_sms_setup.feature index 8b75e1ad6ff..c072fa5ad0c 100644 --- a/admin/tool/mfa/factor/sms/tests/behat/factor_sms_setup.feature +++ b/admin/tool/mfa/factor/sms/tests/behat/factor_sms_setup.feature @@ -7,7 +7,7 @@ Feature: Set up SMS factor in user preferences Background: Given I log in as "admin" And I navigate to "Plugins > SMS > Manage SMS gateways" in site administration - And I follow "Create a new SMS gateway" + And I follow "Create new SMS gateway" And I set the following fields to these values: | SMS gateway provider | AWS | | Gateway name | Dummy gateway | diff --git a/admin/tool/mfa/factor/sms/tests/behat/factor_sms_setup_gateway.feature b/admin/tool/mfa/factor/sms/tests/behat/factor_sms_setup_gateway.feature index 909f77409a9..3314535d526 100644 --- a/admin/tool/mfa/factor/sms/tests/behat/factor_sms_setup_gateway.feature +++ b/admin/tool/mfa/factor/sms/tests/behat/factor_sms_setup_gateway.feature @@ -18,11 +18,11 @@ Feature: Set up SMS factor when relevant gateway is not configured Then I should see "To use SMS as an authentication factor, you first need to set up an SMS gateway." And I should see "set up an SMS gateway" And I follow "set up an SMS gateway" - And I should see "Configure SMS gateway" + And I should see "Create new SMS gateway" And I set the following fields to these values: | SMS gateway provider | AWS | | Gateway name | First AWS gateway | - | Country code | 61 | + | Default country code | 61 | | Access key | key123 | | Secret access key | secret456 | | Amazon API gateway region | ap-southeast-2 | @@ -30,11 +30,11 @@ Feature: Set up SMS factor when relevant gateway is not configured And I should see "SMS mobile phone" And the "SMS gateway" select box should contain "First AWS gateway (AWS)" And I follow "create a new gateway" - And I should see "Configure SMS gateway" + And I should see "Create new SMS gateway" And I set the following fields to these values: | SMS gateway provider | AWS | | Gateway name | Second one | - | Country code | 1 | + | Default country code | 1 | | Access key | key1234 | | Secret access key | secret4567 | | Amazon API gateway region | ap-southeast-2 | diff --git a/lang/en/sms.php b/lang/en/sms.php index 3a11332facf..6e0c3c1a3cb 100644 --- a/lang/en/sms.php +++ b/lang/en/sms.php @@ -23,12 +23,12 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ $string['actions'] = 'Actions'; -$string['configure_sms_gateway'] = 'Configure SMS gateway'; -$string['countrycode'] = 'Country code'; -$string['countrycode_help'] = 'Set the default phone number format to exclude the "+" symbol if user does not enter an international number with it.'; -$string['createnewgateway'] = 'Create a new SMS gateway'; +$string['countrycode'] = 'Default country code'; +$string['countrycode_help'] = 'Country code to be added to phone numbers if users don\'t enter their own country code. Enter the number without the leading \'+\' symbol.'; +$string['createnewgateway'] = 'Create new SMS gateway'; $string['delete_sms_gateway'] = 'Delete SMS gateway'; -$string['delete_sms_gateway_confirmation'] = 'Are you sure you want to delete the {$a->gateway} SMS gateway?'; +$string['delete_sms_gateway_confirmation'] = 'This will delete the {$a->gateway} SMS gateway.'; +$string['edit_sms_gateway'] = 'Edit {$a->gateway} SMS gateway'; $string['gateway'] = 'Gateway'; $string['gateway_name'] = 'Gateway name'; $string['manage_sms_gateways'] = 'Manage SMS gateways'; @@ -41,8 +41,8 @@ $string['privacy:metadata:sms_messages:recipientuserid'] = 'The user who the mes $string['privacy:metadata:sms_messages:status'] = 'The status of the message'; $string['privacy:metadata:sms_messages:timecreated'] = 'The time the message was created'; $string['privacy:sms:sensitive_not_shown'] = 'The content of this message was not stored as it was marked as containing sensitive content.'; +$string['select_sms_gateways'] = 'SMS gateway provider'; $string['sms'] = 'SMS'; -$string['sms_form_information'] = 'This page allow you to set up and manage your SMS gateway for sending text messages.'; $string['status:gateway_failed'] = 'The gateway has failed to send the message'; $string['status:gateway_not_available'] = 'The gateway is not available to send the message'; $string['status:gateway_queued'] = 'The message is queued to be sent by the gateway'; @@ -50,8 +50,8 @@ $string['status:gateway_rejected'] = 'The gateway has rejected the message'; $string['status:gateway_sent'] = 'The message has been sent by the gateway'; $string['status:message_over_size'] = 'The message is too large to be sent by the gateway'; $string['status:unknown'] = 'Unable to determine the status of the message'; -$string['sms_gateways'] = 'SMS gateways'; -$string['sms_gateway_deleted'] = '{$a->gateway} SMS gateway has been deleted'; +$string['sms_gateway_deleted'] = '{$a->gateway} SMS gateway deleted'; $string['sms_gateway_delete_failed'] = 'Cannot delete the {$a->gateway} SMS gateway. The gateway is either in use or there\'s a database issue. Check if the gateway is active or contact your database administrator for help.'; $string['sms_gateway_disable_failed'] = 'Cannot disable the SMS gateway. The gateway is either in use or there\'s a database issue. Check if the gateway is active or contact your database administrator for help.'; -$string['select_sms_gateways'] = 'SMS gateway provider'; +$string['sms_gateways'] = 'SMS gateways'; +$string['sms_gateways_info'] = 'Create and manage SMS gateways to send SMS messages from your site.'; diff --git a/sms/classes/form/sms_gateway_form.php b/sms/classes/form/sms_gateway_form.php index 9f9265cda02..da30ffdf9ed 100644 --- a/sms/classes/form/sms_gateway_form.php +++ b/sms/classes/form/sms_gateway_form.php @@ -46,8 +46,6 @@ class sms_gateway_form extends moodleform { $smsplugins[$plugin] = get_string('pluginname', $plugin); } - $mform->addElement('static', 'information', get_string('sms_form_information', 'sms')); - $mform->addElement( 'select', 'smsgateway', diff --git a/sms/configure.php b/sms/configure.php index e2169323912..10110bcba34 100644 --- a/sms/configure.php +++ b/sms/configure.php @@ -32,6 +32,8 @@ $id = optional_param('id', null, PARAM_INT); $gateway = optional_param('smsgateway', null, PARAM_PLUGIN); $returnurl = optional_param('returnurl', null, PARAM_LOCALURL); +$title = get_string('createnewgateway', 'sms'); +$data = []; $urlparams = []; if ($id) { $urlparams['id'] = $id; @@ -40,21 +42,6 @@ if ($gateway) { $urlparams['gateway'] = $gateway; } -$title = get_string('configure_sms_gateway', 'sms'); -$PAGE->set_context($context); -$PAGE->set_url('/sms/configure.php', $urlparams); -$PAGE->set_title($title); -$PAGE->set_heading($title); - -if (empty($returnurl)) { - $returnurl = new moodle_url('/sms/sms_gateways.php'); -} else { - $returnurl = new moodle_url($returnurl); -} -$data = [ - 'returnurl' => $returnurl, -]; - if (!empty($gateway)) { $configs = new stdClass(); $configs->smsgateway = $gateway; @@ -77,8 +64,23 @@ if (!empty($id)) { $data = [ 'gatewayconfigs' => $configs, ]; + + $a = ['gateway' => $gatewayrecord->name]; + $title = get_string('edit_sms_gateway', 'sms', $a); } +$PAGE->set_context($context); +$PAGE->set_url('/sms/configure.php', $urlparams); +$PAGE->set_title($title); +$PAGE->set_heading($title); + +if (empty($returnurl)) { + $returnurl = new moodle_url('/sms/sms_gateways.php'); +} else { + $returnurl = new moodle_url($returnurl); +} +$data['returnurl'] = $returnurl; + $mform = new \core_sms\form\sms_gateway_form(customdata: $data); if ($mform->is_cancelled()) { diff --git a/sms/sms_gateways.php b/sms/sms_gateways.php index 881d72d6296..2686934544f 100644 --- a/sms/sms_gateways.php +++ b/sms/sms_gateways.php @@ -38,25 +38,24 @@ $confirm = optional_param('confirm', 0, PARAM_BOOL); // Set up the page. $title = get_string('sms_gateways', 'sms'); $returnurl = new moodle_url('/sms/sms_gateways.php'); +admin_externalpage_setup('smsgateway'); +$PAGE->set_primary_active_tab('siteadminnode'); +$PAGE->navbar->add($title, $returnurl); $PAGE->set_context($context); $PAGE->set_url($returnurl); $PAGE->set_title($title); $PAGE->set_heading($title); -admin_externalpage_setup('smsgateway'); -$PAGE->set_primary_active_tab('siteadminnode'); -$PAGE->navbar->add($title, $returnurl); - if (!empty($id) && !empty($action)) { $manager = \core\di::get(\core_sms\manager::class); $gatewayrecord = $manager->get_gateway_records(['id' => $id]); $gatewayrecord = reset($gatewayrecord); $pluginname = explode('\\', $gatewayrecord->gateway); $pluginname = $pluginname[0]; - $a = new stdClass(); - $a->gateway = get_string('pluginname', $pluginname); $gateway = $manager->get_gateway_instances(['id' => $id]); $gateway = reset($gateway); + $a = new stdClass(); + $a->gateway = $gateway->name; } if ($action === 'delete') { @@ -78,8 +77,12 @@ if ($action === 'delete') { echo $OUTPUT->header(); $yesurl = new moodle_url($returnurl, ['id' => $id, 'action' => 'delete', 'confirm' => 1]); + $deletedisplay = [ + 'confirmtitle' => get_string('deletecheck', '', $a->gateway), + 'continuestr' => get_string('delete'), + ]; $message = get_string('delete_sms_gateway_confirmation', 'sms', $a); - echo $OUTPUT->confirm($message, $yesurl, $returnurl); + echo $OUTPUT->confirm($message, $yesurl, $returnurl, $deletedisplay); echo $OUTPUT->footer(); die; } diff --git a/sms/templates/sms_gateways.mustache b/sms/templates/sms_gateways.mustache index d0081046fa5..508875456a9 100644 --- a/sms/templates/sms_gateways.mustache +++ b/sms/templates/sms_gateways.mustache @@ -27,6 +27,9 @@ } }} +
+ {{#str}}sms_gateways_info, sms{{/str}} +
 {{#str}}createnewgateway, sms{{/str}} diff --git a/sms/tests/behat/list_sms_gateways.feature b/sms/tests/behat/list_sms_gateways.feature index 3bdf14ef77f..d211e9a217d 100644 --- a/sms/tests/behat/list_sms_gateways.feature +++ b/sms/tests/behat/list_sms_gateways.feature @@ -15,9 +15,10 @@ Feature: Access the SMS gateways page Given I log in as "admin" And I navigate to "Plugins > SMS > Manage SMS gateways" in site administration And I should see "SMS gateways" - And I should see "Create a new SMS gateway" - And I should see "Default" - And I should see "Europe" + And I should see "Create new SMS gateway" + And I should see "Default" in the "sms_gateways_table" "table" + And I should see "Europe" in the "sms_gateways_table" "table" + And I should see "Europe" in the "sms_gateways_table" "table" And I should see "Disable Default" in the "Default" "table_row" And I should see "Disable Europe" in the "Europe" "table_row" When I toggle the "Disable Default" admin switch "off" @@ -26,7 +27,7 @@ Feature: Access the SMS gateways page And I should see "Edit" in the "Default" "table_row" And I should see "Delete" in the "Default" "table_row" And I click on "Delete" "link" in the "Default" "table_row" - And I should see "Are you sure you want to delete the AWS SMS gateway?" - And I click on "Continue" "button" - And I should see "AWS SMS gateway has been deleted" - And I should not see "Default" + And I should see "This will delete the Default SMS gateway." + And I click on "Delete" "button" + And I should see "Default SMS gateway deleted" + And I should not see "Default" in the "sms_gateways_table" "table"