From e3f778b52d3c10ee450e0a1293e83e24f258399b Mon Sep 17 00:00:00 2001 From: Patryk Mroczko Date: Thu, 24 Oct 2024 11:16:49 +0200 Subject: [PATCH] Fix Moodle plugin CI errors part 1 --- auth/oidc/auth.php | 6 +- auth/oidc/binding_username_claim.php | 4 +- .../auth_oidc_admin_setting_iconselect.php | 8 +- .../auth_oidc_admin_setting_label.php | 13 ++-- .../auth_oidc_admin_setting_loginflow.php | 4 +- .../auth_oidc_admin_setting_redirecturi.php | 12 +-- auth/oidc/classes/event/action_failed.php | 2 - auth/oidc/classes/event/user_authed.php | 2 - auth/oidc/classes/event/user_connected.php | 2 - auth/oidc/classes/event/user_created.php | 2 - auth/oidc/classes/event/user_disconnected.php | 2 - auth/oidc/classes/event/user_loggedin.php | 2 - .../classes/event/user_rename_attempt.php | 4 +- auth/oidc/classes/form/application.php | 14 ++-- .../classes/form/binding_username_claim.php | 18 ++++- ...ange_binding_username_claim_tool_form1.php | 2 - ...ange_binding_username_claim_tool_form2.php | 4 +- auth/oidc/classes/httpclient.php | 4 +- auth/oidc/classes/httpclientinterface.php | 4 +- auth/oidc/classes/jwt.php | 2 - auth/oidc/classes/loginflow/authcode.php | 30 +++---- auth/oidc/classes/loginflow/base.php | 26 +++---- auth/oidc/classes/loginflow/rocreds.php | 8 +- auth/oidc/classes/observers.php | 2 + auth/oidc/classes/oidcclient.php | 19 ++--- auth/oidc/classes/preview.php | 6 +- auth/oidc/classes/privacy/provider.php | 23 +++--- auth/oidc/classes/process.php | 17 +++- .../task/cleanup_oidc_state_and_token.php | 2 - auth/oidc/classes/tests/mockhttpclient.php | 4 +- auth/oidc/classes/tests/mockoidcclient.php | 10 ++- auth/oidc/classes/upload_process_tracker.php | 11 +-- auth/oidc/classes/utils.php | 8 +- auth/oidc/db/access.php | 36 ++++----- auth/oidc/db/upgrade.php | 7 +- auth/oidc/index.php | 1 + auth/oidc/lang/cs/auth_oidc.php | 6 ++ auth/oidc/lang/de/auth_oidc.php | 6 ++ auth/oidc/lang/en/auth_oidc.php | 6 ++ auth/oidc/lang/es/auth_oidc.php | 6 ++ auth/oidc/lang/fi/auth_oidc.php | 6 ++ auth/oidc/lang/fr/auth_oidc.php | 6 ++ auth/oidc/lang/it/auth_oidc.php | 6 ++ auth/oidc/lang/ja/auth_oidc.php | 6 ++ auth/oidc/lang/nl/auth_oidc.php | 6 ++ auth/oidc/lang/pl/auth_oidc.php | 6 ++ auth/oidc/lang/pt_br/auth_oidc.php | 6 ++ auth/oidc/lib.php | 78 ++++++++++++++----- auth/oidc/logout.php | 5 +- auth/oidc/sass/styles.scss | 55 ------------- auth/oidc/tests/jwt_test.php | 39 ++++++---- auth/oidc/tests/oidcclient_test.php | 43 +++++----- auth/oidc/tests/privacy_provider_test.php | 69 +++++++++------- local/office365/classes/privacy/provider.php | 2 - local/onenote/classes/api/base.php | 52 ++++++++----- local/onenote/classes/api/o365.php | 2 - local/onenote/classes/privacy/provider.php | 34 ++++---- local/onenote/classes/utils.php | 4 +- local/onenote/db/upgrade.php | 11 ++- local/onenote/lang/cs/local_onenote.php | 8 ++ local/onenote/lang/de/local_onenote.php | 8 ++ local/onenote/lang/en/local_onenote.php | 6 ++ local/onenote/lang/es/local_onenote.php | 8 ++ local/onenote/lang/fi/local_onenote.php | 8 ++ local/onenote/lang/fr/local_onenote.php | 8 ++ local/onenote/lang/it/local_onenote.php | 8 ++ local/onenote/lang/ja/local_onenote.php | 8 ++ local/onenote/lang/nl/local_onenote.php | 8 ++ local/onenote/lang/pl/local_onenote.php | 8 ++ local/onenote/lang/pt_br/local_onenote.php | 8 ++ local/onenote/styles.css | 10 +-- local/onenote/tests/generator/lib.php | 2 - local/onenote/tests/onenoteapi_test.php | 59 +++++++++----- local/onenote/tests/privacy_provider_test.php | 49 ++++++++---- .../office365/classes/privacy/provider.php | 2 +- repository/office365/db/access.php | 6 +- repository/office365/db/caches.php | 4 +- .../lang/en/repository_office365.php | 10 +-- repository/office365/lib.php | 4 +- 79 files changed, 617 insertions(+), 396 deletions(-) delete mode 100644 auth/oidc/sass/styles.scss diff --git a/auth/oidc/auth.php b/auth/oidc/auth.php index e067f2292..9637a00c5 100644 --- a/auth/oidc/auth.php +++ b/auth/oidc/auth.php @@ -78,7 +78,7 @@ public function __construct($forceloginflow = null) { * * @return bool */ - function can_be_manually_set() { + public function can_be_manually_set() { return true; } @@ -197,8 +197,8 @@ public function handleredirect() { * @param null $userid * @return mixed */ - public function disconnect($justremovetokens = false, $donotremovetokens = false, \moodle_url $redirect = null, - \moodle_url $selfurl = null, $userid = null) { + public function disconnect($justremovetokens = false, $donotremovetokens = false, ?\moodle_url $redirect = null, + ?\moodle_url $selfurl = null, $userid = null) { return $this->loginflow->disconnect($justremovetokens, $donotremovetokens, $redirect, $selfurl, $userid); } diff --git a/auth/oidc/binding_username_claim.php b/auth/oidc/binding_username_claim.php index 1aa7bcc87..dcb2a1da3 100644 --- a/auth/oidc/binding_username_claim.php +++ b/auth/oidc/binding_username_claim.php @@ -50,11 +50,11 @@ $oidcconfig = get_config('auth_oidc'); if (!isset($oidcconfig->bindingusernameclaim)) { - // bindingusernameclaim is not set, set default value. + // Bindingusernameclaim is not set, set default value. $formdata['bindingusernameclaim'] = 'auto'; $formdata['customclaimname'] = ''; set_config('bindingusernameclaim', 'auto', 'auth_oidc'); -} else if(!$oidcconfig->bindingusernameclaim) { +} else if (!$oidcconfig->bindingusernameclaim) { $formdata['bindingusernameclaim'] = 'auto'; $formdata['customclaimname'] = ''; } else if (in_array($oidcconfig->bindingusernameclaim, $predefinedbindingclaims)) { diff --git a/auth/oidc/classes/adminsetting/auth_oidc_admin_setting_iconselect.php b/auth/oidc/classes/adminsetting/auth_oidc_admin_setting_iconselect.php index 88186a47a..1fa8c8425 100644 --- a/auth/oidc/classes/adminsetting/auth_oidc_admin_setting_iconselect.php +++ b/auth/oidc/classes/adminsetting/auth_oidc_admin_setting_iconselect.php @@ -25,8 +25,6 @@ namespace auth_oidc\adminsetting; -defined('MOODLE_INTERNAL') || die(); - /** * Choose an icon for the identity provider entry on the login page. */ @@ -93,8 +91,8 @@ public function write_setting($data) { */ public function output_html($data, $query = '') { global $CFG, $OUTPUT; - $attrs = array('type' => 'text/css', 'rel' => 'stylesheet', - 'href' => new \moodle_url('/auth/oidc/classes/adminsetting/iconselect.css')); + $attrs = ['type' => 'text/css', 'rel' => 'stylesheet', + 'href' => new \moodle_url('/auth/oidc/classes/adminsetting/iconselect.css')]; $html = \html_writer::empty_tag('link', $attrs); $html .= \html_writer::start_tag('div', ['style' => 'max-width: 390px']); $selected = (!empty($data)) ? $data : $this->defaultsetting; @@ -114,7 +112,7 @@ public function output_html($data, $query = '') { } $html .= \html_writer::empty_tag('input', $inputattrs); $labelattrs = [ - 'class' => 'iconselect' + 'class' => 'iconselect', ]; $html .= \html_writer::label($iconhtml, $id, true, $labelattrs); } diff --git a/auth/oidc/classes/adminsetting/auth_oidc_admin_setting_label.php b/auth/oidc/classes/adminsetting/auth_oidc_admin_setting_label.php index 510efd40d..18917d0a2 100644 --- a/auth/oidc/classes/adminsetting/auth_oidc_admin_setting_label.php +++ b/auth/oidc/classes/adminsetting/auth_oidc_admin_setting_label.php @@ -27,21 +27,22 @@ use admin_setting; -defined('MOODLE_INTERNAL') || die(); - /** * Display a static text. */ class auth_oidc_admin_setting_label extends admin_setting { + /** + * @var string $label The label for display purposes. + */ private $label; /** * Constructor. * - * @param $name - * @param $label - * @param $visiblename - * @param $description + * @param string $name The setting name. + * @param string $label The label to display. + * @param string $visiblename The visible name for the setting. + * @param string $description A description of the setting. */ public function __construct($name, $label, $visiblename, $description) { parent::__construct($name, $visiblename, $description, ''); diff --git a/auth/oidc/classes/adminsetting/auth_oidc_admin_setting_loginflow.php b/auth/oidc/classes/adminsetting/auth_oidc_admin_setting_loginflow.php index b1c6fc5c5..7a7dcb49c 100644 --- a/auth/oidc/classes/adminsetting/auth_oidc_admin_setting_loginflow.php +++ b/auth/oidc/classes/adminsetting/auth_oidc_admin_setting_loginflow.php @@ -25,8 +25,6 @@ namespace auth_oidc\adminsetting; -defined('MOODLE_INTERNAL') || die(); - /** * Displays the redirect URI for easier config. */ @@ -79,7 +77,7 @@ public function output_html($data, $query = '') { 'type' => 'radio', 'name' => $inputname, 'id' => $flowtypeid, - 'value' => $flowtype + 'value' => $flowtype, ]; if ($data === $flowtype || (empty($data) && $flowtype === $this->get_defaultsetting())) { $radioattrs['checked'] = 'checked'; diff --git a/auth/oidc/classes/adminsetting/auth_oidc_admin_setting_redirecturi.php b/auth/oidc/classes/adminsetting/auth_oidc_admin_setting_redirecturi.php index f2b509027..9473805a6 100644 --- a/auth/oidc/classes/adminsetting/auth_oidc_admin_setting_redirecturi.php +++ b/auth/oidc/classes/adminsetting/auth_oidc_admin_setting_redirecturi.php @@ -27,20 +27,22 @@ use auth_oidc\utils; -defined('MOODLE_INTERNAL') || die(); - /** * Displays the redirect URI for easier config. */ class auth_oidc_admin_setting_redirecturi extends \admin_setting { + /** + * @var string $url The redirect URL for the configuration. + */ private $url; /** * Constructor. * - * @param $name - * @param $heading - * @param $description + * @param string $name The setting name. + * @param string $heading The setting heading. + * @param string $description The setting description. + * @param string $url The redirect URL. */ public function __construct($name, $heading, $description, $url) { $this->nosave = true; diff --git a/auth/oidc/classes/event/action_failed.php b/auth/oidc/classes/event/action_failed.php index 3ae6b9240..ff99cb06e 100644 --- a/auth/oidc/classes/event/action_failed.php +++ b/auth/oidc/classes/event/action_failed.php @@ -25,8 +25,6 @@ namespace auth_oidc\event; -defined('MOODLE_INTERNAL') || die(); - /** * Event fired whenever we need to record a debug message. */ diff --git a/auth/oidc/classes/event/user_authed.php b/auth/oidc/classes/event/user_authed.php index 60b31135f..97bf2a825 100644 --- a/auth/oidc/classes/event/user_authed.php +++ b/auth/oidc/classes/event/user_authed.php @@ -25,8 +25,6 @@ namespace auth_oidc\event; -defined('MOODLE_INTERNAL') || die(); - /** * Event fired when a user authenticated with OIDC, but does not log in. */ diff --git a/auth/oidc/classes/event/user_connected.php b/auth/oidc/classes/event/user_connected.php index 502dc795c..3f543a996 100644 --- a/auth/oidc/classes/event/user_connected.php +++ b/auth/oidc/classes/event/user_connected.php @@ -25,8 +25,6 @@ namespace auth_oidc\event; -defined('MOODLE_INTERNAL') || die(); - /** * Fired when a user connects to OpenID Connect. */ diff --git a/auth/oidc/classes/event/user_created.php b/auth/oidc/classes/event/user_created.php index 1dab15ea9..74c8626da 100644 --- a/auth/oidc/classes/event/user_created.php +++ b/auth/oidc/classes/event/user_created.php @@ -25,8 +25,6 @@ namespace auth_oidc\event; -defined('MOODLE_INTERNAL') || die(); - /** * Event fired when OIDC creates a new user. */ diff --git a/auth/oidc/classes/event/user_disconnected.php b/auth/oidc/classes/event/user_disconnected.php index 31dba0697..5fe9ce37d 100644 --- a/auth/oidc/classes/event/user_disconnected.php +++ b/auth/oidc/classes/event/user_disconnected.php @@ -25,8 +25,6 @@ namespace auth_oidc\event; -defined('MOODLE_INTERNAL') || die(); - /** * Fired when a user disconnects from OpenID Connect. */ diff --git a/auth/oidc/classes/event/user_loggedin.php b/auth/oidc/classes/event/user_loggedin.php index a11bc6ce3..1c5c0342a 100644 --- a/auth/oidc/classes/event/user_loggedin.php +++ b/auth/oidc/classes/event/user_loggedin.php @@ -25,8 +25,6 @@ namespace auth_oidc\event; -defined('MOODLE_INTERNAL') || die(); - /** * Fired when a user uses OIDC to log in. */ diff --git a/auth/oidc/classes/event/user_rename_attempt.php b/auth/oidc/classes/event/user_rename_attempt.php index 86e437635..86bb7971f 100644 --- a/auth/oidc/classes/event/user_rename_attempt.php +++ b/auth/oidc/classes/event/user_rename_attempt.php @@ -28,8 +28,6 @@ use context_system; use core\event\base; -defined('MOODLE_INTERNAL') || die(); - /** * Fired when a user attempts to change their username from the auth_oidc plugin. */ @@ -63,4 +61,4 @@ protected function init() { $this->data['edulevel'] = self::LEVEL_OTHER; $this->data['objecttable'] = 'user'; } -} \ No newline at end of file +} diff --git a/auth/oidc/classes/form/application.php b/auth/oidc/classes/form/application.php index c477c71c1..089c2ebd9 100644 --- a/auth/oidc/classes/form/application.php +++ b/auth/oidc/classes/form/application.php @@ -86,7 +86,7 @@ protected function definition() { // Certificate source. $mform->addElement('select', 'clientcertsource', auth_oidc_config_name_in_form('clientcertsource'), [ AUTH_OIDC_AUTH_CERT_SOURCE_TEXT => get_string('cert_source_text', 'auth_oidc'), - AUTH_OIDC_AUTH_CERT_SOURCE_FILE => get_string('cert_source_path', 'auth_oidc') + AUTH_OIDC_AUTH_CERT_SOURCE_FILE => get_string('cert_source_path', 'auth_oidc'), ]); $mform->setDefault('clientcertsource', 0); $mform->disabledIf('clientcertsource', 'clientauthmethod', 'neq', AUTH_OIDC_AUTH_METHOD_CERTIFICATE); @@ -146,7 +146,7 @@ protected function definition() { $mform->addElement('static', 'tokenendpoint_help', '', get_string('tokenendpoint_help', 'auth_oidc')); $mform->addRule('tokenendpoint', null, 'required', null, 'client'); - // "Other parameters" header. + // Other parameters header. $mform->addElement('header', 'otherparams', get_string('settings_section_other_params', 'auth_oidc')); $mform->setExpanded('otherparams'); @@ -184,11 +184,11 @@ protected function definition() { /** * Additional validate rules. * - * @param $data - * @param $files - * @return array + * @param array $data Submitted data for validation. + * @param array $files Uploaded files for validation. + * @return array An array of validation errors, if any. */ - function validation($data, $files) { + public function validation($data, $files) { $errors = parent::validation($data, $files); if (!isset($data['clientauthmethod'])) { @@ -278,4 +278,4 @@ function validation($data, $files) { return $errors; } -} \ No newline at end of file +} diff --git a/auth/oidc/classes/form/binding_username_claim.php b/auth/oidc/classes/form/binding_username_claim.php index eeef1954b..46ec1292a 100644 --- a/auth/oidc/classes/form/binding_username_claim.php +++ b/auth/oidc/classes/form/binding_username_claim.php @@ -36,8 +36,19 @@ * Class bindingusernameclaim represents the form on the binding username claim configuration page. */ class binding_username_claim extends moodleform { + /** + * Option for setting a non-Microsoft IdP. + */ const OPTION_SET_NON_MS_IDP = 1; + + /** + * Option for setting a Microsoft IdP without user sync. + */ const OPTION_SET_MS_NO_USER_SYNC = 2; + + /** + * Option for setting a Microsoft IdP with user sync enabled. + */ const OPTION_SET_MS_WITH_USER_SYNC = 3; /** @var int */ @@ -102,7 +113,12 @@ protected function definition() { throw new moodle_exception('missing_idp_type', 'auth_oidc'); } - $mform->addElement('select', 'bindingusernameclaim', auth_oidc_config_name_in_form('binding_username_claim'), $bindingusernameoptions); + $mform->addElement( + 'select', + 'bindingusernameclaim', + auth_oidc_config_name_in_form('binding_username_claim'), + $bindingusernameoptions + ); $mform->setDefault('bindingusernameclaim', 'auto'); $mform->addElement('static', 'bindingusernameclaim_description', '', get_string($descriptionidentifier, 'auth_oidc')); diff --git a/auth/oidc/classes/form/change_binding_username_claim_tool_form1.php b/auth/oidc/classes/form/change_binding_username_claim_tool_form1.php index 981820d47..4e9172d80 100644 --- a/auth/oidc/classes/form/change_binding_username_claim_tool_form1.php +++ b/auth/oidc/classes/form/change_binding_username_claim_tool_form1.php @@ -31,8 +31,6 @@ use moodle_url; use moodleform; -defined('MOODLE_INTERNAL') || die(); - /** * Class change_binding_username_claim_tool_form1 represents the form on the change binding username claim tool page. */ diff --git a/auth/oidc/classes/form/change_binding_username_claim_tool_form2.php b/auth/oidc/classes/form/change_binding_username_claim_tool_form2.php index ed41c5f65..75ee51458 100644 --- a/auth/oidc/classes/form/change_binding_username_claim_tool_form2.php +++ b/auth/oidc/classes/form/change_binding_username_claim_tool_form2.php @@ -27,8 +27,6 @@ use moodleform; -defined('MOODLE_INTERNAL') || die(); - /** * Class change_binding_username_claim_tool_form2 represents the form on the change binding username claim tool page. */ @@ -38,7 +36,7 @@ class change_binding_username_claim_tool_form2 extends moodleform { * * @return void */ - function definition() { + public function definition() { $mform =& $this->_form; $data = $this->_customdata['data']; diff --git a/auth/oidc/classes/httpclient.php b/auth/oidc/classes/httpclient.php index 16c749a75..a8d5f2f7a 100644 --- a/auth/oidc/classes/httpclient.php +++ b/auth/oidc/classes/httpclient.php @@ -85,7 +85,7 @@ protected function get_moodle_version() { * @param array $options * @return bool */ - protected function request($url, $options = array()) { + protected function request($url, $options = []) { $this->setHeader($this->get_clienttag_headers()); $result = parent::request($url, $options); $this->resetHeader(); @@ -100,7 +100,7 @@ protected function request($url, $options = array()) { * @param array $options * @return bool */ - public function post($url, $params = '', $options = array()) { + public function post($url, $params = '', $options = []) { // Encode data to disable uploading files when values are prefixed @. if (is_array($params)) { $params = http_build_query($params, '', '&'); diff --git a/auth/oidc/classes/httpclientinterface.php b/auth/oidc/classes/httpclientinterface.php index f81c88a77..f4b5529d3 100644 --- a/auth/oidc/classes/httpclientinterface.php +++ b/auth/oidc/classes/httpclientinterface.php @@ -25,8 +25,6 @@ namespace auth_oidc; -defined('MOODLE_INTERNAL') || die(); - /** * Interface defining an HTTP client. */ @@ -39,5 +37,5 @@ interface httpclientinterface { * @param array $options * @return bool */ - public function post($url, $params = '', $options = array()); + public function post($url, $params = '', $options = []); } diff --git a/auth/oidc/classes/jwt.php b/auth/oidc/classes/jwt.php index f6cd27d76..d66de9e59 100644 --- a/auth/oidc/classes/jwt.php +++ b/auth/oidc/classes/jwt.php @@ -27,8 +27,6 @@ use moodle_exception; -defined('MOODLE_INTERNAL') || die(); - /** * Class for working with JWTs. */ diff --git a/auth/oidc/classes/loginflow/authcode.php b/auth/oidc/classes/loginflow/authcode.php index 01869dc4b..c81cc7d45 100644 --- a/auth/oidc/classes/loginflow/authcode.php +++ b/auth/oidc/classes/loginflow/authcode.php @@ -76,7 +76,7 @@ public function loginpage_idp_list($wantsurl) { 'url' => new moodle_url('/auth/oidc/', ['source' => 'loginpage']), 'icon' => $icon, 'name' => strip_tags(format_text($this->config->opname)), - ] + ], ]; } @@ -158,7 +158,7 @@ public function handleredirect() { $this->handleauthresponse($requestparams); } else { if (isloggedin() && !isguestuser() && empty($justauth) && empty($promptaconsent)) { - if (isset($SESSION->wantsurl) and (strpos($SESSION->wantsurl, $CFG->wwwroot) === 0)) { + if (isset($SESSION->wantsurl) && (strpos($SESSION->wantsurl, $CFG->wwwroot) === 0)) { $urltogo = $SESSION->wantsurl; unset($SESSION->wantsurl); } else { @@ -209,8 +209,8 @@ public function user_login($username, $password = null) { * @param array $extraparams Additional parameters to send with the OIDC request. * @param bool $selectaccount Whether to prompt the user to select an account. */ - public function initiateauthrequest($promptlogin = false, array $stateparams = array(), array $extraparams = array(), - bool $selectaccount = false) { + public function initiateauthrequest($promptlogin = false, array $stateparams = [], array $extraparams = [], + bool $selectaccount = false) { $client = $this->get_oidcclient(); $client->authrequest($promptlogin, $stateparams, $extraparams, $selectaccount); } @@ -228,7 +228,9 @@ public function initiateadminconsentrequest(array $stateparams = [], array $extr } /** - * @param array $authparams + * Handles the response for certificate-based admin consent authorization. + * + * @param array $authparams Array of authorization parameters. * @return void * @throws moodle_exception */ @@ -274,7 +276,7 @@ protected function handlecertadminconsentresponse(array $authparams) { 'authparams' => $authparams, 'tokenparams' => $tokenparams, 'statedata' => $additionaldata, - ] + ], ]; $event = user_authed::create($eventdata); $event->trigger(); @@ -350,7 +352,7 @@ protected function handleauthresponse(array $authparams) { 'authparams' => $authparams, 'tokenparams' => $tokenparams, 'statedata' => $additionaldata, - ] + ], ]; $event = user_authed::create($eventdata); $event->trigger(); @@ -494,7 +496,7 @@ protected function handlemigration($oidcuniqid, $authparams, $tokenparams, $idto /** * Determines whether the given Microsoft Entra ID UPN is already matched to a Moodle user (and has not been completed). * - * @param $entraidupn + * @param string $entraidupn The Microsoft Entra ID UPN to check for a match. * @return false|stdClass Either the matched Moodle user record, or false if not matched. */ protected function check_for_matched($entraidupn) { @@ -620,8 +622,8 @@ protected function handlelogin(string $oidcuniqid, array $authparams, array $tok throw new moodle_exception('erroruserwithusernamealreadyexists', 'auth_oidc', null, null, '2'); } else { // Username does not exist: - // 1. can change Moodle account username (if the user uses auth_oidc), - // 2. can change token record. + // 1. can change Moodle account username (if the user uses auth_oidc), + // 2. can change token record. if ($user->auth == 'oidc') { $user->username = strtolower($oidcusername); user_update_user($user, false); @@ -662,9 +664,9 @@ protected function handlelogin(string $oidcuniqid, array $authparams, array $tok } else if ($usernamechanged) { // User has connection record, but no token; and the user has been renamed in Microsoft. // In this case, we need to: - // 1. attempt to update Moodle username, - // 2. create token record, - // 3. update connection record in local_o365_objects table. + // 1. attempt to update Moodle username, + // 2. create token record, + // 3. update connection record in local_o365_objects table. if ($supportupnchangeconfig != 1) { throw new moodle_exception('errorupnchangeisnotsupported', 'local_o365', null, null, '2'); @@ -769,7 +771,7 @@ protected function handlelogin(string $oidcuniqid, array $authparams, array $tok if (empty($CFG->authpreventaccountcreation)) { if (!$CFG->allowaccountssameemail) { $userinfo = $this->get_userinfo($username); - if ($DB->count_records('user', array('email' => $userinfo['email'], 'deleted' => 0)) > 0) { + if ($DB->count_records('user', ['email' => $userinfo['email'], 'deleted' => 0]) > 0) { throw new moodle_exception('errorauthloginfaileddupemail', 'auth_oidc', null, null, '1'); } } diff --git a/auth/oidc/classes/loginflow/base.php b/auth/oidc/classes/loginflow/base.php index a4896ca91..7dda180b8 100644 --- a/auth/oidc/classes/loginflow/base.php +++ b/auth/oidc/classes/loginflow/base.php @@ -52,7 +52,7 @@ class base { */ public function __construct() { $default = [ - 'opname' => get_string('pluginname', 'auth_oidc') + 'opname' => get_string('pluginname', 'auth_oidc'), ]; $storedconfig = (array)get_config('auth_oidc'); @@ -89,9 +89,9 @@ public function user_login($username, $password = null) { /** * Provides a hook into the login page. * - * @param object &$frm Form object. - * @param object &$user User object. - * @return bool + * @param object $frm The form object containing login page data. + * @param object $user The user object related to the login attempt. + * @return bool True if the hook was processed successfully. */ public function loginpage_hook(&$frm, &$user) { return true; @@ -350,15 +350,15 @@ public function set_httpclient(\auth_oidc\httpclientinterface $httpclient) { /** * Handle OIDC disconnection from Moodle account. * - * @param bool $justremovetokens If true, just remove the stored OIDC tokens for the user, otherwise revert login methods. - * @param bool $donotremovetokens If true, do not remove tokens when disconnecting. This migrates from a login account to a - * "linked" account. - * @param \moodle_url|null $redirect Where to redirect if successful. - * @param \moodle_url|null $selfurl The page this is accessed from. Used for some redirects. - * @param $userid + * @param bool $justremovetokens If true, just remove the stored OIDC tokens for the user; otherwise, revert login methods. + * @param bool $donotremovetokens If true, do not remove tokens when disconnecting. This migrates from a login account + * to a "linked" account. + * @param \moodle_url|null $redirect URL to redirect to if successful. + * @param \moodle_url|null $selfurl The page this is accessed from, used for some redirects. + * @param int|null $userid ID of the user to disconnect; uses the current user if not provided. */ - public function disconnect($justremovetokens = false, $donotremovetokens = false, \moodle_url $redirect = null, - \moodle_url $selfurl = null, $userid = null) { + public function disconnect($justremovetokens = false, $donotremovetokens = false, ?\moodle_url $redirect = null, + ?\moodle_url $selfurl = null, $userid = null) { global $USER, $DB, $CFG; if ($redirect === null) { $redirect = new \moodle_url('/auth/oidc/ucp.php'); @@ -724,7 +724,7 @@ protected function updatetoken($tokenid, $authparams, $tokenparams) { * @param string $bindingusernameclaim The configured binding username claim. * @return string|null The OIDC username if found, null otherwise. */ - protected function get_oidc_username_from_token_claim(jwt $idtoken, string $bindingusernameclaim = '') : ?string { + protected function get_oidc_username_from_token_claim(jwt $idtoken, string $bindingusernameclaim = ''): ?string { if (empty($idtoken)) { return ''; } diff --git a/auth/oidc/classes/loginflow/rocreds.php b/auth/oidc/classes/loginflow/rocreds.php index d6ccd814d..8eb1226bf 100644 --- a/auth/oidc/classes/loginflow/rocreds.php +++ b/auth/oidc/classes/loginflow/rocreds.php @@ -62,8 +62,8 @@ protected function check_objects($o356username) { /** * Provides a hook into the login page. * - * @param object &$frm Form object. - * @param object &$user User object. + * @param stdClass $frm Form object. + * @param stdClass $user User object. * @return bool */ public function loginpage_hook(&$frm, &$user) { @@ -122,8 +122,8 @@ public function loginpage_hook(&$frm, &$user) { $failurereason = AUTH_LOGIN_UNAUTHORISED; // Trigger login failed event. - $event = \core\event\user_login_failed::create(array('other' => array('username' => $username, - 'reason' => $failurereason))); + $event = \core\event\user_login_failed::create(['other' => ['username' => $username, + 'reason' => $failurereason]]); $event->trigger(); debugging('[client '.getremoteaddr()."] $CFG->wwwroot Unknown user, can not create new accounts: $username ". diff --git a/auth/oidc/classes/observers.php b/auth/oidc/classes/observers.php index 1720b072c..a92cec86f 100644 --- a/auth/oidc/classes/observers.php +++ b/auth/oidc/classes/observers.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see . /** + * Event observer handlers for auth_oidc plugin. + * * @package auth_oidc * @author James McQuillan * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later diff --git a/auth/oidc/classes/oidcclient.php b/auth/oidc/classes/oidcclient.php index 8da112517..54a57f5f0 100644 --- a/auth/oidc/classes/oidcclient.php +++ b/auth/oidc/classes/oidcclient.php @@ -156,9 +156,10 @@ public function setendpoints($endpoints) { } /** - * Validate the return the endpoint. - * @param $endpoint - * @return mixed|null + * Validate and return the specified endpoint. + * + * @param string $endpoint The endpoint key to retrieve. + * @return mixed|null The endpoint URL if available, otherwise null. */ public function get_endpoint($endpoint) { return (isset($this->endpoints[$endpoint])) ? $this->endpoints[$endpoint] : null; @@ -173,7 +174,7 @@ public function get_endpoint($endpoint) { * @param bool $selectaccount Whether to prompt the user to select an account. * @return array Array of request parameters. */ - protected function getauthrequestparams($promptlogin = false, array $stateparams = array(), array $extraparams = array(), + protected function getauthrequestparams($promptlogin = false, array $stateparams = [], array $extraparams = [], bool $selectaccount = false) { global $SESSION; @@ -186,7 +187,7 @@ protected function getauthrequestparams($promptlogin = false, array $stateparams 'nonce' => $nonce, 'response_mode' => 'form_post', 'state' => $this->getnewstate($nonce, $stateparams), - 'redirect_uri' => $this->redirecturi + 'redirect_uri' => $this->redirecturi, ]; if (get_config('auth_oidc', 'idptype') != AUTH_OIDC_IDP_TYPE_MICROSOFT_IDENTITY_PLATFORM) { @@ -244,7 +245,7 @@ protected function getadminconsentrequestparams(array $stateparams = [], array $ * @param array $stateparams * @return string The new state value. */ - protected function getnewstate($nonce, array $stateparams = array()) { + protected function getnewstate($nonce, array $stateparams = []) { global $DB; $staterec = new \stdClass; $staterec->sesskey = sesskey(); @@ -264,7 +265,7 @@ protected function getnewstate($nonce, array $stateparams = array()) { * @param array $extraparams Additional parameters to send with the OIDC request. * @param bool $selectaccount Whether to prompt the user to select an account. */ - public function authrequest($promptlogin = false, array $stateparams = array(), array $extraparams = array(), + public function authrequest($promptlogin = false, array $stateparams = [], array $extraparams = [], bool $selectaccount = false) { if (empty($this->clientid)) { throw new moodle_exception('erroroidcclientnocreds', 'auth_oidc'); @@ -395,7 +396,7 @@ public function app_access_token_request() { * @return string * @throws moodle_exception */ - public static function generate_client_assertion() : string { + public static function generate_client_assertion(): string { $authoidcconfig = get_config('auth_oidc'); $certsource = $authoidcconfig->clientcertsource; @@ -413,7 +414,7 @@ public static function generate_client_assertion() : string { } else { throw new moodle_exception('errorinvalidcertificatesource', 'auth_oidc'); } - + $sh1hash = openssl_x509_fingerprint($cert); $x5t = base64_encode(hex2bin($sh1hash)); diff --git a/auth/oidc/classes/preview.php b/auth/oidc/classes/preview.php index 0f12ca2a3..ba373e80d 100644 --- a/auth/oidc/classes/preview.php +++ b/auth/oidc/classes/preview.php @@ -79,14 +79,14 @@ public function __construct(csv_import_reader $cir, array $filecolumns, int $pre * * @return array */ - protected function read_data() : array { + protected function read_data(): array { global $DB; $data = []; $this->cir->init(); $linenum = 1; - while ($linenum <= $this->previewrows and $fields = $this->cir->next()) { + while ($linenum <= $this->previewrows && $fields = $this->cir->next()) { $hasfatalerror = false; $linenum++; $rowcols = []; @@ -137,7 +137,7 @@ protected function read_data() : array { * * @return bool */ - public function get_no_error() : bool { + public function get_no_error(): bool { return $this->noerror; } } diff --git a/auth/oidc/classes/privacy/provider.php b/auth/oidc/classes/privacy/provider.php index f30b51756..4a6beb724 100644 --- a/auth/oidc/classes/privacy/provider.php +++ b/auth/oidc/classes/privacy/provider.php @@ -27,11 +27,16 @@ defined('MOODLE_INTERNAL') || die(); -use \core_privacy\local\metadata\collection; -use \core_privacy\local\request\contextlist; -use \core_privacy\local\request\approved_contextlist; -use \core_privacy\local\request\writer; +use core_privacy\local\metadata\collection; +use core_privacy\local\request\contextlist; +use core_privacy\local\request\approved_contextlist; +use core_privacy\local\request\writer; +/** + * Interface for handling user lists in the OIDC authentication plugin. + * + * @package auth_oidc + */ interface auth_oidc_userlist extends \core_privacy\local\request\core_userlist_provider { }; @@ -49,7 +54,7 @@ class provider implements * @param collection $collection The initialised collection to add items to. * @return collection A listing of user data stored through this system. */ - public static function get_metadata(collection $collection) : collection { + public static function get_metadata(collection $collection): collection { $tables = [ 'auth_oidc_prevlogin' => [ @@ -94,7 +99,7 @@ public static function get_metadata(collection $collection) : collection { * @param int $userid The user to search. * @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin. */ - public static function get_contexts_for_userid(int $userid) : contextlist { + public static function get_contexts_for_userid(int $userid): contextlist { $contextlist = new \core_privacy\local\request\contextlist(); $sql = "SELECT ctx.id @@ -128,7 +133,7 @@ public static function get_users_in_context(\core_privacy\local\request\userlist $params = [ 'contextuser' => CONTEXT_USER, - 'contextid' => $context->id + 'contextid' => $context->id, ]; $sql = "SELECT ctx.instanceid as userid @@ -163,7 +168,7 @@ public static function export_user_data(approved_contextlist $contextlist) { foreach ($records as $record) { writer::with_context($context)->export_data([ get_string('privacy:metadata:auth_oidc', 'auth_oidc'), - get_string('privacy:metadata:'.$table, 'auth_oidc') + get_string('privacy:metadata:'.$table, 'auth_oidc'), ], $record); } } @@ -175,7 +180,7 @@ public static function export_user_data(approved_contextlist $contextlist) { * @param \stdClass $user The user to get the map for. * @return array The table user map. */ - protected static function get_table_user_map(\stdClass $user) : array { + protected static function get_table_user_map(\stdClass $user): array { $tables = [ 'auth_oidc_prevlogin' => ['userid' => $user->id], 'auth_oidc_token' => ['userid' => $user->id], diff --git a/auth/oidc/classes/process.php b/auth/oidc/classes/process.php index d046218e1..63349258c 100644 --- a/auth/oidc/classes/process.php +++ b/auth/oidc/classes/process.php @@ -39,7 +39,18 @@ * Class process represents the process binding username claim tool. */ class process { + /** + * Route for renaming in auth_oidc. + * + * @var int + */ const ROUTE_AUTH_OIDC_RENAME = 1; + + /** + * Route for matching other authentication methods. + * + * @var int + */ const ROUTE_AUTH_OTHER_MATCH = 2; /** @var csv_import_reader */ @@ -70,7 +81,7 @@ public function __construct(csv_import_reader $cir) { * @return array * @throws moodle_exception */ - public function get_file_columns() : array { + public function get_file_columns(): array { if ($this->filecolumns === null) { $columns = $this->cir->get_columns(); if (count($columns) != 2) { @@ -86,7 +97,7 @@ public function get_file_columns() : array { $field = $columns[$key]; $field = trim($field); $lcfield = core_text::strtolower($field); - if (in_array($field, $stdfields) or in_array($lcfield, $stdfields)) { + if (in_array($field, $stdfields) || in_array($lcfield, $stdfields)) { $newfield = $lcfield; } if (in_array($newfield, $this->filecolumns)) { @@ -274,7 +285,7 @@ protected function process_line(array $line) { * * @return array */ - public function get_stats() : array { + public function get_stats(): array { $lines = []; $lines[] = get_string('update_stats_users_updated', 'auth_oidc', $this->usersupdated); diff --git a/auth/oidc/classes/task/cleanup_oidc_state_and_token.php b/auth/oidc/classes/task/cleanup_oidc_state_and_token.php index 624c985b0..eb5304c2f 100644 --- a/auth/oidc/classes/task/cleanup_oidc_state_and_token.php +++ b/auth/oidc/classes/task/cleanup_oidc_state_and_token.php @@ -25,8 +25,6 @@ namespace auth_oidc\task; -defined('MOODLE_INTERNAL') || die(); - use core\task\scheduled_task; /** diff --git a/auth/oidc/classes/tests/mockhttpclient.php b/auth/oidc/classes/tests/mockhttpclient.php index 7dc840448..fd873b8c5 100644 --- a/auth/oidc/classes/tests/mockhttpclient.php +++ b/auth/oidc/classes/tests/mockhttpclient.php @@ -27,8 +27,6 @@ use moodle_exception; -defined('MOODLE_INTERNAL') || die(); - /** * A mock HTTP client allowing set responses. */ @@ -69,7 +67,7 @@ public function set_responses(array $responses) { * @param array $options Additional curl options. * @return string The set response. */ - protected function request($url, $options = array()) { + protected function request($url, $options = []) { if (isset($this->mockresponse[$this->curresponse])) { $response = $this->mockresponse[$this->curresponse]; $this->curresponse++; diff --git a/auth/oidc/classes/tests/mockoidcclient.php b/auth/oidc/classes/tests/mockoidcclient.php index 0167582aa..209806162 100644 --- a/auth/oidc/classes/tests/mockoidcclient.php +++ b/auth/oidc/classes/tests/mockoidcclient.php @@ -25,8 +25,6 @@ namespace auth_oidc\tests; -defined('MOODLE_INTERNAL') || die(); - /** * A mock oidcclient class providing access to all inaccessible properties/methods. */ @@ -43,9 +41,15 @@ class mockoidcclient extends \auth_oidc\oidcclient { * @param bool $promptlogin Whether to prompt for login or use existing session. * @param array $stateparams Parameters to store as state. * @param array $extraparams Additional parameters to send with the OIDC request. + * @param bool $selectaccount Whether to prompt the user to select an account. * @return array Array of request parameters. */ - public function getauthrequestparams($promptlogin = false, array $stateparams = array(), array $extraparams = array(), bool $selectaccount = false) { + public function getauthrequestparams( + $promptlogin = false, + array $stateparams = [], + array $extraparams = [], + bool $selectaccount = false + ) { return parent::getauthrequestparams($promptlogin, $stateparams); } } diff --git a/auth/oidc/classes/upload_process_tracker.php b/auth/oidc/classes/upload_process_tracker.php index a9ebfdfac..7935c9be2 100644 --- a/auth/oidc/classes/upload_process_tracker.php +++ b/auth/oidc/classes/upload_process_tracker.php @@ -27,8 +27,9 @@ use html_writer; -defined('MOODLE_INTERNAL') || die(); - +/** + * Class to track the progress of processing username claims uploads. + */ class upload_process_tracker { /** @var array */ protected $_row; @@ -74,8 +75,8 @@ public function start() { * @return void */ public function flush() { - if (empty($this->_row) or empty($this->_row['line']['normal'])) { - // Nothing to print - each line has to have at least number + if (empty($this->_row) || empty($this->_row['line']['normal'])) { + // Nothing to print - each line has to have at least number. $this->_row = []; foreach ($this->columns as $col) { $this->_row[$col] = ['normal' => '', 'info' => '', 'warning' => '', 'error' => '']; @@ -145,4 +146,4 @@ public function close() { $this->flush(); echo html_writer::end_tag('table'); } -} \ No newline at end of file +} diff --git a/auth/oidc/classes/utils.php b/auth/oidc/classes/utils.php index 002e77506..f0753f74d 100644 --- a/auth/oidc/classes/utils.php +++ b/auth/oidc/classes/utils.php @@ -29,8 +29,6 @@ use moodle_exception; use auth_oidc\event\action_failed; -defined('MOODLE_INTERNAL') || die(); - /** * General purpose utility class. */ @@ -43,7 +41,7 @@ class utils { * @return array The parsed JSON. * @throws moodle_exception */ - public static function process_json_response($response, array $expectedstructure = array()) { + public static function process_json_response($response, array $expectedstructure = []) { $result = @json_decode($response, true); if (empty($result) || !is_array($result)) { self::debug('Bad response received', __METHOD__, $response); @@ -104,9 +102,9 @@ public static function tostring($val) { $valinfo['errorcode'] = $val->errorcode; $valinfo['module'] = $val->module; } - return print_r($valinfo, true); + return json_encode($valinfo, JSON_PRETTY_PRINT); } else { - return print_r($val, true); + return json_encode($val, JSON_PRETTY_PRINT); } } diff --git a/auth/oidc/db/access.php b/auth/oidc/db/access.php index 44352a498..715315eba 100644 --- a/auth/oidc/db/access.php +++ b/auth/oidc/db/access.php @@ -28,22 +28,22 @@ global $CFG; $capabilities = [ - 'auth/oidc:manageconnection' => [ - 'riskbitmask' => RISK_CONFIG, - 'captype' => 'write', - 'contextlevel' => CONTEXT_USER, - 'archetypes' => [] - ], - 'auth/oidc:manageconnectionconnect' => [ - 'riskbitmask' => RISK_CONFIG, - 'captype' => 'write', - 'contextlevel' => CONTEXT_USER, - 'archetypes' => [] - ], - 'auth/oidc:manageconnectiondisconnect' => [ - 'riskbitmask' => RISK_CONFIG, - 'captype' => 'write', - 'contextlevel' => CONTEXT_USER, - 'archetypes' => [] - ], + 'auth/oidc:manageconnection' => [ + 'riskbitmask' => RISK_CONFIG, + 'captype' => 'write', + 'contextlevel' => CONTEXT_USER, + 'archetypes' => [], + ], + 'auth/oidc:manageconnectionconnect' => [ + 'riskbitmask' => RISK_CONFIG, + 'captype' => 'write', + 'contextlevel' => CONTEXT_USER, + 'archetypes' => [], + ], + 'auth/oidc:manageconnectiondisconnect' => [ + 'riskbitmask' => RISK_CONFIG, + 'captype' => 'write', + 'contextlevel' => CONTEXT_USER, + 'archetypes' => [], + ], ]; diff --git a/auth/oidc/db/upgrade.php b/auth/oidc/db/upgrade.php index e51dc2e05..3276e64c5 100644 --- a/auth/oidc/db/upgrade.php +++ b/auth/oidc/db/upgrade.php @@ -398,7 +398,12 @@ function xmldb_auth_oidc_upgrade($oldversion) { case AUTH_OIDC_MICROSOFT_ENDPOINT_VERSION_2: $existingidptype = get_config('auth_oidc', 'idptype'); if ($existinglocksetting != AUTH_OIDC_IDP_TYPE_MICROSOFT_IDENTITY_PLATFORM) { - add_to_config_log('idptype', $existingidptype, AUTH_OIDC_IDP_TYPE_MICROSOFT_IDENTITY_PLATFORM, 'auth_oidc'); + add_to_config_log( + 'idptype', + $existingidptype, + AUTH_OIDC_IDP_TYPE_MICROSOFT_IDENTITY_PLATFORM, + 'auth_oidc' + ); } set_config('idptype', AUTH_OIDC_IDP_TYPE_MICROSOFT_IDENTITY_PLATFORM, 'auth_oidc'); break; diff --git a/auth/oidc/index.php b/auth/oidc/index.php index e286b692d..1abea2e81 100644 --- a/auth/oidc/index.php +++ b/auth/oidc/index.php @@ -23,6 +23,7 @@ * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ +// phpcs:ignore moodle.Files.RequireLogin.Missing require_once(__DIR__.'/../../config.php'); require_once(__DIR__.'/auth.php'); diff --git a/auth/oidc/lang/cs/auth_oidc.php b/auth/oidc/lang/cs/auth_oidc.php index e9c9187dd..08e46baf9 100644 --- a/auth/oidc/lang/cs/auth_oidc.php +++ b/auth/oidc/lang/cs/auth_oidc.php @@ -24,6 +24,9 @@ * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'OpenID Connect'; $string['auth_oidcdescription'] = 'Plugin OpenID Connect poskytuje funkci jednotného přihlašování pomocí konfigurovatelných poskytovatelů identity.'; $string['cfg_authendpoint_key'] = 'Koncový bod autorizace'; @@ -125,3 +128,6 @@ $string['ucp_disconnect_title'] = 'Odpojení {$a}'; $string['ucp_disconnect_details'] = 'Váš účet Moodle bude odpojen od {$a}. Budete si muset vytvořit uživatelské jméno a heslo pro přihlašování do Moodlu.'; $string['ucp_title'] = 'Správa {$a}'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/auth/oidc/lang/de/auth_oidc.php b/auth/oidc/lang/de/auth_oidc.php index a35d5e19a..fb3bd3238 100644 --- a/auth/oidc/lang/de/auth_oidc.php +++ b/auth/oidc/lang/de/auth_oidc.php @@ -24,6 +24,9 @@ * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'OpenID Connect'; $string['auth_oidcdescription'] = 'Das Plugin OpenID Connect bietet eine Single-Sign-On-Funktion mit konfigurierbaren Identitätsprovidern.'; $string['cfg_authendpoint_key'] = 'Autorisierungsendpunkt'; @@ -125,3 +128,6 @@ $string['ucp_disconnect_title'] = '{$a} Trennung'; $string['ucp_disconnect_details'] = 'Damit wird Ihr Moodle-Konto von {$a} getrennt. Sie müssen einen Benutzernamen und ein Kennwort erstellen, um sich bei Moodle anzumelden.'; $string['ucp_title'] = '{$a} Verwaltung'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/auth/oidc/lang/en/auth_oidc.php b/auth/oidc/lang/en/auth_oidc.php index b0cdb154f..123bbf84e 100644 --- a/auth/oidc/lang/en/auth_oidc.php +++ b/auth/oidc/lang/en/auth_oidc.php @@ -26,6 +26,9 @@ defined('MOODLE_INTERNAL') || die(); +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'OpenID Connect'; $string['auth_oidcdescription'] = 'The OpenID Connect authentication plugin provides single-sign-on functionality using configurable IdP.'; @@ -490,3 +493,6 @@ $string['update_username_results'] = 'Update username results'; $string['new_username'] = 'New username'; $string['missing_idp_type'] = 'This configuration is only available if an IdP type is configured.'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/auth/oidc/lang/es/auth_oidc.php b/auth/oidc/lang/es/auth_oidc.php index 919bb8c45..d77020ff8 100644 --- a/auth/oidc/lang/es/auth_oidc.php +++ b/auth/oidc/lang/es/auth_oidc.php @@ -24,6 +24,9 @@ * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'OpenID Connect'; $string['auth_oidcdescription'] = 'El complemento OpenID Connect ofrece funcionalidad de inicio de sesión único a través de proveedores de identidad configurables.'; $string['cfg_authendpoint_key'] = 'Extremo de autorización'; @@ -125,3 +128,6 @@ $string['ucp_disconnect_title'] = 'Desconexión de {$a}'; $string['ucp_disconnect_details'] = 'Esto desconectará su cuenta de Moodle de {$a}. Deberá crear un nombre de usuario y una contraseña para iniciar sesión en Moodle.'; $string['ucp_title'] = 'Administración de {$a}'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/auth/oidc/lang/fi/auth_oidc.php b/auth/oidc/lang/fi/auth_oidc.php index bec58bdb3..272309fcf 100644 --- a/auth/oidc/lang/fi/auth_oidc.php +++ b/auth/oidc/lang/fi/auth_oidc.php @@ -24,6 +24,9 @@ * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'OpenID Connect'; $string['auth_oidcdescription'] = 'OpenID Connect -lisäosa mahdollistaa kertakirjautumisen käyttämällä määritettävissä olevaa identiteetintarjoajaa.'; $string['cfg_authendpoint_key'] = 'Todennuksen päätepiste'; @@ -125,3 +128,6 @@ $string['ucp_disconnect_title'] = '{$a} -yhteyden katkaisu'; $string['ucp_disconnect_details'] = 'Tämä katkaisee Moodle-tilin yhteyden kohteesta {$a}. Tarvitset käyttäjänimen ja salasanan, jotta voit kirjautua Moodleen.'; $string['ucp_title'] = '{$a} -hallinta'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/auth/oidc/lang/fr/auth_oidc.php b/auth/oidc/lang/fr/auth_oidc.php index 54aedd01a..885f66c91 100644 --- a/auth/oidc/lang/fr/auth_oidc.php +++ b/auth/oidc/lang/fr/auth_oidc.php @@ -24,6 +24,9 @@ * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'OpenID Connect'; $string['auth_oidcdescription'] = 'Le plug-in OpenID Connect fournit une fonctionnalité SSO avec des fournisseurs d\'identité configurables.'; @@ -161,3 +164,6 @@ $string['ucp_disconnect_details'] = 'Cette opération déconnectera votre compte Moodle de {$a}. Vous aurez besoin de créer un nom d\'utilisateur et un mot de passe pour vous connecter à Moodle.'; $string['ucp_title'] = 'Gestion de {$a}'; $string['ucp_o365accountconnected'] = 'Ce compte Microsoft 365 est déjà associé à un autre compte Moodle.'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/auth/oidc/lang/it/auth_oidc.php b/auth/oidc/lang/it/auth_oidc.php index 5e62f79da..eed128572 100644 --- a/auth/oidc/lang/it/auth_oidc.php +++ b/auth/oidc/lang/it/auth_oidc.php @@ -24,6 +24,9 @@ * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'OpenID Connect'; $string['auth_oidcdescription'] = 'Il plugin OpenID Connect fornisce funzionalità single-sign-on utilizzando Identity Provider configurabili.'; $string['cfg_authendpoint_key'] = 'Endpoint di autorizzazione'; @@ -125,3 +128,6 @@ $string['ucp_disconnect_title'] = 'Disconnessione {$a}'; $string['ucp_disconnect_details'] = 'Il tuo account Moodle verrà disconnesso da {$a}. Per accedere a Moodle dovrai creare un nome utente e una password.'; $string['ucp_title'] = 'Gestione {$a}'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/auth/oidc/lang/ja/auth_oidc.php b/auth/oidc/lang/ja/auth_oidc.php index 205c60dfe..12adba749 100644 --- a/auth/oidc/lang/ja/auth_oidc.php +++ b/auth/oidc/lang/ja/auth_oidc.php @@ -24,6 +24,9 @@ * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'OpenID Connect'; $string['auth_oidcdescription'] = 'OpenID Connectプラグインは、設定可能なアイデンティティプロバイダを使用してシングルサインオン機能を提供します。'; $string['cfg_authendpoint_key'] = '認証エンドポイント'; @@ -125,3 +128,6 @@ $string['ucp_disconnect_title'] = '{$a} 接続解除'; $string['ucp_disconnect_details'] = 'Moodleアカウントを {$a} から接続解除します。Moodleにログインするには、ユーザ名とパスワードを作成する必要があります。'; $string['ucp_title'] = '{$a} 管理'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/auth/oidc/lang/nl/auth_oidc.php b/auth/oidc/lang/nl/auth_oidc.php index 9c4780cec..c79ec3585 100644 --- a/auth/oidc/lang/nl/auth_oidc.php +++ b/auth/oidc/lang/nl/auth_oidc.php @@ -24,6 +24,9 @@ * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'OpenID Connect'; $string['auth_oidcdescription'] = 'De OpenID Connect-plugin verschaft de mogelijkheid voor eenmalige aanmelding met configureerbare identiteitsproviders.'; $string['cfg_authendpoint_key'] = 'Autorisatie-eindpunt'; @@ -125,3 +128,6 @@ $string['ucp_disconnect_title'] = 'Verbinding met {$a} verbroken'; $string['ucp_disconnect_details'] = 'Hiermee wordt de verbinding tussen je Moodle-account en {$a} verbroken. Je moet een gebruikersnaam en wachtwoord maken om je aan te melden bij Moodle.'; $string['ucp_title'] = '{$a}-beheer'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/auth/oidc/lang/pl/auth_oidc.php b/auth/oidc/lang/pl/auth_oidc.php index 99954f2be..0280a4009 100644 --- a/auth/oidc/lang/pl/auth_oidc.php +++ b/auth/oidc/lang/pl/auth_oidc.php @@ -24,6 +24,9 @@ * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'OpenID Connect'; $string['auth_oidcdescription'] = 'Wtyczka OpenID Connect udostępnia funkcję rejestracji jednokrotnej przy użyciu dostawców tożsamości, których można skonfigurować.'; $string['cfg_authendpoint_key'] = 'Punkt końcowy autoryzacji'; @@ -125,3 +128,6 @@ $string['ucp_disconnect_title'] = 'Rozłączono {$a}'; $string['ucp_disconnect_details'] = 'Spowoduje to odłączenie konta na platformie Moodle od {$a}. Konieczne będzie utworzenie nazwy użytkownika i hasła w celu zalogowania się do platformy Moodle.'; $string['ucp_title'] = 'Zarządzanie {$a}'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/auth/oidc/lang/pt_br/auth_oidc.php b/auth/oidc/lang/pt_br/auth_oidc.php index 1e4339c40..1d2218978 100644 --- a/auth/oidc/lang/pt_br/auth_oidc.php +++ b/auth/oidc/lang/pt_br/auth_oidc.php @@ -24,6 +24,9 @@ * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'OpenID Connect'; $string['auth_oidcdescription'] = 'O plugin OpenID Connect oferece o recurso de logon único usando provedores de identidade que podem ser configurados.'; $string['cfg_authendpoint_key'] = 'Ponto de extremidade de autorização'; @@ -125,3 +128,6 @@ $string['ucp_disconnect_title'] = 'Desconexão do {$a}'; $string['ucp_disconnect_details'] = 'Essa ação desconectará sua conta do Moodle do {$a}. Você precisará criar um nome de usuário e uma senha para fazer login no Moodle.'; $string['ucp_title'] = 'Gerenciamento do {$a}'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/auth/oidc/lib.php b/auth/oidc/lib.php index 8216ff0c7..8f3b71691 100644 --- a/auth/oidc/lib.php +++ b/auth/oidc/lib.php @@ -27,31 +27,68 @@ use auth_oidc\jwt; use auth_oidc\utils; -defined('MOODLE_INTERNAL') || die(); - // IdP types. -CONST AUTH_OIDC_IDP_TYPE_MICROSOFT_ENTRA_ID = 1; -CONST AUTH_OIDC_IDP_TYPE_MICROSOFT_IDENTITY_PLATFORM = 2; -CONST AUTH_OIDC_IDP_TYPE_OTHER = 3; +/** + * Microsoft Entra ID identity provider type. + */ +const AUTH_OIDC_IDP_TYPE_MICROSOFT_ENTRA_ID = 1; + +/** + * Microsoft Identity Platform identity provider type. + */ +const AUTH_OIDC_IDP_TYPE_MICROSOFT_IDENTITY_PLATFORM = 2; + +/** + * Other identity provider type. + */ +const AUTH_OIDC_IDP_TYPE_OTHER = 3; // Microsoft Entra ID / Microsoft endpoint version. -CONST AUTH_OIDC_MICROSOFT_ENDPOINT_VERSION_UNKNOWN = 0; -CONST AUTH_OIDC_MICROSOFT_ENDPOINT_VERSION_1 = 1; -CONST AUTH_OIDC_MICROSOFT_ENDPOINT_VERSION_2 = 2; +/** + * Unknown Microsoft endpoint version. + */ +const AUTH_OIDC_MICROSOFT_ENDPOINT_VERSION_UNKNOWN = 0; + +/** + * Microsoft endpoint version 1. + */ +const AUTH_OIDC_MICROSOFT_ENDPOINT_VERSION_1 = 1; + +/** + * Microsoft endpoint version 2. + */ +const AUTH_OIDC_MICROSOFT_ENDPOINT_VERSION_2 = 2; // OIDC application authentication method. -CONST AUTH_OIDC_AUTH_METHOD_SECRET = 1; -CONST AUTH_OIDC_AUTH_METHOD_CERTIFICATE = 2; +/** + * OIDC application authentication method using secret. + */ +const AUTH_OIDC_AUTH_METHOD_SECRET = 1; + +/** + * OIDC application authentication method using certificate. + */ +const AUTH_OIDC_AUTH_METHOD_CERTIFICATE = 2; // OIDC application auth certificate source. -CONST AUTH_OIDC_AUTH_CERT_SOURCE_TEXT = 1; -CONST AUTH_OIDC_AUTH_CERT_SOURCE_FILE = 2; +/** + * OIDC application authentication certificate source from text. + */ +const AUTH_OIDC_AUTH_CERT_SOURCE_TEXT = 1; /** - * Initialize custom icon. + * OIDC application authentication certificate source from file. + */ +const AUTH_OIDC_AUTH_CERT_SOURCE_FILE = 2; + +/** + * Initialize custom icon for OIDC authentication. + * + * This function sets up a custom icon for the OIDC plugin by creating necessary directories + * and copying the file into the specified location in Moodle's data directory. * - * @param $filefullname - * @return false|void + * @param string $filefullname Full name of the custom icon file. + * @return bool False if the file is missing or is a directory; void otherwise. */ function auth_oidc_initialize_customicon($filefullname) { global $CFG; @@ -61,7 +98,7 @@ function auth_oidc_initialize_customicon($filefullname) { $fullpath = "/{$systemcontext->id}/auth_oidc/customicon/0{$file}"; $fs = get_file_storage(); - if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { + if (!$file = $fs->get_file_by_hash(sha1($fullpath)) || $file->is_directory()) { return false; } $pixpluginsdir = 'pix_plugins/auth/oidc/0'; @@ -416,7 +453,7 @@ function auth_oidc_apply_default_email_mapping() { * @param array $customfields list of custom profile fields */ function auth_oidc_display_auth_lock_options($settings, $auth, $userfields, $helptext, $mapremotefields, $updateremotefields, - $customfields = array()) { + $customfields = []) { global $DB; // Introductory explanation and help text. @@ -538,7 +575,8 @@ function auth_oidc_get_all_user_fields() { /** * Determine the endpoint version of the given Microsoft Entra ID / Microsoft authorization or token endpoint. * - * @return int + * @param string $endpoint The URL of the endpoint to be checked. + * @return int The version of the Microsoft endpoint (1 or 2) or unknown. */ function auth_oidc_determine_endpoint_version(string $endpoint) { $endpointversion = AUTH_OIDC_MICROSOFT_ENDPOINT_VERSION_UNKNOWN; @@ -663,7 +701,7 @@ function auth_oidc_get_client_auth_method_name() { * * @return string */ -function auth_oidc_get_binding_username_claim() : string { +function auth_oidc_get_binding_username_claim(): string { $bindingusernameclaim = get_config('auth_oidc', 'bindingusernameclaim'); if (empty($bindingusernameclaim)) { @@ -684,7 +722,7 @@ function auth_oidc_get_binding_username_claim() : string { * @return array * @throws moodle_exception */ -function auth_oidc_get_existing_claims() : array { +function auth_oidc_get_existing_claims(): array { global $DB; $sql = 'SELECT * diff --git a/auth/oidc/logout.php b/auth/oidc/logout.php index 57903fbbd..be5dc718b 100644 --- a/auth/oidc/logout.php +++ b/auth/oidc/logout.php @@ -23,6 +23,7 @@ * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ +// phpcs:ignore moodle.Files.RequireLogin.Missing require_once(__DIR__ . '/../../config.php'); $PAGE->set_url('/auth/oidc/logout.php'); @@ -33,8 +34,8 @@ if ($sid) { if ($authoidctokenrecord = $DB->get_record('auth_oidc_token', ['sid' => $sid])) { if ($authoidctokenrecord->userid == $USER->id) { - $authsequence = get_enabled_auth_plugins(); // auths, in sequence - foreach($authsequence as $authname) { + $authsequence = get_enabled_auth_plugins(); // Auths, in sequence. + foreach ($authsequence as $authname) { $authplugin = get_auth_plugin($authname); $authplugin->logoutpage_hook(); } diff --git a/auth/oidc/sass/styles.scss b/auth/oidc/sass/styles.scss deleted file mode 100644 index 433f98f73..000000000 --- a/auth/oidc/sass/styles.scss +++ /dev/null @@ -1,55 +0,0 @@ -.auth_oidc_ucp_indicator { - h4 { - display: inline-block; - margin-right: 0.5rem; - } - - h5 { - display: inline-block; - margin-left: 0.5rem; - - + span { - display: block; - } - } -} - -.cert_content { - textarea { - font-family: 'Courier New', Courier, monospace; - } -} - -.path-admin-auth-oidc { - .warning_header { - border: 1px solid #f00; - background-color: #ffe5e5; - padding: 10px; - margin: 10px 0; - color: #f00; - font-weight: bold; - } - - .warning { - color: #f00; - font-weight: bold; - } - - .existing_claims { - display: inline-block; /* Box width as long as the code */ - background-color: #f0f0f0; /* Grey background */ - border: 1px solid #ccc; /* Border */ - padding: 10px; /* Padding */ - font-family: 'Courier New', Courier, monospace; /* Monospace font */ - white-space: pre; /* Preserve whitespace */ - } - - .not_support_user_sync { - color: #f00; - } - - .code { - font-family: 'Courier New', Courier, monospace; - white-space: pre; - } -} diff --git a/auth/oidc/tests/jwt_test.php b/auth/oidc/tests/jwt_test.php index 73f3d048e..2eb99095b 100644 --- a/auth/oidc/tests/jwt_test.php +++ b/auth/oidc/tests/jwt_test.php @@ -23,6 +23,8 @@ * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ +namespace auth_oidc; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -33,11 +35,11 @@ * @group auth_oidc * @group office365 */ -class auth_oidc_jwt_testcase extends \advanced_testcase { +final class jwt_test extends \advanced_testcase { /** * Perform setup before every test. This tells Moodle's phpunit to reset the database after every test. */ - protected function setUp():void { + protected function setUp(): void { parent::setUp(); $this->resetAfterTest(true); } @@ -47,53 +49,53 @@ protected function setUp():void { * * @return array Array of arrays of test parameters. */ - public function dataprovider_decode() { + public static function dataprovider_decode(): array { $tests = []; $tests['emptytest'] = [ - '', '', ['Exception', 'Empty or non-string JWT received.'] + '', '', ['Exception', 'Empty or non-string JWT received.'], ]; $tests['nonstringtest'] = [ - 100, '', ['Exception', 'Empty or non-string JWT received.'] + 100, '', ['Exception', 'Empty or non-string JWT received.'], ]; $tests['malformed1'] = [ - 'a', '', ['Exception', 'Malformed JWT received.'] + 'a', '', ['Exception', 'Malformed JWT received.'], ]; $tests['malformed2'] = [ - 'a.b', '', ['Exception', 'Malformed JWT received.'] + 'a.b', '', ['Exception', 'Malformed JWT received.'], ]; $tests['malformed3'] = [ - 'a.b.c.d', '', ['Exception', 'Malformed JWT received.'] + 'a.b.c.d', '', ['Exception', 'Malformed JWT received.'], ]; $tests['badheader1'] = [ - 'h.p.s', '', ['Exception', 'Could not read JWT header'] + 'h.p.s', '', ['Exception', 'Could not read JWT header'], ]; $header = base64_encode(json_encode(['key' => 'val'])); $tests['invalidheader1'] = [ - $header.'.p.s', '', ['Exception', 'Invalid JWT header'] + $header . '.p.s', '', ['Exception', 'Invalid JWT header'], ]; $header = base64_encode(json_encode(['alg' => 'ROT13'])); $tests['badalg1'] = [ - $header.'.p.s', '', ['Exception', 'JWS Alg or JWE not supported'] + $header . '.p.s', '', ['Exception', 'JWS Alg or JWE not supported'], ]; $header = base64_encode(json_encode(['alg' => 'RS256'])); $payload = 'p'; $tests['badpayload1'] = [ - $header.'.'.$payload.'.s', '', ['Exception', 'Could not read JWT payload.'] + $header . '.' . $payload . '.s', '', ['Exception', 'Could not read JWT payload.'], ]; $header = base64_encode(json_encode(['alg' => 'RS256'])); $payload = base64_encode('nothing'); $tests['badpayload2'] = [ - $header.'.'.$payload.'.s', '', ['Exception', 'Could not read JWT payload.'] + $header . '.' . $payload . '.s', '', ['Exception', 'Could not read JWT payload.'], ]; $header = ['alg' => 'RS256']; @@ -102,7 +104,7 @@ public function dataprovider_decode() { $payloadenc = base64_encode(json_encode($payload)); $expected = [$header, $payload]; $tests['goodpayload1'] = [ - $headerenc.'.'.$payloadenc.'.s', $expected, [] + $headerenc . '.' . $payloadenc . '.s', $expected, [], ]; return $tests; @@ -112,14 +114,19 @@ public function dataprovider_decode() { * Test decode. * * @dataProvider dataprovider_decode + * @covers \auth_oidc\jwt::decode + * + * @param string $encodedjwt The JWT token to be decoded. + * @param mixed $expectedresult The expected result after decoding. + * @param array $expectedexception The expected exception class and message if an error occurs. + * @return void */ - public function test_decode($encodedjwt, $expectedresult, $expectedexception) { + public function test_decode($encodedjwt, $expectedresult, $expectedexception): void { if (!empty($expectedexception)) { $this->expectException($expectedexception[0]); $this->expectExceptionMessage($expectedexception[1]); } $actualresult = \auth_oidc\jwt::decode($encodedjwt); $this->assertEquals($expectedresult, $actualresult); - } } diff --git a/auth/oidc/tests/oidcclient_test.php b/auth/oidc/tests/oidcclient_test.php index a50fbdeb7..47e2a4118 100644 --- a/auth/oidc/tests/oidcclient_test.php +++ b/auth/oidc/tests/oidcclient_test.php @@ -23,6 +23,10 @@ * @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/) */ + + +namespace auth_oidc; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -33,19 +37,21 @@ * @group auth_oidc * @group office365 */ -class auth_oidc_oidcclient_testcase extends \advanced_testcase { +final class oidcclient_test extends \advanced_testcase { /** * Perform setup before every test. This tells Moodle's phpunit to reset the database after every test. */ - protected function setUp():void { + protected function setUp(): void { parent::setUp(); $this->resetAfterTest(true); } /** * Test getting and setting credentials. + * + * @covers \auth_oidc\tests\mockoidcclient::setcreds */ - public function test_creds_getters_and_setters() { + public function test_creds_getters_and_setters(): void { $httpclient = new \auth_oidc\tests\mockhttpclient(); $client = new \auth_oidc\tests\mockoidcclient($httpclient); @@ -58,7 +64,7 @@ public function test_creds_getters_and_setters() { $redirecturi = 'redirecturi'; $tokenresource = 'resource'; $scope = (isset($this->config->oidcscope)) ? $this->config->oidcscope : null; - $client->setcreds($id, $secret, $redirecturi, $tokenresource,$scope); + $client->setcreds($id, $secret, $redirecturi, $tokenresource, $scope); $this->assertEquals($id, $client->get_clientid()); $this->assertEquals($secret, $client->get_clientsecret()); @@ -71,32 +77,32 @@ public function test_creds_getters_and_setters() { * * @return array Array of arrays of test parameters. */ - public function dataprovider_endpoints() { + public static function dataprovider_endpoints(): array { $tests = []; $tests['oneinvalid'] = [ - ['auth' => 100], - ['Exception', 'Invalid Endpoint URI received.'] + ['auth' => 100], + ['Exception', 'Invalid Endpoint URI received.'], ]; $tests['oneinvalidonevalid1'] = [ - ['auth' => 100, 'token' => 'http://example.com/token'], - ['Exception', 'Invalid Endpoint URI received.'] + ['auth' => 100, 'token' => 'http://example.com/token'], + ['Exception', 'Invalid Endpoint URI received.'], ]; $tests['oneinvalidonevalid2'] = [ - ['token' => 'http://example.com/token', 'auth' => 100], - ['Exception', 'Invalid Endpoint URI received.'] + ['token' => 'http://example.com/token', 'auth' => 100], + ['Exception', 'Invalid Endpoint URI received.'], ]; $tests['onevalid'] = [ - ['token' => 'http://example.com/token'], - [] + ['token' => 'http://example.com/token'], + [], ]; $tests['twovalid'] = [ - ['auth' => 'http://example.com/auth', 'token' => 'http://example.com/token'], - [] + ['auth' => 'http://example.com/auth', 'token' => 'http://example.com/token'], + [], ]; return $tests; @@ -106,10 +112,11 @@ public function dataprovider_endpoints() { * Test setting and getting endpoints. * * @dataProvider dataprovider_endpoints - * @param $endpoints - * @param $expectedexception + * @covers \auth_oidc\tests\mockoidcclient::setendpoints + * @param array $endpoints + * @param array $expectedexception */ - public function test_endpoints_getters_and_setters($endpoints, $expectedexception) { + public function test_endpoints_getters_and_setters(array $endpoints, array $expectedexception): void { if (!empty($expectedexception)) { $this->expectException($expectedexception[0]); $this->expectExceptionMessage($expectedexception[1]); diff --git a/auth/oidc/tests/privacy_provider_test.php b/auth/oidc/tests/privacy_provider_test.php index 43738331d..dc60bbf6f 100644 --- a/auth/oidc/tests/privacy_provider_test.php +++ b/auth/oidc/tests/privacy_provider_test.php @@ -23,9 +23,9 @@ * @copyright (C) 2019 Remote Learner.net Inc http://www.remote-learner.net */ -defined('MOODLE_INTERNAL') || die(); +namespace auth_oidc; -use \auth_oidc\privacy\provider; +use auth_oidc\privacy\provider; /** * Privacy test for auth_oidc @@ -35,11 +35,12 @@ * @group office365 * @group office365_privacy */ -class auth_oidc_privacy_testcase extends \core_privacy\tests\provider_testcase { +final class privacy_provider_test extends \core_privacy\tests\provider_testcase { + /** * Tests set up. */ - public function setUp():void { + public function setUp(): void { global $CFG; $this->resetAfterTest(); $this->setAdminUser(); @@ -47,8 +48,10 @@ public function setUp():void { /** * Check that a user context is returned if there is any user data for this user. + * + * @covers \auth_oidc\privacy\provider::get_contexts_for_userid */ - public function test_get_contexts_for_userid() { + public function test_get_contexts_for_userid(): void { $user = $this->getDataGenerator()->create_user(); $this->assertEmpty(provider::get_contexts_for_userid($user->id)); @@ -67,14 +70,16 @@ public function test_get_contexts_for_userid() { /** * Test that only users with a user context are fetched. + * + * @covers \auth_oidc\privacy\provider::get_users_in_context */ - public function test_get_users_in_context() { + public function test_get_users_in_context(): void { $this->resetAfterTest(); $component = 'auth_oidc'; // Create a user. $user = $this->getDataGenerator()->create_user(); - $usercontext = context_user::instance($user->id); + $usercontext = \context_user::instance($user->id); // The list of users should not return anything yet (related data still haven't been created). $userlist = new \core_privacy\local\request\userlist($usercontext, $component); @@ -93,15 +98,17 @@ public function test_get_users_in_context() { $this->assertEquals($expected, $actual); // The list of users for system context should not return any users. - $userlist = new \core_privacy\local\request\userlist(context_system::instance(), $component); + $userlist = new \core_privacy\local\request\userlist(\context_system::instance(), $component); provider::get_users_in_context($userlist); $this->assertCount(0, $userlist); } /** * Test that user data is exported correctly. + * + * @covers \auth_oidc\privacy\provider::export_user_data */ - public function test_export_user_data() { + public function test_export_user_data(): void { // Create a user record. $user = $this->getDataGenerator()->create_user(); $tokenrecord = self::create_token($user->id); @@ -111,19 +118,19 @@ public function test_export_user_data() { $writer = \core_privacy\local\request\writer::with_context($usercontext); $this->assertFalse($writer->has_any_data()); - $approvedlist = new core_privacy\local\request\approved_contextlist($user, 'auth_oidc', [$usercontext->id]); + $approvedlist = new \core_privacy\local\request\approved_contextlist($user, 'auth_oidc', [$usercontext->id]); provider::export_user_data($approvedlist); // Token. $data = $writer->get_data([ - get_string('privacy:metadata:auth_oidc', 'auth_oidc'), - get_string('privacy:metadata:auth_oidc_token', 'auth_oidc') + get_string('privacy:metadata:auth_oidc', 'auth_oidc'), + get_string('privacy:metadata:auth_oidc_token', 'auth_oidc'), ]); $this->assertEquals($tokenrecord->userid, $data->userid); $this->assertEquals($tokenrecord->token, $data->token); // Previous login. $data = $writer->get_data([ - get_string('privacy:metadata:auth_oidc', 'auth_oidc'), - get_string('privacy:metadata:auth_oidc_prevlogin', 'auth_oidc') + get_string('privacy:metadata:auth_oidc', 'auth_oidc'), + get_string('privacy:metadata:auth_oidc_prevlogin', 'auth_oidc'), ]); $this->assertEquals($prevloginrecord->userid, $data->userid); $this->assertEquals($prevloginrecord->method, $data->method); @@ -132,8 +139,10 @@ public function test_export_user_data() { /** * Test deleting all user data for a specific context. + * + * @covers \auth_oidc\privacy\provider::delete_data_for_all_users_in_context */ - public function test_delete_data_for_all_users_in_context() { + public function test_delete_data_for_all_users_in_context(): void { global $DB; // Create a user record. @@ -163,8 +172,10 @@ public function test_delete_data_for_all_users_in_context() { /** * This should work identical to the above test. + * + * @covers \auth_oidc\privacy\provider::delete_data_for_user */ - public function test_delete_data_for_user() { + public function test_delete_data_for_user(): void { global $DB; // Create a user record. @@ -195,20 +206,22 @@ public function test_delete_data_for_user() { /** * Test that data for users in approved userlist is deleted. + * + * @covers \auth_oidc\privacy\provider::delete_data_for_users */ - public function test_delete_data_for_users() { + public function test_delete_data_for_users(): void { $this->resetAfterTest(); $component = 'auth_oidc'; // Create user1. $user1 = $this->getDataGenerator()->create_user(); - $usercontext1 = context_user::instance($user1->id); + $usercontext1 = \context_user::instance($user1->id); self::create_token($user1->id); self::create_prevlogin($user1->id); // Create user2. $user2 = $this->getDataGenerator()->create_user(); - $usercontext2 = context_user::instance($user2->id); + $usercontext2 = \context_user::instance($user2->id); self::create_token($user2->id); self::create_prevlogin($user2->id); @@ -244,7 +257,7 @@ public function test_delete_data_for_users() { $this->assertCount(1, $userlist2); // User data should be only removed in the user context. - $systemcontext = context_system::instance(); + $systemcontext = \context_system::instance(); // Add userlist2 to the approved user list in the system context. $approvedlist = new \core_privacy\local\request\approved_userlist($systemcontext, $component, $userlist2->get_userids()); // Delete user1 data using delete_data_for_user. @@ -259,12 +272,12 @@ public function test_delete_data_for_users() { * Create a token record for the specified userid. * * @param int $userid - * @return stdClass - * @throws dml_exception + * @return \stdClass + * @throws \dml_exception */ - static private function create_token(int $userid) : \stdClass { + private static function create_token(int $userid): \stdClass { global $DB; - $record = new stdClass(); + $record = new \stdClass(); $record->oidcuniqid = "user@example.com"; $record->username = "user@example.com"; $record->userid = $userid; @@ -285,12 +298,12 @@ static private function create_token(int $userid) : \stdClass { * Create a previous login record for the specified userid. * * @param int $userid - * @return stdClass - * @throws dml_exception + * @return \stdClass + * @throws \dml_exception */ - static private function create_prevlogin(int $userid) : \stdClass { + private static function create_prevlogin(int $userid): \stdClass { global $DB; - $record = new stdClass(); + $record = new \stdClass(); $record->userid = $userid; $record->method = "manual"; $record->password = "abc123"; diff --git a/local/office365/classes/privacy/provider.php b/local/office365/classes/privacy/provider.php index 458a4a44e..065192621 100644 --- a/local/office365/classes/privacy/provider.php +++ b/local/office365/classes/privacy/provider.php @@ -25,8 +25,6 @@ namespace local_office365\privacy; -defined('MOODLE_INTERNAL') || die(); - /** * Privacy subsystem implementation of local_office365. */ diff --git a/local/onenote/classes/api/base.php b/local/onenote/classes/api/base.php index 525c5614f..314d63ba1 100644 --- a/local/onenote/classes/api/base.php +++ b/local/onenote/classes/api/base.php @@ -39,8 +39,6 @@ use moodle_url; use stdClass; -defined('MOODLE_INTERNAL') || die(); - /** * A helper class to access Microsoft OneNote using the REST api. */ @@ -352,7 +350,7 @@ public function download_page($pageid, $path) { * @param string $path The path containing notebook id / section id / page id. * @return array Array of items formatted for fileapi. */ - public function get_items_list($path = '') : array { + public function get_items_list($path = ''): array { global $OUTPUT; if (empty($path)) { @@ -398,11 +396,17 @@ public function get_items_list($path = '') : array { $itemlastmodified = $item['lastModifiedDateTime']; } - $items[] = ['title' => $itemname, 'path' => $path . '/' . urlencode($item['id']), - 'date' => strtotime($itemlastmodified), - 'thumbnail' => $OUTPUT->image_url(file_extension_icon($itemname))->out(false), 'source' => $item['id'], - 'url' => $item['links']['oneNoteWebUrl']['href'], 'author' => $item['createdBy'], 'id' => $item['id'], - 'children' => [],]; + $items[] = [ + 'title' => $itemname, + 'path' => $path . '/' . urlencode($item['id']), + 'date' => strtotime($itemlastmodified), + 'thumbnail' => $OUTPUT->image_url(file_extension_icon($itemname))->out(false), + 'source' => $item['id'], + 'url' => $item['links']['oneNoteWebUrl']['href'], + 'author' => $item['createdBy'], + 'id' => $item['id'], + 'children' => [], + ]; break; case 'section': @@ -415,10 +419,17 @@ public function get_items_list($path = '') : array { $itemlastmodified = $item['lastModifiedDateTime']; } - $items[] = ['title' => $itemname, 'path' => $path . '/' . urlencode($item['id']), - 'date' => strtotime($itemlastmodified), - 'thumbnail' => $OUTPUT->image_url(file_extension_icon($itemname))->out(false), 'source' => $item['id'], - 'url' => $item['self'], 'author' => $item['createdBy'], 'id' => $item['id'], 'children' => [],]; + $items[] = [ + 'title' => $itemname, + 'path' => $path . '/' . urlencode($item['id']), + 'date' => strtotime($itemlastmodified), + 'thumbnail' => $OUTPUT->image_url(file_extension_icon($itemname))->out(false), + 'source' => $item['id'], + 'url' => $item['self'], + 'author' => $item['createdBy'], + 'id' => $item['id'], + 'children' => [], + ]; break; case 'page': @@ -427,11 +438,16 @@ public function get_items_list($path = '') : array { $itemcreatedtime = $item['createdDateTime']; } - $items[] = ['title' => $item['title'] . ".zip", 'path' => $path . '/' . urlencode($item['id']), - 'date' => strtotime($itemcreatedtime), - 'thumbnail' => $OUTPUT->image_url(file_extension_icon($item['title']))->out(false), - 'source' => $item['id'], 'url' => $item['links']['oneNoteWebUrl']['href'], - 'author' => $item['createdByAppId'], 'id' => $item['id'],]; + $items[] = [ + 'title' => $item['title'] . ".zip", + 'path' => $path . '/' . urlencode($item['id']), + 'date' => strtotime($itemcreatedtime), + 'thumbnail' => $OUTPUT->image_url(file_extension_icon($item['title']))->out(false), + 'source' => $item['id'], + 'url' => $item['links']['oneNoteWebUrl']['href'], + 'author' => $item['createdByAppId'], + 'id' => $item['id'], + ]; break; } } @@ -563,7 +579,7 @@ public function render_action_button($buttontext, $cmid, $wantfeedbackpage = fal $url = new moodle_url('/local/onenote/onenote_actions.php', $actionparams); - $attrs = ['onclick' => 'window.open(this.href,\'_blank\'); return false;', 'class' => 'local_onenote_linkbutton',]; + $attrs = ['onclick' => 'window.open(this.href,\'_blank\'); return false;', 'class' => 'local_onenote_linkbutton']; return html_writer::link($url->out(false), $buttontext, $attrs); } diff --git a/local/onenote/classes/api/o365.php b/local/onenote/classes/api/o365.php index 751f1c76e..f97b80263 100644 --- a/local/onenote/classes/api/o365.php +++ b/local/onenote/classes/api/o365.php @@ -31,8 +31,6 @@ use local_o365\rest\unified; use moodle_exception; -defined('MOODLE_INTERNAL') || die(); - /** * General purpose utility class. */ diff --git a/local/onenote/classes/privacy/provider.php b/local/onenote/classes/privacy/provider.php index 65c2d26ca..20a70781a 100644 --- a/local/onenote/classes/privacy/provider.php +++ b/local/onenote/classes/privacy/provider.php @@ -27,19 +27,15 @@ defined('MOODLE_INTERNAL') || die(); -use \core_privacy\local\metadata\collection; -use \core_privacy\local\request\contextlist; -use \core_privacy\local\request\approved_contextlist; -use \core_privacy\local\request\writer; +use core_privacy\local\metadata\collection; +use core_privacy\local\request\contextlist; +use core_privacy\local\request\approved_contextlist; +use core_privacy\local\request\writer; -if (interface_exists('\core_privacy\local\request\core_userlist_provider')) { - interface local_onenote_userlist extends \core_privacy\local\request\core_userlist_provider { - } -} else { - interface local_onenote_userlist { - } - - ; +/** + * Interface for the local_onenote user list provider. + */ +interface local_onenote_userlist extends \core_privacy\local\request\core_userlist_provider { } /** @@ -54,11 +50,11 @@ class provider * @param collection $collection The initialised collection to add items to. * @return collection A listing of user data stored through this system. */ - public static function get_metadata(collection $collection) : collection { + public static function get_metadata(collection $collection): collection { - $tables = ['local_onenote_user_sections' => ['user_id', 'course_id', 'section_id',], - 'local_onenote_assign_pages' => ['user_id', 'assign_id', 'submission_student_page_id', 'feedback_student_page_id', - 'submission_teacher_page_id', 'feedback_teacher_page_id', 'teacher_lastviewed', 'student_lastmodified',],]; + $tables = ['local_onenote_user_sections' => ['user_id', 'course_id', 'section_id'], + 'local_onenote_assign_pages' => ['user_id', 'assign_id', 'submission_student_page_id', 'feedback_student_page_id', + 'submission_teacher_page_id', 'feedback_teacher_page_id', 'teacher_lastviewed', 'student_lastmodified']]; foreach ($tables as $table => $fields) { $fielddata = []; @@ -77,7 +73,7 @@ public static function get_metadata(collection $collection) : collection { * @param int $userid The user to search. * @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin. */ - public static function get_contexts_for_userid(int $userid) : contextlist { + public static function get_contexts_for_userid(int $userid): contextlist { $contextlist = new \core_privacy\local\request\contextlist(); if (self::user_has_onenote_data($userid)) { $contextlist->add_user_context($userid); @@ -198,9 +194,9 @@ private static function delete_user_data(int $userid) { * @param int $userid The user to get the map for. * @return array The table user map. */ - protected static function get_table_user_map(int $userid) : array { + protected static function get_table_user_map(int $userid): array { $tables = - ['local_onenote_user_sections' => ['user_id' => $userid], 'local_onenote_assign_pages' => ['user_id' => $userid],]; + ['local_onenote_user_sections' => ['user_id' => $userid], 'local_onenote_assign_pages' => ['user_id' => $userid]]; return $tables; } } diff --git a/local/onenote/classes/utils.php b/local/onenote/classes/utils.php index 7836174f4..eb660487f 100644 --- a/local/onenote/classes/utils.php +++ b/local/onenote/classes/utils.php @@ -25,8 +25,6 @@ namespace local_onenote; -defined('MOODLE_INTERNAL') || die(); - /** * General purpose utility class. */ @@ -47,7 +45,7 @@ public static function tostring($val) { } else if (is_null($val)) { return '(null)'; } else { - return print_r($val, true); + return json_encode($val, JSON_PRETTY_PRINT); } } diff --git a/local/onenote/db/upgrade.php b/local/onenote/db/upgrade.php index 5430dec60..663e01402 100644 --- a/local/onenote/db/upgrade.php +++ b/local/onenote/db/upgrade.php @@ -22,8 +22,6 @@ * @copyright Microsoft, Inc. */ -defined('MOODLE_INTERNAL') || die(); - /** * Upgrade the local_onenote plugin. * @@ -46,7 +44,7 @@ function xmldb_local_onenote_upgrade($oldversion) { $table->add_field('section_id', XMLDB_TYPE_CHAR, '255', null, null, null, null); // Adding keys to table. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); // Create table. if ($dbman->table_exists($table)) { @@ -68,7 +66,7 @@ function xmldb_local_onenote_upgrade($oldversion) { $table->add_field('feedback_teacher_page_id', XMLDB_TYPE_CHAR, '255', null, null, null, null); // Adding keys to table. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); // Create table. if ($dbman->table_exists($table)) { @@ -83,7 +81,8 @@ function xmldb_local_onenote_upgrade($oldversion) { if ($oldversion < 2015111905) { // Define field submission_teacher_lastview to be added to onenote_assign_pages. $table = new xmldb_table('onenote_assign_pages'); - $field = new xmldb_field('teacher_lastviewed', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'feedback_teacher_page_id'); + $field = new xmldb_field('teacher_lastviewed', XMLDB_TYPE_INTEGER, '10', null, null, null, null, + 'feedback_teacher_page_id'); // Conditionally launch add field submission_teacher_lastview. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); @@ -119,7 +118,7 @@ function xmldb_local_onenote_upgrade($oldversion) { } if ($oldversion < 2021051716) { - // Make sure teacher_lastviewed is a integer + // Make sure teacher_lastviewed is an integer. $table = new xmldb_table('local_onenote_assign_pages'); $field = new xmldb_field('teacher_lastviewed', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'feedback_teacher_page_id'); diff --git a/local/onenote/lang/cs/local_onenote.php b/local/onenote/lang/cs/local_onenote.php index 656da11c0..946c9832f 100644 --- a/local/onenote/lang/cs/local_onenote.php +++ b/local/onenote/lang/cs/local_onenote.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Language strings * @@ -21,6 +22,10 @@ * @copyright Microsoft, Inc. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'Microsoft OneNote'; $string['submissiontitle'] = 'Odeslaný příspěvek: {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; $string['feedbacktitle'] = 'Zpětná vazba: {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; @@ -28,3 +33,6 @@ $string['onenote_page_error'] = 'Nelze otevřít stránku OneNote pro tento příspěvek nebo zpětnou vazbu.'; $string['error_noapiavailable'] = 'Není k dispozici žádné rozhraní OneNote API. S použitím sady pluginů Microsoft 365 se nám nepodařilo OneNote kontaktovat.'; $string['notebookname'] = 'Poznámkový blok Moodle'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/local/onenote/lang/de/local_onenote.php b/local/onenote/lang/de/local_onenote.php index c96152266..1336d08e7 100644 --- a/local/onenote/lang/de/local_onenote.php +++ b/local/onenote/lang/de/local_onenote.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Language strings * @@ -21,6 +22,10 @@ * @copyright Microsoft, Inc. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'Microsoft OneNote'; $string['submissiontitle'] = 'Abgegebene Aufgabe: {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; $string['feedbacktitle'] = 'Feedback: {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; @@ -28,3 +33,6 @@ $string['onenote_page_error'] = 'Die OneNote-Seite für diese abgegebene Aufgabe oder dieses Feedback konnte nicht geöffnet werden.'; $string['error_noapiavailable'] = 'Keine OneNote-API verfügbar. Bei Verwendung des Microsoft 365-Plugin-Satzes konnte OneNote nicht erreicht werden.'; $string['notebookname'] = 'Moodle-Notizbuch'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/local/onenote/lang/en/local_onenote.php b/local/onenote/lang/en/local_onenote.php index 5fc00c4a7..5550a9aea 100644 --- a/local/onenote/lang/en/local_onenote.php +++ b/local/onenote/lang/en/local_onenote.php @@ -22,6 +22,9 @@ * @copyright Microsoft, Inc. */ +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'Microsoft OneNote'; $string['submissiontitle'] = 'Submission: {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; $string['feedbacktitle'] = 'Feedback: {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; @@ -50,3 +53,6 @@ $string['privacy:metadata:local_onenote_assign_pages:feedback_teacher_page_id'] = 'The page ID for the teacher feedback'; $string['privacy:metadata:local_onenote_assign_pages:teacher_lastviewed'] = 'The time the teacher last viewed the submission'; $string['privacy:metadata:local_onenote_assign_pages:student_lastmodified'] = 'The time the student last modified the submission'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/local/onenote/lang/es/local_onenote.php b/local/onenote/lang/es/local_onenote.php index 2ba4d5f21..181c626f2 100644 --- a/local/onenote/lang/es/local_onenote.php +++ b/local/onenote/lang/es/local_onenote.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Language strings * @@ -21,6 +22,10 @@ * @copyright Microsoft, Inc. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'Microsoft OneNote'; $string['submissiontitle'] = 'Entrega: {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; $string['feedbacktitle'] = 'Comentarios: {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; @@ -28,3 +33,6 @@ $string['onenote_page_error'] = 'No se pudo abrir la página de OneNote para esta entrega o comentario.'; $string['error_noapiavailable'] = 'No hay ninguna API de OneNote disponible. Si utiliza el conjunto de extensiones de Microsoft 365, no pudimos comunicarnos con OneNote.'; $string['notebookname'] = 'Cuaderno de Moodle'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/local/onenote/lang/fi/local_onenote.php b/local/onenote/lang/fi/local_onenote.php index 68c2da7c4..fb0fb64ad 100644 --- a/local/onenote/lang/fi/local_onenote.php +++ b/local/onenote/lang/fi/local_onenote.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Language strings * @@ -21,6 +22,10 @@ * @copyright Microsoft, Inc. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'Microsoft OneNote'; $string['submissiontitle'] = 'Palautus: {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; $string['feedbacktitle'] = 'Palaute: {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; @@ -28,3 +33,6 @@ $string['onenote_page_error'] = 'Tämän palautuksen tai palautteen OneNote-sivua ei voitu avata.'; $string['error_noapiavailable'] = 'OneNote-ohjelmointirajapinta ei ole käytettävissä. Jos Microsoft 365 -laajennuspaketti on käytössä, OneNote-yhteyttä ei voitu muodostaa.'; $string['notebookname'] = 'Moodle-muistikirja'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/local/onenote/lang/fr/local_onenote.php b/local/onenote/lang/fr/local_onenote.php index b1af7a12f..daf4e8245 100644 --- a/local/onenote/lang/fr/local_onenote.php +++ b/local/onenote/lang/fr/local_onenote.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Language strings * @@ -21,6 +22,10 @@ * @copyright Microsoft, Inc. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'Microsoft OneNote'; $string['submissiontitle'] = 'Remise : {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; $string['feedbacktitle'] = 'Feed-back : {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; @@ -28,3 +33,6 @@ $string['onenote_page_error'] = 'Impossible d\'ouvrir la page OneNote pour cette remise ou ce feed-back.'; $string['error_noapiavailable'] = 'Aucune API OneNote n\'est disponible. Si vous utilisez l\'ensemble de plug-ins Microsoft 365, nous ne sommes pas parvenus à contacter OneNote.'; $string['notebookname'] = 'Carnet de notes Moodle'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/local/onenote/lang/it/local_onenote.php b/local/onenote/lang/it/local_onenote.php index 6e25afedf..839a43501 100644 --- a/local/onenote/lang/it/local_onenote.php +++ b/local/onenote/lang/it/local_onenote.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Language strings * @@ -21,6 +22,10 @@ * @copyright Microsoft, Inc. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'Microsoft OneDrive'; $string['submissiontitle'] = 'Consegna: {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; $string['feedbacktitle'] = 'Feedback: {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; @@ -28,3 +33,6 @@ $string['onenote_page_error'] = 'Non è possibile aprire la pagina OneNote per questa consegna o feedback.'; $string['error_noapiavailable'] = 'Nessuna API OneNote disponibile. Se utilizzi il set di plugin di Microsoft 365, non è possibile contattare OneNote.'; $string['notebookname'] = 'Blocco appunti Moodle'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/local/onenote/lang/ja/local_onenote.php b/local/onenote/lang/ja/local_onenote.php index 72cdff34c..c7b9e71ed 100644 --- a/local/onenote/lang/ja/local_onenote.php +++ b/local/onenote/lang/ja/local_onenote.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Language strings * @@ -21,6 +22,10 @@ * @copyright Microsoft, Inc. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'Microsoft OneNote'; $string['submissiontitle'] = '提出 : {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; $string['feedbacktitle'] = 'フィードバック : {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; @@ -28,3 +33,6 @@ $string['onenote_page_error'] = 'この提出またはフィードバックのOneNoteページを開けませんでした。'; $string['error_noapiavailable'] = 'OneNote APIを使用できません。Microsoft 365プラグインのセットを使用している場合、OneNoteにはアクセスできません。'; $string['notebookname'] = 'Moodleノートブック'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/local/onenote/lang/nl/local_onenote.php b/local/onenote/lang/nl/local_onenote.php index 18bb78d29..98e803c19 100644 --- a/local/onenote/lang/nl/local_onenote.php +++ b/local/onenote/lang/nl/local_onenote.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Language strings * @@ -21,6 +22,10 @@ * @copyright Microsoft, Inc. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'Microsoft OneNote'; $string['submissiontitle'] = 'Inzending: {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; $string['feedbacktitle'] = 'Feedback: {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; @@ -28,3 +33,6 @@ $string['onenote_page_error'] = 'Kan de OneNote-pagina voor deze inzending of feedback niet openen.'; $string['error_noapiavailable'] = 'Er is geen OneNote API beschikbaar. Als je de Microsoft 365-pluginset gebruikt, hebben we geen contact kunnen maken met OneNote.'; $string['notebookname'] = 'Moodle Notebook'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/local/onenote/lang/pl/local_onenote.php b/local/onenote/lang/pl/local_onenote.php index 4eaeec20e..50c0baab3 100644 --- a/local/onenote/lang/pl/local_onenote.php +++ b/local/onenote/lang/pl/local_onenote.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Language strings * @@ -21,6 +22,10 @@ * @copyright Microsoft, Inc. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'Microsoft OneNote'; $string['submissiontitle'] = 'Przesłana praca: {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; $string['feedbacktitle'] = 'Informacja zwrotna: {$a->assign_name} [{$a->student_firstname} {$a->student_lastname}]'; @@ -28,3 +33,6 @@ $string['onenote_page_error'] = 'Nie można otworzyć strony programu OneNote dla tej przesłanej pracy lub informacji zwrotnej.'; $string['error_noapiavailable'] = 'Interfejs OneNote API nie jest dostępny. Jeśli używany jest zestaw wtyczek Microsoft 365, nie możemy nawiązać połączenia z programem OneNote.'; $string['notebookname'] = 'Notatnik na platformie Moodle'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/local/onenote/lang/pt_br/local_onenote.php b/local/onenote/lang/pt_br/local_onenote.php index 4dfa906f5..6128005a0 100644 --- a/local/onenote/lang/pt_br/local_onenote.php +++ b/local/onenote/lang/pt_br/local_onenote.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + /** * Language strings * @@ -21,6 +22,10 @@ * @copyright Microsoft, Inc. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ + +// phpcs:disable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:disable moodle.Files.LangFilesOrdering.UnexpectedComment + $string['pluginname'] = 'Microsoft OneNote'; $string['submissiontitle'] = 'Envio: {$a->assign_name} ({$a->student_firstname} {$a->student_lastname})'; $string['feedbacktitle'] = 'Feedback: {$a->assign_name} ({$a->student_firstname} {$a->student_lastname})'; @@ -28,3 +33,6 @@ $string['onenote_page_error'] = 'Não foi possível abrir a página do OneNote para este envio ou feedback.'; $string['error_noapiavailable'] = 'Não há nenhuma API do OneNote disponível. Caso você esteja usando o conjunto de plugins do Microsoft 365, não foi possível estabelecer contato com o OneNote.'; $string['notebookname'] = 'Bloco de anotações do Moodle'; + +// phpcs:enable moodle.Files.LangFilesOrdering.IncorrectOrder +// phpcs:enable moodle.Files.LangFilesOrdering.UnexpectedComment \ No newline at end of file diff --git a/local/onenote/styles.css b/local/onenote/styles.css index e13d45420..1da777433 100644 --- a/local/onenote/styles.css +++ b/local/onenote/styles.css @@ -1,19 +1,19 @@ .local_onenote_linkbutton { - background-image: url([[pix:local_onenote|onenote]]); - background-position: 2px 0px; - background-size: 32px 32px; + background-image: url([[pix:local_onenote|onenote]]); + background-position: 2px 0; + background-size: 32px 32px; background-repeat: no-repeat; background-color: #80397b; color: #fff; display: inline-block; padding: 6px 6px 6px 40px; - margin: 5px 0px; + margin: 5px 0; font-size: 14px; } .local_onenote_linkbutton:active, .local_onenote_linkbutton:hover, .local_onenote_linkbutton:visited { - text-decoration: none !important; + text-decoration: none; color: #fff; } \ No newline at end of file diff --git a/local/onenote/tests/generator/lib.php b/local/onenote/tests/generator/lib.php index 6b6ddafbd..a5490cc06 100644 --- a/local/onenote/tests/generator/lib.php +++ b/local/onenote/tests/generator/lib.php @@ -23,8 +23,6 @@ * @copyright Microsoft, Inc. */ -defined('MOODLE_INTERNAL') || die(); - /** * Class repository_onenote_generator */ diff --git a/local/onenote/tests/onenoteapi_test.php b/local/onenote/tests/onenoteapi_test.php index 0ccff7521..5ed596cac 100644 --- a/local/onenote/tests/onenoteapi_test.php +++ b/local/onenote/tests/onenoteapi_test.php @@ -39,6 +39,8 @@ * 3) Run the unit tests using the standard process for running PHP Unit tests for Moodle. */ +namespace local_onenote; + defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/mod/assign/tests/base_test.php'); @@ -49,7 +51,7 @@ * @group local_onenote * @group office365 */ -class local_onenote_onenoteapi_testcase extends advanced_testcase { +final class onenoteapi_test extends \advanced_testcase { /** @var \onenoteapi */ private $onenoteapi; /** @var \user */ @@ -80,7 +82,7 @@ class local_onenote_onenoteapi_testcase extends advanced_testcase { * * @return bool */ - public function setup() : void { + public function setup(): void { global $CFG; return; // Need to update tests to not contact external services. $this->resetAfterTest(true); @@ -142,9 +144,11 @@ public function set_user($index) { /** * Test for checking create_temp_folder + * + * @covers \local_onenote\api\base::create_temp_folder */ - public function test_createtempfolder() { - return true; // Need to update test to not require config data. + public function test_createtempfolder(): void { + return; // Need to update test to not require config data. $this->set_test_config(); $this->set_user(0); @@ -153,9 +157,11 @@ public function test_createtempfolder() { /** * Test for onenote action button + * + * @covers \local_onenote\api\base::render_action_button */ - public function test_renderactionbutton() { - return true; // Need to update test to not require config data. + public function test_renderactionbutton(): void { + return; // Need to update test to not require config data. $this->set_test_config(); $this->set_user(0); global $CFG; @@ -175,9 +181,11 @@ public function test_renderactionbutton() { /** * Test for checking if the user is teacher + * + * @covers \local_onenote\api\base::is_teacher */ - public function test_isteacher() { - return true; // Need to update test to not require config data. + public function test_isteacher(): void { + return; // Need to update test to not require config data. $this->set_test_config(); $this->set_user(0); $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign'); @@ -189,9 +197,11 @@ public function test_isteacher() { /** * Test for getitemlist api + * + * @covers \local_onenote\api\base::get_items_list */ - public function test_getitemlist() { - return true; // Need to update test to not require config data. + public function test_getitemlist(): void { + return; // Need to update test to not require config data. $this->set_test_config(); $this->set_user(0); @@ -219,10 +229,12 @@ public function test_getitemlist() { } /** - * Test for checking if assignment submission size is greater than than assignment limit. + * Test for checking if assignment submission size is greater than assignment limit. + * + * @covers \local_onenote\api\base::check_size_limits */ - public function test_sizelimits() { - return true; // Need to update test to not require config data. + public function test_sizelimits(): void { + return; // Need to update test to not require config data. $this->set_test_config(); $this->set_user(0); @@ -269,9 +281,11 @@ public function test_sizelimits() { /** * Test for checking html processing. + * + * @covers \local_onenote\api\base::download_page */ - public function test_downloadpagehtml() { - return true; // Need to update test to not require config data. + public function test_downloadpagehtml(): void { + return; // Need to update test to not require config data. global $DB; $this->set_test_config(); $this->set_user(0); @@ -324,7 +338,8 @@ public function test_downloadpagehtml() { $expectedhtml = '

'; $expectedhtml .= 'Heading 1

'; - $expectedhtml .= '

This is test assignment.

'; + $expectedhtml .= '

'; + $expectedhtml .= 'This is test assignment.

'; $expectedhtml .= '

 

'; $output = trim(preg_replace('/\s+/', ' ', $output)); @@ -334,9 +349,11 @@ public function test_downloadpagehtml() { /** * Test for getpage method. + * + * @covers \local_onenote\api\base::get_page */ - public function test_getpage() { - return true; // Need to update test to not require config data. + public function test_getpage(): void { + return; // Need to update test to not require config data. $this->set_test_config(); $this->set_user(0); @@ -391,9 +408,11 @@ public function test_getpage() { /** * Test for download page method. + * + * @covers \local_onenote\api\base::download_page */ - public function test_downloadpage() { - return true; // Need to update test to not require config data. + public function test_downloadpage(): void { + return; // Need to update test to not require config data. $this->set_test_config(); $this->set_user(0); diff --git a/local/onenote/tests/privacy_provider_test.php b/local/onenote/tests/privacy_provider_test.php index aa045362a..90cdb67df 100644 --- a/local/onenote/tests/privacy_provider_test.php +++ b/local/onenote/tests/privacy_provider_test.php @@ -23,14 +23,17 @@ * @copyright (C) 2019 Remote Learner.net Inc http://www.remote-learner.net */ -defined('MOODLE_INTERNAL') || die(); +namespace local_onenote; +use context_system; +use context_user; use core_privacy\local\request\approved_contextlist; use core_privacy\local\request\approved_userlist; use core_privacy\local\request\userlist; use core_privacy\local\request\writer; use core_privacy\tests\provider_testcase; -use \local_onenote\privacy\provider; +use local_onenote\privacy\provider; +use stdClass; /** * Privacy test for local_onenote @@ -40,11 +43,11 @@ * @group office365 * @group office365_privacy */ -class local_onenote_privacy_testcase extends provider_testcase { +final class privacy_provider_test extends provider_testcase { /** * Tests set up. */ - public function setUp() : void { + public function setUp(): void { global $CFG; $this->resetAfterTest(); $this->setAdminUser(); @@ -52,8 +55,10 @@ public function setUp() : void { /** * Check that a user context is returned if there is any user data for this user. + * + * @covers \local_onenote\privacy\provider::get_contexts_for_userid */ - public function test_get_contexts_for_userid() { + public function test_get_contexts_for_userid(): void { $user = $this->getDataGenerator()->create_user(); $this->assertEmpty(provider::get_contexts_for_userid($user->id)); @@ -71,8 +76,10 @@ public function test_get_contexts_for_userid() { /** * Test that only users with a user context are fetched. + * + * @covers \local_onenote\privacy\provider::get_users_in_context */ - public function test_get_users_in_context() { + public function test_get_users_in_context(): void { $this->resetAfterTest(); $component = 'local_onenote'; @@ -103,8 +110,10 @@ public function test_get_users_in_context() { /** * Test that user data is exported correctly. + * + * @covers \local_onenote\privacy\provider::export_user_data */ - public function test_export_user_data() { + public function test_export_user_data(): void { // Create a user record. $user = $this->getDataGenerator()->create_user(); @@ -115,7 +124,7 @@ public function test_export_user_data() { $writer = writer::with_context($usercontext); $this->assertFalse($writer->has_any_data()); - $approvedlist = new core_privacy\local\request\approved_contextlist($user, 'local_onenote', [$usercontext->id]); + $approvedlist = new approved_contextlist($user, 'local_onenote', [$usercontext->id]); provider::export_user_data($approvedlist); foreach ($userrecords as $table => $record) { @@ -129,8 +138,10 @@ public function test_export_user_data() { /** * Test deleting all user data for a specific context. + * + * @covers \local_onenote\privacy\provider::delete_data_for_all_users_in_context */ - public function test_delete_data_for_all_users_in_context() { + public function test_delete_data_for_all_users_in_context(): void { global $DB; // Create user data. @@ -160,8 +171,10 @@ public function test_delete_data_for_all_users_in_context() { /** * This should work identical to the above test. + * + * @covers \local_onenote\privacy\provider::delete_data_for_user */ - public function test_delete_data_for_user() { + public function test_delete_data_for_user(): void { global $DB; // Create a user record. @@ -192,8 +205,10 @@ public function test_delete_data_for_user() { /** * Test that data for users in approved userlist is deleted. + * + * @covers \local_onenote\privacy\provider::delete_data_for_users */ - public function test_delete_data_for_users() { + public function test_delete_data_for_users(): void { $this->resetAfterTest(); $component = 'local_onenote'; @@ -256,9 +271,11 @@ public function test_delete_data_for_users() { * @param int $userid The user's ID. * @return array Array of records, indexed by table name. */ - private static function create_userdata(int $userid) { - $records = ['local_onenote_user_sections' => self::create_usersections_record($userid), - 'local_onenote_assign_pages' => self::create_assignpages_record($userid),]; + private static function create_userdata(int $userid): array { + $records = [ + 'local_onenote_user_sections' => self::create_usersections_record($userid), + 'local_onenote_assign_pages' => self::create_assignpages_record($userid), + ]; return $records; } @@ -269,7 +286,7 @@ private static function create_userdata(int $userid) { * @return stdClass * @throws dml_exception */ - private static function create_usersections_record(int $userid) : \stdClass { + private static function create_usersections_record(int $userid): stdClass { global $DB; $record = new stdClass(); $record->user_id = $userid; @@ -286,7 +303,7 @@ private static function create_usersections_record(int $userid) : \stdClass { * @return stdClass * @throws dml_exception */ - private static function create_assignpages_record(int $userid) : \stdClass { + private static function create_assignpages_record(int $userid): stdClass { global $DB; $record = new stdClass(); $record->user_id = $userid; diff --git a/repository/office365/classes/privacy/provider.php b/repository/office365/classes/privacy/provider.php index 06eab99d8..f29f58bf7 100644 --- a/repository/office365/classes/privacy/provider.php +++ b/repository/office365/classes/privacy/provider.php @@ -38,7 +38,7 @@ class provider implements \core_privacy\local\metadata\null_provider { * * @return string */ - public static function get_reason() : string { + public static function get_reason(): string { return 'privacy:metadata'; } } diff --git a/repository/office365/db/access.php b/repository/office365/db/access.php index 7015079d1..9092e2e5a 100644 --- a/repository/office365/db/access.php +++ b/repository/office365/db/access.php @@ -29,7 +29,7 @@ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, 'archetypes' => [ - 'user' => CAP_ALLOW - ] - ] + 'user' => CAP_ALLOW, + ], + ], ]; diff --git a/repository/office365/db/caches.php b/repository/office365/db/caches.php index 883177419..e77052589 100644 --- a/repository/office365/db/caches.php +++ b/repository/office365/db/caches.php @@ -26,9 +26,9 @@ $definitions = [ 'unifiedfolderids' => [ - 'mode' => cache_store::MODE_SESSION + 'mode' => cache_store::MODE_SESSION, ], 'unifiedgroupfolderids' => [ - 'mode' => cache_store::MODE_SESSION + 'mode' => cache_store::MODE_SESSION, ], ]; diff --git a/repository/office365/lang/en/repository_office365.php b/repository/office365/lang/en/repository_office365.php index d3e68ae0d..a7efe3486 100644 --- a/repository/office365/lang/en/repository_office365.php +++ b/repository/office365/lang/en/repository_office365.php @@ -26,7 +26,6 @@ $string['cachedef_unifiedgroupfolderids'] = 'Microsoft 365 Repository - Unified folder IDs for groups'; $string['configplugin'] = 'Configure Microsoft 365 Repository'; $string['coursegroup'] = 'Disable Groups (Courses) folder in file picker'; -$string['groups'] = 'Groups (Courses)'; $string['defaultgroupsfolder'] = 'Course Files'; $string['erroraccessdenied'] = 'Access denied'; @@ -34,17 +33,18 @@ $string['errorbadclienttype'] = 'Invalid client type.'; $string['errorbadpath'] = 'Bad Path'; $string['errorcoursenotfound'] = 'Course not found'; -$string['errorwhiledownload'] = 'An error occurred while downloading the file'; $string['erroro365required'] = 'This file is currently only available to Microsoft 365 users.'; +$string['errorwhiledownload'] = 'An error occurred while downloading the file'; $string['file'] = 'File'; +$string['groups'] = 'Groups (Courses)'; $string['myfiles'] = 'My OneDrive'; +$string['notconfigured'] = '

To use this plugin, you must first configure the Microsoft 365 plugins

'; $string['office365:view'] = 'View Microsoft 365 repository'; $string['onedrivegroup'] = 'Disable My OneDrive folder in file picker'; $string['pluginname'] = 'Microsoft 365'; $string['pluginname_help'] = 'A Microsoft 365 Repository'; +$string['privacy:metadata'] = 'This plugin communicates with the Microsoft 365 OneDrive API as the current user. Any files uploaded will be sent to the remote server'; +$string['trendingaround'] = 'Files Trending Around Me'; $string['trendinggroup'] = 'Disable Files Trending Around Me folder in file picker'; $string['upload'] = 'Upload New File'; -$string['notconfigured'] = '

To use this plugin, you must first configure the Microsoft 365 plugins

'; -$string['trendingaround'] = 'Files Trending Around Me'; -$string['privacy:metadata'] = 'This plugin communicates with the Microsoft 365 OneDrive API as the current user. Any files uploaded will be sent to the remote server'; diff --git a/repository/office365/lib.php b/repository/office365/lib.php index 6274ba4d4..47fcfd13a 100644 --- a/repository/office365/lib.php +++ b/repository/office365/lib.php @@ -51,7 +51,7 @@ class repository_office365 extends repository { * @param array $options repository options * @param int $readonly indicate this repo is readonly or not */ - public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array(), $readonly = 0) { + public function __construct($repositoryid, $context = SYSCONTEXTID, $options = [], $readonly = 0) { parent::__construct($repositoryid, $context, $options, $readonly); $this->httpclient = new httpclient(); if (utils::is_connected()) { @@ -1025,7 +1025,7 @@ public function do_embedding($reference, $forcedownload) { * @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin * @param array|null $options additional options affecting the file serving */ - public function send_file($storedfile, $lifetime = null , $filter = 0, $forcedownload = false, array $options = null) { + public function send_file($storedfile, $lifetime = null , $filter = 0, $forcedownload = false, ?array $options = null) { global $USER; $reference = $this->unpack_reference($storedfile->get_reference());