Skip to content

Commit

Permalink
MDL-77973 core: fix broken navigation when moodlenet misconfigured
Browse files Browse the repository at this point in the history
Instead of failing with an exception, throw a debugging notice.
  • Loading branch information
snake committed Apr 20, 2023
1 parent 05a0d7c commit fffc7eb
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4884,17 +4884,22 @@ protected function load_module_settings() {
// Send to MoodleNet.
$usercanshare = utilities::can_user_share($this->context->get_course_context(), $USER->id);
$issuerid = get_config('moodlenet', 'oauthservice');
$issuer = \core\oauth2\api::get_issuer($issuerid);
$isvalidinstance = utilities::is_valid_instance($issuer);
if ($usercanshare && $isvalidinstance) {
$this->page->requires->js_call_amd('core/moodlenet/send_resource', 'init');
$action = new action_link(new moodle_url(''), '', null, [
'data-action' => 'sendtomoodlenet',
'data-type' => 'activity',
'data-sharetype' => 'resource',
]);
$modulenode->add(get_string('moodlenet:sharetomoodlenet', 'moodle'),
$action, self::TYPE_SETTING, null, 'exportmoodlenet')->set_force_into_more_menu(true);
try {
$issuer = \core\oauth2\api::get_issuer($issuerid);
$isvalidinstance = utilities::is_valid_instance($issuer);
if ($usercanshare && $isvalidinstance) {
$this->page->requires->js_call_amd('core/moodlenet/send_resource', 'init');
$action = new action_link(new moodle_url(''), '', null, [
'data-action' => 'sendtomoodlenet',
'data-type' => 'activity',
'data-sharetype' => 'resource',
]);
$modulenode->add(get_string('moodlenet:sharetomoodlenet', 'moodle'),
$action, self::TYPE_SETTING, null, 'exportmoodlenet')->set_force_into_more_menu(true);
}
} catch (dml_missing_record_exception $e) {
debugging("Invalid MoodleNet OAuth 2 service set in site administration: 'moodlenet | oauthservice'. " .
"This must be a valid issuer.");
}

// Remove the module node if there are no children.
Expand Down

0 comments on commit fffc7eb

Please sign in to comment.