Fixing an issue with user syncing on save to app DBs as well as fixing a problem with pretty app URLs not setting the app ID correctly into the context.

This commit is contained in:
mike12345567 2022-02-04 17:37:13 +00:00
parent a214400e03
commit 30b6c1f3ca
2 changed files with 34 additions and 34 deletions

View File

@ -16,7 +16,7 @@ const { clientLibraryPath } = require("../../../utilities")
const { upload } = require("../../../utilities/fileSystem")
const { attachmentsRelativeURL } = require("../../../utilities")
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_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
)[0]
if (app && app.appId) {
return app.appId
} else {
return ctx.params.appId
}
const appId = app && app.appId ? app.appId : ctx.params.appId
updateAppId(appId)
return appId
}
exports.serveBuilder = async function (ctx) {

View File

@ -14,7 +14,7 @@ const {
dbExists,
} = require("@budibase/backend-core/db")
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() {
const db = getAppDB()
@ -105,34 +105,36 @@ exports.syncUser = async function (ctx) {
if (!(await dbExists(appId))) {
continue
}
const db = getAppDB()
const metadataId = generateUserMetadataID(userId)
let metadata
try {
metadata = await db.get(metadataId)
} catch (err) {
if (deleting) {
continue
}
metadata = {
tableId: InternalTables.USER_METADATA,
}
}
// assign the roleId for the metadata doc
if (roleId) {
metadata.roleId = roleId
}
let combined = !deleting
? combineMetadataAndUser(user, metadata)
: {
...metadata,
status: UserStatus.INACTIVE,
metadata: BUILTIN_ROLE_IDS.PUBLIC,
await doInAppContext(appId, async () => {
const db = getAppDB()
const metadataId = generateUserMetadataID(userId)
let metadata
try {
metadata = await db.get(metadataId)
} catch (err) {
if (deleting) {
return
}
// if its null then there was no updates required
if (combined) {
await db.put(combined)
}
metadata = {
tableId: InternalTables.USER_METADATA,
}
}
// assign the roleId for the metadata doc
if (roleId) {
metadata.roleId = roleId
}
let combined = !deleting
? combineMetadataAndUser(user, metadata)
: {
...metadata,
status: UserStatus.INACTIVE,
metadata: BUILTIN_ROLE_IDS.PUBLIC,
}
// if its null then there was no updates required
if (combined) {
await db.put(combined)
}
})
}
}
ctx.body = {