mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
Merge branch 'MDL-73008-master' of https://github.com/jleyva/moodle
This commit is contained in:
commit
245edd9a11
165
admin/tool/policy/classes/external/get_user_acceptances.php
vendored
Normal file
165
admin/tool/policy/classes/external/get_user_acceptances.php
vendored
Normal file
@ -0,0 +1,165 @@
|
||||
<?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/>.
|
||||
|
||||
namespace tool_policy\external;
|
||||
|
||||
use core_external\external_api;
|
||||
use core_external\external_function_parameters;
|
||||
use core_external\external_single_structure;
|
||||
use core_external\external_multiple_structure;
|
||||
use core_external\external_format_value;
|
||||
use core_external\external_value;
|
||||
use core_external\external_warnings;
|
||||
use tool_policy\api;
|
||||
use context_user;
|
||||
use core_user;
|
||||
use core_external\util;
|
||||
|
||||
/**
|
||||
* External function for retrieving user policies acceptances.
|
||||
*
|
||||
* @package tool_policy
|
||||
* @copyright 2023 Juan Leyva <juan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 4.4
|
||||
*/
|
||||
class get_user_acceptances extends external_api {
|
||||
|
||||
/**
|
||||
* Webservice parameters.
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters(
|
||||
[
|
||||
'userid' => new external_value(PARAM_INT, 'The user id we want to retrieve the acceptances.',
|
||||
VALUE_DEFAULT, 0),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the acceptance status for all the policies the given user can see.
|
||||
*
|
||||
* @param int $userid the user id we want to retrieve the acceptances
|
||||
* @throws \required_capability_exception
|
||||
* @return array policies and acceptance status
|
||||
*/
|
||||
public static function execute(int $userid = 0): array {
|
||||
global $USER;
|
||||
|
||||
$params = self::validate_parameters(self::execute_parameters(),
|
||||
[
|
||||
'userid' => $userid,
|
||||
]
|
||||
);
|
||||
|
||||
// Do not check for the site policies in validate_context() to avoid the redirect loop.
|
||||
if (!defined('NO_SITEPOLICY_CHECK')) {
|
||||
define('NO_SITEPOLICY_CHECK', true);
|
||||
}
|
||||
|
||||
$systemcontext = \context_system::instance();
|
||||
external_api::validate_context($systemcontext);
|
||||
|
||||
if (empty($params['userid']) || $params['userid'] == $USER->id) {
|
||||
$user = $USER;
|
||||
} else {
|
||||
$user = core_user::get_user($params['userid'], '*', MUST_EXIST);
|
||||
core_user::require_active_user($user);
|
||||
$usercontext = context_user::instance($user->id);
|
||||
// Check capability to view acceptances. No capability is needed to view your own acceptances.
|
||||
if (!has_capability('tool/policy:acceptbehalf', $usercontext)) {
|
||||
require_capability('tool/policy:viewacceptances', $usercontext);
|
||||
}
|
||||
}
|
||||
|
||||
$canviewfullnames = has_capability('moodle/site:viewfullnames', $systemcontext);
|
||||
$userpolicies = api::get_policies_with_acceptances($user->id);
|
||||
|
||||
$policies = [];
|
||||
foreach ($userpolicies as $userpolicy) {
|
||||
foreach ($userpolicy->versions as $version) {
|
||||
|
||||
$policy = (array) clone $version;
|
||||
unset($policy['acceptance']); // This might return NULL and break the WS response.
|
||||
$policy['versionid'] = $version->id;
|
||||
$policy['name'] = util::format_string($version->name, $systemcontext);
|
||||
$policy['revision'] = util::format_string($version->revision, $systemcontext);
|
||||
[$policy['summary'], $policy['summaryformat']] = util::format_text($version->summary,
|
||||
$version->summaryformat, $systemcontext);
|
||||
[$policy['content'], $policy['contentformat']] = util::format_text($version->content,
|
||||
$version->contentformat, $systemcontext);
|
||||
|
||||
if (!empty($version->acceptance)) {
|
||||
$policy['acceptance'] = (array) $version->acceptance;
|
||||
if ($version->acceptance->usermodified && $version->acceptance->usermodified != $user->id) {
|
||||
// Get the full name of who accepted on behalf.
|
||||
$usermodified = (object)['id' => $version->acceptance->usermodified];
|
||||
username_load_fields_from_object($usermodified, $version->acceptance, 'mod');
|
||||
$override = $canviewfullnames || has_capability('moodle/site:viewfullnames', context_user::instance($version->acceptance->usermodified));
|
||||
$policy['acceptance']['modfullname'] = fullname($usermodified, $override);
|
||||
}
|
||||
if (!empty($version->acceptance->note)) {
|
||||
[$policy['acceptance']['note']] = util::format_text($version->acceptance->note, FORMAT_MOODLE, $systemcontext);
|
||||
}
|
||||
}
|
||||
$policies[] = $policy;
|
||||
}
|
||||
}
|
||||
|
||||
$return = [
|
||||
'policies' => $policies,
|
||||
'warnings' => [],
|
||||
];
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Webservice returns.
|
||||
*
|
||||
* @return external_single_structure
|
||||
*/
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return new external_single_structure([
|
||||
'policies' => new external_multiple_structure(
|
||||
new external_single_structure([
|
||||
'policyid' => new external_value(PARAM_INT, 'The policy id.'),
|
||||
'versionid' => new external_value(PARAM_INT, 'The policy version id.'),
|
||||
'agreementstyle' => new external_value(PARAM_INT, 'The policy agreement style. 0: consent page, 1: own page.'),
|
||||
'optional' => new external_value(PARAM_INT, 'Whether the policy is optional. 0: compulsory, 1: optional'),
|
||||
'revision' => new external_value(PARAM_TEXT, 'The policy revision.'),
|
||||
'status' => new external_value(PARAM_INT, 'The policy status. 0: draft, 1: active, 2: archived.'),
|
||||
'name' => new external_value(PARAM_TEXT, 'The policy name'),
|
||||
'summary' => new external_value(PARAM_RAW, 'The policy summary.', VALUE_OPTIONAL),
|
||||
'summaryformat' => new external_format_value('summary'),
|
||||
'content' => new external_value(PARAM_RAW, 'The policy content.', VALUE_OPTIONAL),
|
||||
'contentformat' => new external_format_value('content'),
|
||||
'acceptance' => new external_single_structure([
|
||||
'status' => new external_value(PARAM_INT, 'The acceptance status. 0: declined, 1: accepted.'),
|
||||
'lang' => new external_value(PARAM_LANG, 'The policy lang.'),
|
||||
'timemodified' => new external_value(PARAM_INT, 'The time the acceptance was set.'),
|
||||
'usermodified' => new external_value(PARAM_INT, 'The user who accepted.'),
|
||||
'note' => new external_value(PARAM_TEXT, 'The policy note/remarks.', VALUE_OPTIONAL),
|
||||
'modfullname' => new external_value(PARAM_NOTAGS, 'The fullname who accepted on behalf.', VALUE_OPTIONAL),
|
||||
], 'Acceptance status for the given user.', VALUE_OPTIONAL),
|
||||
]), 'Policies and acceptance status for the given user.', VALUE_OPTIONAL
|
||||
),
|
||||
'warnings' => new external_warnings(),
|
||||
]);
|
||||
}
|
||||
}
|
137
admin/tool/policy/classes/external/set_acceptances_status.php
vendored
Normal file
137
admin/tool/policy/classes/external/set_acceptances_status.php
vendored
Normal file
@ -0,0 +1,137 @@
|
||||
<?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/>.
|
||||
|
||||
namespace tool_policy\external;
|
||||
|
||||
use core_external\external_api;
|
||||
use core_external\external_function_parameters;
|
||||
use core_external\external_single_structure;
|
||||
use core_external\external_multiple_structure;
|
||||
use core_external\external_value;
|
||||
use core_external\external_warnings;
|
||||
use tool_policy\api;
|
||||
use tool_policy\policy_version;
|
||||
use core_user;
|
||||
|
||||
/**
|
||||
* External function for setting user policies acceptances.
|
||||
*
|
||||
* @package tool_policy
|
||||
* @copyright 2023 Juan Leyva <juan@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 4.4
|
||||
*/
|
||||
class set_acceptances_status extends external_api {
|
||||
|
||||
/**
|
||||
* Webservice parameters.
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function execute_parameters(): external_function_parameters {
|
||||
return new external_function_parameters(
|
||||
[
|
||||
'policies' => new external_multiple_structure(
|
||||
new external_single_structure([
|
||||
'versionid' => new external_value(PARAM_INT, 'The policy version id.'),
|
||||
'status' => new external_value(PARAM_INT, 'The policy acceptance status. 0: decline, 1: accept.'),
|
||||
]), 'Policies acceptances for the given user.'
|
||||
),
|
||||
'userid' => new external_value(PARAM_INT,
|
||||
'The user id we want to set the acceptances. Default is the current user.', VALUE_DEFAULT, 0
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the acceptance status (accept or decline only) for the indicated policies for the given user.
|
||||
*
|
||||
* @param array $policies the policies to set the acceptance status
|
||||
* @param int $userid the user id we want to retrieve the acceptances
|
||||
* @throws \moodle_exception
|
||||
* @return array policies and acceptance status
|
||||
*/
|
||||
public static function execute(array $policies, int $userid = 0): array {
|
||||
global $USER;
|
||||
|
||||
$params = self::validate_parameters(self::execute_parameters(),
|
||||
[
|
||||
'policies' => $policies,
|
||||
'userid' => $userid,
|
||||
]
|
||||
);
|
||||
|
||||
// Do not check for the site policies in validate_context() to avoid the redirect loop.
|
||||
if (!defined('NO_SITEPOLICY_CHECK')) {
|
||||
define('NO_SITEPOLICY_CHECK', true);
|
||||
}
|
||||
|
||||
$systemcontext = \context_system::instance();
|
||||
external_api::validate_context($systemcontext);
|
||||
|
||||
if (empty($params['userid']) || $params['userid'] == $USER->id) {
|
||||
$user = $USER;
|
||||
} else {
|
||||
$user = core_user::get_user($params['userid'], '*', MUST_EXIST);
|
||||
core_user::require_active_user($user);
|
||||
}
|
||||
|
||||
// Split acceptances.
|
||||
$allcurrentpolicies = api::list_current_versions(policy_version::AUDIENCE_LOGGEDIN);
|
||||
$requestedpolicies = $agreepolicies = $declinepolicies = [];
|
||||
foreach ($params['policies'] as $policy) {
|
||||
$requestedpolicies[$policy['versionid']] = $policy['status'];
|
||||
}
|
||||
|
||||
foreach ($allcurrentpolicies as $policy) {
|
||||
if (isset($requestedpolicies[$policy->id])) {
|
||||
if ($requestedpolicies[$policy->id] === 1) {
|
||||
$agreepolicies[] = $policy->id;
|
||||
} else if ($requestedpolicies[$policy->id] === 0) {
|
||||
$declinepolicies[] = $policy->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Permissions check.
|
||||
api::can_accept_policies($agreepolicies, $user->id, true);
|
||||
api::can_decline_policies($declinepolicies, $user->id, true);
|
||||
|
||||
// Good to go.
|
||||
api::accept_policies($agreepolicies, $user->id, null);
|
||||
api::decline_policies($declinepolicies, $user->id, null);
|
||||
|
||||
$return = [
|
||||
'policyagreed' => (int) $user->policyagreed, // Final policy agreement status for $user.
|
||||
'warnings' => [],
|
||||
];
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Webservice returns.
|
||||
*
|
||||
* @return external_single_structure
|
||||
*/
|
||||
public static function execute_returns(): external_single_structure {
|
||||
return new external_single_structure([
|
||||
'policyagreed' => new external_value(PARAM_INT,
|
||||
'Whether the user has provided acceptance to all current site policies. 1 if yes, 0 if not'),
|
||||
'warnings' => new external_warnings(),
|
||||
]);
|
||||
}
|
||||
}
|
@ -45,4 +45,18 @@ $functions = [
|
||||
'ajax' => true,
|
||||
'type' => 'write',
|
||||
],
|
||||
|
||||
'tool_policy_get_user_acceptances' => [
|
||||
'classname' => '\tool_policy\external\get_user_acceptances',
|
||||
'description' => 'Get user policies acceptances.',
|
||||
'type' => 'read',
|
||||
'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE],
|
||||
],
|
||||
|
||||
'tool_policy_set_acceptances_status' => [
|
||||
'classname' => '\tool_policy\external\set_acceptances_status',
|
||||
'description' => 'Set the acceptance status (accept or decline only) for the indicated policies for the given user.',
|
||||
'type' => 'write',
|
||||
'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE],
|
||||
],
|
||||
];
|
||||
|
@ -239,4 +239,161 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
$this->expectException(\required_capability_exception::class);
|
||||
$sitepolicymanager->accept();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for external function get_user_acceptances().
|
||||
*/
|
||||
public function test_external_get_user_acceptances() {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$CFG->sitepolicyhandler = 'tool_policy';
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
// Create optional policy.
|
||||
$formdata = api::form_policydoc_data(new \tool_policy\policy_version(0));
|
||||
$formdata->name = 'Test optional policy';
|
||||
$formdata->revision = 'v1';
|
||||
$formdata->optional = 1;
|
||||
$formdata->summary_editor = ['text' => 'summary', 'format' => FORMAT_HTML, 'itemid' => 0];
|
||||
$formdata->content_editor = ['text' => 'content', 'format' => FORMAT_HTML, 'itemid' => 0];
|
||||
$optionalpolicy = api::form_policydoc_add($formdata);
|
||||
api::make_current($optionalpolicy->get('id'));
|
||||
|
||||
$policies = \tool_policy\external\get_user_acceptances::execute();
|
||||
$policies = \core_external\external_api::clean_returnvalue(
|
||||
\tool_policy\external\get_user_acceptances::execute_returns(), $policies);
|
||||
|
||||
$this->assertCount(2, $policies['policies']);
|
||||
$this->assertCount(0, $policies['warnings']);
|
||||
foreach ($policies['policies'] as $policy) {
|
||||
if ($policy['versionid'] == $this->policy2->get('id')) {
|
||||
$this->assertEquals($this->policy2->get('name'), $policy['name']);
|
||||
$this->assertEquals(0, $policy['optional']);
|
||||
} else {
|
||||
$this->assertEquals($optionalpolicy->get('name'), $policy['name']);
|
||||
$this->assertEquals(1, $policy['optional']);
|
||||
}
|
||||
$this->assertNotContains('acceptance', $policy); // Nothing accepted yet.
|
||||
}
|
||||
|
||||
// Get other user acceptances.
|
||||
$this->parent->policyagreed = 1;
|
||||
$this->setUser($this->parent);
|
||||
$policies = \tool_policy\external\get_user_acceptances::execute($this->child->id);
|
||||
$policies = \core_external\external_api::clean_returnvalue(
|
||||
\tool_policy\external\get_user_acceptances::execute_returns(), $policies);
|
||||
$this->assertCount(2, $policies['policies']);
|
||||
|
||||
// Get other user acceptances without permission.
|
||||
$this->expectException(\required_capability_exception::class);
|
||||
$policies = \tool_policy\external\get_user_acceptances::execute($user->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for external function set_acceptances_status().
|
||||
*/
|
||||
public function test_external_set_acceptances_status() {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$CFG->sitepolicyhandler = 'tool_policy';
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
// Create optional policy.
|
||||
$formdata = api::form_policydoc_data(new \tool_policy\policy_version(0));
|
||||
$formdata->name = 'Test optional policy';
|
||||
$formdata->revision = 'v1';
|
||||
$formdata->optional = 1;
|
||||
$formdata->summary_editor = ['text' => 'summary', 'format' => FORMAT_HTML, 'itemid' => 0];
|
||||
$formdata->content_editor = ['text' => 'content', 'format' => FORMAT_HTML, 'itemid' => 0];
|
||||
$optionalpolicy = api::form_policydoc_add($formdata);
|
||||
api::make_current($optionalpolicy->get('id'));
|
||||
|
||||
// Accept all the policies.
|
||||
$ids = [['versionid' => $this->policy2->get('id'), 'status' => 1], ['versionid' => $optionalpolicy->get('id'), 'status' => 1]];
|
||||
|
||||
$policies = \tool_policy\external\set_acceptances_status::execute($ids);
|
||||
$policies = \core_external\external_api::clean_returnvalue(
|
||||
\tool_policy\external\set_acceptances_status::execute_returns(), $policies);
|
||||
|
||||
$this->assertEquals(1, $policies['policyagreed']);
|
||||
$this->assertCount(0, $policies['warnings']);
|
||||
|
||||
$policies = \tool_policy\external\get_user_acceptances::execute();
|
||||
$policies = \core_external\external_api::clean_returnvalue(
|
||||
\tool_policy\external\get_user_acceptances::execute_returns(), $policies);
|
||||
|
||||
$this->assertCount(2, $policies['policies']);
|
||||
foreach ($policies['policies'] as $policy) {
|
||||
$this->assertEquals(1, $policy['acceptance']['status']); // Check all accepted.
|
||||
}
|
||||
|
||||
// Decline optional only.
|
||||
$policies = \tool_policy\external\set_acceptances_status::execute([['versionid' => $optionalpolicy->get('id'), 'status' => 0]]);
|
||||
$policies = \core_external\external_api::clean_returnvalue(
|
||||
\tool_policy\external\set_acceptances_status::execute_returns(), $policies);
|
||||
|
||||
$this->assertEquals(1, $policies['policyagreed']);
|
||||
$this->assertCount(0, $policies['warnings']);
|
||||
|
||||
$policies = \tool_policy\external\get_user_acceptances::execute();
|
||||
$policies = \core_external\external_api::clean_returnvalue(
|
||||
\tool_policy\external\get_user_acceptances::execute_returns(), $policies);
|
||||
|
||||
$this->assertCount(2, $policies['policies']);
|
||||
foreach ($policies['policies'] as $policy) {
|
||||
if ($policy['versionid'] == $this->policy2->get('id')) {
|
||||
$this->assertEquals(1, $policy['acceptance']['status']); // Still accepted.
|
||||
} else {
|
||||
$this->assertEquals(0, $policy['acceptance']['status']); // Not accepted.
|
||||
}
|
||||
}
|
||||
|
||||
// Parent & child case now. Accept the optional ONLY on behalf of someone else.
|
||||
$this->parent->policyagreed = 1;
|
||||
$this->setUser($this->parent);
|
||||
$policies = \tool_policy\external\set_acceptances_status::execute([['versionid' => $optionalpolicy->get('id'), 'status' => 1]], $this->child->id);
|
||||
$policies = \core_external\external_api::clean_returnvalue(
|
||||
\tool_policy\external\set_acceptances_status::execute_returns(), $policies);
|
||||
|
||||
$this->assertEquals(0, $policies['policyagreed']); // Mandatory missing.
|
||||
$this->assertCount(0, $policies['warnings']);
|
||||
|
||||
$policies = \tool_policy\external\get_user_acceptances::execute($this->child->id);
|
||||
$policies = \core_external\external_api::clean_returnvalue(
|
||||
\tool_policy\external\get_user_acceptances::execute_returns(), $policies);
|
||||
|
||||
$this->assertCount(2, $policies['policies']);
|
||||
foreach ($policies['policies'] as $policy) {
|
||||
if ($policy['versionid'] == $this->policy2->get('id')) {
|
||||
$this->assertNotContains('acceptance', $policy); // Not yet accepted.
|
||||
} else {
|
||||
$this->assertEquals(1, $policy['acceptance']['status']); // Accepted.
|
||||
}
|
||||
}
|
||||
|
||||
// Try to accept on behalf of other user with no permissions.
|
||||
$this->expectException(\required_capability_exception::class);
|
||||
$policies = \tool_policy\external\set_acceptances_status::execute([['versionid' => $optionalpolicy->get('id'), 'status' => 1]], $user->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for external function set_acceptances_status decline mandatory.
|
||||
*/
|
||||
public function test_external_set_acceptances_status_decline_mandatory() {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$CFG->sitepolicyhandler = 'tool_policy';
|
||||
$this->parent->policyagreed = 1;
|
||||
$this->setUser($this->parent);
|
||||
|
||||
$this->expectException(\moodle_exception::class);
|
||||
$this->expectExceptionMessage(get_string('errorpolicyversioncompulsory', 'tool_policy'));
|
||||
$ids = [['versionid' => $this->policy2->get('id'), 'status' => 0]];
|
||||
$policies = \tool_policy\external\set_acceptances_status::execute($ids, $this->child->id);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2023100900; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2023100901; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2023100400; // Requires this Moodle version.
|
||||
$plugin->component = 'tool_policy'; // Full name of the plugin (used for diagnostics).
|
||||
|
@ -210,6 +210,8 @@ class core_webservice_external extends \core_external\external_api {
|
||||
$siteinfo['usersessionscount'] = $DB->count_records('sessions', ['userid' => $USER->id]);
|
||||
}
|
||||
|
||||
$siteinfo['policyagreed'] = $USER->policyagreed;
|
||||
|
||||
return $siteinfo;
|
||||
}
|
||||
|
||||
@ -282,6 +284,7 @@ class core_webservice_external extends \core_external\external_api {
|
||||
'limitconcurrentlogins' => new external_value(PARAM_INT, 'Number of concurrent sessions allowed', VALUE_OPTIONAL),
|
||||
'usersessionscount' => new external_value(PARAM_INT, 'Number of active sessions for current user.
|
||||
Only returned when limitconcurrentlogins is used.', VALUE_OPTIONAL),
|
||||
'policyagreed' => new external_value(PARAM_INT, 'Whether user accepted all the policies.', VALUE_OPTIONAL),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -141,6 +141,7 @@ class externallib_test extends externallib_advanced_testcase {
|
||||
$this->assertFalse($siteinfo['userissiteadmin']);
|
||||
$this->assertEquals($CFG->calendartype, $siteinfo['sitecalendartype']);
|
||||
$this->assertEquals($user['theme'], $siteinfo['theme']);
|
||||
$this->assertEquals($USER->policyagreed, $siteinfo['policyagreed']);
|
||||
|
||||
// Now as admin.
|
||||
$this->setAdminUser();
|
||||
|
Loading…
x
Reference in New Issue
Block a user