budibase/packages/server/utilities/injectedPlugins/createUser.js

20 lines
657 B
JavaScript
Raw Normal View History

module.exports = ({ masterAppInternal, instanceKey, app }) => async ({
user,
}) => {
const { bbMaster } = masterAppInternal
const existingUser = await masterAppInternal.getUser(app.id, user.name)
2019-07-09 08:29:50 +02:00
if (existingUser) return
2019-07-09 08:29:50 +02:00
const masterUser = bbMaster.recordApi.getNew(`${app.key}/users`, "user")
masterUser.name = user.name
bbMaster.recordApi.setCustomId(masterUser, masterUser.name)
masterUser.createdByMaster = false
masterUser.instance = await bbMaster.recordApi.load(instanceKey)
2019-07-11 08:35:29 +02:00
masterUser.active = user.enabled
await bbMaster.recordApi.save(masterUser)
2019-07-09 08:29:50 +02:00
}
2020-02-25 16:21:23 +01:00
exports.timeout = ms => new Promise(resolve => setTimeout(resolve, ms))