Skip to content

The open alternative to Salesforce, designed for AI.

Refuse to send a campaign whose list is in the trash (#28112)

neo77365029e42af29
diff --git a/packages/twenty-server/src/modules/emailing/services/message-campaign.service.ts b/packages/twenty-server/src/modules/emailing/services/message-campaign.service.ts
index a956b832040..e730c428d7f 100644
--- a/packages/twenty-server/src/modules/emailing/services/message-campaign.service.ts
+++ b/packages/twenty-server/src/modules/emailing/services/message-campaign.service.ts
@@ -1,5 +1,6 @@
import { Injectable } from '@nestjs/common';
+import { msg } from '@lingui/core/macro';
import { isNonEmptyString } from '@sniptt/guards';
import { MessageCampaignStatus } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
@@ -344,6 +345,7 @@ export class MessageCampaignService {
const campaign = await campaignRepository.findOne({
where: { id: campaignId },
+ relations: { list: true },
});
if (!isDefined(campaign)) {
@@ -353,6 +355,20 @@ export class MessageCampaignService {
);
}
+ const isListInTrash =
+ isDefined(campaign.listId) &&
+ (!isDefined(campaign.list) || isDefined(campaign.list.deletedAt));
+
+ if (isListInTrash) {
+ throw new EmailingDomainException(
+ `Campaign ${campaignId} is not sendable: list ${campaign.listId} is in the trash`,
+ EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_NOT_SENDABLE,
+ {
+ userFriendlyMessage: msg`This campaign's list is in the trash. Restore it or pick another list in the To field.`,
+ },
+ );
+ }
+
const sendableCampaign = sendableCampaignSchema.safeParse(campaign);
if (!sendableCampaign.success) {