The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Only let paying customers send or schedule campaigns (#26486)
neo773964199914006
diff --git a/packages/twenty-server/src/engine/core-modules/emailing-domain/exceptions/emailing-domain.exception.ts b/packages/twenty-server/src/engine/core-modules/emailing-domain/exceptions/emailing-domain.exception.tsindex 0940676ab3b..beb44b1f437 100644--- a/packages/twenty-server/src/engine/core-modules/emailing-domain/exceptions/emailing-domain.exception.ts+++ b/packages/twenty-server/src/engine/core-modules/emailing-domain/exceptions/emailing-domain.exception.ts@@ -15,6 +15,7 @@ export enum EmailingDomainExceptionCode {MESSAGE_CAMPAIGN_INSUFFICIENT_CREDITS = 'MESSAGE_CAMPAIGN_INSUFFICIENT_CREDITS',MESSAGE_CAMPAIGN_SUBSCRIPTION_INACTIVE = 'MESSAGE_CAMPAIGN_SUBSCRIPTION_INACTIVE',MESSAGE_CAMPAIGN_USAGE_LIMIT_REACHED = 'MESSAGE_CAMPAIGN_USAGE_LIMIT_REACHED',+ MESSAGE_CAMPAIGN_REQUIRES_PAID_PLAN = 'MESSAGE_CAMPAIGN_REQUIRES_PAID_PLAN',MESSAGE_CAMPAIGN_NOT_CANCELABLE = 'MESSAGE_CAMPAIGN_NOT_CANCELABLE',MESSAGE_CAMPAIGN_SCHEDULE_NOT_IN_FUTURE = 'MESSAGE_CAMPAIGN_SCHEDULE_NOT_IN_FUTURE',}@@ -41,6 +42,8 @@ const getEmailingDomainExceptionUserFriendlyMessage = (return msg`This campaign cannot be sent while the workspace subscription is inactive.`;case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_USAGE_LIMIT_REACHED:return msg`This campaign is stopped by an email usage limit set on this workspace. Raise the limit or send to a smaller list.`;+ case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_REQUIRES_PAID_PLAN:+ return msg`Sending campaigns is available once your workspace is on a paid plan and has been billed.`;case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_NOT_SENDABLE:return msg`This campaign cannot be sent. It may be missing a sender, subject or recipient list, or it was already sent.`;case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_NOT_CANCELABLE:diff --git a/packages/twenty-server/src/engine/core-modules/emailing-domain/filters/emailing-domain-graphql-api-exception.filter.ts b/packages/twenty-server/src/engine/core-modules/emailing-domain/filters/emailing-domain-graphql-api-exception.filter.tsindex c66f2ceada0..e0fd3890d05 100644--- a/packages/twenty-server/src/engine/core-modules/emailing-domain/filters/emailing-domain-graphql-api-exception.filter.ts+++ b/packages/twenty-server/src/engine/core-modules/emailing-domain/filters/emailing-domain-graphql-api-exception.filter.ts@@ -28,6 +28,7 @@ export class EmailingDomainGraphqlApiExceptionFilter implements ExceptionFiltercase EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_INSUFFICIENT_CREDITS:case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_SUBSCRIPTION_INACTIVE:case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_USAGE_LIMIT_REACHED:+ case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_REQUIRES_PAID_PLAN:case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_NOT_SENDABLE:case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_NOT_CANCELABLE:case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_SCHEDULE_NOT_IN_FUTURE:diff --git a/packages/twenty-server/src/engine/metadata-modules/message-channel/utils/message-channel-graphql-api-exception-handler.util.ts b/packages/twenty-server/src/engine/metadata-modules/message-channel/utils/message-channel-graphql-api-exception-handler.util.tsindex 66b5d6231ea..a4674da001a 100644--- a/packages/twenty-server/src/engine/metadata-modules/message-channel/utils/message-channel-graphql-api-exception-handler.util.ts+++ b/packages/twenty-server/src/engine/metadata-modules/message-channel/utils/message-channel-graphql-api-exception-handler.util.ts@@ -51,6 +51,7 @@ export const messageChannelGraphqlApiExceptionHandler = (error: Error) => {case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_INSUFFICIENT_CREDITS:case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_SUBSCRIPTION_INACTIVE:case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_USAGE_LIMIT_REACHED:+ case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_REQUIRES_PAID_PLAN:case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_NOT_SENDABLE:case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_NOT_CANCELABLE:case EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_SCHEDULE_NOT_IN_FUTURE:diff --git a/packages/twenty-server/src/modules/emailing/resolvers/emailing-send.resolver.ts b/packages/twenty-server/src/modules/emailing/resolvers/emailing-send.resolver.tsindex 8ff2894f412..77b6624fa99 100644--- a/packages/twenty-server/src/modules/emailing/resolvers/emailing-send.resolver.ts+++ b/packages/twenty-server/src/modules/emailing/resolvers/emailing-send.resolver.ts@@ -6,6 +6,7 @@ import { FeatureFlagKey } from 'twenty-shared/types';import { isDefined } from 'twenty-shared/utils';import { MetadataResolver } from 'src/engine/api/graphql/graphql-config/decorators/metadata-resolver.decorator';+import { BillingService } from 'src/engine/core-modules/billing/services/billing.service';import { CampaignAudiencePreviewDTO } from 'src/engine/core-modules/emailing-domain/dtos/campaign-audience-preview.dto';import { CancelMessageCampaignInput } from 'src/engine/core-modules/emailing-domain/dtos/cancel-message-campaign.input';import { CancelMessageCampaignOutputDTO } from 'src/engine/core-modules/emailing-domain/dtos/cancel-message-campaign-output.dto';@@ -17,6 +18,10 @@ import { SendEmailViaDomainOutputDTO } from 'src/engine/core-modules/emailing-doimport { SendMessageCampaignInput } from 'src/engine/core-modules/emailing-domain/dtos/send-message-campaign.input';import { SendMessageCampaignTestInput } from 'src/engine/core-modules/emailing-domain/dtos/send-message-campaign-test.input';import { SendMessageCampaignOutputDTO } from 'src/engine/core-modules/emailing-domain/dtos/send-message-campaign-output.dto';+import {+ EmailingDomainException,+ EmailingDomainExceptionCode,+} from 'src/engine/core-modules/emailing-domain/exceptions/emailing-domain.exception';import { EmailGroupAccessService } from 'src/engine/core-modules/emailing-domain/services/email-group-access.service';import { ResolverValidationPipe } from 'src/engine/core-modules/graphql/pipes/resolver-validation.pipe';import { UsageLimitGraphqlApiExceptionFilter } from 'src/engine/core-modules/usage-limit/filters/usage-limit-graphql-api-exception.filter';@@ -66,6 +71,7 @@ export class EmailingSendResolver {private readonly messageCampaignLifecycleService: MessageCampaignLifecycleService,private readonly emailGroupAccessService: EmailGroupAccessService,private readonly emailBillingService: EmailBillingService,+ private readonly billingService: BillingService,) {}@Mutation(() => SendEmailViaDomainOutputDTO)@@ -107,6 +113,18 @@ export class EmailingSendResolver {@AuthUserWorkspaceId() userWorkspaceId: string,): Promise<SendMessageCampaignOutputDTO> {this.emailGroupAccessService.validateEmailGroupAccessOrThrow();++ const isPayingCustomer = await this.billingService.isPayingCustomer(+ currentWorkspace.id,+ );++ if (!isPayingCustomer) {+ throw new EmailingDomainException(+ `Campaign ${input.campaignId} cannot be sent: workspace ${currentWorkspace.id} is not on a paid plan`,+ EmailingDomainExceptionCode.MESSAGE_CAMPAIGN_REQUIRES_PAID_PLAN,+ );+ }+await this.emailBillingService.validateEmailSendOrThrow({workspaceId: currentWorkspace.id,spenders: { userWorkspaceId },