MDL-70763 core: export preferences for correct user.
Ensure we are using the ID of the given user rather than falling back to that of the current user during privacy export.
This commit is contained in:
@@ -61,7 +61,7 @@ class provider implements
|
||||
* @param int $userid The userid of the user whose data is to be exported.
|
||||
*/
|
||||
public static function export_user_preferences(int $userid) {
|
||||
$preference = get_user_preferences('htmleditor');
|
||||
$preference = get_user_preferences('htmleditor', null, $userid);
|
||||
if (!empty($preference)) {
|
||||
$desc = get_string('privacy:preference:htmleditor', 'core_editor',
|
||||
get_string('pluginname', "editor_{$preference}"));
|
||||
|
||||
@@ -53,14 +53,19 @@ class core_editor_privacy_provider_testcase extends \core_privacy\tests\provider
|
||||
* When preference exists but is empty, there should be no export.
|
||||
*/
|
||||
public function test_empty_preference() {
|
||||
global $USER;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create test user, add some preferences.
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
set_user_preference('htmleditor', '', $user);
|
||||
|
||||
// Switch to admin user (so we can validate preferences of the correct user are being exported).
|
||||
$this->setAdminUser();
|
||||
|
||||
set_user_preference('htmleditor', '');
|
||||
|
||||
provider::export_user_preferences($USER->id);
|
||||
// Export test users preferences.
|
||||
provider::export_user_preferences($user->id);
|
||||
$this->assertFalse(writer::with_context(\context_system::instance())->has_any_data());
|
||||
}
|
||||
|
||||
@@ -68,13 +73,19 @@ class core_editor_privacy_provider_testcase extends \core_privacy\tests\provider
|
||||
* When an editor is set, the name of that editor will be reported.
|
||||
*/
|
||||
public function test_editor_atto() {
|
||||
global $USER;
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create test user, add some preferences.
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
set_user_preference('htmleditor', 'atto');
|
||||
|
||||
provider::export_user_preferences($USER->id);
|
||||
// Switch to admin user (so we can validate preferences of the correct user are being exported).
|
||||
$this->setAdminUser();
|
||||
|
||||
// Export test users preferences.
|
||||
provider::export_user_preferences($user->id);
|
||||
$this->assertTrue(writer::with_context(\context_system::instance())->has_any_data());
|
||||
|
||||
$prefs = writer::with_context(\context_system::instance())->get_user_preferences('core_editor');
|
||||
|
||||
@@ -63,9 +63,7 @@ class provider implements
|
||||
* @param int $userid The ID of the user whose data is to be exported.
|
||||
*/
|
||||
public static function export_user_preferences(int $userid) {
|
||||
|
||||
$preference = get_user_preferences('filemanager_recentviewmode');
|
||||
|
||||
$preference = get_user_preferences('filemanager_recentviewmode', null, $userid);
|
||||
if ($preference !== null) {
|
||||
switch ($preference) {
|
||||
case 1:
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use core_form\privacy\provider;
|
||||
use core_privacy\local\request\writer;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
@@ -43,7 +44,7 @@ class core_form_privacy_provider_testcase extends \core_privacy\tests\provider_t
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
\core_form\privacy\provider::export_user_preferences($USER->id);
|
||||
provider::export_user_preferences($USER->id);
|
||||
$this->assertFalse(writer::with_context(\context_system::instance())->has_any_data());
|
||||
}
|
||||
|
||||
@@ -55,13 +56,19 @@ class core_form_privacy_provider_testcase extends \core_privacy\tests\provider_t
|
||||
* @param string $desc Text describing the preference
|
||||
*/
|
||||
public function test_filemanager_recentviewmode(string $val, string $desc) {
|
||||
global $USER;
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create test user, add some preferences.
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
set_user_preference('filemanager_recentviewmode', $val, $user);
|
||||
|
||||
// Switch to admin user (so we can validate preferences of the correct user are being exported).
|
||||
$this->setAdminUser();
|
||||
|
||||
set_user_preference('filemanager_recentviewmode', $val);
|
||||
|
||||
core_form\privacy\provider::export_user_preferences($USER->id);
|
||||
// Export test users preferences.
|
||||
provider::export_user_preferences($user->id);
|
||||
$this->assertTrue(writer::with_context(\context_system::instance())->has_any_data());
|
||||
|
||||
$prefs = writer::with_context(\context_system::instance())->get_user_preferences('core_form');
|
||||
|
||||
Reference in New Issue
Block a user