2020-02-03 10:24:25 +01:00
|
|
|
const createUser = require("./createUser")
|
|
|
|
const enableUser = require("./enableUser")
|
|
|
|
const disableUser = require("./disableUser")
|
2019-07-09 08:29:50 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
module.exports = async (
|
|
|
|
appPackage,
|
|
|
|
masterAppInternal,
|
|
|
|
appName,
|
|
|
|
instanceKey
|
|
|
|
) => {
|
|
|
|
const plugin = await constructPlugin(masterAppInternal, appName, instanceKey)
|
2019-07-09 08:29:50 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
appPackage.behaviourSources._injected = plugin
|
2019-07-09 08:29:50 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
createActions(appPackage)
|
|
|
|
createTriggers(appPackage)
|
2019-07-09 08:29:50 +02:00
|
|
|
}
|
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const createTriggers = appPackage => {
|
|
|
|
const appDef = appPackage.appDefinition
|
|
|
|
appDef.triggers.push({
|
|
|
|
actionName: "createUser",
|
|
|
|
eventName: "authApi:createUser:onComplete",
|
|
|
|
optionsCreator: "return {user:context.result};",
|
|
|
|
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: "",
|
|
|
|
})
|
2019-07-09 08:29:50 +02:00
|
|
|
}
|
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const createActions = appPackage => {
|
|
|
|
const appDef = appPackage.appDefinition
|
|
|
|
appDef.actions.createUser = {
|
|
|
|
name: "createUser",
|
|
|
|
behaviourSource: "_injected",
|
|
|
|
behaviourName: "createUser",
|
|
|
|
initialOptions: {},
|
|
|
|
}
|
|
|
|
appDef.actions.enableUser = {
|
|
|
|
name: "enableUser",
|
|
|
|
behaviourSource: "_injected",
|
|
|
|
behaviourName: "enableUser",
|
|
|
|
initialOptions: {},
|
|
|
|
}
|
|
|
|
appDef.actions.disableUser = {
|
|
|
|
name: "disableUser",
|
|
|
|
behaviourSource: "_injected",
|
|
|
|
behaviourName: "disableUser",
|
|
|
|
initialOptions: {},
|
|
|
|
}
|
2019-07-09 08:29:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const constructPlugin = async (masterAppInternal, appName, instanceKey) => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const app = await masterAppInternal.getApplication(appName)
|
|
|
|
const initialiseObj = {
|
|
|
|
masterAppInternal,
|
|
|
|
app,
|
|
|
|
instanceKey,
|
|
|
|
}
|
2019-07-09 08:29:50 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
return {
|
|
|
|
createUser: createUser(initialiseObj),
|
|
|
|
enableUser: enableUser(initialiseObj),
|
|
|
|
disableUser: disableUser(initialiseObj),
|
|
|
|
}
|
|
|
|
}
|