Remove old body on note and tasks (#13290)

Fixes: https://github.com/twentyhq/twenty/issues/13110

I'm deprecating note.body and task.body to remove confusion between body
and bodyV2

What will be left but should be done later to avoid breaking changes:
- re-add a body field in the graphql API only that points to the same
bodyV2 field in SQL (need to be handled in fields and filter for note
and task)
- (wait some time)
- remove bodyV2 field
This commit is contained in:
Charles Bochet
2025-07-19 11:25:49 +02:00
committed by GitHub
parent 62202af1a9
commit fdc6705a75
23 changed files with 124 additions and 128 deletions

View File

@ -13,7 +13,7 @@ export const createOneActivityOperationSignatureFactory: RecordGqlOperationSigna
createdAt: true,
updatedAt: true,
attachments: true,
body: true,
bodyV2: true,
title: true,
},
}
@ -32,7 +32,7 @@ export const createOneActivityOperationSignatureFactory: RecordGqlOperationSigna
__typename: true,
},
attachments: true,
body: true,
bodyV2: true,
title: true,
status: true,
dueAt: true,

View File

@ -3,6 +3,7 @@ import { ReactNode } from 'react';
import { RecoilRoot } from 'recoil';
import { useActivities } from '@/activities/hooks/useActivities';
import { Task } from '@/activities/types/Task';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
jest.mock('@/activities/hooks/useActivityTargetsForTargetableObjects', () => ({
@ -24,17 +25,20 @@ const mockActivityTarget = {
const mockActivity = {
__typename: 'Task',
companyId: '123',
updatedAt: '2021-08-03T19:20:06.000Z',
createdAt: '2021-08-03T19:20:06.000Z',
status: 'DONE',
reminderAt: '2021-08-03T19:20:06.000Z',
title: 'title',
body: 'body',
dueAt: '2021-08-03T19:20:06.000Z',
assigneeId: '1',
id: '234',
};
bodyV2: {
blocknote: 'My Body',
markdown: 'My Body',
},
assignee: null,
taskTargets: [],
} satisfies Task;
const Wrapper = ({ children }: { children: ReactNode }) => (
<RecoilRoot>{children}</RecoilRoot>

View File

@ -39,7 +39,10 @@ const taskTarget = {
createdAt: '2023-04-26T10:12:42.33625+00:00',
updatedAt: '2023-04-26T10:23:42.33625+00:00',
dueAt: null,
body: '{}',
bodyV2: {
blocknote: '',
markdown: '',
},
title: 'Task title',
assigneeId: null,
__typename: 'Task',
@ -95,7 +98,6 @@ const task = {
createdAt: '2023-04-26T10:12:42.33625+00:00',
updatedAt: '2023-04-26T10:23:42.33625+00:00',
title: 'Task title',
body: '',
bodyV2: {
blocknote: null,
markdown: null,

View File

@ -13,7 +13,7 @@ const toISOStringMock = jest.fn(() => mockedDate);
global.Date.prototype.toISOString = toISOStringMock;
const mockedActivity = {
...pick(mockedTasks[0], ['id', 'title', 'body', 'type', 'status', 'dueAt']),
...pick(mockedTasks[0], ['id', 'title', 'bodyV2', 'type', 'status', 'dueAt']),
updatedAt: mockedDate,
};
@ -56,7 +56,10 @@ const mocks: MockedResponse[] = [
}
}
}
body
bodyV2 {
blocknote
markdown
}
createdAt
dueAt
id

View File

@ -17,7 +17,7 @@ const toISOStringMock = jest.fn(() => mockedDate);
global.Date.prototype.toISOString = toISOStringMock;
const mockedActivity = {
...pick(mockedTasks[0], ['id', 'title', 'body', 'type', 'status', 'dueAt']),
...pick(mockedTasks[0], ['id', 'title', 'bodyV2', 'type', 'status', 'dueAt']),
updatedAt: mockedDate,
};

View File

@ -74,7 +74,6 @@ const mocks: MockedResponse[] = [
}
}
}
body
bodyV2 {
blocknote
markdown
@ -181,7 +180,6 @@ const mocks: MockedResponse[] = [
assignee: null,
assigneeId: '123',
attachments: { edges: [] },
body: 'Test',
bodyV2: {
blocknote: 'Test',
markdown: 'Test',

View File

@ -197,7 +197,6 @@ const UPDATE_ONE_FAVORITE_MUTATION = gql`
id
note {
__typename
body
bodyV2 {
blocknote
markdown
@ -393,7 +392,6 @@ const UPDATE_ONE_FAVORITE_MUTATION = gql`
task {
__typename
assigneeId
body
bodyV2 {
blocknote
markdown
@ -592,7 +590,6 @@ export const mocks = [
id
note {
__typename
body
bodyV2 {
blocknote
markdown
@ -788,7 +785,6 @@ export const mocks = [
task {
__typename
assigneeId
body
bodyV2 {
blocknote
markdown

View File

@ -128,7 +128,6 @@ const mocks: MockedResponse[] = [
id
note {
__typename
body
bodyV2 {
blocknote
markdown
@ -571,7 +570,6 @@ const mocks: MockedResponse[] = [
task {
__typename
assigneeId
body
bodyV2 {
blocknote
markdown

View File

@ -7197,27 +7197,6 @@ export const mockedStandardObjectMetadataQueryResult: ObjectMetadataItemsQuery =
"description": "Task title",
"icon": "IconNotes"
},
{
"__typename": "Field",
"id": "7fd11cd9-16c5-4b29-aa2d-8b4796fc07dd",
"type": "RICH_TEXT",
"name": "body",
"isCustom": false,
"isActive": true,
"isSystem": false,
"isNullable": true,
"isUnique": false,
"createdAt": "2025-06-09T18:53:47.000Z",
"updatedAt": "2025-06-09T18:53:47.000Z",
"defaultValue": null,
"options": null,
"settings": null,
"isLabelSyncedWithName": false,
"relation": null,
"label": "Body (deprecated)",
"description": "Task body",
"icon": "IconFilePencil"
},
{
"__typename": "Field",
"id": "9b83c867-18c1-4c25-bd45-2d3a38ebdbb3",
@ -13000,27 +12979,6 @@ export const mockedStandardObjectMetadataQueryResult: ObjectMetadataItemsQuery =
"description": "Note title",
"icon": "IconNotes"
},
{
"__typename": "Field",
"id": "21285048-5fd7-4d15-bf60-aec6762cf591",
"type": "RICH_TEXT",
"name": "body",
"isCustom": false,
"isActive": true,
"isSystem": false,
"isNullable": true,
"isUnique": false,
"createdAt": "2025-06-09T18:53:47.000Z",
"updatedAt": "2025-06-09T18:53:47.000Z",
"defaultValue": null,
"options": null,
"settings": null,
"isLabelSyncedWithName": false,
"relation": null,
"label": "Body (deprecated)",
"description": "Note body",
"icon": "IconFilePencil"
},
{
"__typename": "Field",
"id": "b44eecda-a7e8-44ff-8db1-4ce2ca80f34c",

View File

@ -2832,7 +2832,6 @@ export const oneSucceededWorkflowRunQueryResult = {
},
'753b124e-f427-44a4-ab08-bacfe9c2f746': {
id: '0455ca41-bae1-4a3a-968c-b268a4e809bb',
body: null,
title: 'Proposal for ',
bodyV2: {
markdown: '',
@ -2968,13 +2967,6 @@ export const oneSucceededWorkflowRunQueryResult = {
value: '123e4567-e89b-12d3-a456-426614174000',
isLeaf: true,
},
body: {
icon: 'IconFilePencil',
type: 'RICH_TEXT',
label: 'Body (deprecated)',
value: 'My rich text',
isLeaf: true,
},
title: {
icon: 'IconNotes',
type: 'TEXT',
@ -4436,7 +4428,6 @@ export const oneSucceededWorkflowRunQueryResult = {
'753b124e-f427-44a4-ab08-bacfe9c2f746': {
result: {
id: '0455ca41-bae1-4a3a-968c-b268a4e809bb',
body: null,
title: 'Proposal for ',
bodyV2: {
markdown: '',
@ -4573,13 +4564,6 @@ export const oneSucceededWorkflowRunQueryResult = {
value: '123e4567-e89b-12d3-a456-426614174000',
isLeaf: true,
},
body: {
icon: 'IconFilePencil',
type: 'RICH_TEXT',
label: 'Body (deprecated)',
value: 'My rich text',
isLeaf: true,
},
title: {
icon: 'IconNotes',
type: 'TEXT',
@ -8889,7 +8873,6 @@ export const oneSucceededWorkflowRunQueryResult = {
'753b124e-f427-44a4-ab08-bacfe9c2f746': {
result: {
id: '0455ca41-bae1-4a3a-968c-b268a4e809bb',
body: null,
title: 'Proposal for ',
bodyV2: {
markdown: '',
@ -9056,13 +9039,6 @@ export const oneSucceededWorkflowRunQueryResult = {
value: '123e4567-e89b-12d3-a456-426614174000',
isLeaf: true,
},
body: {
icon: 'IconFilePencil',
type: 'RICH_TEXT',
label: 'Body (deprecated)',
value: 'My rich text',
isLeaf: true,
},
title: {
icon: 'IconNotes',
type: 'TEXT',

View File

@ -13,7 +13,6 @@ const baseNote = {
},
position: 1,
title: 'Test',
body: 'Test',
createdBy: {
name: 'Test',
source: FieldActorSource.MANUAL,

View File

@ -41,6 +41,7 @@ import { TransientTokenService } from 'src/engine/core-modules/auth/token/servic
import { WorkspaceAgnosticTokenService } from 'src/engine/core-modules/auth/token/services/workspace-agnostic-token.service';
import { JwtTokenTypeEnum } from 'src/engine/core-modules/auth/types/auth-context.type';
import { CaptchaGuard } from 'src/engine/core-modules/captcha/captcha.guard';
import { CaptchaGraphqlApiExceptionFilter } from 'src/engine/core-modules/captcha/filters/captcha-graphql-api-exception.filter';
import { DomainManagerService } from 'src/engine/core-modules/domain-manager/services/domain-manager.service';
import { EmailVerificationExceptionFilter } from 'src/engine/core-modules/email-verification/email-verification-exception-filter.util';
import { EmailVerificationService } from 'src/engine/core-modules/email-verification/services/email-verification.service';
@ -78,6 +79,7 @@ import { AuthService } from './services/auth.service';
@UsePipes(ResolverValidationPipe)
@Resolver()
@UseFilters(
CaptchaGraphqlApiExceptionFilter,
AuthGraphqlApiExceptionFilter,
PermissionsGraphqlApiExceptionFilter,
EmailVerificationExceptionFilter,

View File

@ -0,0 +1,16 @@
import { CustomException } from 'src/utils/custom-exception';
export class CaptchaException extends CustomException {
declare code: CaptchaExceptionCode;
constructor(
message: string,
code: CaptchaExceptionCode,
{ userFriendlyMessage }: { userFriendlyMessage?: string } = {},
) {
super(message, code, userFriendlyMessage);
}
}
export enum CaptchaExceptionCode {
INVALID_CAPTCHA = 'INVALID_CAPTCHA',
}

View File

@ -1,11 +1,12 @@
import {
BadRequestException,
CanActivate,
ExecutionContext,
Injectable,
} from '@nestjs/common';
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { GqlExecutionContext } from '@nestjs/graphql';
import { t } from '@lingui/core/macro';
import {
CaptchaException,
CaptchaExceptionCode,
} from 'src/engine/core-modules/captcha/captcha.exception';
import { CaptchaService } from 'src/engine/core-modules/captcha/captcha.service';
import { MetricsService } from 'src/engine/core-modules/metrics/metrics.service';
import { MetricsKeys } from 'src/engine/core-modules/metrics/types/metrics-keys.type';
@ -33,8 +34,10 @@ export class CaptchaGuard implements CanActivate {
...(result.error ? { attributes: { error: result.error } } : {}),
});
throw new BadRequestException(
throw new CaptchaException(
'Invalid Captcha, please try another device',
CaptchaExceptionCode.INVALID_CAPTCHA,
{ userFriendlyMessage: t`Invalid Captcha, please try another device` },
);
}
}

View File

@ -0,0 +1,11 @@
import { Catch, ExceptionFilter } from '@nestjs/common';
import { CaptchaException } from 'src/engine/core-modules/captcha/captcha.exception';
import { captchaGraphqlApiExceptionHandler } from 'src/engine/core-modules/captcha/utils/captcha-graphql-api-exception-handler.util';
@Catch(CaptchaException)
export class CaptchaGraphqlApiExceptionFilter implements ExceptionFilter {
catch(exception: CaptchaException) {
return captchaGraphqlApiExceptionHandler(exception);
}
}

View File

@ -0,0 +1,20 @@
import {
CaptchaException,
CaptchaExceptionCode,
} from 'src/engine/core-modules/captcha/captcha.exception';
import { UserInputError } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
export const captchaGraphqlApiExceptionHandler = (
exception: CaptchaException,
) => {
switch (exception.code) {
case CaptchaExceptionCode.INVALID_CAPTCHA:
throw new UserInputError(exception);
default: {
const _exhaustiveCheck: never = exception.code;
throw exception;
}
}
};

View File

@ -4,9 +4,8 @@ type NoteDataSeed = {
id: string;
position: number;
title: string;
body: string | null;
bodyV2Blocknote: string | null;
bodyV2Markdown: string | null;
bodyV2Blocknote: string
bodyV2Markdown: string;
createdBySource: string;
createdByWorkspaceMemberId: string;
createdByName: string;
@ -17,7 +16,6 @@ export const NOTE_DATA_SEED_COLUMNS: (keyof NoteDataSeed)[] = [
'id',
'position',
'title',
'body',
'bodyV2Blocknote',
'bodyV2Markdown',
'createdBySource',
@ -145,7 +143,6 @@ const GENERATE_NOTE_SEEDS = (): NoteDataSeed[] => {
id: NOTE_DATA_SEED_IDS[`ID_${INDEX}`],
position: INDEX,
title: TEMPLATE.title,
body: null,
bodyV2Blocknote: JSON.stringify([
{
id: `block-${INDEX}`,
@ -176,7 +173,6 @@ const GENERATE_NOTE_SEEDS = (): NoteDataSeed[] => {
id: NOTE_DATA_SEED_IDS[`ID_${INDEX}`],
position: INDEX,
title: TEMPLATE.title,
body: null,
bodyV2Blocknote: JSON.stringify([
{
id: `block-${INDEX}`,

View File

@ -4,7 +4,8 @@ type TaskDataSeed = {
id: string;
position: number;
title: string;
body: string | null;
bodyV2Blocknote: string;
bodyV2Markdown: string;
status: string;
dueAt: string | null;
assigneeId: string;
@ -17,7 +18,8 @@ export const TASK_DATA_SEED_COLUMNS: (keyof TaskDataSeed)[] = [
'id',
'position',
'title',
'body',
'bodyV2Blocknote',
'bodyV2Markdown',
'status',
'dueAt',
'assigneeId',
@ -188,7 +190,20 @@ const GENERATE_TASK_SEEDS = (): TaskDataSeed[] => {
id: TASK_DATA_SEED_IDS[`ID_${INDEX}`],
position: INDEX,
title: TEMPLATE.title,
body: TEMPLATE.body,
bodyV2Blocknote: JSON.stringify([
{
id: `block-${INDEX}`,
type: 'paragraph',
props: {
textColor: 'default',
backgroundColor: 'default',
textAlignment: 'left',
},
content: [{ type: 'text', text: TEMPLATE.body, styles: {} }],
children: [],
},
]),
bodyV2Markdown: TEMPLATE.body,
status: TEMPLATE.status,
dueAt: FORMAT_DUE_DATE(TEMPLATE.daysFromNow),
assigneeId: GET_RANDOM_ASSIGNEE(),
@ -207,7 +222,20 @@ const GENERATE_TASK_SEEDS = (): TaskDataSeed[] => {
id: TASK_DATA_SEED_IDS[`ID_${INDEX}`],
position: INDEX,
title: TEMPLATE.title,
body: TEMPLATE.body,
bodyV2Blocknote: JSON.stringify([
{
id: `block-${INDEX}`,
type: 'paragraph',
props: {
textColor: 'default',
backgroundColor: 'default',
textAlignment: 'left',
},
content: [{ type: 'text', text: TEMPLATE.body, styles: {} }],
children: [],
},
]),
bodyV2Markdown: TEMPLATE.body,
status: TEMPLATE.status,
dueAt: FORMAT_DUE_DATE(TEMPLATE.daysFromNow),
assigneeId: GET_RANDOM_ASSIGNEE(),

View File

@ -96,7 +96,7 @@ export const tasksAssignedToMeView = (
{
fieldMetadataId:
taskObjectMetadata.fields.find(
(field) => field.standardId === TASK_STANDARD_FIELD_IDS.body,
(field) => field.standardId === TASK_STANDARD_FIELD_IDS.bodyV2,
)?.id ?? '',
position: 7,
isVisible: true,

View File

@ -69,16 +69,6 @@ export class NoteWorkspaceEntity extends BaseWorkspaceEntity {
})
title: string;
@WorkspaceField({
standardId: NOTE_STANDARD_FIELD_IDS.body,
type: FieldMetadataType.RICH_TEXT,
label: msg`Body (deprecated)`,
description: msg`Note body`,
icon: 'IconFilePencil',
})
@WorkspaceIsNullable()
body: string | null;
@WorkspaceField({
standardId: NOTE_STANDARD_FIELD_IDS.bodyV2,
type: FieldMetadataType.RICH_TEXT_V2,

View File

@ -72,16 +72,6 @@ export class TaskWorkspaceEntity extends BaseWorkspaceEntity {
})
title: string;
@WorkspaceField({
standardId: TASK_STANDARD_FIELD_IDS.body,
type: FieldMetadataType.RICH_TEXT,
label: msg`Body (deprecated)`,
description: msg`Task body`,
icon: 'IconFilePencil',
})
@WorkspaceIsNullable()
body: string | null;
@WorkspaceField({
standardId: TASK_STANDARD_FIELD_IDS.bodyV2,
type: FieldMetadataType.RICH_TEXT_V2,

View File

@ -12,7 +12,10 @@ describe('notesResolver (e2e)', () => {
node {
position
title
body
bodyV2 {
markdown
blocknote
}
id
createdAt
updatedAt
@ -46,7 +49,7 @@ describe('notesResolver (e2e)', () => {
expect(notes).toHaveProperty('position');
expect(notes).toHaveProperty('title');
expect(notes).toHaveProperty('body');
expect(notes).toHaveProperty('bodyV2');
expect(notes).toHaveProperty('id');
expect(notes).toHaveProperty('createdAt');
expect(notes).toHaveProperty('updatedAt');

View File

@ -12,7 +12,10 @@ describe('tasksResolver (e2e)', () => {
node {
position
title
body
bodyV2 {
markdown
blocknote
}
dueAt
status
id
@ -49,7 +52,7 @@ describe('tasksResolver (e2e)', () => {
expect(tasks).toHaveProperty('position');
expect(tasks).toHaveProperty('title');
expect(tasks).toHaveProperty('body');
expect(tasks).toHaveProperty('bodyV2');
expect(tasks).toHaveProperty('dueAt');
expect(tasks).toHaveProperty('status');
expect(tasks).toHaveProperty('id');