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:
@ -13,7 +13,6 @@ const baseNote = {
|
||||
},
|
||||
position: 1,
|
||||
title: 'Test',
|
||||
body: 'Test',
|
||||
createdBy: {
|
||||
name: 'Test',
|
||||
source: FieldActorSource.MANUAL,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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',
|
||||
}
|
||||
@ -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` },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -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}`,
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user