instance - create user started
This commit is contained in:
parent
44a25fddbe
commit
2781a9fabb
|
@ -186,6 +186,18 @@
|
|||
"label": "Name",
|
||||
"getInitialValue": "default",
|
||||
"getUndefinedValue": "default"
|
||||
},
|
||||
{
|
||||
"name": "defaultAccessLevel",
|
||||
"type": "string",
|
||||
"typeOptions": {
|
||||
"maxLength": 200,
|
||||
"values": null,
|
||||
"allowDeclaredValuesOnly": false
|
||||
},
|
||||
"label": "Default Access Level",
|
||||
"getInitialValue": "default",
|
||||
"getUndefinedValue": "default"
|
||||
}
|
||||
],
|
||||
"children": [],
|
||||
|
@ -424,6 +436,12 @@
|
|||
"behaviourSource": "main",
|
||||
"behaviourName": "initialiseInstance",
|
||||
"initialOptions": {}
|
||||
},
|
||||
"create_user": {
|
||||
"name": "create_user",
|
||||
"behaviourSource": "main",
|
||||
"behaviourName": "createNewUser",
|
||||
"initialOptions": {}
|
||||
}
|
||||
},
|
||||
"triggers": [
|
||||
|
@ -431,7 +449,13 @@
|
|||
"actionName": "initialise_instance",
|
||||
"eventName": "recordApi:save:onRecordCreated",
|
||||
"optionsCreator": "return { instance:context.record, apis };",
|
||||
"condition": "context.record.type === \"instance\""
|
||||
"condition": "record.type === \"instance\""
|
||||
},
|
||||
{
|
||||
"actionName": "create_user",
|
||||
"eventName": "recordApi:save:onRecordCreated",
|
||||
"optionsCreator": "return ({ user:context.record, apis });",
|
||||
"condition": "context.record.type === \"user\""
|
||||
}
|
||||
]
|
||||
}
|
|
@ -8,8 +8,12 @@ const { getRuntimePackageDirectory } = require("../../utilities/runtimePackages"
|
|||
const { exists } = require("../../utilities/fsawait");
|
||||
const createInstanceDb = require("../../initialise/createInstanceDb");
|
||||
const { createWriteStream } = require("fs");
|
||||
const { applictionVersionPackage } = require("../../utilities/createAppPackage");
|
||||
const { getApisWithFullAccess } = require("../../utilities/budibaseApi");
|
||||
|
||||
module.exports = (config) => ({
|
||||
module.exports = (config) => {
|
||||
const datastoreModule = require(`../../../datastores/datastores/${config.datastore}`);
|
||||
return ({
|
||||
initialiseInstance : async ({ instance, apis }) => {
|
||||
const appKey = $(instance.key, [
|
||||
splitKey,
|
||||
|
@ -19,7 +23,6 @@ module.exports = (config) => ({
|
|||
|
||||
const application = await apis.recordApi.load(appKey);
|
||||
|
||||
const datastoreModule = require(`../../../datastores/datastores/${config.datastore}`);
|
||||
const dbConfig = await createInstanceDb(
|
||||
datastoreModule,
|
||||
config.datastoreConfig,
|
||||
|
@ -43,8 +46,42 @@ module.exports = (config) => ({
|
|||
instance.datastoreconfig = JSON.stringify(dbConfig);
|
||||
instance.isNew = false;
|
||||
await apis.recordApi.save(instance);
|
||||
},
|
||||
|
||||
createNewUser: async ({user, apis}) => {
|
||||
const instance = apis.recordApi.load(user.instance.key);
|
||||
|
||||
const appKey = $(instance.key, [
|
||||
splitKey,
|
||||
take(2),
|
||||
joinKey
|
||||
]);
|
||||
|
||||
const application = await apis.recordApi.load(appKey);
|
||||
|
||||
const versionId = $(instance.version.key, [
|
||||
splitKey,
|
||||
takeRight(1),
|
||||
joinKey
|
||||
]);
|
||||
|
||||
const appPackage = applictionVersionPackage(
|
||||
application.name,
|
||||
versionId);
|
||||
|
||||
const instanceApis = getApisWithFullAccess(
|
||||
datastoreModule.getDatastore(instance.datastoreconfig),
|
||||
appPackage);
|
||||
|
||||
const authUser = instanceApis.authApi.getNewUser();
|
||||
authUser.name = user.name;
|
||||
authUser.accessLevels = [instance.version.defaultAccessLevel];
|
||||
await instanceApis.authApi.createUser(authUser);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
const downloadAppPackage = async (apis, instance, appName, versionId) => {
|
||||
const inputStream = await apis.recordApi.downloadFile(instance.version.key, "package.tar.gz");
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,9 @@
|
|||
const fs = require("fs");
|
||||
|
||||
module.exports = (config) => ({
|
||||
main: {
|
||||
outputToFile : ({filename, content}) => {
|
||||
fs.writeFile(`./tests/.data/${filename}`, content, {encoding:"utf8"});
|
||||
}
|
||||
}
|
||||
})
|
|
@ -64,13 +64,18 @@ module.exports = (app) => {
|
|||
.getNew(`${newAppKey}/instances`, "instance");
|
||||
instance1.name = "instance 1";
|
||||
instance1.active = true;
|
||||
instance1.version = {key:version1Key, name:"v1"};
|
||||
instance1.version = {key:version1Key, name:"v1", defaultAccessLevel:"owner"};
|
||||
instance1Key = instance1.key;
|
||||
|
||||
await app.post(`/_master/api/record/${instance1.key}`, instance1)
|
||||
.set("cookie", app.masterAuth.cookie)
|
||||
.expect(statusCodes.OK);
|
||||
|
||||
});
|
||||
|
||||
it("should be able to create new user on instance", async () => {
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue