diff --git a/packages/twenty-server/src/engine/core-modules/auth/auth.resolver.ts b/packages/twenty-server/src/engine/core-modules/auth/auth.resolver.ts index 9b360b5703..23989431fc 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/auth.resolver.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/auth.resolver.ts @@ -707,7 +707,7 @@ export class AuthResolver { const hasServerLevelImpersonatePermission = impersonatorUserWorkspace.user.canImpersonate === true && - impersonatorUserWorkspace.workspace.allowImpersonation === true; + toImpersonateUserWorkspace.workspace.allowImpersonation === true; if (isServerLevelImpersonation) { if (!hasServerLevelImpersonatePermission) { diff --git a/packages/twenty-server/src/engine/core-modules/auth/strategies/jwt.auth.strategy.ts b/packages/twenty-server/src/engine/core-modules/auth/strategies/jwt.auth.strategy.ts index e8fc233d9c..f3e997ad01 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/strategies/jwt.auth.strategy.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/strategies/jwt.auth.strategy.ts @@ -124,10 +124,7 @@ export class JwtAuthStrategy extends PassportStrategy(Strategy, 'jwt') { } if (payload.isImpersonating === true) { - context.impersonationContext = await this.validateImpersonation( - payload, - workspace, - ); + context.impersonationContext = await this.validateImpersonation(payload); } const userId = payload.sub ?? payload.userId; @@ -179,10 +176,7 @@ export class JwtAuthStrategy extends PassportStrategy(Strategy, 'jwt') { return context; } - private async validateImpersonation( - payload: AccessTokenJwtPayload, - workspace: Workspace, - ) { + private async validateImpersonation(payload: AccessTokenJwtPayload) { // Validate required impersonation fields if ( !payload.impersonatorUserWorkspaceId || @@ -239,7 +233,7 @@ export class JwtAuthStrategy extends PassportStrategy(Strategy, 'jwt') { const hasServerLevelImpersonatePermission = impersonatorUserWorkspace.user.canImpersonate === true && - workspace.allowImpersonation === true; + impersonatedUserWorkspace.workspace.allowImpersonation === true; if (isServerLevelImpersonation) { if (!hasServerLevelImpersonatePermission) diff --git a/packages/twenty-server/src/engine/core-modules/impersonation/services/impersonation.service.ts b/packages/twenty-server/src/engine/core-modules/impersonation/services/impersonation.service.ts index 78efe64670..29587d27ed 100644 --- a/packages/twenty-server/src/engine/core-modules/impersonation/services/impersonation.service.ts +++ b/packages/twenty-server/src/engine/core-modules/impersonation/services/impersonation.service.ts @@ -69,7 +69,7 @@ export class ImpersonationService { const hasServerLevelImpersonatePermission = impersonatorUserWorkspace.user.canImpersonate === true && - impersonatorUserWorkspace.workspace.allowImpersonation === true; + toImpersonateUserWorkspace.workspace.allowImpersonation === true; if (isServerLevelImpersonation) { if (!hasServerLevelImpersonatePermission) {