mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 21:45:37 +02:00
MDL-81924 smsgateway_aws: Add hooks for SMS gateway management
Originally implemented as MDL-81732. Co-authored by: Michael Hawkins <michaelh@moodle.com>
This commit is contained in:
parent
a1209ab882
commit
3348832b78
110
sms/gateway/aws/classes/hook_listener.php
Normal file
110
sms/gateway/aws/classes/hook_listener.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace smsgateway_aws;
|
||||
|
||||
use core_sms\hook\after_sms_gateway_form_hook;
|
||||
|
||||
/**
|
||||
* Hook listener for aws sms gateway.
|
||||
*
|
||||
* @package smsgateway_aws
|
||||
* @copyright 2024 Safat Shahin <safat.shahin@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class hook_listener {
|
||||
|
||||
/**
|
||||
* Hook listener for the sms gateway setup form.
|
||||
*
|
||||
* @param after_sms_gateway_form_hook $hook The hook to add to sms gateway setup.
|
||||
*/
|
||||
public static function set_form_definition_for_aws_sms_gateway(after_sms_gateway_form_hook $hook): void {
|
||||
if ($hook->plugin !== 'smsgateway_aws') {
|
||||
return;
|
||||
}
|
||||
|
||||
$mform = $hook->mform;
|
||||
|
||||
$mform->addElement('static', 'information', get_string('aws_information', 'smsgateway_aws'));
|
||||
|
||||
$gateways = [
|
||||
'aws_sns' => get_string('aws_sns', 'smsgateway_aws'),
|
||||
];
|
||||
$mform->addElement(
|
||||
'select',
|
||||
'gateway',
|
||||
get_string('gateway', 'smsgateway_aws'),
|
||||
$gateways,
|
||||
);
|
||||
$mform->setDefault(
|
||||
elementName: 'gateway',
|
||||
defaultValue: 'aws_sns',
|
||||
);
|
||||
// Remove this if more aws gateway implemented, eg sqs.
|
||||
$mform->hardFreeze('gateway');
|
||||
|
||||
$mform->addElement(
|
||||
'checkbox',
|
||||
'usecredchain',
|
||||
get_string('usecredchain', 'smsgateway_aws'),
|
||||
' ',
|
||||
);
|
||||
$mform->setDefault(
|
||||
elementName: 'usecredchain',
|
||||
defaultValue: 0,
|
||||
);
|
||||
|
||||
$mform->addElement(
|
||||
'text',
|
||||
'api_key',
|
||||
get_string('api_key', 'smsgateway_aws'),
|
||||
'maxlength="255" size="20"',
|
||||
);
|
||||
$mform->setType('api_key', PARAM_TEXT);
|
||||
$mform->addRule('api_key', get_string('maximumchars', '', 255), 'maxlength', 255);
|
||||
$mform->setDefault(
|
||||
elementName: 'api_key',
|
||||
defaultValue: '',
|
||||
);
|
||||
$mform->addElement(
|
||||
'passwordunmask',
|
||||
'api_secret',
|
||||
get_string('api_secret', 'smsgateway_aws'),
|
||||
'maxlength="255" size="20"',
|
||||
);
|
||||
$mform->setType('api_secret', PARAM_TEXT);
|
||||
$mform->addRule('api_secret', get_string('maximumchars', '', 255), 'maxlength', 255);
|
||||
$mform->setDefault(
|
||||
elementName: 'api_secret',
|
||||
defaultValue: '',
|
||||
);
|
||||
|
||||
$mform->addElement(
|
||||
'text',
|
||||
'api_region',
|
||||
get_string('api_region', 'smsgateway_aws'),
|
||||
'maxlength="255" size="20"',
|
||||
);
|
||||
$mform->setType('api_region', PARAM_TEXT);
|
||||
$mform->addRule('api_region', get_string('maximumchars', '', 255), 'maxlength', 255);
|
||||
$mform->setDefault(
|
||||
elementName: 'api_region',
|
||||
defaultValue: 'ap-southeast-2',
|
||||
);
|
||||
}
|
||||
|
||||
}
|
32
sms/gateway/aws/db/hooks.php
Normal file
32
sms/gateway/aws/db/hooks.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Hook listener callbacks for aws sms gateway.
|
||||
*
|
||||
* @package smsgateway_aws
|
||||
* @copyright 2024 Safat Shahin <safat.shahin@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$callbacks = [
|
||||
[
|
||||
'hook' => \core_sms\hook\after_sms_gateway_form_hook::class,
|
||||
'callback' => \smsgateway_aws\hook_listener::class . '::set_form_definition_for_aws_sms_gateway',
|
||||
],
|
||||
];
|
@ -22,21 +22,13 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['api_key'] = 'Key';
|
||||
$string['api_key_help'] = 'Amazon API key credential.';
|
||||
$string['api_region'] = 'Region';
|
||||
$string['api_region_help'] = 'Amazon API gateway region.';
|
||||
$string['api_secret'] = 'Secret';
|
||||
$string['api_secret_help'] = 'Amazon API secret credential.';
|
||||
$string['api_key'] = 'Access key';
|
||||
$string['api_region'] = 'Amazon API gateway region';
|
||||
$string['api_secret'] = 'Secret access key';
|
||||
$string['aws_information'] = 'Complete the following fields using the information provided by AWS';
|
||||
$string['aws_sns'] = 'AWS SNS';
|
||||
$string['countrycode'] = 'Country number code';
|
||||
$string['countrycode_help'] = 'The calling code without the leading + as a default if users do not enter an international number with a + prefix.
|
||||
|
||||
See this link for a list of calling codes: {$a}';
|
||||
$string['gateway'] = 'SMS Gateway';
|
||||
$string['gateway_help'] = 'The SMS provider you wish to send messages via';
|
||||
$string['gateway'] = 'AWS service';
|
||||
$string['aws_information'] = 'Complete the following fields using the information provided by AWS';
|
||||
$string['pluginname'] = 'AWS';
|
||||
$string['privacy:metadata'] = 'The AWS SMS gateway plugin does not store any personal data.';
|
||||
$string['usecredchain'] = 'Find AWS credentials using the default credential provider chain';
|
||||
|
||||
|
||||
$string['usecredchain'] = 'Find AWS credentials using the default provider chain';
|
||||
|
@ -32,9 +32,22 @@ class gateway_test extends \advanced_testcase {
|
||||
public function test_update_message_status(): void {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$config = new \stdClass();
|
||||
$config->api_key = 'test_api_key';
|
||||
|
||||
$manager = \core\di::get(\core_sms\manager::class);
|
||||
$gw = $manager->create_gateway_instance(gateway::class, true);
|
||||
$othergw = $manager->create_gateway_instance(gateway::class, true);
|
||||
$gw = $manager->create_gateway_instance(
|
||||
classname: gateway::class,
|
||||
name: 'aws',
|
||||
enabled: true,
|
||||
config: $config,
|
||||
);
|
||||
$othergw = $manager->create_gateway_instance(
|
||||
classname: gateway::class,
|
||||
name: 'aws',
|
||||
enabled: true,
|
||||
config: $config,
|
||||
);
|
||||
|
||||
$message = new message(
|
||||
recipientnumber: '1234567890',
|
||||
@ -42,7 +55,7 @@ class gateway_test extends \advanced_testcase {
|
||||
component: 'smsgateway_aws',
|
||||
messagetype: 'test',
|
||||
recipientuserid: null,
|
||||
sensitive: false,
|
||||
issensitive: false,
|
||||
gatewayid: $gw->id,
|
||||
);
|
||||
$message2 = new message(
|
||||
@ -51,7 +64,7 @@ class gateway_test extends \advanced_testcase {
|
||||
component: 'smsgateway_aws',
|
||||
messagetype: 'test',
|
||||
recipientuserid: null,
|
||||
sensitive: false,
|
||||
issensitive: false,
|
||||
gatewayid: $gw->id,
|
||||
);
|
||||
|
||||
|
@ -25,6 +25,6 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = 'smsgateway_aws';
|
||||
$plugin->version = 2024042200;
|
||||
$plugin->version = 2024082200;
|
||||
$plugin->requires = 2024041600;
|
||||
$plugin->maturity = MATURITY_STABLE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user