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

25 lines
791 B
JavaScript
Raw Normal View History

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