1
0
mirror of https://github.com/moodle/moodle.git synced 2025-03-20 07:30:01 +01:00

MDL-78072 airnotifier: Allow to set publickey when creating new device

Backport of MDL-77893.

Co-authored by: Andrew Lyons <andrew@nicols.co.uk>
This commit is contained in:
Juan Leyva 2023-04-17 11:03:15 +02:00 committed by Andrew Nicols
parent 1201526dbc
commit 2ad6fecca5
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
3 changed files with 20 additions and 8 deletions

@ -24,7 +24,6 @@
*/
defined('MOODLE_INTERNAL') || die();
require_once("$CFG->libdir/externallib.php");
/**
@ -1260,7 +1259,8 @@ class core_user_external extends external_api {
'platform' => new external_value(PARAM_NOTAGS, 'the device platform \'iOS\' or \'Android\' etc.'),
'version' => new external_value(PARAM_NOTAGS, 'the device version \'6.1.2\' or \'4.2.2\' etc.'),
'pushid' => new external_value(PARAM_RAW, 'the device PUSH token/key/identifier/registration id'),
'uuid' => new external_value(PARAM_RAW, 'the device UUID')
'uuid' => new external_value(PARAM_RAW, 'the device UUID'),
'publickey' => new external_value(PARAM_RAW, 'the app generated public key', VALUE_DEFAULT, null),
)
);
}
@ -1276,10 +1276,11 @@ class core_user_external extends external_api {
* @param string $version The device version 6.1.2 or 4.2.2 etc.
* @param string $pushid The device PUSH token/key/identifier/registration id.
* @param string $uuid The device UUID.
* @param string $publickey The app generated public key
* @return array List of possible warnings.
* @since Moodle 2.6
*/
public static function add_user_device($appid, $name, $model, $platform, $version, $pushid, $uuid) {
public static function add_user_device($appid, $name, $model, $platform, $version, $pushid, $uuid, $publickey = null) {
global $CFG, $USER, $DB;
require_once($CFG->dirroot . "/user/lib.php");
@ -1290,7 +1291,8 @@ class core_user_external extends external_api {
'platform' => $platform,
'version' => $version,
'pushid' => $pushid,
'uuid' => $uuid
'uuid' => $uuid,
'publickey' => $publickey,
));
$warnings = array();
@ -1313,6 +1315,7 @@ class core_user_external extends external_api {
foreach ($userdevices as $userdevice) {
$userdevice->version = $params['version']; // Maybe the user upgraded the device.
$userdevice->pushid = $params['pushid'];
$userdevice->publickey = $params['publickey'];
$userdevice->timemodified = time();
$DB->update_record('user_devices', $userdevice);
}
@ -1327,6 +1330,7 @@ class core_user_external extends external_api {
$userdevice->version = $params['version'];
$userdevice->pushid = $params['pushid'];
$userdevice->uuid = $params['uuid'];
$userdevice->publickey = $params['publickey'];
$userdevice->timecreated = time();
$userdevice->timemodified = $userdevice->timecreated;

@ -16,7 +16,12 @@
namespace core_user\external;
use core_external\external_api;
global $CFG;
defined('MOODLE_INTERNAL') || die();
require_once("{$CFG->libdir}/externallib.php");
use external_api;
use stdClass;
/**

@ -29,6 +29,7 @@ namespace core_user;
use core_files_external;
use core_user_external;
use externallib_advanced_testcase;
use external_api;
defined('MOODLE_INTERNAL') || die();
@ -1085,7 +1086,8 @@ class externallib_test extends externallib_advanced_testcase {
'platform' => 'Android',
'version' => '4.2.2',
'pushid' => 'apushdkasdfj4835',
'uuid' => 'asdnfl348qlksfaasef859'
'uuid' => 'asdnfl348qlksfaasef859',
'publickey' => null,
);
// Call the external function.
@ -1106,9 +1108,10 @@ class externallib_test extends externallib_advanced_testcase {
// Test update an existing device.
$device['pushid'] = 'different than before';
$device['publickey'] = 'MFsxCzAJBgNVBAYTAkZSMRMwEQYDVQQ';
$warnings = core_user_external::add_user_device($device['appid'], $device['name'], $device['model'], $device['platform'],
$device['version'], $device['pushid'], $device['uuid']);
$warnings = \external_api::clean_returnvalue(core_user_external::add_user_device_returns(), $warnings);
$device['version'], $device['pushid'], $device['uuid'], $device['publickey']);
$warnings = external_api::clean_returnvalue(core_user_external::add_user_device_returns(), $warnings);
$this->assertEquals(1, $DB->count_records('user_devices'));
$updated = $DB->get_record('user_devices', array('pushid' => $device['pushid']));