MOBILE-3948 h5p: User uniqueness by id instead of email

main
Dani Palou 2021-12-20 12:42:34 +01:00
parent 4ec6096482
commit 8f4b2df43a
2 changed files with 49 additions and 9 deletions

View File

@ -53,3 +53,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'
};
}
};

View File

@ -19,10 +19,8 @@ import { CoreSites } from '@services/sites';
import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils';
import { CoreUser } from '@features/user/services/user';
import { CoreH5P } from '../services/h5p';
import { CoreH5PCore, CoreH5PDisplayOptions } from './core';
import { Translate } from '@singletons';
import { CoreError } from '@classes/errors/error';
/**
@ -117,11 +115,11 @@ export class CoreH5PHelper {
const site = await CoreSites.getSite(siteId);
const userId = site.getUserId();
const user = await CoreUtils.ignoreErrors(CoreUser.getProfile(userId, undefined, false, siteId));
const info = site.getInfo();
if (!user || !user.email) {
throw new CoreError(Translate.instant('core.h5p.errorgetemail'));
if (!info) {
// Shouldn't happen for authenticated sites.
throw new CoreError('Site info could not be fetched.');
}
const basePath = CoreFile.getBasePathInstant();
@ -151,7 +149,7 @@ export class CoreH5PHelper {
l10n: {
H5P: CoreH5P.h5pCore.getLocalization(), // eslint-disable-line @typescript-eslint/naming-convention
},
user: { name: site.getInfo()!.fullname, mail: user.email },
user: { name: info.username, id: info.userid },
hubIsEnabled: false,
reportingIsEnabled: false,
crossorigin: null,
@ -252,7 +250,8 @@ export type CoreH5PCoreSettings = {
};
user: {
name: string;
mail: string;
id?: number;
mail?: string;
};
hubIsEnabled: boolean;
reportingIsEnabled: boolean;