This commit is contained in:
Sara Arjona 2024-09-30 07:41:37 +02:00
commit f608faef01
No known key found for this signature in database
9 changed files with 54 additions and 45 deletions

View File

@ -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 |

View File

@ -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 |

View File

@ -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.';

View File

@ -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',

View File

@ -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]

View File

@ -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()) {

View File

@ -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;
}

View File

@ -27,6 +27,9 @@
}
}}
<div class="d-flex mb-3">
{{#str}}sms_gateways_info, sms{{/str}}
</div>
<div class="d-flex flex-row-reverse">
<a href="{{createurl}}" title="{{#str}}createnewgateway, sms{{/str}}" class="btn btn-primary mb-3">
<i class="fa fa-plus"></i>&nbsp;{{#str}}createnewgateway, sms{{/str}}

View File

@ -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"