mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 00:16:46 +02:00
MDL-65518 badges: Admin settings warning
If the backpack is changed to Open Badges V2 backpack, attempt the authenticate with the site settings and return a warning if it fails.
This commit is contained in:
parent
5c159cb309
commit
d48a52ddb1
5 changed files with 47 additions and 2 deletions
|
@ -105,6 +105,13 @@ if (($hassiteconfig || has_any_capability(array(
|
|||
new lang_string('sitebackpack_help', 'badges'),
|
||||
1, $choices));
|
||||
|
||||
$warning = badges_verify_site_backpack();
|
||||
if (!empty($warning)) {
|
||||
$backpacksettings->add(new admin_setting_description('badges_site_backpack_verify',
|
||||
new lang_string('sitebackpackverify', 'badges'),
|
||||
$warning));
|
||||
}
|
||||
|
||||
$ADMIN->add('badges', $backpacksettings);
|
||||
|
||||
$ADMIN->add('badges',
|
||||
|
|
|
@ -70,6 +70,7 @@ class external_backpacks_page implements \renderable {
|
|||
}
|
||||
$data->backpacks[] = $backpack;
|
||||
}
|
||||
$data->warning = badges_verify_site_backpack();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
{
|
||||
"backpacks": [
|
||||
{"backpackweburl": "http://localhost/", "sitebackpack": true, "canedit": false}
|
||||
]
|
||||
],
|
||||
"warning": "<span class='text-warning'>Could not login</span>"
|
||||
}
|
||||
}}
|
||||
<table class="generaltable fullwidth">
|
||||
|
@ -54,3 +55,4 @@
|
|||
{{/backpacks}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{{warning}}}
|
||||
|
|
|
@ -503,7 +503,9 @@ $string['selectgroup_start'] = 'Select collections from your backpack to display
|
|||
$string['selecting'] = 'With selected badges...';
|
||||
$string['setup'] = 'Set up connection';
|
||||
$string['sitebackpack'] = 'Active external backpack';
|
||||
$string['sitebackpack_help'] = 'An external backpack allows users to share their badges. Only one external backpack can be selected for the site. Changing this setting after users have connected their backpacks will require each user to disconnect and reconnect from their backpack settings page.';
|
||||
$string['sitebackpack_help'] = 'An external backpack allows users to share their badges. Only one external backpack can be active for the site. Changing this setting after users have connected their backpacks will require each user to disconnect and reconnect from their backpack settings page.';
|
||||
$string['sitebackpackverify'] = 'Backpack connection';
|
||||
$string['sitebackpackwarning'] = 'Could not connect to backpack. <br/><br/>Check that the "Badge issuer email address" admin setting is the valid email for an account on the backpack website. <br/><br/>Check that the "Badge issuer password" on the <a href="{$a->url}">site backpack settings page</a>, is the correct password for the account on the backpack website. <br/><br/>The backpack returned: "{$a->warning}"';
|
||||
$string['sitebadges'] = 'Site badges';
|
||||
$string['sitebadges_help'] = 'Site badges can only be awarded to users for site-related activities. These include completing a set of courses or parts of user profiles. Site badges can also be issued manually by one user to another.
|
||||
|
||||
|
|
|
@ -1167,3 +1167,36 @@ function badge_assemble_notification(stdClass $badge) {
|
|||
message_send($eventdata);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to authenticate with the site backpack credentials and return an error
|
||||
* if the authentication fails.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function badges_verify_site_backpack() {
|
||||
global $OUTPUT, $CFG;
|
||||
|
||||
if (empty($CFG->badges_allowexternalbackpack)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$backpack = badges_get_site_backpack($CFG->badges_site_backpack);
|
||||
|
||||
if (empty($backpack->apiversion) || ($backpack->apiversion == OPEN_BADGES_V2)) {
|
||||
$backpackapi = new \core_badges\backpack_api($backpack);
|
||||
|
||||
$result = $backpackapi->authenticate();
|
||||
if ($result === false || !empty($result->error)) {
|
||||
$warning = $backpackapi->get_authentication_error();
|
||||
|
||||
$params = ['id' => $backpack->id, 'action' => 'edit'];
|
||||
$backpackurl = (new moodle_url('/badges/backpacks.php', $params))->out(false);
|
||||
|
||||
$message = get_string('sitebackpackwarning', 'badges', ['url' => $backpackurl, 'warning' => $warning]);
|
||||
$icon = $OUTPUT->pix_icon('i/warning', get_string('warning', 'moodle'));
|
||||
return $OUTPUT->container($icon . $message, 'text-error');
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue