1
0
Fork 0
mirror of synced 2024-07-07 23:35:49 +12:00

Fixing two issues which were blocking previews, one the user was no longer being updated as an admin (when first building/creating an app) and two, role was not being carried across from global user properly.

This commit is contained in:
mike12345567 2021-05-13 18:10:09 +01:00
parent 51bdbb7878
commit 74e6fdddb0
2 changed files with 6 additions and 4 deletions

View file

@ -5,7 +5,7 @@ const {
getGlobalIDFromUserMetadataID,
} = require("../../db/utils")
const { InternalTables } = require("../../db/utils")
const { getRole } = require("../../utilities/security/roles")
const { getRole, BUILTIN_ROLE_IDS } = require("../../utilities/security/roles")
const {
getGlobalUsers,
saveGlobalUser,
@ -73,6 +73,9 @@ exports.createMetadata = async function (ctx) {
exports.updateSelfMetadata = async function (ctx) {
// overwrite the ID with current users
ctx.request.body._id = ctx.user._id
if (ctx.user.builder && ctx.user.builder.global) {
ctx.request.body.roleId = BUILTIN_ROLE_IDS.ADMIN
}
// make sure no stale rev
delete ctx.request.body._rev
await exports.updateMetadata(ctx)

View file

@ -31,9 +31,8 @@ module.exports = async (ctx, next) => {
const globalUser = await getGlobalUsers(ctx, requestAppId, ctx.user._id)
updateCookie = true
appId = requestAppId
if (globalUser.roles && globalUser.roles[requestAppId]) {
roleId = globalUser.roles[requestAppId]
}
// retrieving global user gets the right role
roleId = globalUser.roleId
} else if (appCookie != null) {
appId = appCookie.appId
roleId = appCookie.roleId || BUILTIN_ROLE_IDS.PUBLIC