mirror of
https://github.com/twentyhq/twenty.git
synced 2024-11-22 03:17:40 +03:00
Fix wrong getAll keyValue method (#8603)
Fixes https://github.com/twentyhq/twenty/issues/8520#issuecomment-2485913500 - Fix the getAll key-value pairs method, as it returns incorrect results. The keyVar values were being affected by keyValues from other workspaces. - Fix missing Sync Email step for existing users joining existing workspace Before, this method returned keyValues that verifies: - workspaceId = user.defaultWorkspaceId - userId = user.id This method now returns: - userId = null && workspaceId = user.defaultWorkspaceId - userId = user.id && workspaceId = null - userId = user.id && workspaceId = user.defaultWorkspaceId ## Result https://github.com/user-attachments/assets/b7563db6-a6a8-4e09-a0c6-c372d7e2b712
This commit is contained in:
parent
96c8673278
commit
0f7ebd3026
@ -209,12 +209,10 @@ export class SignInUpService {
|
|||||||
)
|
)
|
||||||
: await this.userWorkspaceService.addUserToWorkspace(user, workspace);
|
: await this.userWorkspaceService.addUserToWorkspace(user, workspace);
|
||||||
|
|
||||||
if (isNewUser) {
|
await this.activateOnboardingForUser(user, workspace, {
|
||||||
await this.activateOnboardingForNewUser(user, workspace, {
|
firstName,
|
||||||
firstName,
|
lastName,
|
||||||
lastName,
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Object.assign(user, updatedUser);
|
return Object.assign(user, updatedUser);
|
||||||
}
|
}
|
||||||
@ -266,7 +264,7 @@ export class SignInUpService {
|
|||||||
return workspace;
|
return workspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async activateOnboardingForNewUser(
|
private async activateOnboardingForUser(
|
||||||
user: User,
|
user: User,
|
||||||
workspace: Workspace,
|
workspace: Workspace,
|
||||||
{ firstName, lastName }: { firstName: string; lastName: string },
|
{ firstName, lastName }: { firstName: string; lastName: string },
|
||||||
@ -331,20 +329,11 @@ export class SignInUpService {
|
|||||||
|
|
||||||
await this.userWorkspaceService.create(user.id, workspace.id);
|
await this.userWorkspaceService.create(user.id, workspace.id);
|
||||||
|
|
||||||
await this.onboardingService.setOnboardingConnectAccountPending({
|
await this.activateOnboardingForUser(user, workspace, {
|
||||||
userId: user.id,
|
firstName,
|
||||||
workspaceId: workspace.id,
|
lastName,
|
||||||
value: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (firstName === '' && lastName === '') {
|
|
||||||
await this.onboardingService.setOnboardingCreateProfilePending({
|
|
||||||
userId: user.id,
|
|
||||||
workspaceId: workspace.id,
|
|
||||||
value: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.onboardingService.setOnboardingInviteTeamPending({
|
await this.onboardingService.setOnboardingInviteTeamPending({
|
||||||
workspaceId: workspace.id,
|
workspaceId: workspace.id,
|
||||||
value: true,
|
value: true,
|
||||||
|
@ -82,25 +82,42 @@ export class UserVarsService<
|
|||||||
userId?: string;
|
userId?: string;
|
||||||
workspaceId?: string;
|
workspaceId?: string;
|
||||||
}): Promise<Map<Extract<keyof KeyValueTypesMap, string>, any>> {
|
}): Promise<Map<Extract<keyof KeyValueTypesMap, string>, any>> {
|
||||||
const userVarsWorkspaceLevel = await this.keyValuePairService.get({
|
let result: any[] = [];
|
||||||
type: KeyValuePairType.USER_VAR,
|
|
||||||
userId: null,
|
|
||||||
workspaceId,
|
|
||||||
});
|
|
||||||
|
|
||||||
let userVarsUserLevel: any[] = [];
|
|
||||||
|
|
||||||
if (userId) {
|
if (userId) {
|
||||||
userVarsUserLevel = await this.keyValuePairService.get({
|
result = [
|
||||||
type: KeyValuePairType.USER_VAR,
|
...result,
|
||||||
userId,
|
...(await this.keyValuePairService.get({
|
||||||
});
|
type: KeyValuePairType.USER_VAR,
|
||||||
|
userId,
|
||||||
|
workspaceId: null,
|
||||||
|
})),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return mergeUserVars<Extract<keyof KeyValueTypesMap, string>>([
|
if (workspaceId) {
|
||||||
...userVarsWorkspaceLevel,
|
result = [
|
||||||
...userVarsUserLevel,
|
...result,
|
||||||
]);
|
...(await this.keyValuePairService.get({
|
||||||
|
type: KeyValuePairType.USER_VAR,
|
||||||
|
userId: null,
|
||||||
|
workspaceId,
|
||||||
|
})),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (workspaceId && userId) {
|
||||||
|
result = [
|
||||||
|
...result,
|
||||||
|
...(await this.keyValuePairService.get({
|
||||||
|
type: KeyValuePairType.USER_VAR,
|
||||||
|
userId,
|
||||||
|
workspaceId,
|
||||||
|
})),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return mergeUserVars<Extract<keyof KeyValueTypesMap, string>>(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
set<K extends keyof KeyValueTypesMap>({
|
set<K extends keyof KeyValueTypesMap>({
|
||||||
|
@ -25,7 +25,10 @@ import { EnvironmentService } from 'src/engine/core-modules/environment/environm
|
|||||||
import { FileUploadService } from 'src/engine/core-modules/file/file-upload/services/file-upload.service';
|
import { FileUploadService } from 'src/engine/core-modules/file/file-upload/services/file-upload.service';
|
||||||
import { FileService } from 'src/engine/core-modules/file/services/file.service';
|
import { FileService } from 'src/engine/core-modules/file/services/file.service';
|
||||||
import { OnboardingStatus } from 'src/engine/core-modules/onboarding/enums/onboarding-status.enum';
|
import { OnboardingStatus } from 'src/engine/core-modules/onboarding/enums/onboarding-status.enum';
|
||||||
import { OnboardingService } from 'src/engine/core-modules/onboarding/onboarding.service';
|
import {
|
||||||
|
OnboardingService,
|
||||||
|
OnboardingStepKeys,
|
||||||
|
} from 'src/engine/core-modules/onboarding/onboarding.service';
|
||||||
import { WorkspaceMember } from 'src/engine/core-modules/user/dtos/workspace-member.dto';
|
import { WorkspaceMember } from 'src/engine/core-modules/user/dtos/workspace-member.dto';
|
||||||
import { UserService } from 'src/engine/core-modules/user/services/user.service';
|
import { UserService } from 'src/engine/core-modules/user/services/user.service';
|
||||||
import { UserVarsService } from 'src/engine/core-modules/user/user-vars/services/user-vars.service';
|
import { UserVarsService } from 'src/engine/core-modules/user/user-vars/services/user-vars.service';
|
||||||
@ -36,6 +39,7 @@ import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorat
|
|||||||
import { DemoEnvGuard } from 'src/engine/guards/demo.env.guard';
|
import { DemoEnvGuard } from 'src/engine/guards/demo.env.guard';
|
||||||
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
||||||
import { streamToBuffer } from 'src/utils/stream-to-buffer';
|
import { streamToBuffer } from 'src/utils/stream-to-buffer';
|
||||||
|
import { AccountsToReconnectKeys } from 'src/modules/connected-account/types/accounts-to-reconnect-key-value.type';
|
||||||
|
|
||||||
const getHMACKey = (email?: string, key?: string | null) => {
|
const getHMACKey = (email?: string, key?: string | null) => {
|
||||||
if (!email || !key) return null;
|
if (!email || !key) return null;
|
||||||
@ -75,20 +79,17 @@ export class UserResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ResolveField(() => GraphQLJSONObject)
|
@ResolveField(() => GraphQLJSONObject)
|
||||||
async userVars(
|
async userVars(@Parent() user: User): Promise<Record<string, any>> {
|
||||||
@Parent() user: User,
|
|
||||||
@AuthWorkspace() workspace: Workspace,
|
|
||||||
): Promise<Record<string, any>> {
|
|
||||||
const userVars = await this.userVarService.getAll({
|
const userVars = await this.userVarService.getAll({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
workspaceId: workspace?.id ?? user.defaultWorkspaceId,
|
workspaceId: user.defaultWorkspaceId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const userVarAllowList = [
|
const userVarAllowList = [
|
||||||
'SYNC_EMAIL_ONBOARDING_STEP',
|
OnboardingStepKeys.ONBOARDING_CONNECT_ACCOUNT_PENDING,
|
||||||
'ACCOUNTS_TO_RECONNECT_INSUFFICIENT_PERMISSIONS',
|
AccountsToReconnectKeys.ACCOUNTS_TO_RECONNECT_INSUFFICIENT_PERMISSIONS,
|
||||||
'ACCOUNTS_TO_RECONNECT_EMAIL_ALIASES',
|
AccountsToReconnectKeys.ACCOUNTS_TO_RECONNECT_EMAIL_ALIASES,
|
||||||
];
|
] as string[];
|
||||||
|
|
||||||
const filteredMap = new Map(
|
const filteredMap = new Map(
|
||||||
[...userVars].filter(([key]) => userVarAllowList.includes(key)),
|
[...userVars].filter(([key]) => userVarAllowList.includes(key)),
|
||||||
|
Loading…
Reference in New Issue
Block a user