Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6658 workflows add a first twenty piece email sender #6965

Merged
merged 24 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Sanitize html
  • Loading branch information
martmull committed Sep 10, 2024
commit cb33021530d4e6427ede58a328524fb6ae018298
9 changes: 5 additions & 4 deletions packages/twenty-emails/src/emails/workflow-action.email.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { BaseEmail } from 'src/components/BaseEmail';
import { Title } from 'src/components/Title';
import { MainText } from 'src/components/MainText';
import { CallToAction } from 'src/components/CallToAction';

type WorkflowActionEmailProps = {
mainText?: string;
dangerousHTML?: string;
title?: string;
callToAction?: {
value: string;
href: string;
};
};
export const WorkflowActionEmail = ({
mainText,
dangerousHTML,
title,
callToAction,
}: WorkflowActionEmailProps) => {
return (
<BaseEmail withLogo={false}>
{title && <Title value={title} />}
{mainText && <MainText>{mainText}</MainText>}
{dangerousHTML && (
<div dangerouslySetInnerHTML={{ __html: dangerousHTML }} />
)}
{callToAction && (
<CallToAction value={callToAction.value} href={callToAction.href} />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type BaseSystemActionSettings = BaseWorkflowSettings & {
};

export type WorkflowSystemSendEmailActionSettings = BaseSystemActionSettings & {
subject: string;
subject?: string;
template?: string;
title?: string;
callToAction?: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Injectable } from '@nestjs/common';

import { WorkflowActionEmail } from 'twenty-emails';
import { render } from '@react-email/components';
import { JSDOM } from 'jsdom';
import DOMPurify from 'dompurify';

import { WorkflowSystemAction } from 'src/modules/workflow/workflow-system-action/workflow-system-action.interface';
import { WorkflowSystemStep } from 'src/modules/workflow/common/types/workflow-step.type';
Expand Down Expand Up @@ -35,9 +37,12 @@ export class SendEmailAction implements WorkflowSystemAction {
(mainText = mainText?.replace(`{{${key}}}`, payload[key])),
);
}
const window = new JSDOM('').window;
const purify = DOMPurify(window);
const safeHTML = purify.sanitize(mainText || '');

const email = WorkflowActionEmail({
mainText: mainText,
dangerousHTML: safeHTML,
title: step.settings.title,
callToAction: step.settings.callToAction,
});
Expand All @@ -53,7 +58,7 @@ export class SendEmailAction implements WorkflowSystemAction {
'EMAIL_FROM_NAME',
)} <${this.environmentService.get('EMAIL_FROM_ADDRESS')}>`,
to: payload.email,
subject: step.settings.subject,
subject: step.settings.subject || '',
text,
html,
});
Expand Down