The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix server level impersonation (#14909)
Etiennec1671c6ff622
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.tsindex 9b360b57030..23989431fc5 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.tsindex e8fc233d9c7..f3e997ad015 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 fieldsif (!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.tsindex 78efe64670a..29587d27edb 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) {