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

[#5164] Alert email subject in the receivers language #8507

Merged
merged 2 commits into from
Jan 6, 2025
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
36 changes: 22 additions & 14 deletions app/mailers/alaveteli_pro/embargo_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,35 @@ def self.alert_expired
def expiring_alert(user, info_requests)
@user = user
@info_requests = info_requests
subject = n_(
"{{count}} request will be made public on {{site_name}} this week",
"{{count}} requests will be made public on {{site_name}} this week",
info_requests.count,
site_name: site_name.html_safe,
count: info_requests.count
mail_user(
@user,
subject: -> {
n_(
"{{count}} request will be made public on {{site_name}} this week",
"{{count}} requests will be made public on {{site_name}} this week",
info_requests.count,
site_name: site_name.html_safe,
count: info_requests.count
)
}
)
mail_user(@user, subject: subject)
end

def expired_alert(user, info_requests)
@user = user
@info_requests = info_requests
subject = n_(
"{{count}} request has been made public on {{site_name}}",
"{{count}} requests have been made public on {{site_name}}",
info_requests.count,
site_name: site_name.html_safe,
count: info_requests.count
mail_user(
@user,
subject: -> {
n_(
"{{count}} request has been made public on {{site_name}}",
"{{count}} requests have been made public on {{site_name}}",
info_requests.count,
site_name: site_name.html_safe,
count: info_requests.count
)
}
)
mail_user(@user, subject: subject)
end
end
end
13 changes: 9 additions & 4 deletions app/mailers/alaveteli_pro/subscription_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ class AlaveteliPro::SubscriptionMailer < ApplicationMailer
def payment_failed(user)
auto_generated_headers(user)

subject = _('Action Required: Payment failed on {{pro_site_name}}',
pro_site_name: pro_site_name)

@user_name = user.name
@pro_site_name = pro_site_name.html_safe
@subscriptions_url = subscriptions_url
mail_user(user, subject: subject)
mail_user(
user,
subject: -> {
_(
'Action Required: Payment failed on {{pro_site_name}}',
pro_site_name: pro_site_name
)
}
)
end

private
Expand Down
5 changes: 3 additions & 2 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ class ApplicationMailer < ActionMailer::Base
# about the errors, and have to do error checking on return codes.
self.raise_delivery_errors = true

# The subject: arg must be a proc, it is localized with the user's locale.
def mail_user(user, subject:, **opts)
if user.is_a?(User)
locale = user.locale
opts[:to] = user.name_and_email
else
opts[:to] = user
Expand All @@ -36,7 +38,6 @@ def mail_user(user, subject:, **opts)
opts[:from] = MailHandler.address_from_name_and_email(
opts[:from].name, blackhole_email
)

else
set_reply_to_headers
opts[:from] ||= blackhole_email
Expand All @@ -45,7 +46,7 @@ def mail_user(user, subject:, **opts)
set_auto_generated_headers

default_opts = {
subject: subject
subject: AlaveteliLocalization.with_locale(locale) { subject.call }
}
default_opts.merge!(opts)
mail(default_opts)
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/contact_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def user_message(from_user, recipient_user, from_user_url, subject, message)
mail_user(
recipient_user,
from: from_user,
subject: subject
subject: -> { subject }
)
end

Expand All @@ -53,7 +53,7 @@ def from_admin_message(recipient_name, recipient_email, subject, message)
to_address,
from: from_address,
bcc: AlaveteliConfiguration.contact_email,
subject: subject
subject: -> { subject }
)
end
end
8 changes: 6 additions & 2 deletions app/mailers/info_request_batch_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ def batch_sent(info_request_batch, unrequestable, user)

mail_user(
user,
subject: _("Your batch request \"{{title}}\" has been sent",
title: info_request_batch.title.html_safe)
subject: -> {
_(
"Your batch request \"{{title}}\" has been sent",
title: info_request_batch.title.html_safe
)
}
)
end
end
67 changes: 37 additions & 30 deletions app/mailers/notification_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ def daily_summary(user, notifications)

mail_user(
user,
subject: _("Your daily request summary from {{pro_site_name}}",
pro_site_name: pro_site_name)
subject: -> {
_("Your daily request summary from {{pro_site_name}}",
pro_site_name: pro_site_name)
}
)
end

Expand All @@ -99,45 +101,46 @@ def response_notification(notification)
@info_request = notification.info_request_event.info_request
@incoming_message = notification.info_request_event.incoming_message

subject = _("New response to your FOI request - {{request_title}}",
request_title: @info_request.title.html_safe)
mail_user(
@info_request.user,
subject: subject,
subject: -> {
_("New response to your FOI request - {{request_title}}",
request_title: @info_request.title.html_safe)
},
template_name: 'response_notification'
)
end

def embargo_expiring_notification(notification)
@info_request = notification.info_request_event.info_request

subject = _(
"Your FOI request - {{request_title}} will be made public on " \
"{{site_name}} this week",
request_title: @info_request.title.html_safe,
site_name: site_name.html_safe
)

mail_user(
@info_request.user,
subject: subject,
subject: -> {
_(
"Your FOI request - {{request_title}} will be made public on " \
"{{site_name}} this week",
request_title: @info_request.title.html_safe,
site_name: site_name.html_safe
)
},
template_name: 'embargo_expiring_notification'
)
end

def expire_embargo_notification(notification)
@info_request = notification.info_request_event.info_request

subject = _(
"Your FOI request - {{request_title}} has been made public on " \
"{{site_name}}",
request_title: @info_request.title.html_safe,
site_name: site_name.html_safe
)

mail_user(
@info_request.user,
subject: subject,
subject: -> {
_(
"Your FOI request - {{request_title}} has been made public on " \
"{{site_name}}",
request_title: @info_request.title.html_safe,
site_name: site_name.html_safe
)
},
template_name: 'expire_embargo_notification'
)
end
Expand All @@ -146,12 +149,14 @@ def overdue_notification(notification)
@info_request = notification.info_request_event.info_request
@url = signin_url(r: respond_to_last_path(@info_request))

subject = _("Delayed response to your FOI request - {{request_title}}",
request_title: @info_request.title.html_safe)

mail_user(
@info_request.user,
subject: subject,
subject: -> {
_(
"Delayed response to your FOI request - {{request_title}}",
request_title: @info_request.title.html_safe
)
},
template_name: 'overdue_notification'
)
end
Expand All @@ -160,13 +165,15 @@ def very_overdue_notification(notification)
@info_request = notification.info_request_event.info_request
@url = signin_url(r: respond_to_last_path(@info_request))

subject = _("You're long overdue a response to your FOI request " \
"- {{request_title}}",
request_title: @info_request.title.html_safe)

mail_user(
@info_request.user,
subject: subject,
subject: -> {
_(
"You're long overdue a response to your FOI request " \
"- {{request_title}}",
request_title: @info_request.title.html_safe
)
},
template_name: 'very_overdue_notification'
)
end
Expand Down
58 changes: 42 additions & 16 deletions app/mailers/request_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ def new_response(info_request, incoming_message)

mail_user(
info_request.user,
subject: _("New response to your FOI request - {{request_title}}",
request_title: info_request.title.html_safe),
subject: -> {
_("New response to your FOI request - {{request_title}}",
request_title: info_request.title.html_safe)
},
charset: "UTF-8"
)
end
Expand All @@ -103,8 +105,12 @@ def overdue_alert(info_request, user)

mail_user(
user,
subject: _("Delayed response to your FOI request - {{request_title}}",
request_title: info_request.title.html_safe)
subject: -> {
_(
"Delayed response to your FOI request - {{request_title}}",
request_title: info_request.title.html_safe
)
}
)
end

Expand All @@ -115,9 +121,13 @@ def very_overdue_alert(info_request, user)

mail_user(
user,
subject: _("You're long overdue a response to your FOI request - " \
"{{request_title}}",
request_title: info_request.title.html_safe)
subject: -> {
_(
"You're long overdue a response to your FOI request - " \
"{{request_title}}",
request_title: info_request.title.html_safe
)
}
)
end

Expand All @@ -133,8 +143,12 @@ def new_response_reminder_alert(info_request, incoming_message)

mail_user(
info_request.user,
subject: _("Please update the status of your request - {{request_title}}",
request_title: info_request.title.html_safe)
subject: -> {
_(
"Please update the status of your request - {{request_title}}",
request_title: info_request.title.html_safe
)
}
)
end

Expand All @@ -145,7 +159,7 @@ def old_unclassified_updated(info_request)

mail_user(
info_request.user,
subject: _("Someone has updated the status of your request")
subject: -> { _("Someone has updated the status of your request") }
)
end

Expand All @@ -162,8 +176,12 @@ def not_clarified_alert(info_request, incoming_message)

mail_user(
info_request.user,
subject: _("Clarify your FOI request - {{request_title}}",
request_title: info_request.title.html_safe)
subject: -> {
_(
"Clarify your FOI request - {{request_title}}",
request_title: info_request.title.html_safe
)
}
)
end

Expand All @@ -175,8 +193,12 @@ def comment_on_alert(info_request, comment)

mail_user(
info_request.user,
subject: _("Somebody added a note to your FOI request - {{request_title}}",
request_title: info_request.title.html_safe)
subject: -> {
_(
"Somebody added a note to your FOI request - {{request_title}}",
request_title: info_request.title.html_safe
)
}
)
end

Expand All @@ -189,8 +211,12 @@ def comment_on_alert_plural(info_request, count, earliest_unalerted_comment)

mail_user(
info_request.user,
subject: _("Some notes have been added to your FOI request - {{request_title}}",
request_title: info_request.title.html_safe)
subject: -> {
_(
"Some notes have been added to your FOI request - {{request_title}}",
request_title: info_request.title.html_safe
)
}
)
end

Expand Down
4 changes: 3 additions & 1 deletion app/mailers/survey_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def survey_alert(info_request)

mail_user(
@user,
subject: _('A survey about your recent Freedom of Information request')
subject: -> {
_('A survey about your recent Freedom of Information request')
}
)
end

Expand Down
5 changes: 3 additions & 2 deletions app/mailers/track_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ def event_digest(user, email_about_things)

mail_user(
user,
subject: _("Your {{site_name}} email alert",
site_name: site_name.html_safe)
subject: -> {
_("Your {{site_name}} email alert", site_name: site_name.html_safe)
}
)
end

Expand Down
Loading
Loading