-
Notifications
You must be signed in to change notification settings - Fork 53
Auto-scheduled monthly announcement #10975
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
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
21b483e
Add template column to announcement
Luke-Oldenburg ba17c29
Add monthly job
Luke-Oldenburg 8f8d0bc
Fix job class name
Luke-Oldenburg d3668d6
Add monthly warning
Luke-Oldenburg abbb5fa
Add back frozen string literal
Luke-Oldenburg 01e5d93
Discard other schema changes
Luke-Oldenburg 0f34cfb
Update title for monthly
Luke-Oldenburg 838ca03
Use find_each
Luke-Oldenburg 227b9fa
Merge branch 'main' into scheduled-announcements
Luke-Oldenburg 385a337
Rename column from `template` to `template_type`
garyhtou 3a2b337
Handle errors from publishing announcement
garyhtou da1e8bd
[Announcement] Add Event::Config for `generate_monthly_announcement`
garyhtou 4cba20b
Make monthly job use `generate_monthly_announcement`
garyhtou 2741dbd
Refactor warning email
garyhtou 0cf7d19
Rename template to template_type
Luke-Oldenburg 534e835
Update app/views/announcement_mailer/monthly_warning.html.erb
Luke-Oldenburg 23a151d
Use announcement created_at for donation summary
Luke-Oldenburg 75ba96d
Rename monthly title
Luke-Oldenburg 330cdc7
Update app/views/announcement_mailer/monthly_warning.html.erb
Luke-Oldenburg 8a86da4
Add two day warning
Luke-Oldenburg 5b0b87c
Delete monthly job
Luke-Oldenburg fce9a12
class.name -> name
Luke-Oldenburg 3e2bc57
Rename before action method
garyhtou 37646c5
Use `self.class.name` instead of `self.name`
garyhtou 51cd76d
Revert "Delete monthly job"
Luke-Oldenburg f468a6a
Update mailer views
Luke-Oldenburg 44ecabc
Merge branch 'main' into scheduled-announcements
Luke-Oldenburg 5a357a0
Update app/models/announcement/templates/monthly.rb
Luke-Oldenburg 67142cb
Merge branch 'main' into scheduled-announcements
Luke-Oldenburg 1420c62
Merge branch 'main' into scheduled-announcements
Luke-Oldenburg 4f70c1e
Remove .to_json
Luke-Oldenburg 64e43a6
Add explanation
Luke-Oldenburg 1526f03
Merge branch 'main' into scheduled-announcements
Luke-Oldenburg e79bc27
Fix render code
Luke-Oldenburg d39fba3
Add to params
Luke-Oldenburg 072639c
Add toggle
Luke-Oldenburg a25d4a6
after_initialize -> after_create
Luke-Oldenburg 8232f3f
Fix monthly
Luke-Oldenburg 477dca8
Move explanation
Luke-Oldenburg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class Announcement | ||
class MonthlyJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform | ||
Announcement.monthly_for(Date.today.prev_month).find_each do |announcement| | ||
Rails.error.handle do | ||
announcement.publish! | ||
end | ||
end | ||
|
||
Event.includes(:config).where(config: { generate_monthly_announcement: true }).find_each do |event| | ||
Announcement::Templates::Monthly.new(event:, author: User.system_user).create | ||
end | ||
end | ||
|
||
end | ||
|
||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class Announcement | ||
class SevenDayWarningJob < ApplicationJob | ||
queue_as :low | ||
|
||
def perform | ||
Announcement.monthly_for(Date.today).where.not(aasm_state: :published).find_each do |announcement| | ||
AnnouncementMailer.with(announcement:).seven_day_warning.deliver_now | ||
end | ||
end | ||
|
||
end | ||
|
||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class Announcement | ||
class TwoDayWarningJob < ApplicationJob | ||
queue_as :low | ||
|
||
def perform | ||
Announcement.monthly_for(Date.today).where(aasm_state: :template_draft).find_each do |announcement| | ||
AnnouncementMailer.with(announcement:).two_day_warning.deliver_now | ||
end | ||
end | ||
|
||
end | ||
|
||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
class AnnouncementMailer < ApplicationMailer | ||
before_action :set_warning_variables, only: [:seven_day_warning, :two_day_warning] | ||
|
||
def announcement_published | ||
@announcement = params[:announcement] | ||
@event = @announcement.event | ||
|
||
mail to: params[:email], subject: "#{@announcement.title} | #{@event.name}", from: hcb_email_with_name_of(@event) | ||
end | ||
|
||
def seven_day_warning | ||
mail to: @emails, subject: "[#{@event.name}] Your scheduled monthly announcement will be delivered on #{@scheduled_for.strftime("%b %-m")}" | ||
end | ||
|
||
def two_day_warning | ||
mail to: @emails, subject: "[#{@event.name}] Your scheduled monthly announcement will be delivered on #{@scheduled_for.strftime("%b %-m")}" | ||
end | ||
|
||
def set_warning_variables | ||
@announcement = params[:announcement] | ||
@event = @announcement.event | ||
|
||
@emails = @event.managers.map(&:email_address_with_name) | ||
@emails << @event.config.contact_email if @event.config.contact_email.present? | ||
|
||
@scheduled_for = Date.today.next_month.beginning_of_month | ||
end | ||
|
||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# frozen_string_literal: true | ||
|
||
class Announcement | ||
module Templates | ||
class Monthly | ||
include ApplicationHelper | ||
|
||
def initialize(event:, author:) | ||
@event = event | ||
@author = author | ||
end | ||
|
||
def title | ||
"#{Date.current.strftime("%B %Y")} Update" | ||
end | ||
|
||
def json_content(block) | ||
{ | ||
type: "doc", | ||
content: [ | ||
{ type: "paragraph", content: [{ type: "text", text: "Hey all!" }] }, | ||
{ | ||
type: "paragraph", | ||
content: [ | ||
{ | ||
type: "text", | ||
text: "Thank you for your support and generosity! With this funding, we'll be able to better work towards our mission.", | ||
}, | ||
], | ||
}, | ||
{ | ||
type: "paragraph", | ||
content: [ | ||
{ | ||
type: "text", | ||
text: "We'd like to thank all of the donors from the past month that contributed towards our organization:", | ||
}, | ||
], | ||
}, | ||
{ type: "donationSummary", attrs: { id: block.id } }, | ||
{ | ||
type: "paragraph", | ||
content: [ | ||
{ type: "text", text: "Best," }, | ||
{ type: "hardBreak" }, | ||
{ type: "text", text: "The #{@event.name} team" }, | ||
], | ||
}, | ||
], | ||
} | ||
end | ||
|
||
def create | ||
announcement = Announcement.create!(event: @event, title:, content: {}, aasm_state: :template_draft, author: @author, template_type: self.class.name) | ||
block = Announcement::Block::DonationSummary.create!(announcement:, parameters: { start_date: Date.current.beginning_of_month }) | ||
announcement.update!(content: json_content(block)) | ||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<h1><%= @announcement.title %></h1> | ||
|
||
<%= @announcement.render_email.html_safe %> <%# erb_lint:disable ErbSafety %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<p> | ||
Announcements are a feature where you can send out updates to users following your organization. | ||
You are receiving this message because you have auto-scheduled monthly announcements enabled in your organization settings. | ||
</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<h1>A scheduled announcement will go out in 7 days</h1> | ||
|
||
Luke-Oldenburg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<%= render "announcement_mailer/explanation" %> | ||
|
||
<i><%= link_to "Update the announcement and share what your organization has been working on here", @announcement %></i> | ||
Luke-Oldenburg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<br> | ||
<br> | ||
|
||
<div class="card shadow-none border"> | ||
<%= render "announcement_mailer/announcement" %> | ||
</div> | ||
|
||
<br> | ||
|
||
<p> | ||
From,<br> | ||
The HCB Team | ||
</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<h1>A scheduled announcement will go out in 2 days</h1> | ||
|
||
<%= render "announcement_mailer/explanation" %> | ||
|
||
<i><%= link_to "Update the announcement and share what your organization has been working on here", @announcement %></i> | ||
|
||
<br> | ||
<br> | ||
|
||
<div class="card shadow-none border"> | ||
<%= render "announcement_mailer/announcement" %> | ||
</div> | ||
|
||
<br> | ||
|
||
<p> | ||
From,<br> | ||
The HCB Team | ||
</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddTemplateToAnnouncements < ActiveRecord::Migration[7.2] | ||
def change | ||
add_column :announcements, :template_type, :string | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.