test app working tf
This commit is contained in:
parent
991bd69671
commit
98127d6eb8
|
@ -52,6 +52,9 @@ module.exports = (context) => {
|
||||||
},
|
},
|
||||||
|
|
||||||
createNewUser: async ({user, apis}) => {
|
createNewUser: async ({user, apis}) => {
|
||||||
|
|
||||||
|
if(!user.createdByMaster) return;
|
||||||
|
|
||||||
const instance = await apis.recordApi.load(user.instance.key);
|
const instance = await apis.recordApi.load(user.instance.key);
|
||||||
|
|
||||||
const appKey = $(instance.key, [
|
const appKey = $(instance.key, [
|
||||||
|
@ -81,8 +84,8 @@ module.exports = (context) => {
|
||||||
const authUser = instanceApis.authApi.getNewUser();
|
const authUser = instanceApis.authApi.getNewUser();
|
||||||
authUser.name = user.name;
|
authUser.name = user.name;
|
||||||
authUser.accessLevels = [instance.version.defaultAccessLevel];
|
authUser.accessLevels = [instance.version.defaultAccessLevel];
|
||||||
|
|
||||||
await instanceApis.authApi.createUser(authUser);
|
await instanceApis.authApi.createUser(authUser);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -73,6 +73,12 @@
|
||||||
"eventName": "authApi:createUser:onComplete",
|
"eventName": "authApi:createUser:onComplete",
|
||||||
"optionsCreator": "return { filename:'tempaccess' + context.user.name, content:context.result.tempCode };",
|
"optionsCreator": "return { filename:'tempaccess' + context.user.name, content:context.result.tempCode };",
|
||||||
"condition": "!context.password"
|
"condition": "!context.password"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"actionName": "output_to_file",
|
||||||
|
"eventName": "authApi:createTemporaryAccess:onComplete",
|
||||||
|
"optionsCreator": "return { filename:'tempaccess' + context.userName, content:context.result };",
|
||||||
|
"condition": ""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
Binary file not shown.
|
@ -73,6 +73,12 @@
|
||||||
"eventName": "authApi:createUser:onComplete",
|
"eventName": "authApi:createUser:onComplete",
|
||||||
"optionsCreator": "return { filename:'tempaccess' + context.user.name, content:context.result.tempCode };",
|
"optionsCreator": "return { filename:'tempaccess' + context.user.name, content:context.result.tempCode };",
|
||||||
"condition": "!context.password"
|
"condition": "!context.password"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"actionName": "output_to_file",
|
||||||
|
"eventName": "authApi:createTemporaryAccess:onComplete",
|
||||||
|
"optionsCreator": "return { filename:'tempaccess' + context.userName, content:context.result };",
|
||||||
|
"condition": ""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -87,7 +87,7 @@ module.exports = (app) => {
|
||||||
.getNew(`${newAppKey}/users`, "user");
|
.getNew(`${newAppKey}/users`, "user");
|
||||||
user1_instance1.name = app.credentials.testApp.username;
|
user1_instance1.name = app.credentials.testApp.username;
|
||||||
user1_instance1.createdByMaster = true;
|
user1_instance1.createdByMaster = true;
|
||||||
|
master.recordApi.setCustomId(user1_instance1, user1_instance1.name);
|
||||||
/*const lookupResponse = await app.get(`/_master/api/lookup_field/${user1_instance1.key}?fields=instance`)
|
/*const lookupResponse = await app.get(`/_master/api/lookup_field/${user1_instance1.key}?fields=instance`)
|
||||||
.set("cookie", app.credentials._master.cookie)
|
.set("cookie", app.credentials._master.cookie)
|
||||||
.expect(statusCodes.OK);
|
.expect(statusCodes.OK);
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
|
|
||||||
|
|
||||||
module.exports = ({ masterAppInternal, instanceKey }) => async ({ user }) => {
|
module.exports = ({ masterAppInternal, instanceKey, app }) => async ({ user }) => {
|
||||||
const { bbMaster } = masterAppInternal;
|
const { bbMaster } = masterAppInternal;
|
||||||
|
const existingUser =await masterAppInternal.getUser(
|
||||||
|
app.id, user.name);
|
||||||
|
|
||||||
|
if(existingUser) return;
|
||||||
|
|
||||||
const masterUser = bbMaster.recordApi
|
const masterUser = bbMaster.recordApi
|
||||||
.getNew(`${newAppKey}/users`, "user");
|
.getNew(`${app.key}/users`, "user");
|
||||||
masterUser.name = user.name;
|
masterUser.name = user.name;
|
||||||
|
bbMaster.recordApi.setCustomId(masterUser, masterUser.name);
|
||||||
masterUser.createdByMaster = false;
|
masterUser.createdByMaster = false;
|
||||||
masterUser.instance = await bbMaster.recordApi
|
masterUser.instance = await bbMaster.recordApi
|
||||||
.load(instanceKey);
|
.load(instanceKey);
|
||||||
|
@ -13,5 +19,6 @@ module.exports = ({ masterAppInternal, instanceKey }) => async ({ user }) => {
|
||||||
await bbMaster.recordApi.save(masterUser);
|
await bbMaster.recordApi.save(masterUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const timeout = ms =>
|
||||||
|
new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ const createUser = require("./createUser");
|
||||||
const enableUser = require("./enableUser");
|
const enableUser = require("./enableUser");
|
||||||
const disableUser = require("./disableUser");
|
const disableUser = require("./disableUser");
|
||||||
|
|
||||||
module.exports = async (appPackage, masterAppInternal, instanceKey, appName) => {
|
module.exports = async (appPackage, masterAppInternal, appName, instanceKey) => {
|
||||||
|
|
||||||
const plugin = await constructPlugin(
|
const plugin = await constructPlugin(
|
||||||
masterAppInternal,
|
masterAppInternal,
|
||||||
|
@ -21,7 +21,7 @@ const createTriggers = (appPackage) => {
|
||||||
appDef.triggers.push({
|
appDef.triggers.push({
|
||||||
actionName: 'createUser',
|
actionName: 'createUser',
|
||||||
eventName: 'authApi:createUser:onComplete',
|
eventName: 'authApi:createUser:onComplete',
|
||||||
optionsCreator: 'return {user:context.user};',
|
optionsCreator: 'return {user:context.result};',
|
||||||
condition: ''
|
condition: ''
|
||||||
});
|
});
|
||||||
appDef.triggers.push({
|
appDef.triggers.push({
|
||||||
|
@ -46,13 +46,13 @@ const createActions = (appPackage) => {
|
||||||
behaviourName: 'createUser',
|
behaviourName: 'createUser',
|
||||||
initialOptions: {}
|
initialOptions: {}
|
||||||
};
|
};
|
||||||
appDef.actions.createUser = {
|
appDef.actions.enableUser = {
|
||||||
name: "enableUser",
|
name: "enableUser",
|
||||||
behaviourSource: '_injected',
|
behaviourSource: '_injected',
|
||||||
behaviourName: 'enableUser',
|
behaviourName: 'enableUser',
|
||||||
initialOptions: {}
|
initialOptions: {}
|
||||||
};
|
};
|
||||||
appDef.actions.createUser = {
|
appDef.actions.disableUser = {
|
||||||
name: "disableUser",
|
name: "disableUser",
|
||||||
behaviourSource: '_injected',
|
behaviourSource: '_injected',
|
||||||
behaviourName: 'disableUser',
|
behaviourName: 'disableUser',
|
||||||
|
|
|
@ -41,13 +41,21 @@ module.exports = async (context) => {
|
||||||
: bb.recordApi.customId("session", sessionId);
|
: bb.recordApi.customId("session", sessionId);
|
||||||
|
|
||||||
|
|
||||||
const getApplication = async (name) => {
|
const getApplication = async (nameOrKey, isRetry=false) => {
|
||||||
if(applications[name])
|
if(applications[nameOrKey])
|
||||||
return applications[name];
|
return applications[nameOrKey];
|
||||||
|
|
||||||
|
for(let name in applications) {
|
||||||
|
const a = applications[name];
|
||||||
|
if(a.key === nameOrKey) return a;
|
||||||
|
if(a.id === nameOrKey) return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isRetry) return;
|
||||||
|
|
||||||
await loadApplications();
|
await loadApplications();
|
||||||
|
|
||||||
return applications[name];
|
return await getApplication(nameOrKey, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getSession = async (sessionId, appname) => {
|
const getSession = async (sessionId, appname) => {
|
||||||
|
@ -90,11 +98,11 @@ module.exports = async (context) => {
|
||||||
|
|
||||||
const app = await getApplication(appname);
|
const app = await getApplication(appname);
|
||||||
|
|
||||||
const userInMaster = await getUser(bb, app.id, username);
|
const userInMaster = await getUser(app.id, username);
|
||||||
if(!userInMaster) return null;
|
if(!userInMaster) return null;
|
||||||
|
|
||||||
const instance = await bb.recordApi.load(
|
const instance = await bb.recordApi.load(
|
||||||
userInMaster.instanceKey);
|
userInMaster.instance.key);
|
||||||
|
|
||||||
const versionId = $(instance.version.key, [
|
const versionId = $(instance.version.key, [
|
||||||
splitKey,
|
splitKey,
|
||||||
|
@ -165,17 +173,15 @@ module.exports = async (context) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getUser = async (bb, appId, username ) => {
|
const getUser = async (appId, username ) => {
|
||||||
const matches = await bb.indexApi.listItems(
|
const userId = bb.recordApi.customId("user", username);
|
||||||
`/applications/${appId}/user_name_lookup`,
|
try {
|
||||||
{
|
return await bb.recordApi.load(
|
||||||
rangeStartParams:{name:username},
|
`/applications/${appId}/users/${userId}`);
|
||||||
rangeEndParams:{name:username},
|
} catch(_) {
|
||||||
searchPhrase:`name:${username}`
|
//empty
|
||||||
}
|
return;
|
||||||
);
|
}
|
||||||
if(matches.length !== 1) return;
|
|
||||||
return matches[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getFullAccessInstanceApiForUsername = async (appname, username) => {
|
const getFullAccessInstanceApiForUsername = async (appname, username) => {
|
||||||
|
@ -185,22 +191,22 @@ module.exports = async (context) => {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const app = await getApplication(appname);
|
const app = await getApplication(appname);
|
||||||
const user = await getUser(bb, app.id, username);
|
const user = await getUser(app.id, username);
|
||||||
|
|
||||||
if(!user) return null;
|
if(!user) return null;
|
||||||
|
|
||||||
const dsConfig = JSON.parse(user.instanceDatastoreConfig);
|
const dsConfig = JSON.parse(user.instance.datastoreconfig);
|
||||||
const instanceDatastore = getInstanceDatastore(
|
const instanceDatastore = getInstanceDatastore(
|
||||||
dsConfig
|
dsConfig
|
||||||
);
|
);
|
||||||
|
|
||||||
const versionId = $((await bb.recordApi.load(user.instanceKey)).version.key, [
|
const versionId = $((await bb.recordApi.load(user.instance.key)).version.key, [
|
||||||
splitKey,
|
splitKey,
|
||||||
last
|
last
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const appPackage = await applictionVersionPackage(
|
const appPackage = await applictionVersionPackage(
|
||||||
context, appname, versionId, user.instanceKey);
|
context, appname, versionId, user.instance.key);
|
||||||
|
|
||||||
return await getApisWithFullAccess(
|
return await getApisWithFullAccess(
|
||||||
instanceDatastore,
|
instanceDatastore,
|
||||||
|
@ -229,8 +235,8 @@ module.exports = async (context) => {
|
||||||
const sessions = await bb.indexApi.listItems(
|
const sessions = await bb.indexApi.listItems(
|
||||||
`/applications/${app.id}/sessions_by_user`,
|
`/applications/${app.id}/sessions_by_user`,
|
||||||
{
|
{
|
||||||
rangeStartParams:{name:username},
|
rangeStartParams:{username},
|
||||||
rangeEndParams:{name:username},
|
rangeEndParams:{username},
|
||||||
searchPhrase:`username:${username}`
|
searchPhrase:`username:${username}`
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -242,14 +248,14 @@ module.exports = async (context) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const disableUser = async (app, username) => {
|
const disableUser = async (app, username) => {
|
||||||
await removeSessionsForUser(appName, username);
|
await removeSessionsForUser(app.name, username);
|
||||||
const userInMaster = await getUser(bb, app.id, username);
|
const userInMaster = await getUser(app.id, username);
|
||||||
userInMaster.active = false;
|
userInMaster.active = false;
|
||||||
await bb.recordApi.save(userInMaster);
|
await bb.recordApi.save(userInMaster);
|
||||||
}
|
}
|
||||||
|
|
||||||
const enableUser = async (app, username) => {
|
const enableUser = async (app, username) => {
|
||||||
const userInMaster = await getUser(bb, app.id, username);
|
const userInMaster = await getUser(app.id, username);
|
||||||
userInMaster.active = true;
|
userInMaster.active = true;
|
||||||
await bb.recordApi.save(userInMaster);
|
await bb.recordApi.save(userInMaster);
|
||||||
}
|
}
|
||||||
|
@ -264,6 +270,7 @@ module.exports = async (context) => {
|
||||||
removeSessionsForUser,
|
removeSessionsForUser,
|
||||||
disableUser,
|
disableUser,
|
||||||
enableUser,
|
enableUser,
|
||||||
|
getUser,
|
||||||
bbMaster:bb
|
bbMaster:bb
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue