Skip to content
Open
24 changes: 24 additions & 0 deletions app/mailers/event_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,28 @@ def negative_balance
mail(to: @emails, subject: "#{@event.name} has a negative balance")
end

def transparency_mode_enabled
@whodunnit = params[:whodunnit]
mail to: @emails, subject: "#{@event.name} has enabled transparency mode"
end

def transparency_mode_disabled
@whodunnit = params[:whodunnit]
mail to: @emails, subject: "#{@event.name} has disabled transparency mode"
end

def monthly_announcements_enabled
@whodunnit = params[:whodunnit]
@monthly_announcement = @event.announcements.monthly_for(Date.today).last
@scheduled_for = Date.today.next_month.beginning_of_month
@warning_date = @scheduled_for - 7.days

mail to: @emails, subject: "#{@event.name} has enabled monthly announcements"
end

def monthly_announcements_disabled
@whodunnit = params[:whodunnit]
mail to: @emails, subject: "#{@event.name} has disabled monthly announcements"
end

end
9 changes: 9 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,15 @@ def ancestor_organizer_positions

after_update :generate_stripe_card_designs, if: -> { attachment_changes["stripe_card_logo"].present? && stripe_card_logo.attached? && !Rails.env.test? }

after_update if: :is_public_previously_changed? do
whodunnit = User.find(self.versions.where_object_changes(is_public:).last.whodunnit)
if is_public
EventMailer.with(event: self, whodunnit:).transparency_mode_enabled.deliver_later
else
EventMailer.with(event: self, whodunnit:).transparency_mode_disabled.deliver_later
end
end

# We can't do this through a normal dependent: :destroy since ActiveRecord does not support deleting records through indirect has_many associations
# https://github.com/rails/rails/commit/05bcb8cecc8573f28ad080839233b4bb9ace07be
after_destroy_commit do
Expand Down
8 changes: 8 additions & 0 deletions app/models/event/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ class Configuration < ApplicationRecord
validates :subevent_plan, inclusion: { in: -> { Event::Plan.available_plans.map(&:name) } }, allow_blank: true

after_save :create_or_destroy_monthly_announcement
after_update if: :generate_monthly_announcement_previously_changed? do
whodunnit = User.find(self.versions.where_object_changes(generate_monthly_announcement:).last.whodunnit)
if generate_monthly_announcement
EventMailer.with(event:, whodunnit:).monthly_announcements_enabled.deliver_later
else
EventMailer.with(event:, whodunnit:).monthly_announcements_disabled.deliver_later
end
end

private

Expand Down
14 changes: 14 additions & 0 deletions app/views/event_mailer/monthly_announcements_disabled.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p><%= @emails.length > 1 ? "Hi all," : "Hi there," %></p>

<p>
<%= @whodunnit.preferred_name.presence || @whodunnit.full_name %> (an <%= @event.users.include?(@whodunnit) ? "organization manager" : "HCB admin" %>) has disabled monthly announcements for <%= @event.name %>.
Any monthly announcements that have already been published will remain published,
but the current monthly announcement draft has been discarded.
</p>

<p>Managers can re-enable monthly announcements at any time in <%= link_to "your organization settings", edit_event_url(@event) %>.</p>

<p>
From,<br>
The HCB Team
</p>
20 changes: 20 additions & 0 deletions app/views/event_mailer/monthly_announcements_enabled.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<p><%= @emails.length > 1 ? "Hi all," : "Hi there," %></p>

<p>
<%= @whodunnit.preferred_name.presence || @whodunnit.full_name %> (an <%= @event.users.include?(@whodunnit) ? "organization manager" : "HCB admin" %>) has enabled monthly announcements for <%= @event.name %>.
This is a feature that automatically generates an announcement each month to send out to your followers.
For more information about announcements, check out <%= link_to "our blog post", "https://blog.hcb.hackclub.com/posts/organization-announcements" %>.
</p>

<p>
By default, each monthly announcement includes summarized data about your organization from the past month, such as donations and spending analyses, but you can edit the announcement to include whatever you'd like.
Your first monthly announcement has been generated and is scheduled to be sent on <%= @scheduled_for.strftime("%B #{@scheduled_for.day.ordinalize}") %> - <%= link_to "view or edit it on HCB", announcement_url(@monthly_announcement) %>!
If your organization doesn't have any activity from this month to include in the announcement by <%= @warning_date.strftime("%B #{@warning_date.day.ordinalize}") %>, the announcement will not be sent.
</p>

<p>Managers can disable monthly announcements at any time in <%= link_to "your organization settings", edit_event_url(@event) %>.</p>

<p>
From,<br>
The HCB Team
</p>
18 changes: 18 additions & 0 deletions app/views/event_mailer/transparency_mode_disabled.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<p><%= @emails.length > 1 ? "Hi all," : "Hi there," %></p>

<p>
<%= @whodunnit.preferred_name.presence || @whodunnit.full_name %> (an <%= @event.users.include?(@whodunnit) ? "organization manager" : "HCB admin" %>) has disabled transparency mode for <%= @event.name %>.
This means your organization is now private to unauthenticated users on HCB.
<% if @event.announcements.published.any? %>
Any published announcements are still visible to the public on your <%= link_to "announcements page", event_announcement_overview_url(@event) %>.
<% end %>
</p>

<p>
Managers can re-enable transparency mode at any time in <%= link_to "your organization settings", edit_event_url(@event) %>.
</p>

<p>
From,<br>
The HCB Team
</p>
36 changes: 36 additions & 0 deletions app/views/event_mailer/transparency_mode_enabled.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<p><%= @emails.length > 1 ? "Hi all," : "Hi there," %></p>

<p>
<%= @whodunnit.preferred_name.presence || @whodunnit.full_name %> (an <%= @event.users.include?(@whodunnit) ? "organization manager" : "HCB admin" %>) has enabled transparency mode for <%= @event.name %>.
With transparency mode enabled:
</p>

<ul>
<li>Unauthenticated users will be able to access a <strong>read-only</strong> version of your organization.</li>
<li>None of HCB&apos;s pages will change for signed in team members.</li>
<li>We&apos;ll do our best to redact contact info, but we can&apos;t guarantee it doesn't show up in these
fields:
<ul>
<li>Transaction display names</li>
<li>Sponsor company names</li>
<li>ACH transfer recipients</li>
<li>Check recipients</li>
</ul>
</li>
<li>Your <%= link_to "announcements page", event_announcement_overview_url(@event) %> will always be visible.</li>
</ul>

<p>
Managers can disable transparency mode at any time in <%= link_to "your organization settings", edit_event_url(@event) %>.
</p>

<p>
Additionally, managers can enable monthly announcements in <%= link_to "your organization settings", edit_event_url(@event) %>.
If enabled, HCB will generate a new announcement each month that includes summarized data about your organization from the past month.
For more information, check out <%= link_to "our blog post", "https://blog.hcb.hackclub.com/posts/monthly-announcements" %>.
</p>

<p>
From,<br>
The HCB Team
</p>
16 changes: 16 additions & 0 deletions spec/mailers/previews/event_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,20 @@ def negative_balance
.negative_balance
end

def transparency_mode_enabled
EventMailer.with(event: Event.first, whodunnit: Event.first.users.first).transparency_mode_enabled
end

def monthly_announcements_enabled
EventMailer.with(event: Announcement.monthly_for(Date.today).first.event, whodunnit: Event.first.users.first).monthly_announcements_enabled
end

def transparency_mode_disabled
EventMailer.with(event: Event.first, whodunnit: Event.first.users.first).transparency_mode_disabled
end

def monthly_announcements_disabled
EventMailer.with(event: Event.first, whodunnit: Event.first.users.first).monthly_announcements_disabled
end

end