Creating a function for the client to be able to pull in client definition from API.
This commit is contained in:
parent
634eacd5b9
commit
1e9e46b8a5
|
@ -15,9 +15,11 @@ const {
|
||||||
DocumentTypes,
|
DocumentTypes,
|
||||||
SEPARATOR,
|
SEPARATOR,
|
||||||
getPageParams,
|
getPageParams,
|
||||||
|
getScreenParams,
|
||||||
generatePageID,
|
generatePageID,
|
||||||
generateScreenID,
|
generateScreenID,
|
||||||
} = require("../../db/utils")
|
} = require("../../db/utils")
|
||||||
|
const { BUILTIN_LEVEL_IDS } = require("../../utilities/security/accessLevels")
|
||||||
const {
|
const {
|
||||||
downloadExtractComponentLibraries,
|
downloadExtractComponentLibraries,
|
||||||
} = require("../../utilities/createAppPackage")
|
} = require("../../utilities/createAppPackage")
|
||||||
|
@ -27,6 +29,20 @@ const { cloneDeep } = require("lodash/fp")
|
||||||
|
|
||||||
const APP_PREFIX = DocumentTypes.APP + SEPARATOR
|
const APP_PREFIX = DocumentTypes.APP + SEPARATOR
|
||||||
|
|
||||||
|
// utility function, need to do away with this
|
||||||
|
async function getMainAndUnauthPage(db) {
|
||||||
|
let pages = await db.allDocs(
|
||||||
|
getPageParams(null, {
|
||||||
|
include_docs: true,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
pages = pages.rows.map(row => row.doc)
|
||||||
|
|
||||||
|
const mainPage = pages.find(page => page.name === PageTypes.MAIN)
|
||||||
|
const unauthPage = pages.find(page => page.name === PageTypes.UNAUTHENTICATED)
|
||||||
|
return { mainPage, unauthPage }
|
||||||
|
}
|
||||||
|
|
||||||
async function createInstance(template) {
|
async function createInstance(template) {
|
||||||
const appId = generateAppID()
|
const appId = generateAppID()
|
||||||
|
|
||||||
|
@ -67,19 +83,36 @@ exports.fetch = async function(ctx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.fetchAppDefinition = async function(ctx) {
|
||||||
|
const db = new CouchDB(ctx.params.appId)
|
||||||
|
// TODO: need to get rid of pages here, they shouldn't be needed anymore
|
||||||
|
const { mainPage, unauthPage } = await getMainAndUnauthPage(db)
|
||||||
|
const userAccessLevelId =
|
||||||
|
!ctx.user.accessLevel || !ctx.user.accessLevel._id
|
||||||
|
? BUILTIN_LEVEL_IDS.PUBLIC
|
||||||
|
: ctx.user.accessLevel._id
|
||||||
|
const correctPage =
|
||||||
|
userAccessLevelId === BUILTIN_LEVEL_IDS.PUBLIC ? unauthPage : mainPage
|
||||||
|
const screens = (
|
||||||
|
await db.allDocs(
|
||||||
|
getScreenParams(correctPage._id, {
|
||||||
|
include_docs: true,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
).rows.map(row => row.doc)
|
||||||
|
// TODO: need to handle access control here, limit screens to user access level
|
||||||
|
ctx.body = {
|
||||||
|
page: correctPage,
|
||||||
|
screens: screens,
|
||||||
|
libraries: ["@budibase/standard-components"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exports.fetchAppPackage = async function(ctx) {
|
exports.fetchAppPackage = async function(ctx) {
|
||||||
const db = new CouchDB(ctx.params.appId)
|
const db = new CouchDB(ctx.params.appId)
|
||||||
const application = await db.get(ctx.params.appId)
|
const application = await db.get(ctx.params.appId)
|
||||||
|
|
||||||
let pages = await db.allDocs(
|
const { mainPage, unauthPage } = await getMainAndUnauthPage(db)
|
||||||
getPageParams(null, {
|
|
||||||
include_docs: true,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
pages = pages.rows.map(row => row.doc)
|
|
||||||
|
|
||||||
const mainPage = pages.find(page => page.name === PageTypes.MAIN)
|
|
||||||
const unauthPage = pages.find(page => page.name === PageTypes.UNAUTHENTICATED)
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
application,
|
application,
|
||||||
pages: {
|
pages: {
|
||||||
|
|
|
@ -6,6 +6,7 @@ const { BUILDER } = require("../../utilities/security/permissions")
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
||||||
router
|
router
|
||||||
|
.get("/api/:appId/definition", controller.fetchAppDefinition)
|
||||||
.get("/api/applications", authorized(BUILDER), controller.fetch)
|
.get("/api/applications", authorized(BUILDER), controller.fetch)
|
||||||
.get(
|
.get(
|
||||||
"/api/:appId/appPackage",
|
"/api/:appId/appPackage",
|
||||||
|
|
Loading…
Reference in New Issue