Fixing some issues with the ctx.user, this was previously filled in by the old auth middleware.
This commit is contained in:
parent
42ed66703a
commit
7e6855262b
|
@ -159,7 +159,6 @@ exports.create = async function(ctx) {
|
||||||
|
|
||||||
const url = await getAppUrlIfNotInUse(ctx)
|
const url = await getAppUrlIfNotInUse(ctx)
|
||||||
const appId = instance._id
|
const appId = instance._id
|
||||||
const version = packageJson.version
|
|
||||||
const newApplication = {
|
const newApplication = {
|
||||||
_id: appId,
|
_id: appId,
|
||||||
type: "app",
|
type: "app",
|
||||||
|
|
|
@ -71,7 +71,8 @@ exports.authenticate = async ctx => {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.fetchSelf = async ctx => {
|
exports.fetchSelf = async ctx => {
|
||||||
const { userId, appId } = ctx.user
|
const appId = ctx.appId
|
||||||
|
const { userId } = ctx.user
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
if (!userId) {
|
if (!userId) {
|
||||||
ctx.body = {}
|
ctx.body = {}
|
||||||
|
|
|
@ -106,15 +106,18 @@ exports.serveComponentLibrary = async function(ctx) {
|
||||||
)
|
)
|
||||||
return send(ctx, "/awsDeploy.js", { root: componentLibraryPath })
|
return send(ctx, "/awsDeploy.js", { root: componentLibraryPath })
|
||||||
}
|
}
|
||||||
|
const db = new CouchDB(appId)
|
||||||
|
const appInfo = await db.get(appId)
|
||||||
|
|
||||||
let componentLib = "componentlibrary"
|
let componentLib = "componentlibrary"
|
||||||
if (ctx.user.version) {
|
if (appInfo && appInfo.version) {
|
||||||
componentLib += `-${ctx.user.version}`
|
componentLib += `-${appInfo.version}`
|
||||||
} else {
|
} else {
|
||||||
componentLib += `-${COMP_LIB_BASE_APP_VERSION}`
|
componentLib += `-${COMP_LIB_BASE_APP_VERSION}`
|
||||||
}
|
}
|
||||||
const S3_URL = encodeURI(
|
const S3_URL = encodeURI(
|
||||||
join(
|
join(
|
||||||
objectStoreUrl(appId),
|
objectStoreUrl(),
|
||||||
componentLib,
|
componentLib,
|
||||||
ctx.query.library,
|
ctx.query.library,
|
||||||
"dist",
|
"dist",
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const { getAppId, setCookie, getCookie, Cookies } = require("@budibase/auth")
|
const { getAppId, setCookie, getCookie, Cookies } = require("@budibase/auth")
|
||||||
const { getRole } = require("../utilities/security/roles")
|
const { getRole } = require("../utilities/security/roles")
|
||||||
|
const { generateUserMetadataID } = require("../db/utils")
|
||||||
const { getGlobalUsers } = require("../utilities/workerRequests")
|
const { getGlobalUsers } = require("../utilities/workerRequests")
|
||||||
const { BUILTIN_ROLE_IDS } = require("../utilities/security/roles")
|
const { BUILTIN_ROLE_IDS } = require("../utilities/security/roles")
|
||||||
|
|
||||||
|
@ -35,9 +36,14 @@ module.exports = async (ctx, next) => {
|
||||||
if (appId) {
|
if (appId) {
|
||||||
ctx.appId = appId
|
ctx.appId = appId
|
||||||
if (roleId) {
|
if (roleId) {
|
||||||
|
const userId = ctx.user
|
||||||
|
? generateUserMetadataID(ctx.user.email)
|
||||||
|
: undefined
|
||||||
ctx.roleId = roleId
|
ctx.roleId = roleId
|
||||||
ctx.user = {
|
ctx.user = {
|
||||||
...ctx.user,
|
...ctx.user,
|
||||||
|
_id: userId,
|
||||||
|
userId,
|
||||||
role: await getRole(appId, roleId),
|
role: await getRole(appId, roleId),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,7 @@ describe("Current app middleware", () => {
|
||||||
expect(cookieFn).not.toHaveBeenCalled()
|
expect(cookieFn).not.toHaveBeenCalled()
|
||||||
}
|
}
|
||||||
expect(config.ctx.roleId).toEqual("BASIC")
|
expect(config.ctx.roleId).toEqual("BASIC")
|
||||||
|
expect(config.ctx.user.role._id).toEqual("BASIC")
|
||||||
expect(config.ctx.appId).toEqual("app_test")
|
expect(config.ctx.appId).toEqual("app_test")
|
||||||
expect(config.next).toHaveBeenCalled()
|
expect(config.next).toHaveBeenCalled()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue