Add 'Generate user key' permission
This commit is contained in:
parent
92555b7d28
commit
99d080f1cd
4 changed files with 47 additions and 2 deletions
37
db/access.php
Normal file
37
db/access.php
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
// This file is part of Moodle - http://moodle.org/
|
||||||
|
//
|
||||||
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// Moodle is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User key auth method caps.
|
||||||
|
*
|
||||||
|
* @package auth_userkey
|
||||||
|
* @copyright 2016 Dmitrii Metelkin (dmitriim@catalyst-au.net)
|
||||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
$capabilities = array(
|
||||||
|
'auth/userkey:generatekey' => array(
|
||||||
|
'riskbitmask' => RISK_PERSONAL | RISK_SPAM | RISK_XSS ,
|
||||||
|
|
||||||
|
'captype' => 'write',
|
||||||
|
'contextlevel' => CONTEXT_SYSTEM,
|
||||||
|
'archetypes' => array(
|
||||||
|
'manager' => CAP_ALLOW
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
|
@ -51,6 +51,9 @@ class auth_userkey_external extends external_api {
|
||||||
*/
|
*/
|
||||||
public static function request_login_url($user) {
|
public static function request_login_url($user) {
|
||||||
|
|
||||||
|
$context = context_system::instance();
|
||||||
|
require_capability('auth/userkey:generatekey', $context);
|
||||||
|
|
||||||
$auth = get_auth_plugin('userkey');
|
$auth = get_auth_plugin('userkey');
|
||||||
$loginurl = $auth->get_login_url($user);
|
$loginurl = $auth->get_login_url($user);
|
||||||
|
|
||||||
|
|
|
@ -32,3 +32,4 @@ $string['keylifetime'] = 'User key life time';
|
||||||
$string['keylifetime_desc'] = 'Life time in seconds of the each user login key.';
|
$string['keylifetime_desc'] = 'Life time in seconds of the each user login key.';
|
||||||
$string['createuser'] = 'Crete user?';
|
$string['createuser'] = 'Crete user?';
|
||||||
$string['createuser_desc'] = 'If enabled, a new user will be created if fail to find one in LMS.';
|
$string['createuser_desc'] = 'If enabled, a new user will be created if fail to find one in LMS.';
|
||||||
|
$string['userkey:generatekey'] = 'Generate login user key';
|
|
@ -44,8 +44,6 @@ class auth_userkey_externallib_testcase extends advanced_testcase {
|
||||||
|
|
||||||
$this->resetAfterTest();
|
$this->resetAfterTest();
|
||||||
|
|
||||||
$this->setAdminUser();
|
|
||||||
|
|
||||||
$user = array();
|
$user = array();
|
||||||
$user['username'] = 'username';
|
$user['username'] = 'username';
|
||||||
$user['email'] = 'exists@test.com';
|
$user['email'] = 'exists@test.com';
|
||||||
|
@ -59,6 +57,8 @@ class auth_userkey_externallib_testcase extends advanced_testcase {
|
||||||
public function test_successful_webservice_calls() {
|
public function test_successful_webservice_calls() {
|
||||||
global $DB, $CFG;
|
global $DB, $CFG;
|
||||||
|
|
||||||
|
$this->setAdminUser();
|
||||||
|
|
||||||
// Email.
|
// Email.
|
||||||
$params = array(
|
$params = array(
|
||||||
'email' => 'exists@test.com',
|
'email' => 'exists@test.com',
|
||||||
|
@ -117,6 +117,8 @@ class auth_userkey_externallib_testcase extends advanced_testcase {
|
||||||
* @expectedExceptionMessage Invalid parameter value detected (Required field "email" is not set or empty.)
|
* @expectedExceptionMessage Invalid parameter value detected (Required field "email" is not set or empty.)
|
||||||
*/
|
*/
|
||||||
public function test_request_incorrect_parameters() {
|
public function test_request_incorrect_parameters() {
|
||||||
|
$this->setAdminUser();
|
||||||
|
|
||||||
$params = array(
|
$params = array(
|
||||||
'bla' => 'exists@test.com',
|
'bla' => 'exists@test.com',
|
||||||
);
|
);
|
||||||
|
@ -132,6 +134,8 @@ class auth_userkey_externallib_testcase extends advanced_testcase {
|
||||||
* @expectedExceptionMessage Invalid parameter value detected (User is not exist)
|
* @expectedExceptionMessage Invalid parameter value detected (User is not exist)
|
||||||
*/
|
*/
|
||||||
public function test_request_not_existing_user() {
|
public function test_request_not_existing_user() {
|
||||||
|
$this->setAdminUser();
|
||||||
|
|
||||||
$params = array(
|
$params = array(
|
||||||
'email' => 'notexists@test.com',
|
'email' => 'notexists@test.com',
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue