1
0
Fork 0
mirror of synced 2024-06-30 03:50:37 +12:00

erge branch 'feature/draft-apps' into admin/user-management-ui

This commit is contained in:
Keviin Åberg Kultalahti 2021-05-17 15:29:33 +02:00
commit b8870ed8c4
3 changed files with 37 additions and 4 deletions

View file

@ -141,6 +141,18 @@ exports.getRoleParams = (roleId = null, otherProps = {}) => {
return getDocParams(DocumentTypes.ROLE, roleId, otherProps)
}
/**
* Convert a development app ID to a deployed app ID.
*/
exports.getDeployedAppID = appId => {
// if dev, convert it
if (appId.startsWith(exports.APP_DEV_PREFIX)) {
const id = appId.split(exports.APP_DEV_PREFIX)[1]
return `${exports.APP_PREFIX}${id}`
}
return appId
}
/**
* Lots of different points in the system need to find the full list of apps, this will
* enumerate the entire CouchDB cluster and get the list of databases (every app).

View file

@ -2,6 +2,7 @@ const fetch = require("node-fetch")
const env = require("../environment")
const { checkSlashesInUrl } = require("./index")
const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles")
const { getDeployedAppID } = require("@budibase/auth/db")
function getAppRole(appId, user) {
if (!user.roles) {
@ -95,6 +96,8 @@ exports.deleteGlobalUser = async (ctx, globalId) => {
}
exports.getGlobalUsers = async (ctx, appId = null, globalId = null) => {
// always use the deployed app
appId = getDeployedAppID(appId)
const endpoint = globalId
? `/api/admin/users/${globalId}`
: `/api/admin/users`
@ -119,9 +122,14 @@ exports.saveGlobalUser = async (ctx, appId, body) => {
const globalUser = body._id
? await exports.getGlobalUsers(ctx, appId, body._id)
: {}
const roles = globalUser.roles || {}
const preRoles = globalUser.roles || {}
if (body.roleId) {
roles[appId] = body.roleId
preRoles[appId] = body.roleId
}
// make sure no dev app IDs in roles
const roles = {}
for (let [appId, roleId] of Object.entries(preRoles)) {
roles[getDeployedAppID(appId)] = roleId
}
const endpoint = `/api/admin/users`
const reqCfg = {

View file

@ -1,24 +1,37 @@
const { getAllRoles } = require("@budibase/auth/roles")
const { getAllApps } = require("@budibase/auth/db")
const { getAllApps, getDeployedAppID, DocumentTypes } = require("@budibase/auth/db")
const CouchDB = require("../../../db")
exports.fetch = async ctx => {
// always use the dev apps as they'll be most up to date (true)
const apps = await getAllApps(true)
const promises = []
for (let app of apps) {
// use dev app IDs
promises.push(getAllRoles(app._id))
}
const roles = await Promise.all(promises)
const response = {}
for (let app of apps) {
response[app._id] = roles.shift()
const deployedAppId = getDeployedAppID(app._id)
response[deployedAppId] = {
roles: roles.shift(),
name: app.name,
version: app.version,
url: app.url,
}
}
ctx.body = response
}
exports.find = async ctx => {
const appId = ctx.params.appId
const db = new CouchDB(appId)
const app = await db.get(DocumentTypes.APP_METADATA)
ctx.body = {
roles: await getAllRoles(appId),
name: app.name,
version: app.version,
url: app.url,
}
}