first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,81 @@
<?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/>.
/**
* This file contains the form add/update oauth2 endpoint.
*
* @package tool_oauth2
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_oauth2\form;
defined('MOODLE_INTERNAL') || die();
use stdClass;
use core\form\persistent;
/**
* Issuer form.
*
* @package tool_oauth2
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class endpoint extends persistent {
/** @var string $persistentclass */
protected static $persistentclass = 'core\\oauth2\\endpoint';
/** @var array $fieldstoremove */
protected static $fieldstoremove = array('submitbutton', 'action');
/**
* Define the form - called by parent constructor
*/
public function definition() {
global $PAGE;
$mform = $this->_form;
$endpoint = $this->get_persistent();
// Name.
$mform->addElement('text', 'name', get_string('endpointname', 'tool_oauth2'));
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addHelpButton('name', 'endpointname', 'tool_oauth2');
// Url.
$mform->addElement('text', 'url', get_string('endpointurl', 'tool_oauth2'));
$mform->addRule('url', null, 'required', null, 'client');
$mform->addRule('url', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client');
$mform->addHelpButton('url', 'endpointurl', 'tool_oauth2');
$mform->addElement('hidden', 'action', 'edit');
$mform->setType('action', PARAM_ALPHA);
$mform->addElement('hidden', 'issuerid', $endpoint->get('issuerid'));
$mform->setType('issuerid', PARAM_INT);
$mform->setConstant('issuerid', $this->_customdata['issuerid']);
$mform->addElement('hidden', 'id', $endpoint->get('id'));
$mform->setType('id', PARAM_INT);
$this->add_action_buttons(true, get_string('savechanges', 'tool_oauth2'));
}
}
+261
View File
@@ -0,0 +1,261 @@
<?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/>.
/**
* This file contains the form add/update oauth2 issuer.
*
* @package tool_oauth2
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_oauth2\form;
defined('MOODLE_INTERNAL') || die();
use stdClass;
use core\form\persistent;
/**
* Issuer form.
*
* @package tool_oauth2
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class issuer extends persistent {
/** @var string $persistentclass */
protected static $persistentclass = 'core\\oauth2\\issuer';
/** @var array $fieldstoremove */
protected static $fieldstoremove = array('type', 'submitbutton', 'action');
/** @var string $type */
protected $type;
/**
* Constructor.
*
* The 'persistent' has to be passed as custom data when 'editing'.
* If a standard issuer is created the type can be passed as custom data, which alters the form according to the
* type.
*
* Note that in order for your persistent to be reloaded after form submission you should
* either override the URL to include the ID to your resource, or add the ID to the form
* fields.
*
* @param mixed $action
* @param mixed $customdata
* @param string $method
* @param string $target
* @param mixed $attributes
* @param bool $editable
* @param array $ajaxformdata
*/
public function __construct($action = null, $customdata = null, $method = 'post', $target = '', $attributes = null,
$editable = true, array $ajaxformdata = null) {
// The type variable defines, if we are in the creation process of a standard issuer.
if (array_key_exists('type', $customdata)) {
$this->type = $customdata['type'];
}
parent::__construct($action, $customdata, $method, $target, $attributes, $editable, $ajaxformdata);
}
/**
* Define the form - called by parent constructor
*/
public function definition() {
global $PAGE, $OUTPUT;
$mform = $this->_form;
$issuer = $this->get_persistent();
$docslink = optional_param('docslink', '', PARAM_ALPHAEXT);
if ($docslink) {
$name = s($issuer->get('name'));
$mform->addElement('html', $OUTPUT->doc_link($docslink, get_string('issuersetuptype', 'tool_oauth2', $name)));
} else {
$mform->addElement('html', $OUTPUT->page_doc_link(get_string('issuersetup', 'tool_oauth2')));
}
// Name.
$mform->addElement('text', 'name', get_string('issuername', 'tool_oauth2'));
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addHelpButton('name', 'issuername', 'tool_oauth2');
// Client ID.
$mform->addElement('text', 'clientid', get_string('issuerclientid', 'tool_oauth2'));
$mform->addRule('clientid', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addHelpButton('clientid', 'issuerclientid', 'tool_oauth2');
// Client Secret.
$mform->addElement('text', 'clientsecret', get_string('issuerclientsecret', 'tool_oauth2'));
$mform->addRule('clientsecret', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addHelpButton('clientsecret', 'issuerclientsecret', 'tool_oauth2');
// Use basic authentication.
$mform->addElement('advcheckbox', 'basicauth', get_string('usebasicauth', 'tool_oauth2'));
$mform->addHelpButton('basicauth', 'usebasicauth', 'tool_oauth2');
// Base Url.
$mform->addElement('text', 'baseurl', get_string('issuerbaseurl', 'tool_oauth2'));
$mform->addRule('baseurl', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client');
$mform->addHelpButton('baseurl', 'issuerbaseurl', 'tool_oauth2');
if ($this->type && $this->type == 'nextcloud') {
$mform->addRule('baseurl', null, 'required', null, 'client');
}
// Image.
$mform->addElement('text', 'image', get_string('issuerimage', 'tool_oauth2'), 'maxlength="1024"');
$mform->addRule('image', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client');
$mform->addHelpButton('image', 'issuername', 'tool_oauth2');
// Show on login page.
$options = [
\core\oauth2\issuer::EVERYWHERE => get_string('issueruseineverywhere', 'tool_oauth2'),
\core\oauth2\issuer::LOGINONLY => get_string('issueruseinloginonly', 'tool_oauth2'),
\core\oauth2\issuer::SERVICEONLY => get_string('issueruseininternalonly', 'tool_oauth2'),
];
$mform->addElement('select', 'showonloginpage', get_string('issuerusein', 'tool_oauth2'), $options);
$mform->addHelpButton('showonloginpage', 'issuerusein', 'tool_oauth2');
// Name on login page.
$mform->addElement('text', 'loginpagename', get_string('issuerloginpagename', 'tool_oauth2'));
$mform->addRule('loginpagename', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addHelpButton('loginpagename', 'issuerloginpagename', 'tool_oauth2');
$mform->hideIf('loginpagename', 'showonloginpage', 'eq', \core\oauth2\issuer::SERVICEONLY);
// Login scopes.
$mform->addElement('text', 'loginscopes', get_string('issuerloginscopes', 'tool_oauth2'));
$mform->addRule('loginscopes', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addHelpButton('loginscopes', 'issuerloginscopes', 'tool_oauth2');
// Login scopes offline.
$mform->addElement('text', 'loginscopesoffline', get_string('issuerloginscopesoffline', 'tool_oauth2'));
$mform->addRule('loginscopesoffline', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addHelpButton('loginscopesoffline', 'issuerloginscopesoffline', 'tool_oauth2');
// Login params.
$mform->addElement('text', 'loginparams', get_string('issuerloginparams', 'tool_oauth2'));
$mform->addRule('loginparams', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addHelpButton('loginparams', 'issuerloginparams', 'tool_oauth2');
// Login params offline.
$mform->addElement('text', 'loginparamsoffline', get_string('issuerloginparamsoffline', 'tool_oauth2'));
$mform->addRule('loginparamsoffline', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addHelpButton('loginparamsoffline', 'issuerloginparamsoffline', 'tool_oauth2');
// Allowed Domains.
$mform->addElement('text', 'alloweddomains', get_string('issueralloweddomains', 'tool_oauth2'));
$mform->addRule('alloweddomains', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client');
$mform->addHelpButton('alloweddomains', 'issueralloweddomains', 'tool_oauth2');
$mform->hideIf('alloweddomains', 'showonloginpage', 'eq', \core\oauth2\issuer::SERVICEONLY);
// Require confirmation email for new accounts.
$mform->addElement('advcheckbox', 'requireconfirmation',
get_string('issuerrequireconfirmation', 'tool_oauth2'));
$mform->addHelpButton('requireconfirmation', 'issuerrequireconfirmation', 'tool_oauth2');
$mform->hideIf('requireconfirmation', 'showonloginpage',
'eq', \core\oauth2\issuer::SERVICEONLY);
$mform->addElement('checkbox', 'acceptrisk', get_string('acceptrisk', 'tool_oauth2'));
$mform->addHelpButton('acceptrisk', 'acceptrisk', 'tool_oauth2');
$mform->hideIf('acceptrisk', 'showonloginpage',
'eq', \core\oauth2\issuer::SERVICEONLY);
$mform->hideIf('acceptrisk', 'requireconfirmation', 'checked');
if ($this->type == 'imsobv2p1' || $issuer->get('servicetype') == 'imsobv2p1'
|| $this->type == 'moodlenet' || $issuer->get('servicetype') == 'moodlenet') {
$mform->addRule('baseurl', null, 'required', null, 'client');
} else {
$mform->addRule('clientid', null, 'required', null, 'client');
$mform->addRule('clientsecret', null, 'required', null, 'client');
}
$mform->addElement('hidden', 'sortorder');
$mform->setType('sortorder', PARAM_INT);
$mform->addElement('hidden', 'servicetype');
$mform->setType('servicetype', PARAM_ALPHANUM);
if ($this->type) {
$mform->addElement('hidden', 'action', 'savetemplate');
$mform->setType('action', PARAM_ALPHA);
$mform->addElement('hidden', 'type', $this->_customdata['type']);
$mform->setType('type', PARAM_ALPHANUM);
} else {
$mform->addElement('hidden', 'action', 'edit');
$mform->setType('action', PARAM_ALPHA);
}
$mform->addElement('hidden', 'enabled', $issuer->get('enabled'));
$mform->setType('enabled', PARAM_BOOL);
$mform->addElement('hidden', 'id', $issuer->get('id'));
$mform->setType('id', PARAM_INT);
$this->add_action_buttons(true, get_string('savechanges', 'tool_oauth2'));
}
/**
* This method implements changes to the form that need to be made once the form data is set.
*/
public function definition_after_data() {
$mform = $this->_form;
if ($this->type) {
// Set servicetype if it's defined.
$mform->getElement('servicetype')->setValue($this->type);
}
}
/**
* Define extra validation mechanims.
*
* The data here:
* - does not include {@see self::$fieldstoremove}.
* - does include {@see self::$foreignfields}.
* - was converted to map persistent-like data, e.g. array $description to string $description + int $descriptionformat.
*
* You can modify the $errors parameter in order to remove some validation errors should you
* need to. However, the best practice is to return new or overriden errors. Only modify the
* errors passed by reference when you have no other option.
*
* Do not add any logic here, it is only intended to be used by child classes.
*
* @param stdClass $data Data to validate.
* @param array $files Array of files.
* @param array $errors Currently reported errors.
* @return array of additional errors, or overridden errors.
*/
protected function extra_validation($data, $files, array &$errors) {
if ($data->showonloginpage != \core\oauth2\issuer::SERVICEONLY) {
if (!strlen(trim($data->loginscopes))) {
$errors['loginscopes'] = get_string('required');
}
if (!strlen(trim($data->loginscopesoffline))) {
$errors['loginscopesoffline'] = get_string('required');
}
if (empty($data->requireconfirmation) && empty($data->acceptrisk)) {
$errors['acceptrisk'] = get_string('required');
}
}
return $errors;
}
}
@@ -0,0 +1,80 @@
<?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/>.
/**
* This file contains the form add/update oauth2 user_field_mapping.
*
* @package tool_oauth2
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_oauth2\form;
defined('MOODLE_INTERNAL') || die();
use stdClass;
use core\form\persistent;
/**
* Issuer form.
*
* @package tool_oauth2
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_field_mapping extends persistent {
/** @var string $persistentclass */
protected static $persistentclass = 'core\\oauth2\\user_field_mapping';
/** @var array $fieldstoremove */
protected static $fieldstoremove = array('submitbutton', 'action');
/**
* Define the form - called by parent constructor
*/
public function definition() {
global $PAGE;
$mform = $this->_form;
$userfieldmapping = $this->get_persistent();
// External.
$mform->addElement('text', 'externalfield', get_string('userfieldexternalfield', 'tool_oauth2'));
$mform->addRule('externalfield', null, 'required', null, 'client');
$mform->addRule('externalfield', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addHelpButton('externalfield', 'userfieldexternalfield', 'tool_oauth2');
// Internal.
$choices = $userfieldmapping->get_internalfield_list();
$mform->addElement('selectgroups', 'internalfield', get_string('userfieldinternalfield', 'tool_oauth2'), $choices);
$mform->addHelpButton('internalfield', 'userfieldinternalfield', 'tool_oauth2');
$mform->addElement('hidden', 'action', 'edit');
$mform->setType('action', PARAM_ALPHA);
$mform->addElement('hidden', 'issuerid', $userfieldmapping->get('issuerid'));
$mform->setConstant('issuerid', $this->_customdata['issuerid']);
$mform->setType('issuerid', PARAM_INT);
$mform->addElement('hidden', 'id', $userfieldmapping->get('id'));
$mform->setType('id', PARAM_INT);
$this->add_action_buttons(true, get_string('savechanges', 'tool_oauth2'));
}
}
@@ -0,0 +1,333 @@
<?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/>.
/**
* Output rendering for the plugin.
*
* @package tool_oauth2
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_oauth2\output;
use plugin_renderer_base;
use html_table;
use html_table_cell;
use html_table_row;
use html_writer;
use core\oauth2\issuer;
use core\oauth2\api;
use moodle_url;
defined('MOODLE_INTERNAL') || die();
/**
* Implements the plugin renderer
*
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends plugin_renderer_base {
/**
* This function will render one beautiful table with all the issuers.
*
* @param \core\oauth2\issuer[] $issuers - list of all issuers.
* @return string HTML to output.
*/
public function issuers_table($issuers) {
global $CFG;
$table = new html_table();
$table->head = [
get_string('name'),
get_string('issuerusedforlogin', 'tool_oauth2'),
get_string('logindisplay', 'tool_oauth2'),
get_string('issuerusedforinternal', 'tool_oauth2'),
get_string('discoverystatus', 'tool_oauth2') . ' ' . $this->help_icon('discovered', 'tool_oauth2'),
get_string('systemauthstatus', 'tool_oauth2') . ' ' . $this->help_icon('systemaccountconnected', 'tool_oauth2'),
get_string('edit'),
];
$table->attributes['class'] = 'admintable generaltable';
$data = [];
$index = 0;
foreach ($issuers as $issuer) {
// We need to handle the first and last ones specially.
$first = false;
if ($index == 0) {
$first = true;
}
$last = false;
if ($index == count($issuers) - 1) {
$last = true;
}
// Name.
$name = $issuer->get('name');
$image = $issuer->get('image');
if ($image) {
$name = '<img width="24" height="24" alt="" src="' . s($image) . '"> ' . s($name);
}
$namecell = new html_table_cell($name);
$namecell->header = true;
// Login issuer.
if ((int)$issuer->get('showonloginpage') == issuer::SERVICEONLY) {
$loginissuer = $this->pix_icon('no', get_string('notloginissuer', 'tool_oauth2'), 'tool_oauth2');
$logindisplayas = '';
} else {
$logindisplayas = s($issuer->get_display_name());
if ($issuer->get('id') && $issuer->is_configured() && !empty($issuer->get_endpoint_url('userinfo'))) {
$loginissuer = $this->pix_icon('yes', get_string('loginissuer', 'tool_oauth2'), 'tool_oauth2');
} else {
$loginissuer = $this->pix_icon('notconfigured', get_string('notconfigured', 'tool_oauth2'), 'tool_oauth2');
}
}
$loginissuerstatuscell = new html_table_cell($loginissuer);
// Internal services issuer.
if ((int)$issuer->get('showonloginpage') == issuer::LOGINONLY) {
$serviceissuer = $this->pix_icon('no', get_string('issuersservicesnotallow', 'tool_oauth2'), 'tool_oauth2');
} else if ($issuer->get('id') && $issuer->is_configured()) {
$serviceissuer = $this->pix_icon('yes', get_string('issuersservicesallow', 'tool_oauth2'), 'tool_oauth2');
} else {
$serviceissuer = $this->pix_icon('notconfigured', get_string('notconfigured', 'tool_oauth2'), 'tool_oauth2');
}
$internalissuerstatuscell = new html_table_cell($serviceissuer);
// Discovered.
if (!empty($issuer->get('scopessupported'))) {
$discovered = $this->pix_icon('yes', get_string('discovered', 'tool_oauth2'), 'tool_oauth2');
} else {
if (!empty($issuer->get_endpoint_url('discovery'))) {
$discovered = $this->pix_icon('no', get_string('notdiscovered', 'tool_oauth2'), 'tool_oauth2');
} else {
$discovered = '-';
}
}
$discoverystatuscell = new html_table_cell($discovered);
// Connected.
if ($issuer->is_system_account_connected()) {
$systemaccount = \core\oauth2\api::get_system_account($issuer);
$systemauth = s($systemaccount->get('email')) . ' (' . s($systemaccount->get('username')). ') ';
$systemauth .= $this->pix_icon('yes', get_string('systemaccountconnected', 'tool_oauth2'), 'tool_oauth2');
} else {
$systemauth = $this->pix_icon('no', get_string('systemaccountnotconnected', 'tool_oauth2'), 'tool_oauth2');
}
$params = ['id' => $issuer->get('id'), 'action' => 'auth'];
$authurl = new moodle_url('/admin/tool/oauth2/issuers.php', $params);
$icon = $this->pix_icon('auth', get_string('connectsystemaccount', 'tool_oauth2'), 'tool_oauth2');
$authlink = html_writer::link($authurl, $icon);
$systemauth .= ' ' . $authlink;
$systemauthstatuscell = new html_table_cell($systemauth);
$links = '';
// Action links.
$editurl = new moodle_url('/admin/tool/oauth2/issuers.php', ['id' => $issuer->get('id'), 'action' => 'edit']);
$editlink = html_writer::link($editurl, $this->pix_icon('t/edit', get_string('edit')));
$links .= ' ' . $editlink;
// Endpoints.
$editendpointsurl = new moodle_url('/admin/tool/oauth2/endpoints.php', ['issuerid' => $issuer->get('id')]);
$str = get_string('editendpoints', 'tool_oauth2');
$editendpointlink = html_writer::link($editendpointsurl, $this->pix_icon('t/viewdetails', $str));
$links .= ' ' . $editendpointlink;
// User field mapping.
$params = ['issuerid' => $issuer->get('id')];
$edituserfieldmappingsurl = new moodle_url('/admin/tool/oauth2/userfieldmappings.php', $params);
$str = get_string('edituserfieldmappings', 'tool_oauth2');
$edituserfieldmappinglink = html_writer::link($edituserfieldmappingsurl, $this->pix_icon('t/user', $str));
$links .= ' ' . $edituserfieldmappinglink;
// Delete.
$deleteurl = new moodle_url('/admin/tool/oauth2/issuers.php', ['id' => $issuer->get('id'), 'action' => 'delete']);
$deletelink = html_writer::link($deleteurl, $this->pix_icon('t/delete', get_string('delete')));
$links .= ' ' . $deletelink;
// Enable / Disable.
if ($issuer->get('enabled')) {
// Disable.
$disableparams = ['id' => $issuer->get('id'), 'sesskey' => sesskey(), 'action' => 'disable'];
$disableurl = new moodle_url('/admin/tool/oauth2/issuers.php', $disableparams);
$disablelink = html_writer::link($disableurl, $this->pix_icon('t/hide', get_string('disable')));
$links .= ' ' . $disablelink;
} else {
// Enable.
$enableparams = ['id' => $issuer->get('id'), 'sesskey' => sesskey(), 'action' => 'enable'];
$enableurl = new moodle_url('/admin/tool/oauth2/issuers.php', $enableparams);
$enablelink = html_writer::link($enableurl, $this->pix_icon('t/show', get_string('enable')));
$links .= ' ' . $enablelink;
}
if (!$last) {
// Move down.
$params = ['id' => $issuer->get('id'), 'action' => 'movedown', 'sesskey' => sesskey()];
$movedownurl = new moodle_url('/admin/tool/oauth2/issuers.php', $params);
$movedownlink = html_writer::link($movedownurl, $this->pix_icon('t/down', get_string('movedown')));
$links .= ' ' . $movedownlink;
}
if (!$first) {
// Move up.
$params = ['id' => $issuer->get('id'), 'action' => 'moveup', 'sesskey' => sesskey()];
$moveupurl = new moodle_url('/admin/tool/oauth2/issuers.php', $params);
$moveuplink = html_writer::link($moveupurl, $this->pix_icon('t/up', get_string('moveup')));
$links .= ' ' . $moveuplink;
}
$editcell = new html_table_cell($links);
$row = new html_table_row([
$namecell,
$loginissuerstatuscell,
$logindisplayas,
$internalissuerstatuscell,
$discoverystatuscell,
$systemauthstatuscell,
$editcell,
]);
if (!$issuer->get('enabled')) {
$row->attributes['class'] = 'dimmed_text';
}
$data[] = $row;
$index++;
}
$table->data = $data;
return html_writer::table($table);
}
/**
* This function will render one beautiful table with all the endpoints.
*
* @param \core\oauth2\endpoint[] $endpoints - list of all endpoints.
* @param int $issuerid
* @return string HTML to output.
*/
public function endpoints_table($endpoints, $issuerid) {
global $CFG;
$table = new html_table();
$table->head = [
get_string('name'),
get_string('url'),
get_string('edit'),
];
$table->attributes['class'] = 'admintable generaltable';
$data = [];
$index = 0;
foreach ($endpoints as $endpoint) {
// Name.
$name = $endpoint->get('name');
$namecell = new html_table_cell(s($name));
$namecell->header = true;
// Url.
$url = $endpoint->get('url');
$urlcell = new html_table_cell(s($url));
$links = '';
// Action links.
$editparams = ['issuerid' => $issuerid, 'endpointid' => $endpoint->get('id'), 'action' => 'edit'];
$editurl = new moodle_url('/admin/tool/oauth2/endpoints.php', $editparams);
$editlink = html_writer::link($editurl, $this->pix_icon('t/edit', get_string('edit')));
$links .= ' ' . $editlink;
// Delete.
$deleteparams = ['issuerid' => $issuerid, 'endpointid' => $endpoint->get('id'), 'action' => 'delete'];
$deleteurl = new moodle_url('/admin/tool/oauth2/endpoints.php', $deleteparams);
$deletelink = html_writer::link($deleteurl, $this->pix_icon('t/delete', get_string('delete')));
$links .= ' ' . $deletelink;
$editcell = new html_table_cell($links);
$row = new html_table_row([
$namecell,
$urlcell,
$editcell,
]);
$data[] = $row;
$index++;
}
$table->data = $data;
return html_writer::table($table);
}
/**
* This function will render one beautiful table with all the user_field_mappings.
*
* @param \core\oauth2\user_field_mapping[] $userfieldmappings - list of all user_field_mappings.
* @param int $issuerid
* @return string HTML to output.
*/
public function user_field_mappings_table($userfieldmappings, $issuerid) {
global $CFG;
$table = new html_table();
$table->head = [
get_string('userfieldexternalfield', 'tool_oauth2'),
get_string('userfieldinternalfield', 'tool_oauth2'),
get_string('edit'),
];
$table->attributes['class'] = 'admintable generaltable';
$data = [];
$index = 0;
foreach ($userfieldmappings as $userfieldmapping) {
// External field.
$externalfield = $userfieldmapping->get('externalfield');
$externalfieldcell = new html_table_cell(s($externalfield));
// Internal field.
$internalfield = $userfieldmapping->get('internalfield');
$internalfieldcell = new html_table_cell(s($internalfield));
$links = '';
// Action links.
$editparams = ['issuerid' => $issuerid, 'userfieldmappingid' => $userfieldmapping->get('id'), 'action' => 'edit'];
$editurl = new moodle_url('/admin/tool/oauth2/userfieldmappings.php', $editparams);
$editlink = html_writer::link($editurl, $this->pix_icon('t/edit', get_string('edit')));
$links .= ' ' . $editlink;
// Delete.
$deleteparams = ['issuerid' => $issuerid, 'userfieldmappingid' => $userfieldmapping->get('id'), 'action' => 'delete'];
$deleteurl = new moodle_url('/admin/tool/oauth2/userfieldmappings.php', $deleteparams);
$deletelink = html_writer::link($deleteurl, $this->pix_icon('t/delete', get_string('delete')));
$links .= ' ' . $deletelink;
$editcell = new html_table_cell($links);
$row = new html_table_row([
$externalfieldcell,
$internalfieldcell,
$editcell,
]);
$data[] = $row;
$index++;
}
$table->data = $data;
return html_writer::table($table);
}
}
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy Subsystem implementation for tool_oauth2.
*
* @package tool_oauth2
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_oauth2\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for tool_oauth2 implementing null_provider.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}