From 97970043f1f35cd82a38a2e924fae10fc641f76d Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 3 Jan 2025 15:16:12 +0000 Subject: [PATCH] Fix global self response type --- .../worker/src/api/controllers/global/self.ts | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/worker/src/api/controllers/global/self.ts b/packages/worker/src/api/controllers/global/self.ts index f8488f526b..3464bff88f 100644 --- a/packages/worker/src/api/controllers/global/self.ts +++ b/packages/worker/src/api/controllers/global/self.ts @@ -84,15 +84,15 @@ export async function fetchAPIKey(ctx: UserCtx) { } /** - * 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) { if (!ctx.user) { @@ -108,13 +108,19 @@ export async function getSelf(ctx: UserCtx) { // 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[]) => {