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

[#172380989] Add html body to DPO's UserDataProcessing email #65

Merged
merged 6 commits into from
Apr 18, 2020

Conversation

AleDore
Copy link
Contributor

@AleDore AleDore commented Apr 17, 2020

Added a custom html to NodeMailer configuration due to error in sending phase.

@codecov-io
Copy link

codecov-io commented Apr 17, 2020

Codecov Report

Merging #65 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #65      +/-   ##
==========================================
+ Coverage   82.29%   82.32%   +0.02%     
==========================================
  Files          22       22              
  Lines         627      628       +1     
  Branches       59       59              
==========================================
+ Hits          516      517       +1     
  Misses        111      111              
Impacted Files Coverage Δ
SendUserDataProcessingEmailActivity/handler.ts 81.08% <100.00%> (+0.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 973b179...03142b2. Read the comment docs.

@pagopa-github-bot
Copy link
Contributor

pagopa-github-bot commented Apr 17, 2020

Affected stories

  • 🐞 #172380989: La funzione che invia l'email al DPO per le richieste degli utenti di eliminazione profilo fallisce

Generated by 🚫 dangerJS

const documentHtml = `
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<body style="background-color:#ffffff;">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<body style="background-color:#ffffff;">
<body>


const documentHtml = `
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<html>
<head>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>${subject}</title>
</head>

);
if (isRight(errorOrMaybeRetrievedProfile)) {
const maybeRetrievedProfile = errorOrMaybeRetrievedProfile.value;
if (isSome(maybeRetrievedProfile)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isNone branch was missing

codice fiscale: ${fiscalCode}
indirizzo email: ${userEmailAddress}.`;
const documentHtml = `
export const getDpoEmailText = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useful in tests to avoid to type mock text

@@ -91,40 +67,75 @@ export const getSendUserDataProcessingEmailActivityHandler = (
<title>${subject}</title>
</head>
<body>
<p>${emailText}</p>
<p>${emailText.replace("\n", "<br>\n")}</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handle newlines in html

logPrefix = "SendUserDataProcessingEmail"
) => async (context: Context, input: unknown) => {
const failure = failActivity(context, logPrefix);
return fromEither(ActivityInput.decode(input))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when possible avoid assignement to .value and calls to isLeft / isSome
use fp-ts methods to transform an input into the expected output


if (isLeft(errorOrSentMessageInfo)) {
context.log.error(
`${logPrefix}|Error sending userDataProcessing email|ERROR=${errorOrSentMessageInfo.value.message}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's not need to repeat userDataProcessing since w have the log prefix

</body>
</html>`;
// Send an email to the DPO containing the information about the IO user's
// choice to download or delete his own private data stored by the platform
const errorOrSentMessageInfo = await sendMail(mailerTransporter, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer working with taskeithers than promise

toError
).foldTaskEither<Error, Option<RetrievedProfile>>(
err => TE.left(new Task(async () => err)),
queryErrorOrMaybeProfile =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all this mess is just to convert QueryError to a simple Error since we don't need to discriminate + the promise to a taskeither

@@ -63,10 +86,16 @@ const mailerTransporter = isProduction
secure: false
});

const sendMailTask = (mt: Mail) => (
options: Mail.Options & { html: Mail.Options["html"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while the proposed changes fix the error, they don't prevent the error (missing html param) to occur again in the future so I've added a required html parameter here

@gunzip gunzip merged commit f0aef87 into master Apr 18, 2020
@gunzip gunzip deleted the 172380989-fix_dpo_userDataProcessing_email branch April 18, 2020 13:25
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants