Skip to content

Fix up ci.yml #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: MOODLE_405
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ on: [push, pull_request]

jobs:
ci:
uses: catalyst/catalyst-moodle-workflows/.github/workflows/ci.yml@main
uses: catalyst/catalyst-moodle-workflows/.github/workflows/ci.yml@main
secrets:
moodle_org_token: ${{ secrets.MOODLE_ORG_TOKEN }}
56 changes: 28 additions & 28 deletions auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
use auth_userkey\userkey_manager_interface;
use core_external\external_value;

require_once($CFG->libdir.'/authlib.php');
require_once($CFG->libdir . '/authlib.php');
require_once($CFG->dirroot . '/user/lib.php');

/**
* User key authentication plugin.
*/
class auth_plugin_userkey extends auth_plugin_base {

/**
* Default mapping field.
*/
Expand All @@ -53,7 +52,7 @@ class auth_plugin_userkey extends auth_plugin_base {
*
* @var array
*/
protected $defaults = array(
protected $defaults = [
'mappingfield' => self::DEFAULT_MAPPING_FIELD,
'keylifetime' => 60,
'iprestriction' => 0,
Expand All @@ -62,7 +61,7 @@ class auth_plugin_userkey extends auth_plugin_base {
'ssourl' => '',
'createuser' => false,
'updateuser' => false,
);
];

/**
* Constructor.
Expand Down Expand Up @@ -297,14 +296,16 @@ protected function create_user(array $data) {
throw new invalid_parameter_exception('Unable to create user, missing value(s): ' . implode(',', $missingfields));
}

if ($DB->record_exists('user', array('username' => $user['username'], 'mnethostid' => $CFG->mnet_localhost_id))) {
throw new invalid_parameter_exception('Username already exists: '.$user['username']);
if ($DB->record_exists('user', ['username' => $user['username'], 'mnethostid' => $CFG->mnet_localhost_id])) {
throw new invalid_parameter_exception('Username already exists: ' . $user['username']);
}
if (!validate_email($user['email'])) {
throw new invalid_parameter_exception('Email address is invalid: '.$user['email']);
} else if (empty($CFG->allowaccountssameemail) &&
$DB->record_exists('user', array('email' => $user['email'], 'mnethostid' => $user['mnethostid']))) {
throw new invalid_parameter_exception('Email address already exists: '.$user['email']);
throw new invalid_parameter_exception('Email address is invalid: ' . $user['email']);
} else if (
empty($CFG->allowaccountssameemail) &&
$DB->record_exists('user', ['email' => $user['email'], 'mnethostid' => $user['mnethostid']])
) {
throw new invalid_parameter_exception('Email address already exists: ' . $user['email']);
}

$userid = user_create_user($user);
Expand Down Expand Up @@ -341,20 +342,20 @@ protected function update_user(\stdClass $user, array $data) {
if (
$user->username != $userdata['username']
&&
$DB->record_exists('user', array('username' => $userdata['username'], 'mnethostid' => $CFG->mnet_localhost_id))
$DB->record_exists('user', ['username' => $userdata['username'], 'mnethostid' => $CFG->mnet_localhost_id])
) {
throw new invalid_parameter_exception('Username already exists: '.$userdata['username']);
throw new invalid_parameter_exception('Username already exists: ' . $userdata['username']);
}
if (!validate_email($userdata['email'])) {
throw new invalid_parameter_exception('Email address is invalid: '.$userdata['email']);
throw new invalid_parameter_exception('Email address is invalid: ' . $userdata['email']);
} else if (
empty($CFG->allowaccountssameemail)
&&
$user->email != $userdata['email']
&&
$DB->record_exists('user', array('email' => $userdata['email'], 'mnethostid' => $CFG->mnet_localhost_id))
$DB->record_exists('user', ['email' => $userdata['email'], 'mnethostid' => $CFG->mnet_localhost_id])
) {
throw new invalid_parameter_exception('Email address already exists: '.$userdata['email']);
throw new invalid_parameter_exception('Email address already exists: ' . $userdata['email']);
}
$userdata['id'] = $user->id;

Expand Down Expand Up @@ -402,10 +403,10 @@ protected function get_user(array $data) {

$mappingfield = $this->get_mapping_field();

$params = array(
$params = [
$mappingfield => $data[$mappingfield],
'mnethostid' => $CFG->mnet_localhost_id,
);
];

$user = $DB->get_record('user', $params);

Expand Down Expand Up @@ -476,11 +477,11 @@ public function get_login_url($data) {
* @return array
*/
public function get_allowed_mapping_fields() {
return array(
return [
'username' => get_string('username'),
'email' => get_string('email'),
'idnumber' => get_string('idnumber'),
);
];
}

/**
Expand All @@ -493,34 +494,34 @@ protected function get_mapping_parameter() {

switch ($mappingfield) {
case 'username':
$parameter = array(
$parameter = [
'username' => new external_value(
PARAM_USERNAME,
'Username'
),
);
];
break;

case 'email':
$parameter = array(
$parameter = [
'email' => new external_value(
PARAM_EMAIL,
'A valid email address'
),
);
];
break;

case 'idnumber':
$parameter = array(
$parameter = [
'idnumber' => new external_value(
PARAM_RAW,
'An arbitrary ID code number perhaps from the institution'
),
);
];
break;

default:
$parameter = array();
$parameter = [];
break;
}

Expand All @@ -533,7 +534,7 @@ protected function get_mapping_parameter() {
* @return array
*/
protected function get_user_fields_parameters() {
$parameters = array();
$parameters = [];

if ($this->is_ip_restriction_enabled()) {
$parameters['ip'] = new external_value(
Expand Down Expand Up @@ -594,7 +595,6 @@ protected function should_login_redirect() {
if (isset($this->config->ssourl) && $this->config->ssourl != '' && !$skipsso) {
return true;
}

}

/**
Expand Down
9 changes: 4 additions & 5 deletions classes/core_userkey_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_userkey_manager implements userkey_manager_interface {

/**
* This script script required by core create_user_key().
*/
Expand Down Expand Up @@ -108,10 +107,10 @@ public function delete_keys($userid) {
public function validate_key($keyvalue) {
global $DB;

$options = array(
$options = [
'script' => self::CORE_USER_KEY_MANAGER_SCRIPT,
'value' => $keyvalue
);
'value' => $keyvalue,
];

if (!$key = $DB->get_record('user_private_key', $options)) {
throw new \moodle_exception('invalidkey');
Expand All @@ -123,7 +122,7 @@ public function validate_key($keyvalue) {

$this->validate_ip_address($key);

if (!$user = $DB->get_record('user', array('id' => $key->userid))) {
if (!$user = $DB->get_record('user', ['id' => $key->userid])) {
throw new \moodle_exception('invaliduserid');
}
return $key;
Expand Down
2 changes: 0 additions & 2 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements null_provider {

use legacy_polyfill;

/**
Expand All @@ -47,5 +46,4 @@ class provider implements null_provider {
public static function _get_reason() {
return 'privacy:metadata';
}

}
1 change: 0 additions & 1 deletion classes/userkey_manager_interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@ public function delete_keys($userid);
* @throws \moodle_exception If provided key is not valid.
*/
public function validate_key($keyvalue);

}
14 changes: 7 additions & 7 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

defined('MOODLE_INTERNAL') || die();

$capabilities = array(
'auth/userkey:generatekey' => array(
'riskbitmask' => RISK_PERSONAL | RISK_SPAM | RISK_XSS ,
$capabilities = [
'auth/userkey:generatekey' => [
'riskbitmask' => RISK_PERSONAL | RISK_SPAM | RISK_XSS,

'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
),
),
);
'archetypes' => [
],
],
];
18 changes: 9 additions & 9 deletions db/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@

defined('MOODLE_INTERNAL') || die;

$functions = array(
'auth_userkey_request_login_url' => array(
$functions = [
'auth_userkey_request_login_url' => [
'classname' => 'auth_userkey_external',
'methodname' => 'request_login_url',
'classpath' => 'auth/userkey/externallib.php',
'description' => 'Return one time key based login URL',
'type' => 'write',
'capabilities' => 'auth/userkey:generatekey',
)
);
],
];

$services = array(
'User key authentication web service' => array(
'functions' => array ('auth_userkey_request_login_url'),
$services = [
'User key authentication web service' => [
'functions' => ['auth_userkey_request_login_url'],
'restrictedusers' => 1,
'enabled' => 1,
)
);
],
];
2 changes: 1 addition & 1 deletion db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function xmldb_auth_userkey_upgrade($oldversion) {

if ($oldversion < 2018050200) {
// Confirm all previously created users.
$DB->execute("UPDATE {user} SET confirmed=? WHERE auth=?", array(1, 'userkey'));
$DB->execute("UPDATE {user} SET confirmed=? WHERE auth=?", [1, 'userkey']);
upgrade_plugin_savepoint(true, 2018050200, 'auth', 'userkey');
}

Expand Down
16 changes: 7 additions & 9 deletions externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,18 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_userkey_external extends external_api {

/**
* Return request_login_url webservice parameters.
*
* @return \external_function_parameters
*/
public static function request_login_url_parameters() {
return new external_function_parameters(
array(
[
'user' => new external_single_structure(
get_auth_plugin('userkey')->get_request_login_url_user_parameters()
)
)
),
]
);
}

Expand All @@ -77,9 +76,9 @@ public static function request_login_url($user) {
$auth = get_auth_plugin('userkey');
$loginurl = $auth->get_login_url($user);

return array(
return [
'loginurl' => $loginurl,
);
];
}

/**
Expand All @@ -89,10 +88,9 @@ public static function request_login_url($user) {
*/
public static function request_login_url_returns() {
return new external_single_structure(
array(
[
'loginurl' => new external_value(PARAM_RAW, 'Login URL for a user to log in'),
)
]
);
}

}
33 changes: 16 additions & 17 deletions lang/en/auth_userkey.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
*/

defined('MOODLE_INTERNAL') || die;

$string['pluginname'] = 'User key authentication';
$string['auth_userkeydescription'] = 'Log in to Moodle using one time user key.';
$string['mappingfield'] = 'Mapping field';
$string['mappingfield_desc'] = 'This user field will be used to find relevant user in the LMS.';
$string['createuser'] = 'Create user?';
$string['createuser_desc'] = 'If enabled, a new user will be created if fail to find one in LMS.';
$string['incorrectkeylifetime'] = 'User key life time should be a number';
$string['incorrectlogout'] = 'Incorrect logout request';
$string['incorrectredirecturl'] = 'You should provide valid URL';
$string['incorrectssourl'] = 'You should provide valid URL';
$string['iprestriction'] = 'IP restriction';
$string['iprestriction_desc'] = 'If enabled, a web call has to contain "ip" parameter when requesting login URL.
A user has to have provided IP to be able to use a key to login to LMS.';
Expand All @@ -37,20 +39,17 @@
\nIf the route to either the system issuing tokens or this Moodle is via a private address range then set this value to 10.0.0.0/8;172.16.0.0/12;192.168.0.0/16";
$string['keylifetime'] = 'User key life time';
$string['keylifetime_desc'] = 'Life time in seconds of the each user login key.';
$string['incorrectkeylifetime'] = 'User key life time should be a number';
$string['createuser'] = 'Create user?';
$string['createuser_desc'] = 'If enabled, a new user will be created if fail to find one in LMS.';
$string['updateuser'] = 'Update user?';
$string['updateuser_desc'] = 'If enabled, users will be updated with the properties supplied when the webservice is called.';
$string['mappingfield'] = 'Mapping field';
$string['mappingfield_desc'] = 'This user field will be used to find relevant user in the LMS.';
$string['noip'] = 'Unable to fetch IP address of client.';
$string['pluginisdisabled'] = 'The userkey authentication plugin is disabled.';
$string['pluginname'] = 'User key authentication';
$string['privacy:metadata'] = 'User key authentication plugin does not store any personal data.';
$string['redirecterrordetected'] = 'Unsupported redirect to {$a} detected, execution terminated.';
$string['redirecturl'] = 'Logout redirect URL';
$string['redirecturl_desc'] = 'Optionally you can redirect users to this URL after they logged out from LMS.';
$string['incorrectredirecturl'] = 'You should provide valid URL';
$string['incorrectssourl'] = 'You should provide valid URL';
$string['userkey:generatekey'] = 'Generate login user key';
$string['pluginisdisabled'] = 'The userkey authentication plugin is disabled.';
$string['ssourl'] = 'URL of SSO host';
$string['ssourl_desc'] = 'URL of the SSO host to redirect users to. If defined users will be redirected here on login instead of the Moodle Login page';
$string['redirecterrordetected'] = 'Unsupported redirect to {$a} detected, execution terminated.';
$string['noip'] = 'Unable to fetch IP address of client.';
$string['privacy:metadata'] = 'User key authentication plugin does not store any personal data.';
$string['incorrectlogout'] = 'Incorrect logout request';
$string['updateuser'] = 'Update user?';
$string['updateuser_desc'] = 'If enabled, users will be updated with the properties supplied when the webservice is called.';
$string['userkey:generatekey'] = 'Generate login user key';
Loading
Loading