Commit fd986869 authored by Plugins bot's avatar Plugins bot
Browse files

PLUGIN-25871 local_obf: cibot precheck request

parent 0f6643a9
This diff is collapsed.
Open Badge Factory -plugin
=================
Open Badge Factory is a cloud platform that provides the tools your organization needs to implement a meaningful and sustainable Open Badges system.
With the local_obf plugin you can issue Open Badges created in Open Badge Factory. To use the plugin, you need an account on [https://openbadgefactory.com](https://openbadgefactory.com) (You can register for free, see [https://openbadgefactory.com/faq](https://openbadgefactory.com/faq) for details about different service levels).
For developers
--------
[See the project README](../../../README.md)
How to install
--------------
Moodle 2.7, 2.9, 3.0, 3.1 and up:
1. Install the zip via Moodle's plugin page. Select "local" as the type of the plugin. (alternative: unzip to moodle's local subdirectory)
2. Update the database using the notifications page
3. Complete the [Post install steps](README.md#post-install)
Totara 11.0 and greater
Totara Learn does not include an add-on installer, all additional plugins must be installed manually by server administrators.
1. Download plugin from https://moodle.org/plugins/local_obf
2. Unzip the file into the Totara installation directory.
3. By using a site administrator account, go to Site administration → Notifications and upgrade Totara database
4. Complete the [Post install steps](README.md#post-install)
Post install
------------------
To connect to Open Badge Factory, the plugin needs a request token or API key.
To generate the required API key, log in to Open Badge Factory. When logged in, navigate to `Admin tools > API`.
Legacy key:
On the API key -page click on `Generate certificate signing request token` for legacy type key. Copy the generated token into OBF Moodle plugin settings, in `Site administration > Open Badges > Settings`.
OAuth2 key:
Pro level clients can also connect with OAuth2. This supports multiple clients on one Moodle installation.
On the API key -page click on `Generate new client secret` for OAuth2 Client Credentials. Give a description for the key and copy the client id and secret values into OBF Moodle plugin settings, in `Site administration > Open Badges > Settings`.
Changelog
------------------
0.5.2
- Fixed warnings for missing page context
- Fixed api call for all user badges when using legacy connection
0.5.1
- Connect multiple Factory clients with OAuth2
- Awarding rules bug fixes
- Other minor fixes and improvements
0.4
- Fixed problem with Moodle 3.10.1
- Added support for Totara program and certications
<?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/>.
/**
* Script for fetching user's badges via Ajax.
*
* @package local_obf
* @copyright 2013-2020, Open Badge Factory Oy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('AJAX_SCRIPT', true);
require_once(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/class/backpack.php');
require_login(); // TODO: Handle login requirement more gracefully for more useful error messages?
$userid = required_param('userid', PARAM_INT);
$provider = optional_param('provider', 0, PARAM_INT);
$context = context_user::instance($userid);
if ((int)$USER->id === $userid) {
require_capability('local/obf:viewownbackpack', $context);
} else {
// TODO: more specific capabilities?
require_capability('local/obf:viewbackpack', $context);
}
$backpack = obf_backpack::get_instance_by_userid($userid, $DB, $provider);
if ($backpack === false || count($backpack->get_group_ids()) == 0) {
die(json_encode(array('error' => 'nogroups')));
}
echo json_encode($backpack->get_assertions_as_array());
<?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/>.
/**
* Plugin configuration page.
*
* @package local_obf
* @copyright 2013-2020, Open Badge Factory Oy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once(__DIR__ . '/class/backpack.php');
require_once(__DIR__ . '/form/backpackconfig.php');
$context = context_system::instance();
$msg = optional_param('msg', '', PARAM_TEXT);
$action = optional_param('action', 'list', PARAM_TEXT);
$providerid = optional_param('id', 0, PARAM_NUMBER);
$urlparams = $action == 'list' ? array() : array('action' => $action);
$url = new moodle_url('/local/obf/backpackconfig.php', $urlparams);
require_login();
require_capability('local/obf:configure', $context);
$PAGE->set_context($context);
$PAGE->set_url($url);
$PAGE->set_pagelayout('admin');
$content = '';
$backpacks = array();
if (!empty($msg)) {
$content .= $OUTPUT->notification($msg);
}
foreach (obf_backpack::get_providers() as $provider) {
$existing = obf_backpack::get_instance($USER, $provider);
$backpacks[] = $existing ? $existing : new obf_backpack(null, $provider);
}
function local_obf_backpackconfig_update_backpack_from_form($form, $backpack, &$content) {
if (!$form->is_cancelled()) {
if ($data = $form->get_data()) {
if (!empty($data->deletebutton)) {
obf_backpack::delete_provider_record($backpack);
if (obf_backpack::save_provider_record($backpack)) {
$redirecturl = new moodle_url('/local/obf/backpackconfig.php');
redirect($redirecturl);
}
} else {
$backpack = (object) array_merge((array) $backpack, (array) $data);
if (obf_backpack::save_provider_record($backpack)) {
$redirecturl = new moodle_url('/local/obf/backpackconfig.php');
redirect($redirecturl);
}
}
} else {
$form->set_data($backpack);
}
$content .= $form->render();
} else {
$redirecturl = new moodle_url('/local/obf/backpackconfig.php');
redirect($redirecturl);
}
}
switch ($action) {
case 'list':
$content .= $PAGE->get_renderer('local_obf')->print_heading('personalbadgecloudservices');
$content .= $PAGE->get_renderer('local_obf')->render_backpack_provider_list($backpacks);
break;
case 'create':
$backpack = new stdClass();
$formurl = new moodle_url('/local/obf/backpackconfig.php', array('action' => 'create'));
$form = new obf_backpack_config($formurl, array('backpack' => $backpack));
local_obf_backpackconfig_update_backpack_from_form($form, $backpack, $content);
break;
case 'edit':
$backpack = obf_backpack::get_provider_record($providerid);
$formurl = new moodle_url('/local/obf/backpackconfig.php', array('action' => 'edit', 'id' => $providerid));
$form = new obf_backpack_config($formurl, array('backpack' => $backpack));
local_obf_backpackconfig_update_backpack_from_form($form, $backpack, $content);
$providername = isset($backpack->fullname) ? $backpack->fullname : '';
$params = array(array('class' => 'delete',
'question' => get_string('confirmdelete', 'local_obf', $providername)));
$PAGE->requires->yui_module('moodle-local_obf-submitconfirm',
'M.local_obf.init_submitconfirm', $params);
break;
}
echo $OUTPUT->header();
echo $content;
echo $OUTPUT->footer();
\ No newline at end of file
<?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/>.
/**
* Page for displaying content closely related to badges.
*
* @package local_obf
* @copyright 2013-2020, Open Badge Factory Oy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/class/badge.php');
require_once($CFG->libdir . '/adminlib.php');
$clientid = optional_param('clientid', null, PARAM_ALPHANUM);
obf_client::connect($clientid, $USER);
$badgeid = optional_param('id', '', PARAM_ALPHANUM);
$action = optional_param('action', 'list', PARAM_ALPHANUM);
$courseid = optional_param('courseid', null, PARAM_INT);
$criteriatype = optional_param('criteriatype', null, PARAM_INT);
$message = optional_param('msg', '', PARAM_TEXT);
$context = empty($courseid) ? context_system::instance() : context_course::instance($courseid);
$url = new moodle_url('/local/obf/badge.php', array('action' => $action));
if (!empty($badgeid)) {
$url->param('id', $badgeid);
}
// Site context.
if (empty($courseid)) {
require_login();
} else { // Course context.
$url->param('courseid', $courseid);
require_login($courseid);
}
$PAGE->set_context($context);
$PAGE->set_url($url);
$PAGE->set_pagelayout(empty($courseid) ? 'admin' : 'course');
$PAGE->set_title(get_string('obf', 'local_obf'));
$PAGE->add_body_class('local-obf');
$badge = empty($badgeid) ? null : obf_badge::get_instance($badgeid);
$content = '';
$hasissuecapability = has_capability('local/obf:issuebadge', $context);
switch ($action) {
// Show issuance history.
case 'history':
require_capability('local/obf:viewhistory', $context);
$page = optional_param('page', 0, PARAM_INT);
try {
$content .= $PAGE->get_renderer('local_obf')->render_client_selector($url, $clientid);
$client = obf_client::get_instance();
$content .= $PAGE->get_renderer('local_obf')->print_badge_info_history(
$client, $badge, $context, $page);
} catch (Exception $e) {
$content .= $OUTPUT->notification($e->getMessage());
}
break;
// Show the list of badges.
case 'list':
require_capability('local/obf:viewallbadges', $context);
$content .= $PAGE->get_renderer('local_obf')->render_client_selector($url, $clientid);
try {
$badges = obf_badge::get_badges();
if ($context instanceof context_system) {
$content .= $PAGE->get_renderer('local_obf')->render_badgelist($badges,
$hasissuecapability, $context, $message);
} else {
$content .= $PAGE->get_renderer('local_obf')->render_badgelist_course($badges,
$hasissuecapability, $context, $message);
}
} catch (Exception $e) {
$content .= $OUTPUT->notification($e->getMessage(), 'notifyproblem');
}
break;
case 'historycsv':
$PAGE->get_renderer('local_obf')->create_csv($badge);
break;
// Display badge info.
case 'show':
require_capability('local/obf:viewdetails', $context);
$client = obf_client::get_instance();
$page = optional_param('page', 0, PARAM_INT);
$show = optional_param('show', 'details', PARAM_ALPHANUM);
$badgeurl = new moodle_url('/local/obf/badge.php',
array('action' => 'show', 'id' => $badgeid, 'clientid' => $clientid));
if ($context instanceof context_system) {
navigation_node::override_active_url(
new moodle_url('/local/obf/badge.php', array('action' => 'list'))
);
$PAGE->navbar->add($badge->get_name(), $badgeurl);
} else {
navigation_node::override_active_url(
new moodle_url('/local/obf/badge.php', array('action' => 'list', 'courseid' => $courseid))
);
$coursebadgeurl = clone $badgeurl;
$coursebadgeurl->param('courseid', $courseid);
$PAGE->navbar->add($badge->get_name(), $coursebadgeurl);
}
$renderer = $PAGE->get_renderer('local_obf', 'badge');
$content .= $PAGE->get_renderer('local_obf')->render_badge_heading($badge,
$context);
switch ($show) {
// Email template.
case 'email':
require_capability('local/obf:configure', $context);
$emailurl = new moodle_url(
'/local/obf/badge.php', array('id' => $badge->get_id(),
'action' => 'show', 'show' => 'email', 'clientid' => $clientid));
/*
$PAGE->navbar->add(
get_string('badgeemail', 'local_obf'), $emailurl);
*/
$form = new obf_email_template_form(
$emailurl, array('badge' => $badge));
$html = '';
if (!empty($message)) {
$html .= $OUTPUT->notification($message, 'notifysuccess');
}
if (!is_null($data = $form->get_data())) {
global $DB;
$email = is_null($badge->get_email()) ? new obf_email() : $badge->get_email();
$email->set_badge_id($badge->get_id());
$email->set_subject($data->emailsubject);
$email->set_body($data->emailbody);
$email->set_footer($data->emailfooter);
$email->set_link_text($data->emaillinktext);
$email->save($DB);
$redirecturl = clone $emailurl;
$redirecturl->param(
'msg', get_string('emailtemplatesaved', 'local_obf'));
redirect($redirecturl);
}
$html .= $form->render();
$content .= $renderer->page($badge, 'email', $html);
break;
// Badge details.
case 'details':
$taburl = clone $badgeurl;
$taburl->param('show', $show);
/*
if ($context instanceof context_system) {
$PAGE->navbar->add(
get_string('badge' . $show, 'local_obf'), $taburl);
}
*/
$content .= $PAGE->get_renderer('local_obf')->page_badgedetails(
$client, $badge, $context, $show, $page, $message);
$content .= $PAGE->get_renderer('local_obf')->issue_button($badge, $context);
break;
// Badge criteria.
case 'criteria':
$content .= $PAGE->get_renderer('local_obf')->page_badgedetails(
$client, $badge, $context, $show, $page, $message);
break;
// Badge issuance history.
case 'history':
$content .= $PAGE->get_renderer('local_obf')->page_badgedetails(
$client, $badge, $context, $show, $page, $message);
break;
}
break;
case 'deletecriterion':
require_capability('local/obf:editcriterion', $context);
$criterionid = required_param('criterionid', PARAM_INT);
if (confirm_sesskey()) {
$criterion = obf_criterion::get_instance($criterionid);
$criterion->delete();
}
$badgeurl = new moodle_url('/local/obf/badge.php',
array('action' => 'show', 'show' => 'criteria', 'id' => $badgeid, 'clientid' => $clientid)
);
if (!empty($courseid)) {
$badgeurl->param('courseid', $courseid);
}
redirect($badgeurl, get_string('criteriondeleted', 'local_obf'));
break;
}
echo $OUTPUT->header();
echo $content;
echo $OUTPUT->footer();
<?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/>.
/**
* Page for blacklisting individual badges from being displayed on the profile page.
*
* @package local_obf
* @copyright 2013-2020, Open Badge Factory Oy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/class/blacklist.php');
require_once(__DIR__ . '/form/blacklist.php');
require_once(__DIR__ . '/class/user_preferences.php');
$error = optional_param('error', '', PARAM_TEXT);
$msg = optional_param('msg', '', PARAM_TEXT);
$action = optional_param('action', 'edit', PARAM_TEXT);
$context = context_system::instance();
require_login();
require_capability('local/obf:configureuser', $context);
$url = new moodle_url('/local/obf/blacklist.php', array('action' => $action));
$PAGE->set_context($context);
$PAGE->set_url($url);
$PAGE->set_pagelayout('standard');
$content = $OUTPUT->header();
$obfuserpreferences = new obf_user_preferences($USER->id);
$formurl = new moodle_url('/local/obf/blacklist.php', array('action' => 'update'));
$form = new obf_blacklist_form($formurl,
array('user' => $USER,
'blacklist' => new obf_blacklist($USER->id)));
switch ($action) {
case 'edit':
if (!empty($msg)) {
$content .= $OUTPUT->notification($msg, 'notifysuccess');
}
$content .= $PAGE->get_renderer('local_obf')->render_blacklistconfig($form, $error);
break;
case 'addbadge':
$badgeid = required_param('badgeid', PARAM_ALPHANUM);
require_sesskey();
$blacklist = new obf_blacklist($USER->id);
$blacklist->add_to_blacklist($badgeid);
$blacklist->save();
$redirecturl = $url;
$redirecturl->param('msg', get_string('blacklistsaved', 'local_obf'));
$redirecturl->param('action', 'edit');
cache_helper::invalidate_by_event('obf_blacklist_changed', array($USER->id));
redirect($redirecturl);
break;
case 'update':
if ($data = $form->get_data()) {
$newblacklist = property_exists($data, 'blacklist') ? array_keys(array_filter($data->blacklist)) : array();
$blacklist = new obf_blacklist($USER->id);
$blacklist->save($newblacklist);
cache_helper::invalidate_by_event('obf_blacklist_changed', array($USER->id));
$redirecturl = $url;
$redirecturl->param('msg', get_string('blacklistsaved', 'local_obf'));
$redirecturl->param('action', 'edit');
redirect($redirecturl);
}
break;
}
$content .= $OUTPUT->footer();
echo $content;
This diff is collapsed.
<?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/>.
/**
* Collection of assertions.
* @package local_obf
* @copyright 2013-2020, Open Badge Factory Oy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/assertion.php');
require_once(__DIR__ . '/backpack.php');
require_once(__DIR__ . '/blacklist.php');
/**
* Represents a collection of events in OBF.
*
* @author olli
* @copyright 2013-2020, Open Badge Factory Oy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class obf_assertion_collection implements Countable, IteratorAggregate {
/**
* @var obf_assertion[] The assertions in this collection.
*/
private $assertions = array();
/**
* Assertion recipients mapped as Moodle users
*
* @var array
*/
private $users = array();
/**
* Class constructor.
*
* @param obf_assertion[] $assertions The assertions.
*/
public function __construct(array $assertions = array()) {
$this->assertions = $assertions;
}
/**
* Adds an assertion to this collection.
*
* @param obf_assertion $assertion The assertion.
*/
public function add_assertion(obf_assertion $assertion) {
$this->assertions[] = $assertion;
}
/**
* Returns an array representing this collection.