mirror of https://github.com/Budibase/budibase.git
committed by
GitHub
25 changed files with 448 additions and 234 deletions
@ -0,0 +1,12 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
const { getRecordKey } = require("./helpers") |
|||
|
|||
module.exports = async ctx => { |
|||
const indexkey = getRecordKey(ctx.params.appname, ctx.request.path) |
|||
ctx.body = await ctx.instance.indexApi.aggregates(indexkey, { |
|||
rangeStartParams: ctx.request.body.rangeStartParams, |
|||
rangeEndParams: ctx.request.body.rangeEndParams, |
|||
searchPhrase: ctx.request.body.searchPhrase, |
|||
}) |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
const send = require("koa-send") |
|||
|
|||
module.exports = async (ctx, next) => { |
|||
const path = ctx.path.replace(`/${ctx.params.appname}`, "") |
|||
|
|||
if (path.startsWith("/api/")) { |
|||
await next() |
|||
} else if (path.startsWith("/_shared/")) { |
|||
await send(ctx, path.replace(`/_shared/`, ""), { root: ctx.sharedPath }) |
|||
} else if ( |
|||
path.endsWith(".js") || |
|||
path.endsWith(".map") || |
|||
path.endsWith(".css") |
|||
) { |
|||
await send(ctx, path, { root: ctx.publicPath }) |
|||
} else { |
|||
await send(ctx, "/index.html", { root: ctx.publicPath }) |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
|
|||
module.exports = async ctx => { |
|||
const user = await ctx.master.authenticate( |
|||
ctx.sessionId, |
|||
ctx.params.appname, |
|||
ctx.request.body.username, |
|||
ctx.request.body.password |
|||
) |
|||
if (!user) { |
|||
ctx.throw(StatusCodes.UNAUTHORIZED, "invalid username or password") |
|||
} |
|||
ctx.body = user.user_json |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
|
|||
module.exports = async ctx => { |
|||
await ctx.instance.authApi.changeMyPassword( |
|||
ctx.request.body.currentPassword, |
|||
ctx.request.body.newPassword |
|||
) |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
|
|||
module.exports = async ctx => { |
|||
const instanceApi = await ctx.master.getFullAccessInstanceApiForUsername( |
|||
ctx.params.appname, |
|||
ctx.request.body.username |
|||
) |
|||
|
|||
if (!instanceApi) { |
|||
ctx.request.status = StatusCodes.OK |
|||
return |
|||
} |
|||
|
|||
await instanceApi.authApi.createTemporaryAccess(ctx.request.body.username) |
|||
|
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
|
|||
module.exports = async ctx => { |
|||
await ctx.instance.authApi.createUser( |
|||
ctx.request.body.user, |
|||
ctx.request.body.password |
|||
) |
|||
|
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
const { getRecordKey } = require("./helpers") |
|||
|
|||
module.exports = async ctx => { |
|||
await ctx.instance.recordApi.delete( |
|||
getRecordKey(ctx.params.appname, ctx.request.path) |
|||
) |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
|
|||
module.exports = async ctx => { |
|||
await ctx.instance.authApi.disableUser(ctx.request.body.username) |
|||
|
|||
await ctx.master.removeSessionsForUser( |
|||
ctx.params.appname, |
|||
ctx.request.body.username |
|||
) |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
|
|||
module.exports = async ctx => { |
|||
await ctx.instance.authApi.enableUser(ctx.request.body.username) |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
|
|||
module.exports = async ctx => { |
|||
ctx.body = await ctx.instance.actionApi.execute( |
|||
ctx.request.body.actionname, |
|||
ctx.request.body.parameters |
|||
) |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
|
|||
module.exports = async ctx => { |
|||
ctx.body = await ctx.instance.authApi.getAccessLevels() |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
const { getRecordKey } = require("./helpers") |
|||
|
|||
module.exports = async ctx => { |
|||
try { |
|||
ctx.body = await ctx.instance.recordApi.load( |
|||
getRecordKey(ctx.params.appname, ctx.request.path) |
|||
) |
|||
ctx.response.status = StatusCodes.OK |
|||
} catch (e) { |
|||
// need to be catching for 404s here
|
|||
ctx.response.status = StatusCodes.INTERAL_ERROR |
|||
ctx.response.body = e.message |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
|
|||
module.exports = async ctx => { |
|||
ctx.body = await ctx.instance.authApi.getUsers() |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
exports.getRecordKey = (appname, wholePath) => |
|||
wholePath |
|||
.replace(`/${appname}/api/files/`, "") |
|||
.replace(`/${appname}/api/lookup_field/`, "") |
|||
.replace(`/${appname}/api/record/`, "") |
|||
.replace(`/${appname}/api/listRecords/`, "") |
|||
.replace(`/${appname}/api/aggregates/`, "") |
|||
@ -0,0 +1,43 @@ |
|||
const authenticate = require("./authenticate") |
|||
const setPasswordFromTemporaryCode = require("./setPasswordFromTemporaryCode") |
|||
const createTemporaryAccess = require("./createTemporaryAccess") |
|||
const appDefault = require("./appDefault") |
|||
const changeMyPassword = require("./changeMyPassword") |
|||
const executeAction = require("./executeAction") |
|||
const createUser = require("./createUser") |
|||
const enableUser = require("./enableUser") |
|||
const disableUser = require("./disableUser") |
|||
const getUsers = require("./getUsers") |
|||
const getAccessLevels = require("./getAccessLevels") |
|||
const listRecordsGet = require("./listRecordsGet") |
|||
const listRecordsPost = require("./listRecordsPost") |
|||
const aggregatesPost = require("./aggregatesPost") |
|||
const postFiles = require("./postFiles") |
|||
const saveRecord = require("./saveRecord") |
|||
const lookupField = require("./lookupField") |
|||
const getRecord = require("./getRecord") |
|||
const deleteRecord = require("./deleteRecord") |
|||
const saveAppHierarchy = require("./saveAppHierarchy") |
|||
|
|||
module.exports = { |
|||
authenticate, |
|||
setPasswordFromTemporaryCode, |
|||
createTemporaryAccess, |
|||
appDefault, |
|||
changeMyPassword, |
|||
executeAction, |
|||
createUser, |
|||
enableUser, |
|||
disableUser, |
|||
getUsers, |
|||
getAccessLevels, |
|||
listRecordsGet, |
|||
listRecordsPost, |
|||
aggregatesPost, |
|||
postFiles, |
|||
saveRecord, |
|||
lookupField, |
|||
getRecord, |
|||
deleteRecord, |
|||
saveAppHierarchy, |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
const { getRecordKey } = require("./helpers") |
|||
|
|||
module.exports = async ctx => { |
|||
const indexkey = getRecordKey(ctx.params.appname, ctx.request.path) |
|||
ctx.body = await ctx.instance.indexApi.listItems(indexkey) |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
const { getRecordKey } = require("./helpers") |
|||
|
|||
module.exports = async ctx => { |
|||
const indexkey = getRecordKey(ctx.params.appname, ctx.request.path) |
|||
ctx.body = await ctx.instance.indexApi.listItems(indexkey, { |
|||
rangeStartParams: ctx.request.body.rangeStartParams, |
|||
rangeEndParams: ctx.request.body.rangeEndParams, |
|||
searchPhrase: ctx.request.body.searchPhrase, |
|||
}) |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
const { getRecordKey } = require("./helpers") |
|||
|
|||
module.exports = async ctx => { |
|||
const recordKey = getRecordKey(ctx.params.appname, ctx.request.path) |
|||
const fields = ctx.query.fields.split(",") |
|||
const recordContext = await ctx.instance.recordApi.getContext(recordKey) |
|||
const allContext = [] |
|||
for (let field of fields) { |
|||
allContext.push(await recordContext.referenceOptions(field)) |
|||
} |
|||
ctx.body = allContext |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
const { getRecordKey } = require("./helpers") |
|||
const fs = require("fs") |
|||
|
|||
module.exports = async ctx => { |
|||
const file = ctx.request.files.file |
|||
ctx.body = await ctx.instance.recordApi.uploadFile( |
|||
getRecordKey(ctx.params.appname, ctx.request.path), |
|||
fs.createReadStream(file.path), |
|||
file.name |
|||
) |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
|
|||
module.exports = async ctx => { |
|||
ctx.body = await ctx.instance.templateApi.saveApplicationHierarchy(ctx.body) |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
|
|||
module.exports = async ctx => { |
|||
ctx.body = await ctx.instance.recordApi.save(ctx.request.body) |
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
const StatusCodes = require("../../utilities/statusCodes") |
|||
|
|||
module.exports = async ctx => { |
|||
const instanceApi = await ctx.master.getFullAccessInstanceApiForUsername( |
|||
ctx.params.appname, |
|||
ctx.request.body.username |
|||
) |
|||
|
|||
if (!instanceApi) { |
|||
ctx.request.status = StatusCodes.OK |
|||
return |
|||
} |
|||
|
|||
await instanceApi.authApi.setPasswordFromTemporaryCode( |
|||
ctx.request.body.tempCode, |
|||
ctx.request.body.newPassword |
|||
) |
|||
|
|||
ctx.response.status = StatusCodes.OK |
|||
} |
|||
Loading…
Reference in new issue