Skip to content

Commit

Permalink
Merge branch 'MDL-67753-master' of git://github.com/jleyva/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed May 7, 2020
2 parents 301cd3e + 37bd67f commit 7bf6fd4
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 14 deletions.
10 changes: 1 addition & 9 deletions admin/tool/mobile/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,7 @@ public function test_get_potential_config_issues() {
$CFG->debugdisplay = 1;
set_config('debugauthdb', 1, 'auth_db');
set_config('debugdb', 1, 'enrol_database');
$expectedissues = array('nohttpsformobilewarning', 'invaliduserquotawarning', 'adodbdebugwarning', 'displayerrorswarning',
'mobilenotificationsdisabledwarning');

$processors = get_message_processors();
foreach ($processors as $processor => $status) {
if ($processor == 'airnotifier' && $status->enabled) {
unset($expectedissues['mobilenotificationsdisabledwarning']);
}
}
$expectedissues = array('nohttpsformobilewarning', 'invaliduserquotawarning', 'adodbdebugwarning', 'displayerrorswarning');

$issues = api::get_potential_config_issues();
$this->assertCount(count($expectedissues), $issues);
Expand Down
8 changes: 8 additions & 0 deletions lib/classes/hub/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,14 @@ public static function confirm_registration($token, $newtoken, $hubname) {
api::update_registration($siteinfo);
self::$registration = null;
}

// Finally, allow other plugins to perform actions once a site is registered for first time.
$pluginsfunction = get_plugins_with_function('post_site_registration_confirmed');
foreach ($pluginsfunction as $plugins) {
foreach ($plugins as $pluginfunction) {
$pluginfunction($registration->id);
}
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions message/output/airnotifier/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
*/
class message_airnotifier_manager {

/** @var string The Airnotifier public instance URL */
const AIRNOTIFIER_PUBLICURL = 'https://messages.moodle.net';

/**
* Include the relevant javascript and language strings for the device
* toolbox YUI module
Expand Down
1 change: 0 additions & 1 deletion message/output/airnotifier/db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function xmldb_message_airnotifier_install() {

$provider = new stdClass();
$provider->name = 'airnotifier';
$provider->enabled = 0;
$DB->insert_record('message_processors', $provider);

return $result;
Expand Down
50 changes: 50 additions & 0 deletions message/output/airnotifier/lib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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/>.

/**
* Callbacks for message_airnotifier.
*
* @package message_airnotifier
* @category external
* @copyright 2020 Moodle Pty Ltd <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.9
*/

/**
* Callback for when a site is first registered. The function generates an Airnotifier accesskey for the new site.
*
* @param int $registrationid the new registration id (registration_hubs table)
*/
function message_airnotifier_post_site_registration_confirmed(int $registrationid) {
global $CFG;

// Do nothing if the site already has an Airnotifier access key configured.
if (!empty($CFG->airnotifieraccesskey)) {
return;
}

$manager = new message_airnotifier_manager();

// Do nothing for custom Airnotifier instances.
if (strpos($CFG->airnotifierurl, $manager::AIRNOTIFIER_PUBLICURL) === false ) {
return;
}

if ($key = $manager->request_accesskey()) {
set_config('airnotifieraccesskey', $key);
}
}
4 changes: 1 addition & 3 deletions message/output/airnotifier/requestaccesskey.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

require('../../../config.php');

define('AIRNOTIFIER_PUBLICURL', 'https://messages.moodle.net');

$PAGE->set_url(new moodle_url('/message/output/airnotifier/requestaccesskey.php'));
$PAGE->set_context(context_system::instance());

Expand All @@ -48,7 +46,7 @@

// If we are requesting a key to the official message system, verify first that this site is registered.
// This check is also done in Airnotifier.
if (strpos($CFG->airnotifierurl, AIRNOTIFIER_PUBLICURL) !== false ) {
if (strpos($CFG->airnotifierurl, message_airnotifier_manager::AIRNOTIFIER_PUBLICURL) !== false ) {
$adminrenderer = $PAGE->get_renderer('core', 'admin');
$msg = $adminrenderer->warn_if_not_registered();
if ($msg) {
Expand Down
3 changes: 2 additions & 1 deletion message/output/airnotifier/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
// The processor should be enabled by the same enable mobile setting.
$settings->add(new admin_setting_configtext('airnotifierurl',
get_string('airnotifierurl', 'message_airnotifier'),
get_string('configairnotifierurl', 'message_airnotifier'), 'https://messages.moodle.net', PARAM_URL));
get_string('configairnotifierurl', 'message_airnotifier'), message_airnotifier_manager::AIRNOTIFIER_PUBLICURL,
PARAM_URL));
$settings->add(new admin_setting_configtext('airnotifierport',
get_string('airnotifierport', 'message_airnotifier'),
get_string('configairnotifierport', 'message_airnotifier'), 443, PARAM_INT));
Expand Down

0 comments on commit 7bf6fd4

Please sign in to comment.