MDL-69792 core_badges: deprecated backpack.js and BADGE_BACKPACKURL

Final deprecation for constant BADGE_BACKPACKURL (it has been removed)
and badges/backpack.js file (it has been removed too).
Besides, some methods have started the deprecation process too:
 - badges_check_backpack_accessibility
 - badges_setup_backpack_js()
 - badges_local_backpack_js()

Apart from that, string 'addbackpack' has been deprecated here
because it's not used anywhere.
This commit is contained in:
Sara Arjona 2021-02-23 12:01:55 +01:00
parent 4c26696e7e
commit 50e9e5b2bd
10 changed files with 37 additions and 152 deletions

View File

@ -1,52 +0,0 @@
/**
* Push badges to backpack.
* @deprecated since 3.7
*/
function addtobackpack(event, args) {
var badgetable = Y.one('#issued-badge-table');
var errordiv = Y.one('#addtobackpack-error');
var errortext = M.util.get_string('error:backpackproblem', 'badges');
var errorhtml = '<div id="addtobackpack-error" class="box boxaligncenter notifyproblem">' + errortext + '</div>';
if (typeof OpenBadges !== 'undefined') {
OpenBadges.issue([args.assertion], function(errors, successes) { });
} else {
// Add error div if it doesn't exist yet.
if (!errordiv) {
var badgerror = Y.Node.create(errorhtml);
badgetable.insert(badgerror, 'before');
}
}
}
/**
* Check if website is externally accessible from the backpack.
* @deprecated since 3.7
*/
function check_site_access() {
var add = Y.one('#check_connection');
var callback = {
method: "GET",
on: {
success: function(id, o) {
var data = Y.JSON.parse(o.responseText);
if (data.code == 'http-unreachable') {
add.setHTML(data.response);
add.removeClass('hide');
}
M.util.js_complete('badge/backpack::check_site_access');
},
failure: function() {
M.util.js_complete('badge/backpack::check_site_access');
}
}
};
Y.use('io-base', function(Y) {
M.util.js_pending('badge/backpack::check_site_access');
Y.io('ajax.php', callback);
});
return false;
}

View File

@ -65,9 +65,6 @@ if (!empty($badge->recipient->id)) {
navigation_node::override_active_url($url);
}
// Include JS files for backpack support.
badges_setup_backpack_js();
echo $OUTPUT->header();
echo $output->render($badge);

View File

@ -104,7 +104,6 @@ if (!has_any_capability(array(
}
$PAGE->set_title($hdr);
badges_local_backpack_js(true);
$output = $PAGE->get_renderer('core', 'badges');
if (($delete || $archive) && has_capability('moodle/badges:deletebadge', $PAGE->context)) {

View File

@ -92,9 +92,6 @@ $PAGE->set_title($title);
$PAGE->set_heading(fullname($USER));
$PAGE->set_pagelayout('standard');
// Include JS files for backpack support.
badges_setup_backpack_js();
$output = $PAGE->get_renderer('core', 'badges');
$badges = badges_get_user_badges($USER->id);

View File

@ -61,8 +61,6 @@ if (($type == BADGE_TYPE_COURSE) && ($course = $DB->get_record('course', array('
require_capability('moodle/badges:createbadge', $PAGE->context);
badges_local_backpack_js(true);
$fordb = new stdClass();
$fordb->id = null;

View File

@ -83,17 +83,14 @@ class core_badges_renderer extends plugin_renderer_base {
$userbackpack = badges_get_user_backpack();
if (!empty($CFG->badges_allowexternalbackpack) && $notexpiredbadge && $userbackpack) {
$assertion = new moodle_url('/badges/assertion.php', array('b' => $badge->uniquehash));
$action = null;
if (badges_open_badges_backpack_api($userbackpack->id) == OPEN_BADGES_V1) {
$action = new component_action('click', 'addtobackpack', array('assertion' => $assertion->out(false)));
$addurl = new moodle_url('#');
$icon = new pix_icon('t/backpack', get_string('addtobackpack', 'badges'));
if (badges_open_badges_backpack_api($userbackpack->id) == OPEN_BADGES_V2) {
$addurl = new moodle_url('/badges/backpack-add.php', array('hash' => $badge->uniquehash));
$push = $this->output->action_icon($addurl, $icon);
} else if (badges_open_badges_backpack_api($userbackpack->id) == OPEN_BADGES_V2P1) {
$addurl = new moodle_url('/badges/backpack-export.php', array('hash' => $badge->uniquehash));
} else {
$addurl = new moodle_url('/badges/backpack-add.php', array('hash' => $badge->uniquehash));
$push = $this->output->action_icon($addurl, $icon);
}
$icon = new pix_icon('t/backpack', get_string('addtobackpack', 'badges'));
$push = $this->output->action_icon($addurl, $icon, $action);
}
$download = $this->output->action_icon($url, new pix_icon('t/download', get_string('download')));
@ -353,23 +350,14 @@ class core_badges_renderer extends plugin_renderer_base {
if (!empty($CFG->badges_allowexternalbackpack) && ($expiration > $now)
&& $userbackpack = badges_get_user_backpack($USER->id)) {
if (badges_open_badges_backpack_api($userbackpack->id) == OPEN_BADGES_V1) {
$assertion = new moodle_url('/badges/assertion.php', array('b' => $ibadge->hash));
$action = new component_action('click', 'addtobackpack', array('assertion' => $assertion->out(false)));
$attributes = array(
'type' => 'button',
'class' => 'btn btn-secondary m-1',
'id' => 'addbutton',
'value' => get_string('addtobackpack', 'badges'));
$tobackpack = html_writer::tag('input', '', $attributes);
$this->output->add_action_handler($action, 'addbutton');
$output .= $tobackpack;
$assertion = null;
if (badges_open_badges_backpack_api($userbackpack->id) == OPEN_BADGES_V2P1) {
$assertion = new moodle_url('/badges/backpack-export.php', array('hash' => $ibadge->hash));
} else {
if (badges_open_badges_backpack_api($userbackpack->id) == OPEN_BADGES_V2P1) {
$assertion = new moodle_url('/badges/backpack-export.php', array('hash' => $ibadge->hash));
} else {
$assertion = new moodle_url('/badges/backpack-add.php', array('hash' => $ibadge->hash));
}
$assertion = new moodle_url('/badges/backpack-add.php', array('hash' => $ibadge->hash));
}
if (!is_null(assertion)) {
$attributes = ['class' => 'btn btn-secondary m-1', 'role' => 'button'];
$tobackpack = html_writer::link($assertion, get_string('addtobackpack', 'badges'), $attributes);
$output .= $tobackpack;

View File

@ -4,6 +4,13 @@ information provided here is intended especially for developers.
=== 3.11 ===
* $CFG->badges_site_backpack setting has been completely removed because it's not required anymore. From now, the primary
site backpack will be the first one in the "Manage backpacks" list (so, the one with lower sortorder value).
* Final deprecation for:
- BADGE_BACKPACKURL constant has been removed.
- badges/backpack.js file has been removed.
* The following methods have been deprecated:
- badges_check_backpack_accessibility()
- badges_setup_backpack_js()
- badges_local_backpack_js()
=== 3.10 ===
* Users can now specify a backpack that differs from the site backpack. In order to do this, connection details need to

View File

@ -34,7 +34,6 @@ $string['addcompetency'] = 'Add competency';
$string['addcompetency_help'] = 'Select all competencies that should be added to this badge requirement. Hold CTRL key to select multiple items.';
$string['addbadgecriteria'] = 'Add badge criteria';
$string['addcriteria'] = 'Add criteria';
$string['addbackpack'] = 'Add backpack';
$string['addcriteriatext'] = 'To start adding criteria, please select one of the options from the drop-down menu.';
$string['addcohort'] = 'Add cohort';
$string['addcohort_help'] = 'Select all cohorts that should be added to this badge requirement. Hold CTRL key to select multiple items.';
@ -286,8 +285,6 @@ $string['enablebadges'] = 'Enable badges';
$string['endorsement'] = 'Endorsement';
$string['error:backpackdatainvalid'] = 'The data return from the backpack was invalid.';
$string['error:backpackemailnotfound'] = 'The email \'{$a}\' is not associated with a backpack. You need to <a href="http://backpack.openbadges.org">create a backpack</a> for that account or sign in with another email address.';
$string['error:backpacknotavailable'] = 'Your site is not accessible from the Internet, so any badges issued from this site cannot be verified by external backpack services.';
$string['error:backpackproblem'] = 'There was a problem connecting to your backpack service provider. Please try again later.';
$string['error:badgeawardnotfound'] = 'Cannot verify this awarded badge. This badge may have been revoked.';
$string['error:badgenotfound'] = 'Badge not found';
$string['error:cannotact'] = 'Cannot activate the badge. ';
@ -577,6 +574,10 @@ $string['sitebackpackverify'] = 'Backpack connection';
// Deprecated since Moodle 3.10.
$string['backpackneedsupdate'] = 'The backpack connected to this profile does not match the backpack for the site. You need to disconnect and reconnect the backpack.';
// Deprecated since Moodle 3.11.
$string['addbackpack'] = 'Add backpack';
$string['error:backpacknotavailable'] = 'Your site is not accessible from the Internet, so any badges issued from this site cannot be verified by external backpack services.';
$string['error:backpackproblem'] = 'There was a problem connecting to your backpack service provider. Please try again later.';
$string['sitebackpack'] = 'Active external backpack';
$string['sitebackpack_help'] = 'The external backpack that users can connect to from this site. Note that changing this setting after users have connected their backpacks will require each user to go to their backpack settings page and disconnect then reconnect.';

View File

@ -131,3 +131,6 @@ sitebackpack,core_badges
sitebackpack_help,core_badges
usernameoridnousererror,core_webservice
usernameoridoccurenceerror,core_webservice
addbackpack,core_badges
error:backpacknotavailable,core_badges
error:backpackproblem,core_badges

View File

@ -99,11 +99,6 @@ define('BADGE_MESSAGE_MONTHLY', 4);
define('BADGRIO_BACKPACKAPIURL', 'https://api.badgr.io/v2');
define('BADGRIO_BACKPACKWEBURL', 'https://badgr.io');
/*
* @deprecated since 3.7. Use the urls in the badge_external_backpack table instead.
*/
define('BADGE_BACKPACKURL', 'https://backpack.openbadges.org');
/*
* @deprecated since 3.9 (MDL-66357).
*/
@ -640,49 +635,15 @@ function badges_download($userid) {
/**
* Checks if badges can be pushed to external backpack.
*
* @deprecated Since Moodle 3.11.
* @return string Code of backpack accessibility status.
*/
function badges_check_backpack_accessibility() {
if (defined('BEHAT_SITE_RUNNING') && BEHAT_SITE_RUNNING) {
// For behat sites, do not poll the remote badge site.
// Behat sites should not be available, but we should pretend as though they are.
return 'available';
}
// This method was used for OBv1.0. It can be deprecated because OBv1.0 support will be removed.
// When this method will be removed, badges/ajax.php can be removed too (if it keeps containing only a call to it).
debugging('badges_check_backpack_accessibility() can not be used any more, it was only used for OBv1.0', DEBUG_DEVELOPER);
if (badges_open_badges_backpack_api() == OPEN_BADGES_V2) {
return 'available';
}
global $CFG;
include_once $CFG->libdir . '/filelib.php';
// Using fake assertion url to check whether backpack can access the web site.
$fakeassertion = new moodle_url('/badges/assertion.php', array('b' => 'abcd1234567890'));
// Curl request to backpack baker.
$curl = new curl();
$options = array(
'FRESH_CONNECT' => true,
'RETURNTRANSFER' => true,
'HEADER' => 0,
'CONNECTTIMEOUT' => 2,
);
// BADGE_BACKPACKURL and the "baker" API is deprecated and should never be used in future.
$location = BADGE_BACKPACKURL . '/baker';
$out = $curl->get($location, array('assertion' => $fakeassertion->out(false)), $options);
$data = json_decode($out);
if (!empty($curl->error)) {
return 'curl-request-timeout';
} else {
if (isset($data->code) && $data->code == 'http-unreachable') {
return 'http-unreachable';
} else {
return 'available';
}
}
return false;
return 'curl-request-timeout';
}
/**
@ -729,39 +690,25 @@ function badges_handle_course_deletion($courseid) {
/**
* Loads JS files required for backpack support.
*
* @uses $CFG, $PAGE
* @deprecated Since Moodle 3.11.
* @return void
*/
function badges_setup_backpack_js() {
global $CFG, $PAGE;
if (!empty($CFG->badges_allowexternalbackpack)) {
if (badges_open_badges_backpack_api() == OPEN_BADGES_V1) {
$PAGE->requires->string_for_js('error:backpackproblem', 'badges');
// The issuer.js API is deprecated and should not be used in future.
$PAGE->requires->js(new moodle_url(BADGE_BACKPACKURL . '/issuer.js'), true);
// The backpack.js file is deprecated and should not be used in future.
$PAGE->requires->js('/badges/backpack.js', true);
}
}
// This method was used for OBv1.0. It can be deprecated because OBv1.0 support will be removed.
debugging('badges_setup_backpack_js() can not be used any more, it was only used for OBv1.0.', DEBUG_DEVELOPER);
}
/**
* No js files are required for backpack support.
* This only exists to directly support the custom V1 backpack api.
*
* @deprecated Since Moodle 3.11.
* @param boolean $checksite Call check site function.
* @return void
*/
function badges_local_backpack_js($checksite = false) {
global $CFG, $PAGE;
if (!empty($CFG->badges_allowexternalbackpack)) {
if (badges_open_badges_backpack_api() == OPEN_BADGES_V1) {
$PAGE->requires->js('/badges/backpack.js', true);
if ($checksite) {
$PAGE->requires->js_init_call('check_site_access', null, false);
}
}
}
// This method was used for OBv1.0. It can be deprecated because OBv1.0 support will be removed.
debugging('badges_local_backpack_js() can not be used any more, it was only used for OBv1.0.', DEBUG_DEVELOPER);
}
/**