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,6 +105,7 @@ exports.syncUser = async function (ctx) {
if (!(await dbExists(appId))) {
continue
}
await doInAppContext(appId, async () => {
const db = getAppDB()
const metadataId = generateUserMetadataID(userId)
let metadata
@ -112,7 +113,7 @@ exports.syncUser = async function (ctx) {
metadata = await db.get(metadataId)
} catch (err) {
if (deleting) {
continue
return
}
metadata = {
tableId: InternalTables.USER_METADATA,
@ -133,6 +134,7 @@ exports.syncUser = async function (ctx) {
if (combined) {
await db.put(combined)
}
})
}
}
ctx.body = {