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

Add organizer summary emails #194

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
07ea523
Update digest_mailer.rb
sampoder Aug 22, 2023
3ac0e14
Create organizer-summary.html.erb
sampoder Aug 22, 2023
7e08a8c
Rename organizer-summary.html.erb to organizer_summary.html.erb
sampoder Aug 22, 2023
325a72e
Update digest_mailer.rb
sampoder Aug 22, 2023
b399e35
Update organizer_summary.html.erb
sampoder Aug 22, 2023
2d5d748
Update digest_mailer.rb
sampoder Aug 22, 2023
5e4c9f0
Update organizer_summary.html.erb
sampoder Aug 22, 2023
28474c9
Update digest_mailer.rb
sampoder Aug 22, 2023
994b8e6
Update digest_mailer.rb
sampoder Aug 22, 2023
e1e15bf
Update digest_mailer.rb
sampoder Aug 22, 2023
19f3094
Update app/mailers/hackathons/digest_mailer.rb
sampoder Aug 22, 2023
a23ec86
Update app/views/hackathons/digest_mailer/organizer_summary.html.erb
sampoder Aug 22, 2023
c8bf0d4
Create organizer_summary.text.erb
sampoder Aug 22, 2023
4c25f3a
Restructure Post-Review
sampoder Aug 22, 2023
7e803ac
Standard
sampoder Aug 22, 2023
c633124
Update send_organizer_summaries_job.rb
sampoder Aug 22, 2023
f08d496
Merge branch 'main' into organizer-summary
sampoder Aug 22, 2023
8c594d4
Update send_organizer_summaries_job.rb
sampoder Aug 23, 2023
1f94a11
Merge branch 'main' into organizer-summary
sampoder Aug 26, 2023
af8f7ed
Merge branch 'main' into organizer-summary
sampoder Nov 11, 2023
728b784
Update send_organizer_summaries_job.rb
sampoder Nov 11, 2023
31243bc
Update app/mailers/hackathons/digest_mailer.rb
sampoder Dec 6, 2023
331ec67
Update app/views/hackathons/digest_mailer/organizer_summary.html.erb
sampoder Dec 6, 2023
1b98f29
Update app/views/hackathons/digest_mailer/organizer_summary.text.erb
sampoder Dec 6, 2023
22c52e1
Update app/mailers/hackathons/digest_mailer.rb
sampoder Dec 6, 2023
cf5b9a2
Update app/jobs/hackathons/send_organizer_summaries_job.rb
sampoder Dec 6, 2023
115a937
Update app/jobs/hackathons/send_organizer_summaries_job.rb
sampoder Dec 6, 2023
1803fe7
Merge branch 'main' into organizer-summary
sampoder Dec 6, 2023
8cb41e4
Add a test
sampoder Dec 6, 2023
41afc2d
Update organizer_summary_test.rb
sampoder Dec 6, 2023
9dec6ae
Update test/mailers/hackathons/organizer_summary_test.rb
sampoder Dec 24, 2023
9095300
Merge branch 'main' into organizer-summary
sampoder Dec 24, 2023
90e38fc
Update app/jobs/hackathons/digests_delivery_job.rb
sampoder Dec 26, 2023
8539a84
rename job
sampoder Dec 26, 2023
9d7c744
move the test
sampoder Dec 26, 2023
ee65871
that was very bad of me
sampoder Dec 26, 2023
9adae8e
run standard and pray
sampoder Dec 26, 2023
9fe0fdc
Merge branch 'main' into organizer-summary
northeastprince Dec 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/jobs/hackathons/digests_delivery_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def perform
sent_digests << digest if digest.persisted?
end
ensure
Hackathons::OrganizerSummaryDeliveriesJob(sent_digests).perform_later if sent_digests.any?
Hackathons::DigestMailer.admin_summary(sent_digests).deliver_later if sent_digests.any?
end

Expand Down
18 changes: 18 additions & 0 deletions app/jobs/hackathons/organizer_summary_deliveries_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Hackathons::OrganizerSummaryDeliveriesJob < ApplicationJob
def perform(sent_digests)
# This reloads the (possible) sent_digests array as an
# ActiveRecord::Relation so that we can use includes to prevent an N+1.
@sent_digests = Hackathon::Digest.where(id: sent_digests.map(&:id))

@sent_digests_by_hackathons = @sent_digests
.includes(listings: :hackathon)
.flat_map(&:listings).group_by(&:hackathon)
.transform_values { |listings| listings.map(&:digest).uniq }

@listed_hackathons = @sent_digests_by_hackathons.keys
@listed_hackathons.each do |hackathon|
sent_digests = @digests_by_hackathons[hackathon]
Hackathons::DigestMailer.organizer_summary(hackathon, sent_digests).deliver_later if @sent_digests.any?
end
end
end
6 changes: 6 additions & 0 deletions app/mailers/hackathons/digest_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ def admin_summary(sent_digests)

mail to: Hackathons::SUPPORT_EMAIL, cc: User.admins.collect(&:email_address), subject:
end

def organizer_summary(hackathon, sent_digests)
@hackathon = hackathon
@count = sent_digests.count
mail to: hackathon.applicant.email_address, subject: "We've just notified #{@count} hackers about #{hackathon.name}!"
end
end
10 changes: 10 additions & 0 deletions app/views/hackathons/digest_mailer/organizer_summary.html.erb
sampoder marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

<p>
We've just sent an email about <%= @hackathon.name %> to <%= @count %> hackers.
</p>

<% content_for :signature do %>
<p>
Best of luck with everything! 🦕 💸
</p>
<% end %>
5 changes: 5 additions & 0 deletions app/views/hackathons/digest_mailer/organizer_summary.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
We've just sent an email about <%= @hackathon.name %> to <%= @count %> hackers.

<% content_for :signature do %>
Best of luck with everything! 🦕 💸
<% end %>
14 changes: 14 additions & 0 deletions test/mailers/hackathons/digest_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,18 @@ class Hackathons::DigestMailerTest < ActionMailer::TestCase
assert_match "unsubscribe", mail.body.encoded
assert_match Hackathons::HACK_CLUB_ADDRESS[:full], mail.body.encoded
end

test "organizer_summary" do
sent_digests = [hackathon_digests(:one)]
hackathon = hackathon_digests(:one).listings.first.hackathon
mail = Hackathons::DigestMailer.organizer_summary(hackathon, sent_digests)

assert_equal "We've just notified #{sent_digests.count} hackers about #{hackathon.name}!", mail.subject
assert_equal [hackathon.applicant.email_address], mail.to

assert_match "We've just sent an email about #{hackathon.name} to #{sent_digests.count} hackers.", mail.body.encoded

# Email CAN-SPAM compliance
assert_match Hackathons::HACK_CLUB_ADDRESS[:full], mail.body.encoded
end
end
Loading