Merge pull request #1921 from dpalou/MOBILE-3033

MOBILE-3033 core: Fix collisions in site plugin stored data
main
Juan Leyva 2019-05-20 11:47:31 +02:00 committed by GitHub
commit 84caaaeaa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 61 additions and 37 deletions

View File

@ -163,6 +163,23 @@ export class CoreDelegate {
return enabled ? this.enabledHandlers[handlerName] : this.handlers[handlerName];
}
/**
* Gets the handler full name for a given name. This is useful when the handlerNameProperty is different than "name".
* E.g. blocks are indexed by blockName. If you call this function passing the blockName it will return the name.
*
* @param {string} name Name used to indentify the handler.
* @return {string} Full name of corresponding handler.
*/
getHandlerName(name: string): string {
const handler = this.getHandler(name, true);
if (!handler) {
return '';
}
return handler.name;
}
/**
* Check if function exists on a handler.
*

View File

@ -163,20 +163,6 @@ export class CoreBlockDelegate extends CoreDelegate {
return this.areBlocksDisabledInSite(site) || super.isFeatureDisabled(handler, site);
}
/**
* Gets the handler name for a given block name.
*
* @param {string} name Block name e.g. 'activity_modules'
* @return {string} Full name of corresponding handler
*/
getHandlerName(name: string): string {
if (!this.isBlockSupported(name)) {
return '';
}
return this.getHandler(name, true).name;
}
/**
* Called when there are new block handlers available. Informs anyone who subscribed to the
* observable.

View File

@ -16,6 +16,7 @@ import { Component, OnInit, Input } from '@angular/core';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreSitePluginsProvider } from '../../providers/siteplugins';
import { CoreSitePluginsCompileInitComponent } from '../../classes/compile-init-component';
import { AddonModAssignFeedbackDelegate } from '@addon/mod/assign/providers/feedback-delegate';
/**
* Component that displays an assign feedback plugin created using a site plugin.
@ -33,7 +34,8 @@ export class CoreSitePluginsAssignFeedbackComponent extends CoreSitePluginsCompi
@Input() canEdit: boolean; // Whether the user can edit.
@Input() edit: boolean; // Whether the user is editing.
constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider) {
constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider,
protected assignFeedbackDelegate: AddonModAssignFeedbackDelegate) {
super(sitePluginsProvider, utils);
}
@ -51,7 +53,7 @@ export class CoreSitePluginsAssignFeedbackComponent extends CoreSitePluginsCompi
this.jsData.canEdit = this.canEdit;
if (this.plugin) {
this.getHandlerData('assignfeedback_' + this.plugin.type);
this.getHandlerData(this.assignFeedbackDelegate.getHandlerName(this.plugin.type));
}
}

View File

@ -16,6 +16,7 @@ import { Component, OnInit, Input } from '@angular/core';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreSitePluginsProvider } from '../../providers/siteplugins';
import { CoreSitePluginsCompileInitComponent } from '../../classes/compile-init-component';
import { AddonModAssignSubmissionDelegate } from '@addon/mod/assign/providers/submission-delegate';
/**
* Component that displays an assign submission plugin created using a site plugin.
@ -32,7 +33,8 @@ export class CoreSitePluginsAssignSubmissionComponent extends CoreSitePluginsCom
@Input() edit: boolean; // Whether the user is editing.
@Input() allowOffline: boolean; // Whether to allow offline.
constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider) {
constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider,
protected assignSubmissionDelegate: AddonModAssignSubmissionDelegate) {
super(sitePluginsProvider, utils);
}
@ -49,7 +51,7 @@ export class CoreSitePluginsAssignSubmissionComponent extends CoreSitePluginsCom
this.jsData.allowOffline = this.allowOffline;
if (this.plugin) {
this.getHandlerData('assignsubmission_' + this.plugin.type);
this.getHandlerData(this.assignSubmissionDelegate.getHandlerName(this.plugin.type));
}
}

View File

@ -16,6 +16,7 @@ import { Component, OnChanges, Input, ViewChild, Output, EventEmitter } from '@a
import { CoreSitePluginsProvider } from '../../providers/siteplugins';
import { CoreSitePluginsPluginContentComponent } from '../plugin-content/plugin-content';
import { CoreCourseFormatComponent } from '@core/course/components/format/format';
import { CoreCourseFormatDelegate } from '@core/course/providers/format-delegate';
/**
* Component that displays the index of a course format site plugin.
@ -46,7 +47,8 @@ export class CoreSitePluginsCourseFormatComponent implements OnChanges {
initResult: any;
data: any;
constructor(protected sitePluginsProvider: CoreSitePluginsProvider) { }
constructor(protected sitePluginsProvider: CoreSitePluginsProvider,
protected courseFormatDelegate: CoreCourseFormatDelegate) { }
/**
* Detect changes on input properties.
@ -55,7 +57,9 @@ export class CoreSitePluginsCourseFormatComponent implements OnChanges {
if (this.course && this.course.format) {
if (!this.component) {
// Initialize the data.
const handler = this.sitePluginsProvider.getSitePluginHandler(this.course.format);
const handlerName = this.courseFormatDelegate.getHandlerName(this.course.format),
handler = this.sitePluginsProvider.getSitePluginHandler(handlerName);
if (handler) {
this.component = handler.plugin.component;
this.method = handler.handlerSchema.method;

View File

@ -17,7 +17,7 @@ import { TranslateService } from '@ngx-translate/core';
import { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreSitePluginsProvider } from '../../providers/siteplugins';
import { CoreCourseModuleMainComponent } from '@core/course/providers/module-delegate';
import { CoreCourseModuleDelegate, CoreCourseModuleMainComponent } from '@core/course/providers/module-delegate';
import { CoreCourseModulePrefetchDelegate } from '@core/course/providers/module-prefetch-delegate';
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
import { CoreSitePluginsPluginContentComponent } from '../plugin-content/plugin-content';
@ -60,7 +60,8 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C
constructor(protected sitePluginsProvider: CoreSitePluginsProvider, protected courseHelper: CoreCourseHelperProvider,
protected prefetchDelegate: CoreCourseModulePrefetchDelegate, protected textUtils: CoreTextUtilsProvider,
protected translate: TranslateService, protected utils: CoreUtilsProvider) { }
protected translate: TranslateService, protected utils: CoreUtilsProvider,
protected moduleDelegate: CoreCourseModuleDelegate) { }
/**
* Component being initialized.
@ -69,7 +70,9 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C
this.refreshIcon = 'spinner';
if (this.module) {
const handler = this.sitePluginsProvider.getSitePluginHandler(this.module.modname);
const handlerName = this.moduleDelegate.getHandlerName(this.module.modname),
handler = this.sitePluginsProvider.getSitePluginHandler(handlerName);
if (handler) {
this.component = handler.plugin.component;
this.method = handler.handlerSchema.method;

View File

@ -16,6 +16,7 @@ import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreSitePluginsProvider } from '../../providers/siteplugins';
import { CoreSitePluginsCompileInitComponent } from '../../classes/compile-init-component';
import { CoreQuestionBehaviourDelegate } from '@core/question/providers/behaviour-delegate';
/**
* Component that displays a question behaviour created using a site plugin.
@ -33,7 +34,8 @@ export class CoreSitePluginsQuestionBehaviourComponent extends CoreSitePluginsCo
@Output() buttonClicked: EventEmitter<any>; // Should emit an event when a behaviour button is clicked.
@Output() onAbort: EventEmitter<void>; // Should emit an event if the question should be aborted.
constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider) {
constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider,
protected questionBehaviourDelegate: CoreQuestionBehaviourDelegate) {
super(sitePluginsProvider, utils);
}
@ -51,7 +53,7 @@ export class CoreSitePluginsQuestionBehaviourComponent extends CoreSitePluginsCo
this.jsData.onAbort = this.onAbort;
if (this.question) {
this.getHandlerData('qbehaviour_' + this.question.preferredBehaviour);
this.getHandlerData(this.questionBehaviourDelegate.getHandlerName(this.question.preferredBehaviour));
}
}
}

View File

@ -16,6 +16,7 @@ import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreSitePluginsProvider } from '../../providers/siteplugins';
import { CoreSitePluginsCompileInitComponent } from '../../classes/compile-init-component';
import { CoreQuestionDelegate } from '@core/question/providers/delegate';
/**
* Component that displays a question created using a site plugin.
@ -33,7 +34,8 @@ export class CoreSitePluginsQuestionComponent extends CoreSitePluginsCompileInit
@Output() buttonClicked: EventEmitter<any>; // Should emit an event when a behaviour button is clicked.
@Output() onAbort: EventEmitter<void>; // Should emit an event if the question should be aborted.
constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider) {
constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider,
protected questionDelegate: CoreQuestionDelegate) {
super(sitePluginsProvider, utils);
}
@ -51,7 +53,7 @@ export class CoreSitePluginsQuestionComponent extends CoreSitePluginsCompileInit
this.jsData.onAbort = this.onAbort;
if (this.question) {
this.getHandlerData('qtype_' + this.question.type);
this.getHandlerData(this.questionDelegate.getHandlerName('qtype_' + this.question.type));
}
}
}

View File

@ -17,6 +17,7 @@ import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreSitePluginsProvider } from '../../providers/siteplugins';
import { CoreSitePluginsCompileInitComponent } from '../../classes/compile-init-component';
import { FormGroup } from '@angular/forms';
import { AddonModQuizAccessRuleDelegate } from '@addon/mod/quiz/providers/access-rules-delegate';
/**
* Component that displays a quiz access rule created using a site plugin.
@ -33,7 +34,8 @@ export class CoreSitePluginsQuizAccessRuleComponent extends CoreSitePluginsCompi
@Input() siteId: string; // Site ID.
@Input() form: FormGroup; // Form where to add the form control.
constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider) {
constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider,
protected accessRulesDelegate: AddonModQuizAccessRuleDelegate) {
super(sitePluginsProvider, utils);
}
@ -50,7 +52,7 @@ export class CoreSitePluginsQuizAccessRuleComponent extends CoreSitePluginsCompi
this.jsData.form = this.form;
if (this.rule) {
this.getHandlerData(this.rule);
this.getHandlerData(this.accessRulesDelegate.getHandlerName(this.rule));
}
}
}

View File

@ -17,6 +17,7 @@ import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreSitePluginsProvider } from '../../providers/siteplugins';
import { CoreSitePluginsCompileInitComponent } from '../../classes/compile-init-component';
import { FormGroup } from '@angular/forms';
import { CoreUserProfileFieldDelegate } from '@core/user/providers/user-profile-field-delegate';
/**
* Component that displays a user profile field created using a site plugin.
@ -33,7 +34,8 @@ export class CoreSitePluginsUserProfileFieldComponent extends CoreSitePluginsCom
@Input() signup = false; // True if editing the field in signup. Defaults to false.
@Input() registerAuth?: string; // Register auth method. E.g. 'email'.
constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider) {
constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider,
protected profileFieldDelegate: CoreUserProfileFieldDelegate) {
super(sitePluginsProvider, utils);
}
@ -51,7 +53,7 @@ export class CoreSitePluginsUserProfileFieldComponent extends CoreSitePluginsCom
this.jsData.registerAuth = this.registerAuth;
if (this.field) {
this.getHandlerData('profilefield_' + (this.field.type || this.field.datatype));
this.getHandlerData(this.profileFieldDelegate.getHandlerName(this.field.type || this.field.datatype));
}
}
}

View File

@ -16,6 +16,7 @@ import { Component, OnInit, Input } from '@angular/core';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreSitePluginsProvider } from '../../providers/siteplugins';
import { CoreSitePluginsCompileInitComponent } from '../../classes/compile-init-component';
import { AddonWorkshopAssessmentStrategyDelegate } from '@addon/mod/workshop/providers/assessment-strategy-delegate';
/**
* Component that displays a workshop assessment strategy plugin created using a site plugin.
@ -32,7 +33,8 @@ export class CoreSitePluginsWorkshopAssessmentStrategyComponent extends CoreSite
@Input() fieldErrors: any;
@Input() strategy: string;
constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider) {
constructor(sitePluginsProvider: CoreSitePluginsProvider, utils: CoreUtilsProvider,
private workshopAssessmentStrategyDelegate: AddonWorkshopAssessmentStrategyDelegate) {
super(sitePluginsProvider, utils);
}
@ -48,6 +50,6 @@ export class CoreSitePluginsWorkshopAssessmentStrategyComponent extends CoreSite
this.jsData.fieldErrors = this.fieldErrors;
this.jsData.strategy = this.strategy;
this.getHandlerData('workshopform_' + this.strategy);
this.getHandlerData(this.workshopAssessmentStrategyDelegate.getHandlerName(this.strategy));
}
}

View File

@ -548,7 +548,7 @@ export class CoreSitePluginsHelperProvider {
this.logger.debug('Register site plugin', plugin, handlerSchema);
// Execute the main method and its JS. The template returned will be used in the right component.
return this.executeMethodAndJS(plugin, handlerSchema.method).then((result) => {
return this.executeMethodAndJS(plugin, handlerSchema.method).then((result): any => {
// Create and register the handler.
const uniqueName = this.sitePluginsProvider.getHandlerUniqueName(plugin, handlerName),
@ -571,7 +571,7 @@ export class CoreSitePluginsHelperProvider {
delegate.registerHandler(handler);
return handlerSchema.moodlecomponent || plugin.component;
return uniqueName;
}).catch((err) => {
this.logger.error('Error executing main method', plugin.component, handlerSchema.method, err);
});
@ -654,7 +654,7 @@ export class CoreSitePluginsHelperProvider {
formatName = (handlerSchema.moodlecomponent || plugin.component).replace('format_', '');
this.courseFormatDelegate.registerHandler(new CoreSitePluginsCourseFormatHandler(uniqueName, formatName, handlerSchema));
return formatName;
return uniqueName;
}
/**
@ -777,7 +777,7 @@ export class CoreSitePluginsHelperProvider {
this.sitePluginsProvider, plugin.component, uniqueName, modName, handlerSchema));
}
return modName;
return uniqueName;
}
/**