Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions app/jobs/one_time_jobs/send_announcement_notice.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module OneTimeJobs
class SendAnnouncementNotice < ApplicationJob
def self.perform
# Rate limit is 14/s, but putting 12 here to be safe and allow for other emails to be sent
queue = Limiter::RateQueue.new(12, interval: 1)

Event.includes(:config).where(config: { generate_monthly_announcement: true }).find_each do |event|
monthly_announcement = event.announcements.monthly.last

if monthly_announcement.present?
Copy link
Member

Choose a reason for hiding this comment

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

concern: does this mean we'll keep sending these until they post an announcement?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, this was just meant to be a one time email - the check for monthly announcement is present is in case an event enabled generating monthly announcements after this month's job ran

queue.shift
AnnouncementMailer.with(event:, monthly_announcement:).notice.deliver_now
end
end
end

end

end
10 changes: 10 additions & 0 deletions app/mailers/announcement_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ def canceled
mail to: @emails, subject: "[#{@event.name}] Your scheduled monthly announcement has been canceled"
end

def notice
@event = params[:event]
@emails = @event.organizer_contact_emails(only_managers: true)

@monthly_announcement = params[:monthly_announcement]
@scheduled_for = Date.today.next_month.beginning_of_month

mail to: @emails, subject: "[#{@event.name}] Monthly announcements have been enabled for your organization"
end

def set_warning_variables
@announcement = params[:announcement]
@event = @announcement.event
Expand Down
26 changes: 26 additions & 0 deletions app/views/announcement_mailer/notice.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<p>
Hey<%= " all" if @emails.size > 1 %>,
</p>

<p>
We recently launched a new feature on HCB - organization announcements! This will help you send out announcements on HCB to people who follow your organization.
For more details, check out <%= link_to "our blog post", "https://blog.hcb.hackclub.com/posts/organization-announcements" %> and the new Announcements page on any of your organizations.
</p>

<p>
Your organization also has monthly announcements enabled!
This is a feature that automatically generates an announcement each month to send out to your followers.
</p>

<p>
By default, they will include a short message and public data about your organization from the past month such as donation and spending summaries, but you can edit the announcement to include whatever you'd like.
We've already generated your first monthly announcement to be sent on <%= @scheduled_for.strftime("%B #{@scheduled_for.day.ordinalize}") %> - <%= link_to "view or edit it on HCB", announcement_url(@monthly_announcement) %>!
</p>

<p>If you would like to disable monthly announcements, you can do so in <%= link_to "your organization settings", edit_event_url(@event) %>.</p>

<p>
Sincerely,
<br><br>
The HCB Team
</p>
4 changes: 4 additions & 0 deletions spec/mailers/previews/announcement_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def two_day_warning
AnnouncementMailer.with(announcement: Announcement.monthly.last).two_day_warning
end

def notice
AnnouncementMailer.with(event: Event.last, monthly_announcement: Announcement.monthly.last).notice
end

def canceled
AnnouncementMailer.with(announcement: Announcement.monthly.last).canceled
end
Expand Down