-
Notifications
You must be signed in to change notification settings - Fork 104
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
feat(reports): implement report emailing #2310
feat(reports): implement report emailing #2310
Conversation
c5a66e1
to
df068fd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made some comments and asked some questions to know more about the code. I waiting for your clarification.
Well done!
Thanks!
client/src/i18n/fr/report.json
Outdated
@@ -131,7 +131,8 @@ | |||
"BACK":"Revenir en arriere", | |||
"OPTIONS":"Options", | |||
"PREVIEW":"Aperçu", | |||
"VIEW_ARCHIVE":"Archives" | |||
"VIEW_ARCHIVE":"Archives", | |||
"EMAIL_HELP_TXT" : "L'e-mail ci-dessus recevra le rapport en pièce jointe. Le serveur doit avoire une connexion Internet pour que l'e-mail soit livré avec succès." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aie ... avoir surelly a typo avoire
@@ -63,6 +65,25 @@ function BaseReportService($http, Modal, util, Languages) { | |||
.then(util.unwrapHttpResponse); | |||
} | |||
|
|||
function emailReport(uuid, email) { | |||
var url = '/reports/archive/'.concat(uuid, '/email'); | |||
return $http.put(url, { address : email }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a PUT
method? We are not updating the report (resource) right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I needed a body
in the request and only PUT
or POST
requests have a body. I just chose PUT. Do you think POST is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, let use POST if possible
vm.reportName = options.reportName; | ||
|
||
vm.params = { | ||
email : Session.user.email, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
}; | ||
|
||
vm.submit = function submit(EmailForm) { | ||
if (EmailForm.$invalid) { return 1; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just return?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was to satisfy ESLint. We should probably turn that rule off - it causes more harm than good, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right
|
||
lookupArchivedReport(uuid) | ||
.then(report => { | ||
debug(`#emailArchived(): sending ${report.label} to ${address}.`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a difference between debug
and winston
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question! Winston uses "error levels" (winston.log(), winston.error(), winston.warn()), which debug simply namespaces logs by module. It's like having console.log()
statements that you can turn on and off.
This is advantageous because you can turn all logs off except the ones you care about, or you can filter logs based on what module it came from. For example, here we log only email logs by using DEBUG=mailer
and it will only print the debug()
calls that are in the mailer
module. That way, if there are errors in the email script, we will be able to easily track them down in production by either filtering through the logs or turning off all logs except the email logs.
This issue gives more of a detailed overview about why debug() works better for our needs than winston.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the explanation
const parameters = { | ||
filename, | ||
date, | ||
user : report.display_name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between the user and the requester?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user created the report originally and archived it. The requester is the person asking for the email to be sent. The AG might create the report, but the MD might request it to be sent somewhere.
*/ | ||
exports.email = function email(address, subject, message, options = {}) { | ||
debug(`#email() sending email ${subject} to ${address} with options %j`, options); | ||
return processAttachments(options.attachments) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No method handle error, so it will be handled outside?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is handled here.
I think we will want to pass back errors to the module that requests the email to be sent. That way, the parent module can decide what to do - throw the error or retry the email or take another action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea
df068fd
to
000e0c2
Compare
@DedrickEnc, Thanks for the review. I've fixed the typo - good catch! I need your feedback on the POST vs PUT issue. Either one works - which makes the most sense to you? |
@jniles |
000e0c2
to
f5c47f5
Compare
This commit implements the email dropdown on reports as a first step towards automatic email reporting. The automatic email reports will depend on a scheduler proposed in IMA-WorldHealth#2308. The email functionality depends on having a mailgun account. You should put your mailgun API key and domain in the .env.development file. Some defaults for this project have been filled out. Partially addresses IMA-WorldHealth#1688 and IMA-WorldHealth#1766.
f5c47f5
to
df86542
Compare
Thanks! bors r+ |
2310: feat(reports): implement report emailing r=jniles a=jniles This commit implements the email dropdown on reports as a first step towards automatic email reporting. The automatic email reports will depend on a scheduler proposed in #2308. The email functionality depends on having a mailgun account. You should put your mailgun API key and domain in the .env.development file. Some defaults for this project have been filled out. Partially addresses #1688 and #1766. ![emailactivatedindropdown](https://user-images.githubusercontent.com/896472/33365180-9add6914-d4e7-11e7-99ad-0bd9c5ce499e.PNG) _Fig 1: The Email Link Dropdown_ ![emailmodal](https://user-images.githubusercontent.com/896472/33365181-9b0fa924-d4e7-11e7-9336-1051137986d0.PNG) _Fig 2: The Email Modal. It defaults to the current user's email address_ ![emailreceivedwithattachment](https://user-images.githubusercontent.com/896472/33365182-9b590790-d4e7-11e7-9821-78c2aad0356f.PNG) _Fig 3: Email in my inbox_
Build succeeded |
This commit implements the email dropdown on reports as a first step
towards automatic email reporting. The automatic email reports will
depend on a scheduler proposed in #2308.
The email functionality depends on having a mailgun account. You should
put your mailgun API key and domain in the .env.development file. Some
defaults for this project have been filled out.
Partially addresses #1688 and #1766.
Fig 1: The Email Link Dropdown
Fig 2: The Email Modal. It defaults to the current user's email address
Fig 3: Email in my inbox