mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
Merge branch 'MDL-63929-master' of git://github.com/jleyva/moodle
This commit is contained in:
commit
610883c007
@ -1559,7 +1559,8 @@ $functions = array(
|
||||
'description' => 'Set user preferences.',
|
||||
'type' => 'write',
|
||||
'capabilities' => 'moodle/site:config',
|
||||
'ajax' => true
|
||||
'ajax' => true,
|
||||
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
|
||||
),
|
||||
'core_user_agree_site_policy' => array(
|
||||
'classname' => 'core_user_external',
|
||||
|
@ -366,7 +366,8 @@ class core_user_external extends external_api {
|
||||
new external_single_structure(
|
||||
array(
|
||||
'type' => new external_value(PARAM_RAW, 'The name of the preference'),
|
||||
'value' => new external_value(PARAM_RAW, 'The value of the preference')
|
||||
'value' => new external_value(PARAM_RAW, 'The value of the preference, do not set this field if you
|
||||
want to remove (unset) the current value.', VALUE_DEFAULT, null),
|
||||
)
|
||||
), 'User preferences', VALUE_DEFAULT, array()
|
||||
)
|
||||
@ -383,7 +384,7 @@ class core_user_external extends external_api {
|
||||
* @return null
|
||||
* @since Moodle 3.2
|
||||
*/
|
||||
public static function update_user_preferences($userid, $emailstop = null, $preferences = array()) {
|
||||
public static function update_user_preferences($userid = 0, $emailstop = null, $preferences = array()) {
|
||||
global $USER, $CFG;
|
||||
|
||||
require_once($CFG->dirroot . '/user/lib.php');
|
||||
@ -401,7 +402,8 @@ class core_user_external extends external_api {
|
||||
'emailstop' => $emailstop,
|
||||
'preferences' => $preferences
|
||||
);
|
||||
self::validate_parameters(self::update_user_preferences_parameters(), $params);
|
||||
$params = self::validate_parameters(self::update_user_preferences_parameters(), $params);
|
||||
$preferences = $params['preferences'];
|
||||
|
||||
// Preferences.
|
||||
if (!empty($preferences)) {
|
||||
|
@ -1239,6 +1239,40 @@ class core_user_externallib_testcase extends externallib_advanced_testcase {
|
||||
$this->assertEquals($user2->id, $result['warnings'][0]['itemid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update_user_preferences unsetting an existing preference.
|
||||
*/
|
||||
public function test_update_user_preferences_unset() {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
$user = self::getDataGenerator()->create_user();
|
||||
|
||||
// Save users preferences.
|
||||
$this->setAdminUser();
|
||||
$preferences = array(
|
||||
array(
|
||||
'name' => 'htmleditor',
|
||||
'value' => 'atto',
|
||||
'userid' => $user->id,
|
||||
)
|
||||
);
|
||||
|
||||
$result = core_user_external::set_user_preferences($preferences);
|
||||
$result = external_api::clean_returnvalue(core_user_external::set_user_preferences_returns(), $result);
|
||||
$this->assertCount(0, $result['warnings']);
|
||||
$this->assertCount(1, $result['saved']);
|
||||
|
||||
// Get preference from DB to avoid cache.
|
||||
$this->assertEquals('atto', $DB->get_field('user_preferences', 'value',
|
||||
array('userid' => $user->id, 'name' => 'htmleditor')));
|
||||
|
||||
// Now, unset.
|
||||
$result = core_user_external::update_user_preferences($user->id, null, array(array('type' => 'htmleditor')));
|
||||
|
||||
$this->assertEquals(0, $DB->count_records('user_preferences', array('userid' => $user->id, 'name' => 'htmleditor')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test agree_site_policy
|
||||
*/
|
||||
|
@ -4,3 +4,5 @@ This files describes API changes for code that uses the user API.
|
||||
|
||||
* The following functions have been finally deprecated and can not be used anymore:
|
||||
* useredit_update_picture()
|
||||
* core_user_external::update_user_preferences() now allows to unset existing preferences values.
|
||||
If the preference value field is not set, the preference will be unset.
|
||||
|
Loading…
x
Reference in New Issue
Block a user