bugfix: escape destroyed objects on workers (#9719)
# This PR - Fixes #9358 @FelixMalfait please check this workaround --------- Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { OnDatabaseBatchEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-batch-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
import { ObjectRecordCreateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-create.event';
|
||||
import { ObjectRecordUpdateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-update.event';
|
||||
import { objectRecordChangedProperties as objectRecordUpdateEventChangedProperties } from 'src/engine/core-modules/event-emitter/utils/object-record-changed-properties.util';
|
||||
@ -16,8 +18,6 @@ import {
|
||||
MessageParticipantUnmatchParticipantJobData,
|
||||
} from 'src/modules/messaging/message-participant-manager/jobs/message-participant-unmatch-participant.job';
|
||||
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
|
||||
import { OnDatabaseBatchEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-batch-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class MessageParticipantPersonListener {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { ObjectRecordBaseEvent } from 'src/engine/core-modules/event-emitter/types/object-record.base.event';
|
||||
import { ObjectRecordEvent } from 'src/engine/core-modules/event-emitter/types/object-record-event.event';
|
||||
import { Process } from 'src/engine/core-modules/message-queue/decorators/process.decorator';
|
||||
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
@ -20,7 +20,7 @@ export class CreateAuditLogFromInternalEvent {
|
||||
|
||||
@Process(CreateAuditLogFromInternalEvent.name)
|
||||
async handle(
|
||||
workspaceEventBatch: WorkspaceEventBatch<ObjectRecordBaseEvent>,
|
||||
workspaceEventBatch: WorkspaceEventBatch<ObjectRecordEvent>,
|
||||
): Promise<void> {
|
||||
for (const eventData of workspaceEventBatch.events) {
|
||||
let workspaceMemberId: string | null = null;
|
||||
@ -34,16 +34,14 @@ export class CreateAuditLogFromInternalEvent {
|
||||
workspaceMemberId = workspaceMember.id;
|
||||
}
|
||||
|
||||
if (eventData.properties.diff) {
|
||||
// we remove "before" and "after" property for a cleaner/slimmer event payload
|
||||
eventData.properties = {
|
||||
diff: eventData.properties.diff,
|
||||
};
|
||||
}
|
||||
|
||||
await this.auditLogRepository.insert(
|
||||
workspaceEventBatch.name,
|
||||
eventData.properties,
|
||||
'diff' in eventData.properties
|
||||
? {
|
||||
// we remove "before" and "after" property for a cleaner/slimmer event payload
|
||||
diff: eventData.properties.diff,
|
||||
}
|
||||
: eventData.properties,
|
||||
workspaceMemberId,
|
||||
workspaceEventBatch.name.split('.')[0],
|
||||
eventData.objectMetadata.id,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { ObjectRecordBaseEvent } from 'src/engine/core-modules/event-emitter/types/object-record.base.event';
|
||||
import { ObjectRecordNonDestructiveEvent } from 'src/engine/core-modules/event-emitter/types/object-record-non-destructive-event';
|
||||
import { Process } from 'src/engine/core-modules/message-queue/decorators/process.decorator';
|
||||
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
@ -7,7 +7,6 @@ import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/wo
|
||||
import { TimelineActivityService } from 'src/modules/timeline/services/timeline-activity.service';
|
||||
import { WorkspaceMemberRepository } from 'src/modules/workspace-member/repositories/workspace-member.repository';
|
||||
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
|
||||
import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity';
|
||||
|
||||
@Processor(MessageQueue.entityEventsToDbQueue)
|
||||
export class UpsertTimelineActivityFromInternalEvent {
|
||||
@ -19,9 +18,7 @@ export class UpsertTimelineActivityFromInternalEvent {
|
||||
|
||||
@Process(UpsertTimelineActivityFromInternalEvent.name)
|
||||
async handle(
|
||||
workspaceEventBatch: WorkspaceEventBatch<
|
||||
ObjectRecordBaseEvent<TimelineActivityWorkspaceEntity>
|
||||
>,
|
||||
workspaceEventBatch: WorkspaceEventBatch<ObjectRecordNonDestructiveEvent>,
|
||||
): Promise<void> {
|
||||
for (const eventData of workspaceEventBatch.events) {
|
||||
if (eventData.userId) {
|
||||
@ -33,13 +30,6 @@ export class UpsertTimelineActivityFromInternalEvent {
|
||||
eventData.workspaceMemberId = workspaceMember.id;
|
||||
}
|
||||
|
||||
if (eventData.properties.diff) {
|
||||
// we remove "before" and "after" property for a cleaner/slimmer event payload
|
||||
eventData.properties = {
|
||||
diff: eventData.properties.diff,
|
||||
};
|
||||
}
|
||||
|
||||
// Temporary
|
||||
// We ignore every that is not a LinkedObject or a Business Object
|
||||
if (
|
||||
@ -51,7 +41,16 @@ export class UpsertTimelineActivityFromInternalEvent {
|
||||
}
|
||||
|
||||
await this.timelineActivityService.upsertEvent({
|
||||
event: eventData,
|
||||
event:
|
||||
// we remove "before" and "after" property for a cleaner/slimmer event payload
|
||||
'diff' in eventData.properties && eventData.properties.diff
|
||||
? {
|
||||
...eventData,
|
||||
properties: {
|
||||
diff: eventData.properties.diff,
|
||||
},
|
||||
}
|
||||
: eventData,
|
||||
eventName: workspaceEventBatch.name,
|
||||
workspaceId: workspaceEventBatch.workspaceId,
|
||||
});
|
||||
|
||||
@ -1,19 +1,20 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { ObjectRecordNonDestructiveEvent } from 'src/engine/core-modules/event-emitter/types/object-record-non-destructive-event';
|
||||
import { ObjectRecordBaseEvent } from 'src/engine/core-modules/event-emitter/types/object-record.base.event';
|
||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
|
||||
import { TimelineActivityRepository } from 'src/modules/timeline/repositiories/timeline-activity.repository';
|
||||
import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity';
|
||||
|
||||
type TimelineActivity =
|
||||
ObjectRecordBaseEvent<TimelineActivityWorkspaceEntity> & {
|
||||
name: string;
|
||||
objectName?: string;
|
||||
linkedRecordCachedName?: string;
|
||||
linkedRecordId?: string;
|
||||
linkedObjectMetadataId?: string;
|
||||
};
|
||||
type TimelineActivity = Omit<ObjectRecordNonDestructiveEvent, 'properties'> & {
|
||||
name: string;
|
||||
objectName?: string;
|
||||
linkedRecordCachedName?: string;
|
||||
linkedRecordId?: string;
|
||||
linkedObjectMetadataId?: string;
|
||||
properties: Record<string, any>; // more relaxed conditions than for internal events
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class TimelineActivityService {
|
||||
@ -33,7 +34,7 @@ export class TimelineActivityService {
|
||||
eventName,
|
||||
workspaceId,
|
||||
}: {
|
||||
event: ObjectRecordBaseEvent<TimelineActivityWorkspaceEntity>;
|
||||
event: ObjectRecordBaseEvent;
|
||||
eventName: string;
|
||||
workspaceId: string;
|
||||
}) {
|
||||
@ -65,7 +66,7 @@ export class TimelineActivityService {
|
||||
workspaceId,
|
||||
eventName,
|
||||
}: {
|
||||
event: ObjectRecordBaseEvent<TimelineActivityWorkspaceEntity>;
|
||||
event: ObjectRecordBaseEvent;
|
||||
workspaceId: string;
|
||||
eventName: string;
|
||||
}): Promise<TimelineActivity[] | undefined> {
|
||||
@ -78,7 +79,10 @@ export class TimelineActivityService {
|
||||
|
||||
// 2 timelines, one for the linked object and one for the task/note
|
||||
if (linkedTimelineActivities && linkedTimelineActivities?.length > 0)
|
||||
return [...linkedTimelineActivities, { ...event, name: eventName }];
|
||||
return [
|
||||
...linkedTimelineActivities,
|
||||
{ ...event, name: eventName },
|
||||
] satisfies TimelineActivity[];
|
||||
}
|
||||
|
||||
if (
|
||||
@ -93,7 +97,7 @@ export class TimelineActivityService {
|
||||
});
|
||||
}
|
||||
|
||||
return [{ ...event, name: eventName }];
|
||||
return [{ ...event, name: eventName }] satisfies TimelineActivity[];
|
||||
}
|
||||
|
||||
private async getLinkedTimelineActivities({
|
||||
@ -101,7 +105,7 @@ export class TimelineActivityService {
|
||||
workspaceId,
|
||||
eventName,
|
||||
}: {
|
||||
event: ObjectRecordBaseEvent<TimelineActivityWorkspaceEntity>;
|
||||
event: ObjectRecordBaseEvent;
|
||||
workspaceId: string;
|
||||
eventName: string;
|
||||
}): Promise<TimelineActivity[] | undefined> {
|
||||
@ -146,7 +150,7 @@ export class TimelineActivityService {
|
||||
eventName,
|
||||
workspaceId,
|
||||
}: {
|
||||
event: ObjectRecordBaseEvent<TimelineActivityWorkspaceEntity>;
|
||||
event: ObjectRecordBaseEvent;
|
||||
dataSourceSchema: string;
|
||||
activityType: string;
|
||||
eventName: string;
|
||||
@ -195,7 +199,7 @@ export class TimelineActivityService {
|
||||
linkedRecordCachedName: activity[0].title,
|
||||
linkedRecordId: activity[0].id,
|
||||
linkedObjectMetadataId: event.objectMetadata.id,
|
||||
} as TimelineActivity;
|
||||
} satisfies TimelineActivity;
|
||||
})
|
||||
.filter((event): event is TimelineActivity => event !== undefined);
|
||||
}
|
||||
@ -207,7 +211,7 @@ export class TimelineActivityService {
|
||||
eventName,
|
||||
workspaceId,
|
||||
}: {
|
||||
event: ObjectRecordBaseEvent<TimelineActivityWorkspaceEntity>;
|
||||
event: ObjectRecordBaseEvent;
|
||||
dataSourceSchema: string;
|
||||
activityType: string;
|
||||
eventName: string;
|
||||
@ -258,7 +262,7 @@ export class TimelineActivityService {
|
||||
linkedRecordCachedName: activity[0].title,
|
||||
linkedRecordId: activity[0].id,
|
||||
linkedObjectMetadataId: activityObjectMetadataId,
|
||||
} as TimelineActivity,
|
||||
} satisfies TimelineActivity,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,19 +2,19 @@ import { Logger } from '@nestjs/common';
|
||||
|
||||
import { ArrayContains } from 'typeorm';
|
||||
|
||||
import { ObjectRecordEvent } from 'src/engine/core-modules/event-emitter/types/object-record-event.event';
|
||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||
import { Process } from 'src/engine/core-modules/message-queue/decorators/process.decorator';
|
||||
import { Processor } from 'src/engine/core-modules/message-queue/decorators/processor.decorator';
|
||||
import { MessageQueue } from 'src/engine/core-modules/message-queue/message-queue.constants';
|
||||
import { MessageQueueService } from 'src/engine/core-modules/message-queue/services/message-queue.service';
|
||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||
import { WebhookWorkspaceEntity } from 'src/modules/webhook/standard-objects/webhook.workspace-entity';
|
||||
import { ObjectRecordBaseEvent } from 'src/engine/core-modules/event-emitter/types/object-record.base.event';
|
||||
import { WorkspaceEventBatch } from 'src/engine/workspace-event-emitter/types/workspace-event.type';
|
||||
import {
|
||||
CallWebhookJob,
|
||||
CallWebhookJobData,
|
||||
} from 'src/modules/webhook/jobs/call-webhook.job';
|
||||
import { WebhookWorkspaceEntity } from 'src/modules/webhook/standard-objects/webhook.workspace-entity';
|
||||
import { removeSecretFromWebhookRecord } from 'src/utils/remove-secret-from-webhook-record';
|
||||
|
||||
@Processor(MessageQueue.webhookQueue)
|
||||
@ -29,7 +29,7 @@ export class CallWebhookJobsJob {
|
||||
|
||||
@Process(CallWebhookJobsJob.name)
|
||||
async handle(
|
||||
workspaceEventBatch: WorkspaceEventBatch<ObjectRecordBaseEvent>,
|
||||
workspaceEventBatch: WorkspaceEventBatch<ObjectRecordEvent>,
|
||||
): Promise<void> {
|
||||
// If you change that function, double check it does not break Zapier
|
||||
// trigger in packages/twenty-zapier/src/triggers/trigger_record.ts
|
||||
@ -60,8 +60,16 @@ export class CallWebhookJobsJob {
|
||||
nameSingular: eventData.objectMetadata.nameSingular,
|
||||
};
|
||||
const workspaceId = workspaceEventBatch.workspaceId;
|
||||
const record = eventData.properties.after || eventData.properties.before;
|
||||
const updatedFields = eventData.properties.updatedFields;
|
||||
const record =
|
||||
'after' in eventData.properties
|
||||
? eventData.properties.after
|
||||
: 'before' in eventData.properties
|
||||
? eventData.properties.before
|
||||
: {};
|
||||
const updatedFields =
|
||||
'updatedFields' in eventData.properties
|
||||
? eventData.properties.updatedFields
|
||||
: undefined;
|
||||
|
||||
const isWebhookEvent = nameSingular === 'webhook';
|
||||
const sanitizedRecord = removeSecretFromWebhookRecord(
|
||||
|
||||
Reference in New Issue
Block a user