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

fix(mailer): get notification_mail when sending email #496

Merged
merged 8 commits into from
Feb 23, 2021

Conversation

WikiRik
Copy link
Member

@WikiRik WikiRik commented Feb 22, 2021

Save normal email in application for exporting or whatever. Will be looked into later
Related to AEGEE/core#238

@WikiRik WikiRik requested a review from a team February 22, 2021 18:50
@@ -46,7 +47,7 @@ exports.sendAll = async (req, res) => {
// TODO: Think, maybe use Pug or EJS for that?
// TODO: Think what else will we need? Probably remove after Agora Bucuresti if there
// won't be something required.
const email = application.email;
const notificationEmail = await core.getMember(req, application.user_id).notification_email;
Copy link
Member

Choose a reason for hiding this comment

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

this one will do like 800 requests to the core each time someone would want to use a massmailer, what I'd do instead is storing the notification email in the application, the same way and for the same reason body name and email is stored here, then you can send email without even querying core

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, but that will not update the notification_email so you might get the wrong one. You normally apply to events a few months in advance so the data is not very recent

Copy link
Member

Choose a reason for hiding this comment

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

what do you think of doing it all with 1 query then?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be awesome, but I wasn't quite sure how to do that. But I haven't given it too much thought yet so with some more time I probably could figure that out.
And figuring out why application creation fails 😅

Copy link
Member

Choose a reason for hiding this comment

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

just use /members endpoint of core, it'll return them all, then you can just find the correct user in results. one issue here is that you have to have the global:view:member permission, otherwise the call to core will fail

Copy link
Member Author

Choose a reason for hiding this comment

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

Would that actually be better? Then we would get a much bigger query back and I am unsure if that will be any quicker in the end. Having the global:view:member permission might not be needed if we use the superadmin information from config.

Copy link
Member

Choose a reason for hiding this comment

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

depends on how much emails needs to be send, but in general, 1 big query is better than 500 smaller ones

Copy link
Member

Choose a reason for hiding this comment

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

but this was also the reason why I added email to application, to reduce it to 0 and to not bother with permissions

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, adding the emails to applications is indeed a nice solution but does not work for fields that can change somewhere else unfortunately

Copy link
Member Author

Choose a reason for hiding this comment

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

I've removed this out of this PR and made a TODO for it. I do want to merge the other changes since those features are broken currently.

@WikiRik WikiRik marked this pull request as draft February 22, 2021 19:26
@codecov
Copy link

codecov bot commented Feb 23, 2021

Codecov Report

Merging #496 (de4cd63) into master (9060691) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #496   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           38        38           
  Lines         1877      1877           
  Branches       342       342           
=========================================
  Hits          1877      1877           
Impacted Files Coverage Δ
lib/massmailer.js 100.00% <ø> (ø)
lib/applications.js 100.00% <100.00%> (ø)

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 9060691...de4cd63. Read the comment docs.

@WikiRik WikiRik marked this pull request as ready for review February 23, 2021 09:56
@@ -624,9 +624,11 @@ exports.postApplication = async (req, res) => {

// We don't need to recalculate the votes amount, as the pax type is not set here.

const notificationEmail = await core.getMember(req, newApplication.user_id).notification_email;
Copy link
Member

Choose a reason for hiding this comment

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

if it's the same user as the one who posts the application, you can just as well use req.user.notification_email, no need for extra request here

Copy link
Member Author

Choose a reason for hiding this comment

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

True, will fix this

@WikiRik WikiRik merged commit 1c16077 into master Feb 23, 2021
@WikiRik WikiRik deleted the notification_email branch February 23, 2021 14:15
@serge1peshcoff
Copy link
Member

🎉 This PR is included in version 1.6.6 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants