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:
parent
a214400e03
commit
30b6c1f3ca
|
@ -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) {
|
||||||
|
|
|
@ -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,34 +105,36 @@ exports.syncUser = async function (ctx) {
|
||||||
if (!(await dbExists(appId))) {
|
if (!(await dbExists(appId))) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const db = getAppDB()
|
await doInAppContext(appId, async () => {
|
||||||
const metadataId = generateUserMetadataID(userId)
|
const db = getAppDB()
|
||||||
let metadata
|
const metadataId = generateUserMetadataID(userId)
|
||||||
try {
|
let metadata
|
||||||
metadata = await db.get(metadataId)
|
try {
|
||||||
} catch (err) {
|
metadata = await db.get(metadataId)
|
||||||
if (deleting) {
|
} catch (err) {
|
||||||
continue
|
if (deleting) {
|
||||||
}
|
return
|
||||||
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
|
metadata = {
|
||||||
if (combined) {
|
tableId: InternalTables.USER_METADATA,
|
||||||
await db.put(combined)
|
}
|
||||||
}
|
}
|
||||||
|
// 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 = {
|
ctx.body = {
|
||||||
|
|
Loading…
Reference in New Issue