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

Initial pass at updating emails for the new parliament #1054

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions app/helpers/number_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module NumberHelper
def number_to_word(number)
I18n.t(number, scope: :"number.words")
end
end
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class ApplicationMailer < ActionMailer::Base
default_url_options[:protocol] = Site.email_protocol
default from: ->(email){ Site.email_from }

helper :date_time, :rejection, :auto_link, :markdown, :moderation
helper :date_time, :rejection, :auto_link, :markdown, :moderation, :number

layout 'default_mail'
end
30 changes: 26 additions & 4 deletions app/mailers/sponsor_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
class SponsorMailer < ApplicationMailer
include NumberHelper

def sponsor_signed_email_below_threshold(sponsor)
@petition, @sponsor = sponsor.petition, sponsor
@sponsor_count = @petition.sponsor_count

mail(
subject: "#{@sponsor.name} supported your petition",
subject: subject_for(:sponsor_signed_email_below_threshold),
to: @petition.creator.email
)
end
Expand All @@ -14,7 +16,7 @@ def sponsor_signed_email_on_threshold(sponsor)
@sponsor_count = @petition.sponsor_count

mail(
subject: "We’re checking your petition",
subject: subject_for(:sponsor_signed_email_on_threshold),
to: @petition.creator.email
)
end
Expand All @@ -23,9 +25,29 @@ def petition_and_email_confirmation_for_sponsor(sponsor)
@petition, @sponsor = sponsor.petition, sponsor

mail(
subject: "Please confirm your email address",
subject: subject_for(:petition_and_email_confirmation_for_sponsor),
to: @sponsor.email
)
end
end

private

def subject_for(key, options = {})
I18n.t key, **(i18n_options.merge(options))
end

def i18n_options
{}.tap do |options|
options[:scope] = :"petitions.emails.subjects"
options[:threshold] = number_to_word(Site.threshold_for_moderation)

if defined?(@sponsor)
options[:name] = @sponsor.name
end

if defined?(@petition)
options[:action] = @petition.action
end
end
end
end
4 changes: 0 additions & 4 deletions app/models/constituency/api_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ def fetch(postcode)
return []
end

def self.before_remove_const
Thread.current[:__api_client__] = nil
end

private

def client
Expand Down
20 changes: 20 additions & 0 deletions app/models/feedback_signature.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
FeedbackSignature = Struct.new(:petition, :name, :email) do
def model_name
@_model_name ||= ActiveModel::Name.new(self, nil, "Signature")
end

def to_model
self
end

def persisted?
true
end

def name
self[:name] || 'Petitions team'
end
Expand All @@ -15,6 +27,14 @@ def to_param
'0'
end

def creator?
false
end

def sponsor?
false
end

def anonymized?
false
end
Expand Down
4 changes: 0 additions & 4 deletions app/models/holiday.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
class Holiday < ActiveRecord::Base
class << self
def before_remove_const
Thread.current[:__holiday__] = nil
end

def instance
Thread.current[:__holiday__] ||= first_or_create(defaults)
end
Expand Down
4 changes: 0 additions & 4 deletions app/models/parliament.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ class Parliament < ActiveRecord::Base
has_many :constituencies, through: :parliament_constituencies

class << self
def before_remove_const
Thread.current[:__parliament__] = nil
end

def instance
Thread.current[:__parliament__] ||= current_or_create
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/petition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ def rejected_state
where(state: REJECTED_STATE)
end

def validated_state
where(state: VALIDATED_STATE)
end

def sponsored_state
where(state: SPONSORED_STATE)
end
Expand Down
14 changes: 1 addition & 13 deletions app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ def table_exists?
false
end

def before_remove_const
Thread.current[:__site__] = nil
end

def instance
Thread.current[:__site__] ||= first_or_create(defaults)
end
Expand All @@ -50,10 +46,6 @@ def enabled?
instance.enabled?
end

def formatted_threshold_for_moderation
instance.formatted_threshold_for_moderation
end

def formatted_threshold_for_response
instance.formatted_threshold_for_response
end
Expand Down Expand Up @@ -455,10 +447,6 @@ def email_protocol
uri.scheme
end

def formatted_threshold_for_moderation
number_to_delimited(threshold_for_moderation)
end

def formatted_threshold_for_response
number_to_delimited(threshold_for_response)
end
Expand Down Expand Up @@ -549,7 +537,7 @@ def signature_count_updated_at
validates :petition_duration, presence: true, numericality: { only_integer: true }
validates :minimum_number_of_sponsors, presence: true, numericality: { only_integer: true }
validates :maximum_number_of_sponsors, presence: true, numericality: { only_integer: true }
validates :threshold_for_moderation, presence: true, numericality: { only_integer: true }
validates :threshold_for_moderation, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 10 }
validates :threshold_for_moderation_delay, presence: true, numericality: { only_integer: true }
validates :threshold_for_response, presence: true, numericality: { only_integer: true }
validates :threshold_for_debate, presence: true, numericality: { only_integer: true }
Expand Down
5 changes: 5 additions & 0 deletions app/views/application_mailer/_footer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%# locals: (closing: "Thanks") -%>
<p><%= closing %>,<br><br>

<%= t("petitions.emails.signoff_prefix") %><br>
<%= t("petitions.emails.signoff_suffix") %></p>
5 changes: 5 additions & 0 deletions app/views/application_mailer/_footer.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%# locals: (closing: "Thanks") -%>
<%= closing %>,

<%= t("petitions.emails.signoff_prefix") %>
<%= t("petitions.emails.signoff_suffix") %>
8 changes: 8 additions & 0 deletions app/views/application_mailer/_reason.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<% if @signature.creator? %>
<p><small>You’re receiving this email because you created the petition: “<%= link_to @petition.action, [@petition] %>”.</small></p>
<% elsif @signature.sponsor? %>
<p><small>You’re receiving this email because you supported the petition: “<%= link_to @petition.action, [@petition] %>”.</small></p>
<% else %>
<p><small>You’re receiving this email because you signed the petition: “<%= link_to @petition.action, [@petition] %>”.</small></p>
<% end %>
<hr>
12 changes: 12 additions & 0 deletions app/views/application_mailer/_reason.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% if @signature.creator? %>
You’re receiving this email because you created the petition “<%= @petition.action %>”:
<%= polymorphic_url(@petition) %>
<% elsif @signature.sponsor? %>
You’re receiving this email because you supported the petition “<%= @petition.action %>”:
<%= polymorphic_url(@petition) %>
<% else %>
You’re receiving this email because you signed the petition “<%= @petition.action %>”:
<%= polymorphic_url(@petition) %>
<% end %>

--
3 changes: 3 additions & 0 deletions app/views/application_mailer/_unsubscribe.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<hr>

<p><small><%= link_to "Unsubscribe", [:unsubscribe, @signature, token: @signature.unsubscribe_token] %> from emails about this petition.</small></p>
4 changes: 4 additions & 0 deletions app/views/application_mailer/_unsubscribe.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--

Unsubscribe from emails about this petition:
<%= polymorphic_url([:unsubscribe, @signature], token: @signature.unsubscribe_token) %>
14 changes: 3 additions & 11 deletions app/views/archived/petition_mailer/email_creator.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
<p><small>You’re receiving this email because you created this petition: “<%= @petition.action %>”.</small></p>
<p><small>To unsubscribe from getting emails about this petition: <%= link_to nil, unsubscribe_archived_signature_url(@signature, token: @signature.unsubscribe_token) %></small></p>
<hr>

<%= render "reason" %>
<p>Dear <%= @signature.name %>,</p>

<p>You recently created the petition “<%= @petition.action %>”:<br />
<%= link_to nil, archived_petition_url(@petition) %></p>

<%= markdown_to_html(@email.body) %>

<p>Thanks,<br />
<%= t("petitions.emails.signoff_prefix") %><br />
<%= t("petitions.emails.signoff_suffix") %></p>

<hr>
<p><small>You’re receiving this email because you created this petition: “<%= @petition.action %>”.</small></p>
<p><small>To unsubscribe from getting emails about this petition: <%= link_to nil, unsubscribe_archived_signature_url(@signature, token: @signature.unsubscribe_token) %></small></p>
<%= render "footer" %>
<%= render "unsubscribe" %>
14 changes: 3 additions & 11 deletions app/views/archived/petition_mailer/email_creator.text.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
You’re receiving this email because you created this petition: “<%= @petition.action %>”.
To unsubscribe from getting emails about this petition: <%= unsubscribe_archived_signature_url(@signature, token: @signature.unsubscribe_token) %>
--

<%= render "reason" %>
Dear <%= @signature.name %>,

You recently created the petition “<%= @petition.action %>”:
<%= archived_petition_url(@petition) %>

<%= markdown_to_text(@email.body) %>

Thanks,
<%= t("petitions.emails.signoff_prefix") %>
<%= t("petitions.emails.signoff_suffix") %>

--
You’re receiving this email because you created this petition: “<%= @petition.action %>”.
To unsubscribe from getting emails about this petition: <%= unsubscribe_archived_signature_url(@signature, token: @signature.unsubscribe_token) %>
<%= render "footer" %>
<%= render "unsubscribe" %>
14 changes: 3 additions & 11 deletions app/views/archived/petition_mailer/email_signer.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
<p><small>You’re receiving this email because you signed this petition: “<%= @petition.action %>”.</small></p>
<p><small>To unsubscribe from getting emails about this petition: <%= link_to nil, unsubscribe_archived_signature_url(@signature, token: @signature.unsubscribe_token) %></small></p>
<hr>

<%= render "reason" %>
<p>Dear <%= @signature.name %>,</p>

<p>You recently signed the petition “<%= @petition.action %>”:<br />
<%= link_to nil, archived_petition_url(@petition) %></p>

<%= markdown_to_html(@email.body) %>

<p>Thanks,<br />
<%= t("petitions.emails.signoff_prefix") %><br />
<%= t("petitions.emails.signoff_suffix") %></p>

<hr>
<p><small>You’re receiving this email because you signed this petition: “<%= @petition.action %>”.</small></p>
<p><small>To unsubscribe from getting emails about this petition: <%= link_to nil, unsubscribe_archived_signature_url(@signature, token: @signature.unsubscribe_token) %></small></p>
<%= render "footer" %>
<%= render "unsubscribe" %>
14 changes: 3 additions & 11 deletions app/views/archived/petition_mailer/email_signer.text.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
You’re receiving this email because you signed this petition: “<%= @petition.action %>”.
To unsubscribe from getting emails about this petition: <%= unsubscribe_archived_signature_url(@signature, token: @signature.unsubscribe_token) %>
--

<%= render "reason" %>
Dear <%= @signature.name %>,

You recently signed the petition “<%= @petition.action %>”:
<%= archived_petition_url(@petition) %>

<%= markdown_to_text(@email.body) %>

Thanks,
<%= t("petitions.emails.signoff_prefix") %>
<%= t("petitions.emails.signoff_suffix") %>

--
You’re receiving this email because you signed this petition: “<%= @petition.action %>”.
To unsubscribe from getting emails about this petition: <%= unsubscribe_archived_signature_url(@signature, token: @signature.unsubscribe_token) %>
<%= render "footer" %>
<%= render "unsubscribe" %>
14 changes: 3 additions & 11 deletions app/views/archived/petition_mailer/mailshot_for_creator.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
<p><small>You’re receiving this email because you created this petition: “<%= @petition.action %>”.</small></p>
<p><small>To unsubscribe from getting emails about this petition: <%= link_to nil, unsubscribe_archived_signature_url(@signature, token: @signature.unsubscribe_token) %></small></p>
<hr>

<%= render "reason" %>
<p>Dear <%= @signature.name %>,</p>

<p>You recently created the petition “<%= @petition.action %>”:<br />
<%= link_to nil, archived_petition_url(@petition) %></p>

<%= markdown_to_html(@mailshot.body) %>

<p>Thanks,<br />
<%= t("petitions.emails.signoff_prefix") %><br />
<%= t("petitions.emails.signoff_suffix") %></p>

<hr>
<p><small>You’re receiving this email because you created this petition: “<%= @petition.action %>”.</small></p>
<p><small>To unsubscribe from getting emails about this petition: <%= link_to nil, unsubscribe_archived_signature_url(@signature, token: @signature.unsubscribe_token) %></small></p>
<%= render "footer" %>
<%= render "unsubscribe" %>
14 changes: 3 additions & 11 deletions app/views/archived/petition_mailer/mailshot_for_creator.text.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
You’re receiving this email because you created this petition: “<%= @petition.action %>”.
To unsubscribe from getting emails about this petition: <%= unsubscribe_archived_signature_url(@signature, token: @signature.unsubscribe_token) %>
--

<%= render "reason" %>
Dear <%= @signature.name %>,

You recently created the petition “<%= @petition.action %>”:
<%= archived_petition_url(@petition) %>

<%= markdown_to_text(@mailshot.body) %>

Thanks,
<%= t("petitions.emails.signoff_prefix") %>
<%= t("petitions.emails.signoff_suffix") %>

--
You’re receiving this email because you created this petition: “<%= @petition.action %>”.
To unsubscribe from getting emails about this petition: <%= unsubscribe_archived_signature_url(@signature, token: @signature.unsubscribe_token) %>
<%= render "footer" %>
<%= render "unsubscribe" %>
14 changes: 3 additions & 11 deletions app/views/archived/petition_mailer/mailshot_for_signer.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
<p><small>You’re receiving this email because you signed this petition: “<%= @petition.action %>”.</small></p>
<p><small>To unsubscribe from getting emails about this petition: <%= link_to nil, unsubscribe_archived_signature_url(@signature, token: @signature.unsubscribe_token) %></small></p>
<hr>

<%= render "reason" %>
<p>Dear <%= @signature.name %>,</p>

<p>You recently signed the petition “<%= @petition.action %>”:<br />
<%= link_to nil, archived_petition_url(@petition) %></p>

<%= markdown_to_html(@mailshot.body) %>

<p>Thanks,<br />
<%= t("petitions.emails.signoff_prefix") %><br />
<%= t("petitions.emails.signoff_suffix") %></p>

<hr>
<p><small>You’re receiving this email because you signed this petition: “<%= @petition.action %>”.</small></p>
<p><small>To unsubscribe from getting emails about this petition: <%= link_to nil, unsubscribe_archived_signature_url(@signature, token: @signature.unsubscribe_token) %></small></p>
<%= render "footer" %>
<%= render "unsubscribe" %>
Loading