MDL-86174 badges: Add Canvas Credentials paid plan alert
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
issueNumber: MDL-86174
|
||||
notes:
|
||||
core_badges:
|
||||
- message: >-
|
||||
A number of new static methods have been added to
|
||||
`core_badges\backpack_api` to support the new Canvas Credentials
|
||||
backpack provider. These methods allow you to retrieve lists of
|
||||
providers and regions, check if Canvas Credentials fields should be
|
||||
displayed, and get a region URL or API URL based on a given region ID.
|
||||
The new methods include `get_providers`, `get_regions`,
|
||||
`display_canvas_credentials_fields`, `get_region_url`,
|
||||
`get_region_api_url`, `get_regionid_from_url`, and
|
||||
`is_canvas_credentials_region`.
|
||||
type: improved
|
||||
@@ -65,6 +65,21 @@ if (($hassiteconfig || has_any_capability(array(
|
||||
new lang_string('allowexternalbackpack', 'badges'),
|
||||
new lang_string('allowexternalbackpack_desc', 'badges'), 1));
|
||||
|
||||
$defaultcanvasregions = [
|
||||
'Australia|https://au.badgr.io|https://api.au.badgr.io/v2',
|
||||
'Canada|https://ca.badgr.io|https://api.ca.badgr.io/v2',
|
||||
'Europe|https://eu.badgr.io|https://api.eu.badgr.io/v2',
|
||||
'Singapore|https://sg.badgr.io|https://api.sg.badgr.io/v2',
|
||||
'United States|https://badgr.io|https://api.badgr.io/v2',
|
||||
];
|
||||
$globalsettings->add(new admin_setting_configtextarea(
|
||||
'badges_canvasregions',
|
||||
new lang_string('canvasregions', 'badges'),
|
||||
new lang_string('canvasregions_desc', 'badges'),
|
||||
implode("\n", $defaultcanvasregions),
|
||||
PARAM_RAW,
|
||||
));
|
||||
|
||||
$ADMIN->add('badges', $globalsettings);
|
||||
|
||||
$ADMIN->add('badges',
|
||||
|
||||
@@ -42,6 +42,17 @@ define('BADGE_EXPIRES_TOKEN', 'expires');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class backpack_api {
|
||||
/** @var int Canvas Credentials backpack provider */
|
||||
public const PROVIDER_CANVAS_CREDENTIALS = 0;
|
||||
|
||||
/** @var int Other backpack provider */
|
||||
public const PROVIDER_OTHER = 1;
|
||||
|
||||
/** @var int Empty provider */
|
||||
public const PROVIDER_EMPTY = -1;
|
||||
|
||||
/** @var int Empty region */
|
||||
public const REGION_EMPTY = -1;
|
||||
|
||||
/** @var string The email address of the issuer or the backpack owner. */
|
||||
private $email;
|
||||
@@ -579,4 +590,123 @@ class backpack_api {
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of backpack providers for OBv2.0.
|
||||
*
|
||||
* @return string[] Array with the OBv2.0 backpack providers.
|
||||
*/
|
||||
public static function get_providers(): array {
|
||||
$allproviders = [
|
||||
self::PROVIDER_CANVAS_CREDENTIALS => 'canvascredentialsprovider',
|
||||
self::PROVIDER_OTHER => 'otherprovider',
|
||||
];
|
||||
|
||||
foreach ($allproviders as $key => $value) {
|
||||
if (get_string_manager()->string_exists($value, 'badges')) {
|
||||
$providers[$key] = get_string($value, 'badges');
|
||||
} else {
|
||||
// If the string does not exist, use the key as a fallback.
|
||||
$providers[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $providers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of regions for backpack providers.
|
||||
*
|
||||
* @return array Regions with the following information: name, url and apiurl.
|
||||
*/
|
||||
public static function get_regions() {
|
||||
global $CFG;
|
||||
|
||||
$regions = [];
|
||||
if (empty(trim($CFG->badges_canvasregions))) {
|
||||
return $regions;
|
||||
}
|
||||
|
||||
$entries = explode("\n", $CFG->badges_canvasregions);
|
||||
foreach ($entries as $entry) {
|
||||
if (empty(trim($entry)) || substr_count($entry, '|') != 2) {
|
||||
continue;
|
||||
}
|
||||
$entry = trim($entry);
|
||||
$parts = explode('|', $entry);
|
||||
$regions[] = [
|
||||
'name' => $parts[0],
|
||||
'url' => rtrim($parts[1], '/'),
|
||||
'apiurl' => rtrim($parts[2], '/'),
|
||||
];
|
||||
}
|
||||
|
||||
return $regions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the Canvas Credentials fields should be displayed or not in the backpack form.
|
||||
*
|
||||
* @return bool True if the fields should be displayed; false otherwise.
|
||||
*/
|
||||
public static function display_canvas_credentials_fields(): bool {
|
||||
return !empty(self::get_providers()) && !empty(self::get_regions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get backpack URL for a given regionid.
|
||||
*
|
||||
* @param int $regionid The region identifier.
|
||||
* @return string|null The backpack URL.
|
||||
*/
|
||||
public static function get_region_url(int $regionid): ?string {
|
||||
$regions = self::get_regions();
|
||||
if (!array_key_exists($regionid, $regions)) {
|
||||
return null;
|
||||
}
|
||||
return $regions[$regionid]['url'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get backpack API URL for a given regionid.
|
||||
*
|
||||
* @param int $regionid The region identifier.
|
||||
* @return string|null The backpack API URL.
|
||||
*/
|
||||
public static function get_region_api_url(int $regionid): ?string {
|
||||
$regions = self::get_regions();
|
||||
if (!array_key_exists($regionid, $regions)) {
|
||||
return null;
|
||||
}
|
||||
return $regions[$regionid]['apiurl'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get region identifier from a given backpack URL.
|
||||
* When the URL is not found, the last region index is returned.
|
||||
*
|
||||
* @param string $url The backpack URL.
|
||||
* @return int The region identifier associated to the given backpack URL or the last region index if not found.
|
||||
*/
|
||||
public static function get_regionid_from_url(string $url): int {
|
||||
$regions = self::get_regions();
|
||||
if (empty($regions)) {
|
||||
return self::REGION_EMPTY;
|
||||
}
|
||||
|
||||
// Normalize the URL by removing the trailing slash.
|
||||
$normalizedurl = rtrim($url, '/');
|
||||
$regionurl = array_search($normalizedurl, array_column($regions, 'url'));
|
||||
return $regionurl !== false ? (int)$regionurl : count($regions) - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given URL is a Canvas Credentials one.
|
||||
*
|
||||
* @param string $url The backpack URL.
|
||||
* @return bool True is the given URL is a Canvas Credentials region; false otherwise.
|
||||
*/
|
||||
public static function is_canvas_credentials_region(string $url): bool {
|
||||
$regions = self::get_regions();
|
||||
return in_array($url, array_column($regions, 'url'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
namespace core_badges\form;
|
||||
|
||||
use core_badges\backpack_api;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
@@ -37,11 +39,7 @@ class external_backpack extends \moodleform {
|
||||
global $CFG;
|
||||
|
||||
$mform = $this->_form;
|
||||
$backpack = false;
|
||||
|
||||
if (isset($this->_customdata['externalbackpack'])) {
|
||||
$backpack = $this->_customdata['externalbackpack'];
|
||||
}
|
||||
$backpack = $this->_customdata['externalbackpack'] ?? null;
|
||||
|
||||
$mform->addElement('hidden', 'action', 'edit');
|
||||
$mform->setType('action', PARAM_ALPHA);
|
||||
@@ -52,14 +50,22 @@ class external_backpack extends \moodleform {
|
||||
$mform->setDefault('apiversion', OPEN_BADGES_V2P1);
|
||||
$mform->addRule('apiversion', null, 'required', null, 'client');
|
||||
|
||||
$this->add_provider_fields();
|
||||
|
||||
$mform->addElement('text', 'backpackweburl', get_string('backpackweburl', 'core_badges'));
|
||||
$mform->setType('backpackweburl', PARAM_URL);
|
||||
$mform->addRule('backpackweburl', null, 'required', null, 'client');
|
||||
$mform->addRule('backpackweburl', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
|
||||
$mform->hideIf('backpackweburl', 'apiversion', 'ne', OPEN_BADGES_V2);
|
||||
|
||||
$mform->addElement('text', 'backpackapiurl', get_string('backpackapiurl', 'core_badges'));
|
||||
$mform->setType('backpackapiurl', PARAM_URL);
|
||||
$mform->addRule('backpackapiurl', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
|
||||
$mform->hideIf('backpackapiurl', 'apiversion', 'ne', OPEN_BADGES_V2);
|
||||
|
||||
$mform->addElement('text', 'backpackweburlv2p1', get_string('backpackweburl', 'core_badges'));
|
||||
$mform->setType('backpackweburlv2p1', PARAM_URL);
|
||||
$mform->addRule('backpackweburlv2p1', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
|
||||
$mform->hideIf('backpackweburlv2p1', 'apiversion', 'ne', (string) OPEN_BADGES_V2P1);
|
||||
|
||||
$mform->addElement('hidden', 'id', ($backpack->id ?? null));
|
||||
$mform->setType('id', PARAM_INT);
|
||||
@@ -70,31 +76,116 @@ class external_backpack extends \moodleform {
|
||||
$mform->addElement('hidden', 'backpackuid', 0);
|
||||
$mform->setType('backpackuid', PARAM_INT);
|
||||
|
||||
$mform->addElement('advcheckbox', 'includeauthdetails', null, get_string('includeauthdetails', 'core_badges'));
|
||||
if (!empty($backpack->backpackemail) || !empty($backpack->password)) {
|
||||
$mform->setDefault('includeauthdetails', 1);
|
||||
// Add rules for backpack URL fields.
|
||||
if (backpack_api::display_canvas_credentials_fields()) {
|
||||
$mform->hideIf('backpackweburl', 'provider', 'ne', backpack_api::PROVIDER_OTHER);
|
||||
$mform->hideIf('backpackapiurl', 'provider', 'ne', backpack_api::PROVIDER_OTHER);
|
||||
}
|
||||
|
||||
$issuercontact = $CFG->badges_defaultissuercontact;
|
||||
$this->add_auth_fields($issuercontact);
|
||||
$issueremail = $CFG->badges_defaultissuercontact;
|
||||
// Connect to a Canvas Credentials provider.
|
||||
$this->add_connect_issuer_canvas_fields($issueremail);
|
||||
|
||||
// Connect to another provider.
|
||||
$this->add_connect_issuer_fields($backpack, $issueremail);
|
||||
|
||||
if ($backpack) {
|
||||
$this->set_data($backpack);
|
||||
}
|
||||
|
||||
$mform->hideIf('includeauthdetails', 'apiversion', 'in', [OPEN_BADGES_V2P1]);
|
||||
$mform->hideIf('backpackemail', 'includeauthdetails');
|
||||
$mform->hideIf('backpackemail', 'apiversion', 'in', [OPEN_BADGES_V2P1]);
|
||||
$mform->hideIf('password', 'includeauthdetails');
|
||||
$mform->hideIf('password', 'apiversion', 'in', [OPEN_BADGES_V2P1]);
|
||||
$mform->hideIf('backpackapiurl', 'apiversion', 'in', [OPEN_BADGES_V2P1]);
|
||||
|
||||
// Disable short forms.
|
||||
$mform->setDisableShortforms();
|
||||
|
||||
$this->add_action_buttons();
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function definition_after_data(): void {
|
||||
parent::definition_after_data();
|
||||
$mform = $this->_form;
|
||||
|
||||
if ($this->is_submitted()) {
|
||||
if (!$mform->elementExists('apiversion')) {
|
||||
return;
|
||||
}
|
||||
$apiversion = $mform->getElement('apiversion')->getValue();
|
||||
$apiversion = $apiversion ? array_pop($apiversion) : null;
|
||||
$provider = $mform->elementExists('provider') ? $mform->getElement('provider')->getValue() : null;
|
||||
$provider = $provider ? array_pop($provider) : null;
|
||||
$region = $mform->elementExists('region') ? $mform->getElement('region')->getValue() : null;
|
||||
$region = $region ? array_pop($region) : null;
|
||||
if ($apiversion == OPEN_BADGES_V2) {
|
||||
if (
|
||||
$provider == backpack_api::PROVIDER_CANVAS_CREDENTIALS
|
||||
&& isset($region) && $region != backpack_api::REGION_EMPTY
|
||||
) {
|
||||
$mform->getElement('backpackweburl')->setValue(
|
||||
backpack_api::get_region_url($region),
|
||||
);
|
||||
$mform->getElement('backpackapiurl')->setValue(
|
||||
backpack_api::get_region_api_url($region),
|
||||
);
|
||||
|
||||
if ($mform->getElement('includeauthdetailscanvas')->getValue()) {
|
||||
$mform->getElement('backpackemail')->setValue(
|
||||
$mform->getElement('backpackemailcanvas')->getValue(),
|
||||
);
|
||||
$mform->getElement('password')->setValue(
|
||||
$mform->getElement('backpackpasswordcanvas')->getValue(),
|
||||
);
|
||||
}
|
||||
} else if (is_null($provider) || $provider == backpack_api::PROVIDER_OTHER) {
|
||||
if ($mform->getElement('includeauthdetails')->getValue() == 0) {
|
||||
// Clear backpack issuer fields when authentication details checkbox is not checked.
|
||||
$mform->getElement('backpackemail')->setValue('');
|
||||
$mform->getElement('password')->setValue('');
|
||||
}
|
||||
}
|
||||
} else if ($apiversion == OPEN_BADGES_V2P1) {
|
||||
if (!empty($mform->getElement('backpackweburlv2p1')->getValue())) {
|
||||
$mform->getElement('backpackweburl')->setValue(
|
||||
$mform->getElement('backpackweburlv2p1')->getValue(),
|
||||
);
|
||||
}
|
||||
// Clear backpack issuer fields when OBv2.1 is selected.
|
||||
$mform->getElement('includeauthdetails')->setValue(0);
|
||||
$mform->getElement('backpackemail')->setValue('');
|
||||
$mform->getElement('password')->setValue('');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function set_data($backpack) {
|
||||
if ($backpack->apiversion == OPEN_BADGES_V2) {
|
||||
if (backpack_api::is_canvas_credentials_region($backpack->backpackweburl)) {
|
||||
// Calculate provider and region fields based on backpack URLs.
|
||||
$backpack->provider = backpack_api::PROVIDER_CANVAS_CREDENTIALS;
|
||||
$backpack->region = backpack_api::get_regionid_from_url($backpack->backpackweburl);
|
||||
$backpack->backpackweburl = '';
|
||||
$backpack->backpackapiurl = '';
|
||||
if (isset($backpack->backpackemail) && !empty($backpack->backpackemail)) {
|
||||
// Update Canvas Credentials fields.
|
||||
$backpack->includeauthdetailscanvas = 1;
|
||||
$backpack->backpackemailcanvas = $backpack->backpackemail;
|
||||
$backpack->backpackpasswordcanvas = $backpack->password;
|
||||
// Clear email and password fields for another providers.
|
||||
$backpack->includeauthdetails = 0;
|
||||
$backpack->backpackemail = '';
|
||||
$backpack->password = '';
|
||||
}
|
||||
} else {
|
||||
$backpack->provider = backpack_api::PROVIDER_OTHER;
|
||||
}
|
||||
} else if ($backpack->apiversion == OPEN_BADGES_V2P1) {
|
||||
$backpack->backpackweburlv2p1 = $backpack->backpackweburl;
|
||||
$backpack->backpackweburl = '';
|
||||
$backpack->backpackapiurl = '';
|
||||
}
|
||||
|
||||
parent::set_data($backpack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the data from the form.
|
||||
*
|
||||
@@ -106,42 +197,212 @@ class external_backpack extends \moodleform {
|
||||
$errors = parent::validation($data, $files);
|
||||
|
||||
// Ensure backpackapiurl and backpackweburl are valid URLs.
|
||||
$isobv21 = isset($data['apiversion']) && $data['apiversion'] == OPEN_BADGES_V2P1;
|
||||
if (!$isobv21) {
|
||||
if (empty($data['backpackapiurl'])) {
|
||||
$errors['backpackapiurl'] = get_string('err_required', 'form');
|
||||
} else if (!preg_match('@^https?://.+@', $data['backpackapiurl'])) {
|
||||
$errors['backpackapiurl'] = get_string('invalidurl', 'badges');
|
||||
}
|
||||
$isobv20 = isset($data['apiversion']) && $data['apiversion'] == OPEN_BADGES_V2;
|
||||
$isobv2p1 = isset($data['apiversion']) && $data['apiversion'] == OPEN_BADGES_V2P1;
|
||||
if ($isobv20) {
|
||||
$errors = array_merge($errors, $this->validate_obv20($data));
|
||||
} else if ($isobv2p1) {
|
||||
$errors = array_merge($errors, $this->validate_obv2p1($data));
|
||||
}
|
||||
if (!empty($data['backpackweburl']) && !preg_match('@^https?://.+@', $data['backpackweburl'])) {
|
||||
$errors['backpackweburl'] = get_string('invalidurl', 'badges');
|
||||
|
||||
// Check email and password are not empty when including auth details.
|
||||
if (!empty($data['includeauthdetails']) && empty($data['backpackemail'])) {
|
||||
$errors['backpackemail'] = get_string('err_required', 'form');
|
||||
}
|
||||
if (!empty($data['includeauthdetails']) && empty($data['password'])) {
|
||||
$errors['password'] = get_string('err_required', 'form');
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return submitted data if properly submitted or returns NULL if validation fails or
|
||||
* if there is no submitted data.
|
||||
* Validate the data for Open Badges v2.0.
|
||||
*
|
||||
* @return object|void
|
||||
* @param array $data Form data.
|
||||
* @return string[] An array of error messages.
|
||||
*/
|
||||
public function get_data() {
|
||||
$data = parent::get_data();
|
||||
if ($data ) {
|
||||
if ((isset($data->includeauthdetails) && !$data->includeauthdetails)
|
||||
|| (isset($data->apiversion) && $data->apiversion == 2.1)) {
|
||||
$data->backpackemail = "";
|
||||
$data->password = "";
|
||||
}
|
||||
private function validate_obv20(array $data): array {
|
||||
$errors = [];
|
||||
|
||||
if ((isset($data->apiversion) && $data->apiversion == 1)) {
|
||||
$data->password = "";
|
||||
$displaycanvasfields = backpack_api::display_canvas_credentials_fields();
|
||||
if (
|
||||
$displaycanvasfields
|
||||
&& (!array_key_exists('provider', $data) || $data['provider'] == backpack_api::PROVIDER_EMPTY)
|
||||
) {
|
||||
// Check provider is set.
|
||||
$errors['provider'] = get_string('err_required', 'form');
|
||||
} else if (
|
||||
$displaycanvasfields
|
||||
&& ($data['provider'] == backpack_api::PROVIDER_CANVAS_CREDENTIALS)
|
||||
) {
|
||||
// Check region is set.
|
||||
if (!array_key_exists('region', $data) || $data['region'] == backpack_api::REGION_EMPTY) {
|
||||
$errors['region'] = get_string('err_required', 'form');
|
||||
}
|
||||
} else {
|
||||
if (empty($data['backpackweburl'])) {
|
||||
$errors['backpackweburl'] = get_string('err_required', 'form');
|
||||
} else if (!preg_match('@^https?://.+@', $data['backpackweburl'])) {
|
||||
$errors['backpackweburl'] = get_string('invalidurl', 'badges');
|
||||
}
|
||||
if (empty($data['backpackapiurl'])) {
|
||||
$errors['backpackapiurl'] = get_string('err_required', 'form');
|
||||
} else if (!preg_match('@^https?://.+@', $data['backpackapiurl'])) {
|
||||
$errors['backpackapiurl'] = get_string('invalidurl', 'badges');
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
if ($displaycanvasfields) {
|
||||
if (!empty($data['includeauthdetailscanvas']) && empty($data['backpackemailcanvas'])) {
|
||||
$errors['backpackemailcanvas'] = get_string('err_required', 'form');
|
||||
}
|
||||
if (!empty($data['includeauthdetailscanvas']) && empty($data['backpackpasswordcanvas'])) {
|
||||
$errors['backpackpasswordcanvas'] = get_string('err_required', 'form');
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the data for Open Badges v2.1.
|
||||
*
|
||||
* @param array $data Form data.
|
||||
* @return string[] An array of error messages.
|
||||
*/
|
||||
private function validate_obv2p1(array $data): array {
|
||||
$errors = [];
|
||||
|
||||
if (empty($data['backpackweburlv2p1'])) {
|
||||
$errors['backpackweburlv2p1'] = get_string('err_required', 'form');
|
||||
} else if (!preg_match('@^https?://.+@', $data['backpackweburlv2p1'])) {
|
||||
$errors['backpackweburlv2p1'] = get_string('invalidurl', 'badges');
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add provider fields to the form.
|
||||
*/
|
||||
protected function add_provider_fields(): void {
|
||||
$mform = $this->_form;
|
||||
|
||||
if (!backpack_api::display_canvas_credentials_fields()) {
|
||||
// If canvas credentials fields are not to be displayed, return early.
|
||||
return;
|
||||
}
|
||||
|
||||
// Add an empty option at the start.
|
||||
$providers = backpack_api::get_providers();
|
||||
$providers = [backpack_api::PROVIDER_EMPTY => ''] + $providers;
|
||||
$mform->addElement('select', 'provider', get_string('provider', 'core_badges'), $providers);
|
||||
$mform->setType('provider', PARAM_RAW);
|
||||
$mform->hideIf('provider', 'apiversion', 'ne', OPEN_BADGES_V2);
|
||||
|
||||
// Add an empty option at the start.
|
||||
$regions = backpack_api::get_regions();
|
||||
$regions = [backpack_api::REGION_EMPTY => ''] + array_column($regions, 'name');
|
||||
$mform->addElement('select', 'region', get_string('region', 'core_badges'), $regions);
|
||||
$mform->setType('region', PARAM_RAW);
|
||||
$mform->hideIf('region', 'provider', 'ne', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
|
||||
$mform->hideIf('region', 'apiversion', 'ne', OPEN_BADGES_V2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Canvas backpack specific issuer auth details.
|
||||
*
|
||||
* @param string|null $email The email addressed provided or null if it's new.
|
||||
*/
|
||||
protected function add_connect_issuer_canvas_fields(?string $email): void {
|
||||
$mform = $this->_form;
|
||||
|
||||
if (!backpack_api::display_canvas_credentials_fields()) {
|
||||
// If canvas credentials fields are not to be displayed, return early.
|
||||
return;
|
||||
}
|
||||
|
||||
$providers = backpack_api::get_providers();
|
||||
$regions = backpack_api::get_regions();
|
||||
if (empty($providers) || empty($regions)) {
|
||||
// If no providers or regions are available, return early.
|
||||
return;
|
||||
}
|
||||
|
||||
// Checkbox and information to enable/disable issuer account.
|
||||
$mform->addElement('static', '', null, '');
|
||||
$mform->addElement(
|
||||
'advcheckbox',
|
||||
'includeauthdetailscanvas',
|
||||
null,
|
||||
'<strong>' . get_string('includeauthdetailscanvas', 'core_badges') . '</strong> '
|
||||
. get_string('includeauthdetailscanvas_subtitle', 'core_badges'),
|
||||
);
|
||||
if (!empty($backpack->backpackemail) || !empty($backpack->password)) {
|
||||
$mform->setDefault('includeauthdetailscanvas', 1);
|
||||
}
|
||||
$mform->addHelpButton('includeauthdetailscanvas', 'includeauthdetailscanvas', 'core_badges');
|
||||
$mform->hideIf('includeauthdetailscanvas', 'apiversion', 'ne', OPEN_BADGES_V2);
|
||||
$mform->hideIf('includeauthdetailscanvas', 'region', 'eq', backpack_api::REGION_EMPTY);
|
||||
$mform->hideIf('includeauthdetailscanvas', 'provider', 'ne', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
|
||||
|
||||
$mform->addElement(
|
||||
'static',
|
||||
'includeauthdetailscanvasdesc',
|
||||
null,
|
||||
get_string('includeauthdetailscanvas_desc', 'core_badges'),
|
||||
);
|
||||
$mform->hideIf('includeauthdetailscanvasdesc', 'includeauthdetailscanvas');
|
||||
$mform->hideIf('includeauthdetailscanvasdesc', 'region', 'eq', backpack_api::REGION_EMPTY);
|
||||
$mform->hideIf('includeauthdetailscanvasdesc', 'provider', 'ne', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
|
||||
$mform->hideIf('includeauthdetailscanvasdesc', 'apiversion', 'ne', OPEN_BADGES_V2);
|
||||
|
||||
// Email.
|
||||
$mform->addElement('text', 'backpackemailcanvas', get_string('issueremail', 'core_badges'));
|
||||
$mform->setType('backpackemailcanvas', PARAM_EMAIL);
|
||||
$mform->setDefault('backpackemailcanvas', $email);
|
||||
$mform->hideIf('backpackemailcanvas', 'includeauthdetailscanvas');
|
||||
$mform->hideIf('backpackemailcanvas', 'apiversion', 'ne', OPEN_BADGES_V2);
|
||||
$mform->hideIf('backpackemailcanvas', 'provider', 'ne', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
|
||||
|
||||
// Password.
|
||||
$mform->addElement('passwordunmask', 'backpackpasswordcanvas', get_string('password'));
|
||||
$mform->setType('backpackpasswordcanvas', PARAM_RAW);
|
||||
$mform->hideIf('backpackpasswordcanvas', 'includeauthdetailscanvas');
|
||||
$mform->hideIf('backpackpasswordcanvas', 'apiversion', 'ne', OPEN_BADGES_V2);
|
||||
$mform->hideIf('backpackpasswordcanvas', 'provider', 'ne', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add generic backpack issuer auth details.
|
||||
*
|
||||
* @param \stdClass|null $backpack The backpack instance.
|
||||
* @param string|null $email The issuer email or null if it's new.
|
||||
*/
|
||||
protected function add_connect_issuer_fields(?\stdClass $backpack, ?string $email): void {
|
||||
$mform = $this->_form;
|
||||
|
||||
// Checkbox and information to enable/disable issuer account.
|
||||
$mform->addElement(
|
||||
'advcheckbox',
|
||||
'includeauthdetails',
|
||||
null,
|
||||
'<strong>' . get_string('includeauthdetails', 'core_badges') . '</strong>',
|
||||
);
|
||||
if ($backpack && (!empty($backpack->backpackemail) || !empty($backpack->password))) {
|
||||
$mform->setDefault('includeauthdetails', 1);
|
||||
}
|
||||
$mform->addHelpButton('includeauthdetails', 'includeauthdetails', 'core_badges');
|
||||
$mform->hideIf('includeauthdetails', 'provider', 'eq', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
|
||||
$mform->hideIf('includeauthdetails', 'apiversion', 'ne', OPEN_BADGES_V2);
|
||||
|
||||
$mform->addElement('static', 'includeauthdetailsdesc', null, get_string('includeauthdetails_desc', 'core_badges'));
|
||||
$mform->hideIf('includeauthdetailsdesc', 'includeauthdetails');
|
||||
$mform->hideIf('includeauthdetailsdesc', 'provider', 'eq', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
|
||||
|
||||
// Email and password fields.
|
||||
$this->add_auth_fields($email);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,25 +414,22 @@ class external_backpack extends \moodleform {
|
||||
*/
|
||||
protected function add_auth_fields(?string $email, bool $includepassword = true) {
|
||||
$mform = $this->_form;
|
||||
$emailstring = get_string('email');
|
||||
$passwordstring = get_string('password');
|
||||
$showpasswordhelp = false;
|
||||
if (!isset($this->_customdata['userbackpack'])) {
|
||||
$emailstring = get_string('defaultissuercontact', 'core_badges');
|
||||
$passwordstring = get_string('defaultissuerpassword', 'core_badges');
|
||||
$showpasswordhelp = true;
|
||||
}
|
||||
|
||||
$mform->addElement('text', 'backpackemail', $emailstring);
|
||||
// Email.
|
||||
$mform->addElement('text', 'backpackemail', get_string('issueremail', 'core_badges'));
|
||||
$mform->setType('backpackemail', PARAM_EMAIL);
|
||||
$mform->setDefault('backpackemail', $email);
|
||||
$mform->hideIf('backpackemail', 'includeauthdetails');
|
||||
$mform->hideIf('backpackemail', 'apiversion', 'ne', OPEN_BADGES_V2);
|
||||
$mform->hideIf('backpackemail', 'provider', 'eq', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
|
||||
|
||||
// Password.
|
||||
if ($includepassword) {
|
||||
$mform->addElement('passwordunmask', 'password', $passwordstring);
|
||||
$mform->addElement('passwordunmask', 'password', get_string('password'));
|
||||
$mform->setType('password', PARAM_RAW);
|
||||
if ($showpasswordhelp) {
|
||||
$mform->addHelpButton('password', 'defaultissuerpassword', 'badges');
|
||||
}
|
||||
}
|
||||
$mform->hideIf('password', 'includeauthdetails');
|
||||
$mform->hideIf('password', 'apiversion', 'ne', OPEN_BADGES_V2);
|
||||
$mform->hideIf('password', 'provider', 'eq', backpack_api::PROVIDER_CANVAS_CREDENTIALS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
<?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/>.
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace core_badges;
|
||||
|
||||
/**
|
||||
* Unit tests for backpack_api class.
|
||||
*
|
||||
* @package core_badges
|
||||
* @copyright 2025 Sara Arjona <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\CoversClass(backpack_api::class)]
|
||||
final class backpack_api_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test get_providers function.
|
||||
*/
|
||||
public function test_get_providers(): void {
|
||||
global $CFG;
|
||||
|
||||
$providers = backpack_api::get_providers();
|
||||
$this->assertCount(2, $providers);
|
||||
$this->assertArrayHasKey(backpack_api::PROVIDER_CANVAS_CREDENTIALS, $providers);
|
||||
$this->assertArrayHasKey(backpack_api::PROVIDER_OTHER, $providers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_regions function.
|
||||
*/
|
||||
public function test_get_regions(): void {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Default: 5 regions (Canvas Credentials).
|
||||
$regions = backpack_api::get_regions();
|
||||
$this->assertCount(5, $regions);
|
||||
|
||||
// No regions.
|
||||
$CFG->badges_canvasregions = '';
|
||||
$regions = backpack_api::get_regions();
|
||||
$this->assertEmpty($regions);
|
||||
|
||||
// One region.
|
||||
$CFG->badges_canvasregions = 'Australia|https://au.badgr.io|https://api.au.badgr.io/v2';
|
||||
$regions = backpack_api::get_regions();
|
||||
$this->assertCount(1, $regions);
|
||||
$this->assertEquals('Australia', $regions[0]['name']);
|
||||
$this->assertEquals('https://au.badgr.io', $regions[0]['url']);
|
||||
$this->assertEquals('https://api.au.badgr.io/v2', $regions[0]['apiurl']);
|
||||
|
||||
// Two regions + empty lines + invalid line.
|
||||
$CFG->badges_canvasregions = "\nUnited States|https://badgr.io|https://api.badgr.io/v2\ninvalidline\n" .
|
||||
'Europe|https://eu.badgr.io|https://api.eu.badgr.io/v2' . "\n";
|
||||
$regions = backpack_api::get_regions();
|
||||
$this->assertCount(2, $regions);
|
||||
$expected = [
|
||||
[
|
||||
'name' => 'United States',
|
||||
'url' => 'https://badgr.io',
|
||||
'apiurl' => 'https://api.badgr.io/v2',
|
||||
],
|
||||
[
|
||||
'name' => 'Europe',
|
||||
'url' => 'https://eu.badgr.io',
|
||||
'apiurl' => 'https://api.eu.badgr.io/v2',
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expected, $regions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test display_canvas_credentials_fields function.
|
||||
*/
|
||||
public function test_display_canvas_credentials_fields(): void {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// By default, the fields should be displayed (5 regions).
|
||||
$this->assertTrue(backpack_api::display_canvas_credentials_fields());
|
||||
|
||||
// No regions configured, fields should not be displayed.
|
||||
$CFG->badges_canvasregions = '';
|
||||
$this->assertFalse(backpack_api::display_canvas_credentials_fields());
|
||||
|
||||
// One region configured, fields should be displayed.
|
||||
$CFG->badges_canvasregions = 'Australia|https://au.badgr.io|https://api.au.badgr.io/v2';
|
||||
$this->assertTrue(backpack_api::display_canvas_credentials_fields());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_region_url and get_region_api_url functions.
|
||||
*/
|
||||
public function test_get_region_urls(): void {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Default: 5 regions (Canvas Credentials).
|
||||
$regions = backpack_api::get_regions();
|
||||
$this->assertCount(5, $regions);
|
||||
$this->assertEquals('https://au.badgr.io', backpack_api::get_region_url(0));
|
||||
$this->assertEquals('https://ca.badgr.io', backpack_api::get_region_url(1));
|
||||
$this->assertEquals('https://eu.badgr.io', backpack_api::get_region_url(2));
|
||||
$this->assertEquals('https://sg.badgr.io', backpack_api::get_region_url(3));
|
||||
$this->assertEquals('https://badgr.io', backpack_api::get_region_url(4));
|
||||
$this->assertEquals('https://api.au.badgr.io/v2', backpack_api::get_region_api_url(0));
|
||||
$this->assertEquals('https://api.ca.badgr.io/v2', backpack_api::get_region_api_url(1));
|
||||
$this->assertEquals('https://api.eu.badgr.io/v2', backpack_api::get_region_api_url(2));
|
||||
$this->assertEquals('https://api.sg.badgr.io/v2', backpack_api::get_region_api_url(3));
|
||||
$this->assertEquals('https://api.badgr.io/v2', backpack_api::get_region_api_url(4));
|
||||
|
||||
// Wrong index.
|
||||
$this->assertNull(backpack_api::get_region_url(10));
|
||||
$this->assertNull(backpack_api::get_region_api_url(10));
|
||||
|
||||
// No regions.
|
||||
$CFG->badges_canvasregions = '';
|
||||
$this->assertNull(backpack_api::get_region_url(0));
|
||||
$this->assertNull(backpack_api::get_region_api_url(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_regionid_from_url function.
|
||||
*/
|
||||
public function test_get_regionid_from_url(): void {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Default: 5 regions (Canvas Credentials).
|
||||
$regions = backpack_api::get_regions();
|
||||
$this->assertCount(5, $regions);
|
||||
$this->assertEquals(0, backpack_api::get_regionid_from_url('https://au.badgr.io'));
|
||||
$this->assertEquals(1, backpack_api::get_regionid_from_url('https://ca.badgr.io'));
|
||||
$this->assertEquals(2, backpack_api::get_regionid_from_url('https://eu.badgr.io'));
|
||||
$this->assertEquals(3, backpack_api::get_regionid_from_url('https://sg.badgr.io'));
|
||||
$this->assertEquals(4, backpack_api::get_regionid_from_url('https://badgr.io'));
|
||||
// Test with trailing slash.
|
||||
$this->assertEquals(0, backpack_api::get_regionid_from_url('https://au.badgr.io/'));
|
||||
|
||||
// Wrong URL.
|
||||
$this->assertEquals(4, backpack_api::get_regionid_from_url('https://unknown.badgr.io'));
|
||||
|
||||
// One region.
|
||||
$CFG->badges_canvasregions = 'Australia|https://au.badgr.io|https://api.au.badgr.io/v2';
|
||||
$regions = backpack_api::get_regions();
|
||||
$this->assertEquals(0, backpack_api::get_regionid_from_url('https://au.badgr.io'));
|
||||
|
||||
// No regions.
|
||||
$CFG->badges_canvasregions = '';
|
||||
$this->assertEquals(backpack_api::REGION_EMPTY, backpack_api::get_regionid_from_url('https://au.badgr.io'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test is_canvas_credentials_region function.
|
||||
*/
|
||||
public function test_is_canvas_credentials_region(): void {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Default: 5 regions (Canvas Credentials).
|
||||
$regions = backpack_api::get_regions();
|
||||
$this->assertCount(5, $regions);
|
||||
$this->assertTrue(backpack_api::is_canvas_credentials_region('https://au.badgr.io'));
|
||||
$this->assertTrue(backpack_api::is_canvas_credentials_region('https://ca.badgr.io'));
|
||||
$this->assertTrue(backpack_api::is_canvas_credentials_region('https://eu.badgr.io'));
|
||||
$this->assertTrue(backpack_api::is_canvas_credentials_region('https://sg.badgr.io'));
|
||||
$this->assertTrue(backpack_api::is_canvas_credentials_region('https://badgr.io'));
|
||||
|
||||
// Non Canvas URL.
|
||||
$this->assertFalse(backpack_api::is_canvas_credentials_region('https://unknown.badgr.io'));
|
||||
|
||||
// No regions.
|
||||
$CFG->badges_canvasregions = '';
|
||||
$this->assertFalse(backpack_api::is_canvas_credentials_region('https://au.badgr.io'));
|
||||
}
|
||||
}
|
||||
@@ -91,12 +91,111 @@ Feature: Backpack badges
|
||||
And "Add to backpack" "link" should exist
|
||||
|
||||
@javascript
|
||||
Scenario: Add a new site backpack
|
||||
Scenario: Add a new site OBv2.1 backpack
|
||||
Given I am on homepage
|
||||
And I log in as "admin"
|
||||
And I navigate to "Badges > Manage backpacks" in site administration
|
||||
When I press "Add a new backpack"
|
||||
And I set the field "apiversion" to "2.1"
|
||||
And I should see "Backpack URL"
|
||||
And I set the field "backpackweburlv2p1" to "http://backpackweburl.cat"
|
||||
And I should not see "Backpack API URL"
|
||||
Then "Connect to backpack provider account" "checkbox" should not be visible
|
||||
And "Connect to a Canvas Credentials issuer account" "checkbox" should not be visible
|
||||
And I should not see "Email"
|
||||
And I should not see "Password"
|
||||
|
||||
@javascript
|
||||
Scenario: Add a new site OBv2.0 backpack with Canvas provider
|
||||
Given I am on homepage
|
||||
And I log in as "admin"
|
||||
And I navigate to "Badges > Manage backpacks" in site administration
|
||||
When I press "Add a new backpack"
|
||||
And I set the field "apiversion" to "2"
|
||||
And I press "Save changes"
|
||||
And I should see "You must supply a value here"
|
||||
And I set the field "provider" to "Canvas Credentials"
|
||||
And I press "Save changes"
|
||||
And I should see "You must supply a value here"
|
||||
And I set the field "region" to "Singapore"
|
||||
And I should not see "Backpack web URL"
|
||||
And I should not see "Backpack API URL"
|
||||
And I press "Save changes"
|
||||
Then I should see "https://sg.badgr.io"
|
||||
And "Delete" "icon" should exist in the "https://sg.badgr.io" "table_row"
|
||||
And "Edit settings" "icon" should exist in the "https://sg.badgr.io" "table_row"
|
||||
And "Test settings" "icon" should exist in the "https://sg.badgr.io" "table_row"
|
||||
# Check that editing the backpack shows the correct values.
|
||||
And I click on "Edit settings" "link" in the "https://sg.badgr.io" "table_row"
|
||||
And I should see "API version supported"
|
||||
And the field "apiversion" matches value "2"
|
||||
And I should see "Provider"
|
||||
And the field "provider" matches value "Canvas Credentials"
|
||||
And I should see "Region"
|
||||
And the field "region" matches value "Singapore"
|
||||
And I should see "Connect to a Canvas Credentials issuer account"
|
||||
And the field "Connect to a Canvas Credentials issuer account" matches value "0"
|
||||
And I should not see "Connect to backpack provider account"
|
||||
|
||||
@javascript
|
||||
Scenario: Add a new site OBv2.0 backpack with Canvas provider and issuer authentication details
|
||||
Given I am on homepage
|
||||
And I log in as "admin"
|
||||
And I navigate to "Badges > Manage backpacks" in site administration
|
||||
When I press "Add a new backpack"
|
||||
And I set the field "apiversion" to "2"
|
||||
And I set the field "provider" to "Canvas Credentials"
|
||||
And I set the field "region" to "Canada"
|
||||
And I should see "Connect to a Canvas Credentials issuer account"
|
||||
And I should not see "Connect to backpack provider account"
|
||||
And the field "Connect to a Canvas Credentials issuer account" matches value "0"
|
||||
And I click on "includeauthdetailscanvas" "checkbox"
|
||||
And I should see "Email"
|
||||
And I should see "Password"
|
||||
And I press "Save changes"
|
||||
And I should see "You must supply a value here"
|
||||
And I set the field "backpackemailcanvas" to "test@test.com"
|
||||
And I should see "You must supply a value here"
|
||||
And I press "Save changes"
|
||||
And I set the field "backpackpasswordcanvas" to "123456"
|
||||
And I press "Save changes"
|
||||
Then I should see "https://ca.badgr.io"
|
||||
# Check that editing the backpack shows the correct values.
|
||||
And I click on "Edit settings" "link" in the "https://ca.badgr.io" "table_row"
|
||||
And I should see "API version supported"
|
||||
And the field "apiversion" matches value "2"
|
||||
And I should see "Provider"
|
||||
And the field "provider" matches value "Canvas Credentials"
|
||||
And I should see "Region"
|
||||
And the field "region" matches value "Canada"
|
||||
And I should see "Connect to a Canvas Credentials issuer account"
|
||||
And the field "Connect to a Canvas Credentials issuer account" matches value "1"
|
||||
And the field "backpackemailcanvas" matches value "test@test.com"
|
||||
And the field "backpackpasswordcanvas" matches value "123456"
|
||||
# Disable authentication details and check that email and password are cleared.
|
||||
But I click on "includeauthdetailscanvas" "checkbox"
|
||||
And I press "Save changes"
|
||||
And I click on "Edit settings" "link" in the "https://ca.badgr.io" "table_row"
|
||||
And I should see "API version supported"
|
||||
And the field "apiversion" matches value "2"
|
||||
And I should see "Provider"
|
||||
And the field "provider" matches value "Canvas Credentials"
|
||||
And I should see "Region"
|
||||
And the field "region" matches value "Canada"
|
||||
And I should see "Connect to a Canvas Credentials issuer account"
|
||||
And the field "Connect to a Canvas Credentials issuer account" matches value "0"
|
||||
And the field "backpackemailcanvas" matches value ""
|
||||
And the field "backpackpasswordcanvas" matches value ""
|
||||
|
||||
@javascript
|
||||
Scenario: Add a new site OBv2.0 backpack with Other provider
|
||||
Given I am on homepage
|
||||
And I log in as "admin"
|
||||
And I navigate to "Badges > Manage backpacks" in site administration
|
||||
When I press "Add a new backpack"
|
||||
And I set the field "apiversion" to "2"
|
||||
And I set the field "provider" to "Other"
|
||||
And I should not see "Region"
|
||||
And I set the field "backpackweburl" to "aaa"
|
||||
And I press "Save changes"
|
||||
And I should see "Invalid URL"
|
||||
@@ -108,6 +207,115 @@ Feature: Backpack badges
|
||||
Then I should see "http://backpackweburl.cat"
|
||||
And "Delete" "icon" should exist in the "http://backpackweburl.cat" "table_row"
|
||||
And "Edit settings" "icon" should exist in the "http://backpackweburl.cat" "table_row"
|
||||
And "Test settings" "icon" should exist in the "http://backpackweburl.cat" "table_row"
|
||||
# Check that editing the backpack shows the correct values.
|
||||
And I click on "Edit settings" "link" in the "http://backpackweburl.cat" "table_row"
|
||||
And I should see "API version supported"
|
||||
And the field "apiversion" matches value "2"
|
||||
And I should see "Provider"
|
||||
And the field "provider" matches value "Other"
|
||||
And I should not see "Region"
|
||||
And the field "backpackweburl" matches value "http://backpackweburl.cat"
|
||||
And the field "backpackapiurl" matches value "http://backpackapiurl.cat"
|
||||
And the field "Connect to backpack provider account" matches value "0"
|
||||
And I should not see "Connect to a Canvas Credentials issuer account"
|
||||
|
||||
@javascript
|
||||
Scenario: Add a new site OBv2.0 backpack with Other provider and issuer authentication details
|
||||
Given I am on homepage
|
||||
And I log in as "admin"
|
||||
And I navigate to "Badges > Manage backpacks" in site administration
|
||||
When I press "Add a new backpack"
|
||||
And I set the field "apiversion" to "2"
|
||||
And I set the field "provider" to "Other"
|
||||
And I set the field "backpackweburl" to "http://backpackweburl.cat"
|
||||
And I set the field "backpackapiurl" to "http://backpackapiurl.cat"
|
||||
And I should see "Connect to backpack provider account"
|
||||
And I should not see "Connect to a Canvas Credentials issuer account"
|
||||
And the field "Connect to backpack provider account" matches value "0"
|
||||
And I click on "includeauthdetails" "checkbox"
|
||||
And I should see "Email"
|
||||
And I should see "Password"
|
||||
And I press "Save changes"
|
||||
And I should see "You must supply a value here"
|
||||
And I set the field "backpackemail" to "test@test.com"
|
||||
And I press "Save changes"
|
||||
And I should see "You must supply a value here"
|
||||
And I set the field "password" to "123456"
|
||||
And I press "Save changes"
|
||||
Then I should see "http://backpackweburl.cat"
|
||||
# Check that editing the backpack shows the correct values.
|
||||
And I click on "Edit settings" "link" in the "http://backpackweburl.cat" "table_row"
|
||||
And I should see "API version supported"
|
||||
And the field "apiversion" matches value "2"
|
||||
And the field "provider" matches value "Other"
|
||||
And the field "backpackweburl" matches value "http://backpackweburl.cat"
|
||||
And the field "backpackapiurl" matches value "http://backpackapiurl.cat"
|
||||
And the field "Connect to backpack provider account" matches value "1"
|
||||
And the field "backpackemail" matches value "test@test.com"
|
||||
And the field "password" matches value "123456"
|
||||
# Disable authentication details and check that email and password are cleared.
|
||||
But I click on "includeauthdetails" "checkbox"
|
||||
And I press "Save changes"
|
||||
And I click on "Edit settings" "link" in the "http://backpackweburl.cat" "table_row"
|
||||
And I should see "API version supported"
|
||||
And the field "apiversion" matches value "2"
|
||||
And the field "provider" matches value "Other"
|
||||
And the field "backpackweburl" matches value "http://backpackweburl.cat"
|
||||
And the field "backpackapiurl" matches value "http://backpackapiurl.cat"
|
||||
And the field "Connect to backpack provider account" matches value "0"
|
||||
And the field "backpackemail" matches value ""
|
||||
And the field "password" matches value ""
|
||||
|
||||
@javascript
|
||||
Scenario: Add a new site OBv2.0 backpack without providers
|
||||
Given the following config values are set as admin:
|
||||
| badges_canvasregions | |
|
||||
And I am on homepage
|
||||
And I log in as "admin"
|
||||
And I navigate to "Badges > Manage backpacks" in site administration
|
||||
When I press "Add a new backpack"
|
||||
And I set the field "apiversion" to "2"
|
||||
And I should not see "Provider"
|
||||
And I should see "Backpack URL"
|
||||
And I should see "Backpack API URL"
|
||||
And I press "Save changes"
|
||||
And I should see "You must supply a value here"
|
||||
And I set the field "backpackweburl" to "https://eu.badgr.io"
|
||||
And I set the field "backpackapiurl" to "https://api.eu.badgr.io/v2"
|
||||
And I should see "Connect to backpack provider account"
|
||||
And I should not see "Connect to a Canvas Credentials issuer account"
|
||||
And I press "Save changes"
|
||||
Then I should see "https://eu.badgr.io"
|
||||
And "Delete" "icon" should exist in the "https://eu.badgr.io" "table_row"
|
||||
And "Edit settings" "icon" should exist in the "https://eu.badgr.io" "table_row"
|
||||
And "Test settings" "icon" should exist in the "https://eu.badgr.io" "table_row"
|
||||
# Check that editing the backpack shows the correct values.
|
||||
And I click on "Edit settings" "link" in the "https://eu.badgr.io" "table_row"
|
||||
And I should see "API version supported"
|
||||
And the field "apiversion" matches value "2"
|
||||
And I should not see "Provider"
|
||||
And the field "backpackweburl" matches value "https://eu.badgr.io"
|
||||
And the field "backpackapiurl" matches value "https://api.eu.badgr.io/v2"
|
||||
And I should see "Connect to backpack provider account"
|
||||
And the field "Connect to backpack provider account" matches value "0"
|
||||
And I should not see "Connect to a Canvas Credentials issuer account"
|
||||
And I press "Cancel"
|
||||
# Add Europe to the providers list and check that editing the backpack shows the correct values.
|
||||
But the following config values are set as admin:
|
||||
| badges_canvasregions | Europe\|https://eu.badgr.io\|https://api.eu.badgr.io/v2 |
|
||||
And I click on "Edit settings" "link" in the "https://eu.badgr.io" "table_row"
|
||||
And I should see "API version supported"
|
||||
And the field "apiversion" matches value "2"
|
||||
And I should see "Provider"
|
||||
And the field "provider" matches value "Canvas Credentials"
|
||||
And I should see "Region"
|
||||
And the field "region" matches value "Europe"
|
||||
And I should see "Connect to a Canvas Credentials issuer account"
|
||||
And the field "Connect to a Canvas Credentials issuer account" matches value "0"
|
||||
And I should not see "Connect to backpack provider account"
|
||||
And I should not see "Backpack URL"
|
||||
And I should not see "Backpack API URL"
|
||||
|
||||
@javascript
|
||||
Scenario: Remove a site backpack
|
||||
@@ -136,36 +344,6 @@ Feature: Backpack badges
|
||||
And "Move up" "icon" should exist in the "https://dc.imsglobal.org" "table_row"
|
||||
And "Move down" "icon" should not exist in the "https://dc.imsglobal.org" "table_row"
|
||||
|
||||
@javascript
|
||||
Scenario: Add a new site backpack with authentication details checkbox
|
||||
Given I am on homepage
|
||||
And I log in as "admin"
|
||||
And I navigate to "Badges > Manage backpacks" in site administration
|
||||
When I press "Add a new backpack"
|
||||
And I set the field "apiversion" to "2.1"
|
||||
And I set the field "backpackweburl" to "http://backpackweburl.cat"
|
||||
And I should not see "Backpack API URL"
|
||||
Then "Include authentication details with the backpack" "checkbox" should not be visible
|
||||
And I should not see "Badge issuer email address"
|
||||
And I should not see "Badge issuer password"
|
||||
And I set the field "apiversion" to "2"
|
||||
And "Include authentication details with the backpack" "checkbox" should be visible
|
||||
And I click on "includeauthdetails" "checkbox"
|
||||
And I should see "Badge issuer email address"
|
||||
And I should see "Badge issuer password"
|
||||
And I set the field "backpackemail" to "test@test.com"
|
||||
And I set the field "password" to "123456"
|
||||
And I set the field "backpackapiurl" to "http://backpackapiurl.cat"
|
||||
And I press "Save changes"
|
||||
And I click on "Edit" "link" in the "http://backpackweburl.cat" "table_row"
|
||||
And the field "Include authentication details with the backpack" matches value "1"
|
||||
And I click on "includeauthdetails" "checkbox"
|
||||
And I press "Save changes"
|
||||
And I click on "Edit" "link" in the "http://backpackweburl.cat" "table_row"
|
||||
And the field "Include authentication details with the backpack" matches value "0"
|
||||
And I click on "includeauthdetails" "checkbox"
|
||||
And I should not see "test@test.com"
|
||||
|
||||
@javascript
|
||||
Scenario: View backpack form as a student
|
||||
Given I log in as "student1"
|
||||
@@ -173,11 +351,11 @@ Feature: Backpack badges
|
||||
And I follow "Backpack settings"
|
||||
When I set the field "externalbackpackid" to "https://dc.imsglobal.org"
|
||||
Then I should not see "Log in to your backpack"
|
||||
And I should not see "Email address"
|
||||
And I should not see "Email"
|
||||
And I should not see "Password"
|
||||
But I set the field "externalbackpackid" to "https://test.com/"
|
||||
And I should see "Log in to your backpack"
|
||||
And I should see "Email address"
|
||||
And I should see "Email"
|
||||
And I should see "Password"
|
||||
|
||||
@javascript
|
||||
|
||||
@@ -180,7 +180,9 @@ $string['bmessage'] = 'Message';
|
||||
$string['boverview'] = 'Overview';
|
||||
$string['brelated'] = 'Related badges ({$a})';
|
||||
$string['bydate'] = ' complete by';
|
||||
$string['imagecaption'] = 'Image caption';
|
||||
$string['canvascredentialsprovider'] = 'Canvas Credentials';
|
||||
$string['canvasregions'] = 'Canvas Credentials regions';
|
||||
$string['canvasregions_desc'] = 'You can configure the contents of the Canvas Credentials regions. Each line is separated by pipe characters and consists of 1) the region name, 2) the backpack URL, and 3) the backpack API URL.';
|
||||
$string['claim'] = 'Claim';
|
||||
$string['claimcomment'] = 'Endorsement comment';
|
||||
$string['claimid'] = 'Claim URL';
|
||||
@@ -276,7 +278,6 @@ $string['deactivatesuccess'] = 'Access to badge \'{$a}\' disabled.';
|
||||
$string['defaultissuercontact'] = 'Badge issuer email address';
|
||||
$string['defaultissuercontact_desc'] = 'An email address associated with the badge issuer. For an Open Badges v2.0 backpack, this is used for authentication when publishing badges to a backpack.';
|
||||
$string['defaultissuerpassword'] = 'Badge issuer password';
|
||||
$string['defaultissuerpassword_help'] = 'An account is required on the backpack site with email address as specified in the badge issuer email address setting in Site administration / Badges / Badges settings. The password for the account should be entered here.';
|
||||
$string['defaultissuername'] = 'Badge issuer name';
|
||||
$string['defaultissuername_desc'] = 'Name of the issuing agent or authority.';
|
||||
$string['delbadge'] = 'Would you like to delete badge \'{$a}\' and remove all existing issued badges?';
|
||||
@@ -369,6 +370,14 @@ $string['hidden'] = 'Hidden';
|
||||
$string['hiddenbadge'] = 'Unfortunately, the badge owner has not made this information available.';
|
||||
$string['hostedurl'] = 'External URL';
|
||||
$string['hostedurldescription'] = 'External URL where the badge is hosted';
|
||||
$string['imagecaption'] = 'Image caption';
|
||||
$string['includeauthdetails'] = "Connect to backpack provider account";
|
||||
$string['includeauthdetails_desc'] = 'Enter your badge issuer credentials to connect to your backpack provider.';
|
||||
$string['includeauthdetails_help'] = "Sends your issuer credentials with each badge exported to this backpack.";
|
||||
$string['includeauthdetailscanvas'] = "Connect to a Canvas Credentials issuer account";
|
||||
$string['includeauthdetailscanvas_desc'] = 'Enter your Canvas Credentials details to connect your issuer account.';
|
||||
$string['includeauthdetailscanvas_help'] = 'Badges exported to Canvas Credentials will show your organisation as the issuer. This also lets you track who received badges, and manage updates.';
|
||||
$string['includeauthdetailscanvas_subtitle'] = '(Requires a Canvas Credentials paid plan)';
|
||||
$string['invalidurl'] = 'Invalid URL';
|
||||
$string['issuancedetails'] = 'Badge expiry';
|
||||
$string['issuedbadge'] = 'Issued badge information';
|
||||
@@ -464,6 +473,7 @@ $string['oauth2issuer'] = 'OAuth 2 services';
|
||||
$string['openbadgesv1'] = 'Open Badges v1.0';
|
||||
$string['openbadgesv2'] = 'Open Badges v2.0';
|
||||
$string['openbadgesv2p1'] = 'Open Badges v2.1';
|
||||
$string['otherprovider'] = 'Other';
|
||||
$string['othernavigation'] = 'Other navigation ...';
|
||||
$string['password_required'] = 'Password can\'t be blank';
|
||||
$string['potentialrecipients'] = 'Potential badge recipients';
|
||||
@@ -502,9 +512,11 @@ $string['privacy:metadata:manualaward:datemet'] = 'The date when the user was aw
|
||||
$string['privacy:metadata:manualaward:issuerid'] = 'The ID of the user awarding the badge';
|
||||
$string['privacy:metadata:manualaward:issuerrole'] = 'The role of the user awarding the badge';
|
||||
$string['privacy:metadata:manualaward:recipientid'] = 'The ID of the user who is manually awarded a badge';
|
||||
$string['provider'] = 'Provider';
|
||||
$string['recipient'] = 'Badge recipient';
|
||||
$string['recipients'] = 'Badge recipients';
|
||||
$string['recipientvalidationproblem'] = 'This user cannot be verified as a recipient of this badge.';
|
||||
$string['region'] = 'Region';
|
||||
$string['relative'] = 'Relative date: this badge expires after a period of time:';
|
||||
$string['relatedbages'] = 'Related badges';
|
||||
$string['revoke'] = 'Revoke badge';
|
||||
@@ -585,7 +597,6 @@ $string['visible'] = 'Visible';
|
||||
$string['version'] = 'Version';
|
||||
$string['warnexpired'] = ' (This badge has expired!)';
|
||||
$string['year'] = 'Year(s)';
|
||||
$string['includeauthdetails'] = "Include authentication details with the backpack";
|
||||
|
||||
// Deprecated since Moodle 4.5.
|
||||
$string['error:cannotact'] = 'Cannot activate the badge. ';
|
||||
@@ -606,3 +617,6 @@ $string['imagecaption_help'] = 'If specified, an image caption is displayed on t
|
||||
$string['issuername_help'] = 'Name of the issuing agent or authority.';
|
||||
$string['language_help'] = 'The language used on the badge page.';
|
||||
$string['version_help'] = 'The version field may be used to keep track of the badge\'s development. If specified, the version is displayed on the badge page.';
|
||||
|
||||
// Deprecated since Moodle 5.1.
|
||||
$string['defaultissuerpassword_help'] = 'An account is required on the backpack site with email address as specified in the badge issuer email address setting in Site administration / Badges / Badges settings. The password for the account should be entered here.';
|
||||
|
||||
@@ -94,3 +94,4 @@ privacy:metadata:schedule:reportempty,core_reportbuilder
|
||||
privacy:metadata:schedule:subject,core_reportbuilder
|
||||
sitename,core_hub
|
||||
sitename_help,core_hub
|
||||
defaultissuerpassword_help,core_badges
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2025091900.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2025091900.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
$release = '5.1dev+ (Build: 20250919)'; // Human-friendly version name
|
||||
|
||||
Reference in New Issue
Block a user