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

feat(reports): implement report emailing #2310

Merged
merged 1 commit into from
Dec 3, 2017

Conversation

jniles
Copy link
Collaborator

@jniles jniles commented Nov 28, 2017

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
Fig 1: The Email Link Dropdown

emailmodal
Fig 2: The Email Modal. It defaults to the current user's email address

emailreceivedwithattachment
Fig 3: Email in my inbox

Copy link
Contributor

@DedrickEnc DedrickEnc left a comment

Choose a reason for hiding this comment

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

@jniles

I made some comments and asked some questions to know more about the code. I waiting for your clarification.

Well done!
Thanks!

@@ -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."
Copy link
Contributor

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 })
Copy link
Contributor

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?

Copy link
Collaborator Author

@jniles jniles Dec 3, 2017

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?

Copy link
Contributor

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,
Copy link
Contributor

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; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just return?

Copy link
Collaborator Author

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.

Copy link
Contributor

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}.`);
Copy link
Contributor

@DedrickEnc DedrickEnc Dec 1, 2017

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

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,
Copy link
Contributor

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?

Copy link
Collaborator Author

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)
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea

@jniles jniles force-pushed the feat-simple-email-of-reports branch from df068fd to 000e0c2 Compare December 3, 2017 11:29
@jniles
Copy link
Collaborator Author

jniles commented Dec 3, 2017

@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?

@DedrickEnc
Copy link
Contributor

@jniles
Every thing is fine, let just change the PUT method to POST one. And you can run bors.

@jniles jniles force-pushed the feat-simple-email-of-reports branch from 000e0c2 to f5c47f5 Compare December 3, 2017 13:42
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.
@jniles jniles force-pushed the feat-simple-email-of-reports branch from f5c47f5 to df86542 Compare December 3, 2017 13:44
@jniles
Copy link
Collaborator Author

jniles commented Dec 3, 2017

Thanks!

bors r+

bors bot added a commit that referenced this pull request Dec 3, 2017
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_
@bors
Copy link
Contributor

bors bot commented Dec 3, 2017

Build succeeded

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.

2 participants