Updating role system to never think about the dev app.
This commit is contained in:
parent
b416207292
commit
277ceb3ad1
|
@ -137,6 +137,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).
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -1,17 +1,24 @@
|
|||
const { getAllRoles } = require("@budibase/auth/roles")
|
||||
const { getAllApps } = require("@budibase/auth/db")
|
||||
const { getAllApps, getDeployedAppID } = require("@budibase/auth/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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue