Merge pull request #4332 from Budibase/fix/various-user-fixes

Various fixes for RBAC and user administration
This commit is contained in:
Michael Drury 2022-02-07 10:44:08 +00:00 committed by GitHub
commit ca209ad3ff
4 changed files with 40 additions and 39 deletions

View File

@ -146,8 +146,9 @@ exports.getRole = async roleId => {
* Simple function to get all the roles based on the top level user role ID. * Simple function to get all the roles based on the top level user role ID.
*/ */
async function getAllUserRoles(userRoleId) { async function getAllUserRoles(userRoleId) {
if (!userRoleId) { // admins have access to all roles
return [BUILTIN_IDS.BASIC] if (userRoleId === BUILTIN_IDS.ADMIN) {
return exports.getAllRoles()
} }
let currentRole = await exports.getRole(userRoleId) let currentRole = await exports.getRole(userRoleId)
let roles = currentRole ? [currentRole] : [] let roles = currentRole ? [currentRole] : []

View File

@ -256,7 +256,7 @@ exports.saveUser = async (
exports.platformLogout = async ({ ctx, userId, keepActiveSession }) => { exports.platformLogout = async ({ ctx, userId, keepActiveSession }) => {
if (!ctx) throw new Error("Koa context must be supplied to logout.") if (!ctx) throw new Error("Koa context must be supplied to logout.")
const currentSession = this.getCookie(ctx, Cookies.Auth) const currentSession = exports.getCookie(ctx, Cookies.Auth)
let sessions = await getUserSessions(userId) let sessions = await getUserSessions(userId)
if (keepActiveSession) { if (keepActiveSession) {
@ -265,8 +265,8 @@ exports.platformLogout = async ({ ctx, userId, keepActiveSession }) => {
) )
} else { } else {
// clear cookies // clear cookies
this.clearCookie(ctx, Cookies.Auth) exports.clearCookie(ctx, Cookies.Auth)
this.clearCookie(ctx, Cookies.CurrentApp) exports.clearCookie(ctx, Cookies.CurrentApp)
} }
await invalidateSessions( await invalidateSessions(

View File

@ -16,7 +16,7 @@ const { clientLibraryPath } = require("../../../utilities")
const { upload } = require("../../../utilities/fileSystem") const { upload } = require("../../../utilities/fileSystem")
const { attachmentsRelativeURL } = require("../../../utilities") const { attachmentsRelativeURL } = require("../../../utilities")
const { DocumentTypes } = require("../../../db/utils") const { DocumentTypes } = require("../../../db/utils")
const { getAppDB } = require("@budibase/backend-core/context") const { getAppDB, updateAppId } = require("@budibase/backend-core/context")
const AWS = require("aws-sdk") const AWS = require("aws-sdk")
const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1" const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1"
@ -49,11 +49,9 @@ async function getAppIdFromUrl(ctx) {
a => a.url && a.url.toLowerCase() === possibleAppUrl a => a.url && a.url.toLowerCase() === possibleAppUrl
)[0] )[0]
if (app && app.appId) { const appId = app && app.appId ? app.appId : ctx.params.appId
return app.appId updateAppId(appId)
} else { return appId
return ctx.params.appId
}
} }
exports.serveBuilder = async function (ctx) { exports.serveBuilder = async function (ctx) {

View File

@ -14,7 +14,7 @@ const {
dbExists, dbExists,
} = require("@budibase/backend-core/db") } = require("@budibase/backend-core/db")
const { UserStatus } = require("@budibase/backend-core/constants") const { UserStatus } = require("@budibase/backend-core/constants")
const { getAppDB } = require("@budibase/backend-core/context") const { getAppDB, doInAppContext } = require("@budibase/backend-core/context")
async function rawMetadata() { async function rawMetadata() {
const db = getAppDB() const db = getAppDB()
@ -105,6 +105,7 @@ exports.syncUser = async function (ctx) {
if (!(await dbExists(appId))) { if (!(await dbExists(appId))) {
continue continue
} }
await doInAppContext(appId, async () => {
const db = getAppDB() const db = getAppDB()
const metadataId = generateUserMetadataID(userId) const metadataId = generateUserMetadataID(userId)
let metadata let metadata
@ -112,7 +113,7 @@ exports.syncUser = async function (ctx) {
metadata = await db.get(metadataId) metadata = await db.get(metadataId)
} catch (err) { } catch (err) {
if (deleting) { if (deleting) {
continue return
} }
metadata = { metadata = {
tableId: InternalTables.USER_METADATA, tableId: InternalTables.USER_METADATA,
@ -133,6 +134,7 @@ exports.syncUser = async function (ctx) {
if (combined) { if (combined) {
await db.put(combined) await db.put(combined)
} }
})
} }
} }
ctx.body = { ctx.body = {