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

Re-add dynamic delivery_method for ApplicationMailer #13994

Merged
merged 8 commits into from
Jun 23, 2021

Conversation

maestromac
Copy link
Contributor

@maestromac maestromac commented Jun 15, 2021

What type of PR is this? (check all applicable)

  • Bug Fix

Description

The reason my previous attempt in #13943 did not work is most likely due setting smtp_settings improperly in the callback. This PR should fix with by altering delivery_method.settings instead.

Related Tickets & Documents

#13943

QA Instructions, Screenshots, Recordings

n/a

Added/updated tests?

  • Yes

[Forem core team only] How will this change be communicated?

  • This change does not need to be communicated yet, will update the doc post POC

[optional] Are there any post deployment tasks we need to perform?

QA on Canary first.

@pr-triage pr-triage bot added the PR: draft bot applied label for PR's that are a work in progress label Jun 15, 2021
@@ -9,7 +9,7 @@ def perform(follow_id, mailer = NotifyMailer.name)

return if EmailMessage.where(user_id: follow.followable_id)
.where("sent_at > ?", rand(15..35).hours.ago)
.exists?(["subject LIKE ?", "%#{NotifyMailer.subjects[:new_follower_email]}"])
.exists?(["subject LIKE ?", "%#{NotifyMailer.new.subjects[:new_follower_email]}"])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I unintentionally found out that this is a syntax error and this code may have been broken the whole time.

Copy link
Contributor

Choose a reason for hiding this comment

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

@maestromac A syntax error? Not a NoMethodError? 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@citizen428 ah yup I meant NoMethodError

@@ -48,6 +46,6 @@ def set_perform_deliveries
protected

def set_delivery_options
self.smtp_settings = Settings::SMTP.settings
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out this is the incorrect way to update SMTP config. In spec, checking ActionMailer::Base.deliveries.last.deliver_methods after any email is sent out would return {}.

@maestromac maestromac requested a review from rhymes June 15, 2021 19:50
@maestromac
Copy link
Contributor Author

maestromac commented Jun 15, 2021

Keeping it draft, for now, to test it on Canary first.

@@ -0,0 +1,16 @@
module Deliverable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is more like a placeholder. Happy to take any naming suggestion here

@andygeorge
Copy link
Contributor

Deployed this to canary1

@maestromac maestromac marked this pull request as ready for review June 21, 2021 17:49
@maestromac maestromac requested a review from a team as a code owner June 21, 2021 17:49
@pr-triage pr-triage bot added PR: unreviewed bot applied label for PR's with no review and removed PR: draft bot applied label for PR's that are a work in progress labels Jun 21, 2021
Copy link
Contributor

@rhymes rhymes left a comment

Choose a reason for hiding this comment

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

Let's do this!

@pr-triage pr-triage bot added PR: partially-approved bot applied label for PR's where a single reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Jun 22, 2021
@maestromac maestromac requested a review from djuber June 22, 2021 17:08
end

def set_delivery_options
mail.delivery_method.settings.merge!(Settings::SMTP.settings)
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this incorporate SENDGRID_API_KEY?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Settings::SMTP.settings returns a hardcoded config if SENDGRID_API_KEY exists.

See https://github.com/forem/forem/blob/main/app/models/settings/smtp.rb#L20

@@ -4,7 +4,7 @@
let(:user) { create(:user) }
let(:email) { VerificationMailer.with(user_id: user.id).account_ownership_verification_email }

xdescribe "#set_perform_deliveries" do
describe "#set_perform_deliveries" do
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick, non-blocking: I think this is a Deliverable test, not specifically an ApplicationMailer test.

@pr-triage pr-triage bot added PR: reviewed-approved bot applied label for PR's where reviewer approves changes and removed PR: partially-approved bot applied label for PR's where a single reviewer approves changes labels Jun 22, 2021
@maestromac maestromac merged commit a8c75fb into main Jun 23, 2021
@maestromac maestromac deleted the mac/mailer/fix-mailer branch June 23, 2021 19:17
@pr-triage pr-triage bot removed the PR: reviewed-approved bot applied label for PR's where reviewer approves changes label Jun 23, 2021
@pr-triage pr-triage bot added the PR: merged bot applied label for PR's that are merged label Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: merged bot applied label for PR's that are merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants