mirror of https://github.com/Budibase/budibase.git
9 changed files with 116 additions and 64 deletions
@ -0,0 +1,24 @@ |
|||||
|
const { getAllRoles } = require("@budibase/auth/roles") |
||||
|
const { getAllApps } = 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) { |
||||
|
promises.push(getAllRoles(app._id)) |
||||
|
} |
||||
|
const roles = await Promise.all(promises) |
||||
|
const response = {} |
||||
|
for (let app of apps) { |
||||
|
response[app._id] = roles.shift() |
||||
|
} |
||||
|
ctx.body = response |
||||
|
} |
||||
|
|
||||
|
exports.find = async ctx => { |
||||
|
const appId = ctx.params.appId |
||||
|
ctx.body = { |
||||
|
roles: await getAllRoles(appId) |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
const Router = require("@koa/router") |
||||
|
const controller = require("../../controllers/admin/roles") |
||||
|
|
||||
|
const router = Router() |
||||
|
|
||||
|
|
||||
|
router |
||||
|
.get("/api/admin/roles", controller.fetch) |
||||
|
.get("/api/admin/roles/:appId", controller.find) |
||||
|
|
||||
|
module.exports = router |
||||
Loading…
Reference in new issue