From e0753cb080360ce3dfef3cbda331d4a57f41e890 Mon Sep 17 00:00:00 2001 From: Sebastian Berm Date: Fri, 10 Dec 2021 14:35:12 +0100 Subject: [PATCH] MDL-69467 core_h5p: User uniqueness by id instead of email --- h5p/classes/helper.php | 6 +++++- h5p/js/h5p_overrides.js | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/h5p/classes/helper.php b/h5p/classes/helper.php index c764790279298..9bca596f96b1f 100644 --- a/h5p/classes/helper.php +++ b/h5p/classes/helper.php @@ -331,7 +331,11 @@ public static function get_core_settings(): array { $core = $factory->get_core(); // When there is a logged in user, her information will be passed to the player. It will be used for tracking. - $usersettings = isloggedin() ? ['name' => $USER->username, 'mail' => $USER->email] : []; + $usersettings = []; + if (isloggedin()) { + $usersettings['name'] = $USER->username; + $usersettings['id'] = $USER->id; + } $settings = array( 'baseUrl' => $basepath, 'url' => "{$basepath}pluginfile.php/{$systemcontext->instanceid}/core_h5p", diff --git a/h5p/js/h5p_overrides.js b/h5p/js/h5p_overrides.js index eea05b484a5e8..a0b6bf3a868a2 100644 --- a/h5p/js/h5p_overrides.js +++ b/h5p/js/h5p_overrides.js @@ -47,3 +47,44 @@ H5P.getMoodleComponent = function () { } return undefined; }; + +/** + * Set the actor. (Moved to overrides due to MDL-69467) + */ +H5P.XAPIEvent.prototype.setActor = function () { + if (H5PIntegration.user !== undefined) { + this.data.statement.actor = { + 'name': H5PIntegration.user.name, + 'objectType': 'Agent' + }; + if (H5PIntegration.user.id !== undefined) { + this.data.statement.actor.account = { + 'name': H5PIntegration.user.id, + 'homePage': H5PIntegration.siteUrl + } + } else if (H5PIntegration.user.mail !== undefined) { + this.data.statement.actor.mbox = 'mailto:' + H5PIntegration.user.mail; + } + } else { + var uuid; + try { + if (localStorage.H5PUserUUID) { + uuid = localStorage.H5PUserUUID; + } else { + uuid = H5P.createUUID(); + localStorage.H5PUserUUID = uuid; + } + } + catch (err) { + // LocalStorage and Cookies are probably disabled. Do not track the user. + uuid = 'not-trackable-' + H5P.createUUID(); + } + this.data.statement.actor = { + 'account': { + 'name': uuid, + 'homePage': H5PIntegration.siteUrl + }, + 'objectType': 'Agent' + }; + } +};