Fix global self response type

This commit is contained in:
Andrew Kingston 2025-01-03 15:16:12 +00:00
parent bffdc95305
commit 97970043f1
No known key found for this signature in database
1 changed files with 17 additions and 11 deletions

View File

@ -84,15 +84,15 @@ export async function fetchAPIKey(ctx: UserCtx<void, FetchAPIKeyResponse>) {
}
/**
* Add the attributes that are session based to the current user.
*
*/
const addSessionAttributesToUser = (ctx: any) => {
ctx.body.account = ctx.user.account
ctx.body.license = ctx.user.license
ctx.body.budibaseAccess = !!ctx.user.budibaseAccess
ctx.body.accountPortalAccess = !!ctx.user.accountPortalAccess
ctx.body.csrfToken = ctx.user.csrfToken
}
const getUserSessionAttributes = (ctx: any) => ({
account: ctx.user.account,
license: ctx.user.license,
budibaseAccess: !!ctx.user.budibaseAccess,
accountPortalAccess: !!ctx.user.accountPortalAccess,
csrfToken: ctx.user.csrfToken,
})
export async function getSelf(ctx: UserCtx<void, GetGlobalSelfResponse>) {
if (!ctx.user) {
@ -108,13 +108,19 @@ export async function getSelf(ctx: UserCtx<void, GetGlobalSelfResponse>) {
// get the main body of the user
const user = await userSdk.db.getUser(userId)
ctx.body = await groups.enrichUserRolesFromGroups(user)
const enrichedUser = await groups.enrichUserRolesFromGroups(user)
// add the attributes that are session based to the current user
const sessionAttributes = getUserSessionAttributes(ctx)
// add the feature flags for this tenant
const flags = await features.flags.fetch()
ctx.body.flags = flags
addSessionAttributesToUser(ctx)
ctx.body = {
...enrichedUser,
...sessionAttributes,
flags,
}
}
export const syncAppFavourites = async (processedAppIds: string[]) => {