forked from tsai/budibase
11 changed files with 132 additions and 117 deletions
@ -1 +1,17 @@ |
|||
exports.fetch = async ctx => {} |
|||
const { getRoutingInfo } = require("../../utilities/routing") |
|||
const { AccessController } = require("../../utilities/security/accessLevels") |
|||
|
|||
async function getRoutingStructure(appId) { |
|||
let baseRouting = await getRoutingInfo(appId) |
|||
return baseRouting |
|||
} |
|||
|
|||
exports.fetch = async ctx => { |
|||
ctx.body = await getRoutingStructure(ctx.appId) |
|||
} |
|||
|
|||
exports.clientFetch = async ctx => { |
|||
const routing = getRoutingStructure(ctx.appId) |
|||
// use the access controller to pick which access level is applicable to this user
|
|||
const accessController = new AccessController(ctx.appId) |
|||
} |
|||
|
|||
@ -1,11 +1,14 @@ |
|||
const CouchDB = require("../db") |
|||
const CouchDB = require("../../db") |
|||
const { createRoutingView } = require("./routingUtils") |
|||
const { ViewNames, getQueryIndex } = require("../db/utils") |
|||
const { ViewNames, getQueryIndex, UNICODE_MAX } = require("../../db/utils") |
|||
|
|||
exports.getRoutingInfo = async appId => { |
|||
const db = new CouchDB(appId) |
|||
try { |
|||
const allRouting = await db.query(getQueryIndex(ViewNames.ROUTING)) |
|||
const allRouting = await db.query(getQueryIndex(ViewNames.ROUTING), { |
|||
startKey: "", |
|||
endKey: UNICODE_MAX, |
|||
}) |
|||
return allRouting.rows.map(row => row.value) |
|||
} catch (err) { |
|||
// check if the view doesn't exist, it should for all new instances
|
|||
@ -1,19 +1,20 @@ |
|||
const CouchDB = require("../db") |
|||
const { DocumentTypes, SEPARATOR, ViewNames } = require("../db/utils") |
|||
const CouchDB = require("../../db") |
|||
const { DocumentTypes, SEPARATOR, ViewNames } = require("../../db/utils") |
|||
const SCREEN_PREFIX = DocumentTypes.SCREEN + SEPARATOR |
|||
|
|||
exports.createRoutingView = async appId => { |
|||
const db = new CouchDB(appId) |
|||
const designDoc = await db.get("_design/database") |
|||
const view = { |
|||
map: function(doc) { |
|||
if (doc._id.startsWith(SCREEN_PREFIX)) { |
|||
// if using variables in a map function need to inject them before use
|
|||
map: `function(doc) {
|
|||
if (doc._id.startsWith("${SCREEN_PREFIX}")) { |
|||
emit(doc._id, { |
|||
id: doc._id, |
|||
routing: doc.routing, |
|||
}) |
|||
} |
|||
}.toString(), |
|||
}`,
|
|||
} |
|||
designDoc.views = { |
|||
...designDoc.views, |
|||
Loading…
Reference in new issue