2019-07-09 08:29:50 +02:00
|
|
|
const createUser = require("./createUser");
|
|
|
|
const enableUser = require("./enableUser");
|
|
|
|
const disableUser = require("./disableUser");
|
|
|
|
|
2019-07-11 08:35:29 +02:00
|
|
|
module.exports = async (appPackage, masterAppInternal, appName, instanceKey) => {
|
2019-07-09 08:29:50 +02:00
|
|
|
|
|
|
|
const plugin = await constructPlugin(
|
|
|
|
masterAppInternal,
|
|
|
|
appName,
|
|
|
|
instanceKey
|
|
|
|
);
|
|
|
|
|
|
|
|
appPackage.behaviourSources._injected = plugin;
|
|
|
|
|
|
|
|
createActions(appPackage);
|
|
|
|
createTriggers(appPackage);
|
|
|
|
}
|
|
|
|
|
|
|
|
const createTriggers = (appPackage) => {
|
|
|
|
const appDef = appPackage.appDefinition;
|
|
|
|
appDef.triggers.push({
|
|
|
|
actionName: 'createUser',
|
|
|
|
eventName: 'authApi:createUser:onComplete',
|
2019-07-11 08:35:29 +02:00
|
|
|
optionsCreator: 'return {user:context.result};',
|
2019-07-09 08:29:50 +02:00
|
|
|
condition: ''
|
|
|
|
});
|
|
|
|
appDef.triggers.push({
|
|
|
|
actionName: 'enableUser',
|
|
|
|
eventName: 'authApi:enableUser:onComplete',
|
|
|
|
optionsCreator: 'return {username:context.username};',
|
|
|
|
condition: ''
|
|
|
|
});
|
|
|
|
appDef.triggers.push({
|
|
|
|
actionName: 'disableUser',
|
|
|
|
eventName: 'authApi:disableUser:onComplete',
|
|
|
|
optionsCreator: 'return {username:context.username};',
|
|
|
|
condition: ''
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const createActions = (appPackage) => {
|
|
|
|
const appDef = appPackage.appDefinition;
|
|
|
|
appDef.actions.createUser = {
|
|
|
|
name: "createUser",
|
|
|
|
behaviourSource: '_injected',
|
|
|
|
behaviourName: 'createUser',
|
|
|
|
initialOptions: {}
|
|
|
|
};
|
2019-07-11 08:35:29 +02:00
|
|
|
appDef.actions.enableUser = {
|
2019-07-09 08:29:50 +02:00
|
|
|
name: "enableUser",
|
|
|
|
behaviourSource: '_injected',
|
|
|
|
behaviourName: 'enableUser',
|
|
|
|
initialOptions: {}
|
|
|
|
};
|
2019-07-11 08:35:29 +02:00
|
|
|
appDef.actions.disableUser = {
|
2019-07-09 08:29:50 +02:00
|
|
|
name: "disableUser",
|
|
|
|
behaviourSource: '_injected',
|
|
|
|
behaviourName: 'disableUser',
|
|
|
|
initialOptions: {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const constructPlugin = async (masterAppInternal, appName, instanceKey) => {
|
|
|
|
|
|
|
|
const app = await masterAppInternal.getApplication(appName);
|
|
|
|
const initialiseObj = {
|
|
|
|
masterAppInternal, app, instanceKey
|
|
|
|
};
|
|
|
|
|
|
|
|
return ({
|
|
|
|
createUser:createUser(initialiseObj),
|
|
|
|
enableUser:enableUser(initialiseObj),
|
|
|
|
disableUser:disableUser(initialiseObj)
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|