mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
Store salutation as setting to make it reusable
This commit is contained in:
@@ -68,4 +68,13 @@ module MailLayoutHelper
|
||||
|
||||
content_tag('td', ' '.html_safe, style:)
|
||||
end
|
||||
|
||||
def user_salutation(user)
|
||||
case Setting.emails_salutation
|
||||
when :name
|
||||
I18n.t(:'mail.salutation', user: user.name)
|
||||
else
|
||||
I18n.t(:'mail.salutation', user: user.firstname)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -33,9 +33,10 @@
|
||||
class AnnouncementMailer < ApplicationMailer
|
||||
include OpenProject::StaticRouting::UrlHelpers
|
||||
include OpenProject::TextFormatting
|
||||
helper :mail_notification
|
||||
helper :mail_notification,
|
||||
:mail_layout
|
||||
|
||||
def announce(user, subject:, body:, salutation: :firstname, body_header: nil, body_subheader: nil)
|
||||
def announce(user, subject:, body:, body_header: nil, body_subheader: nil)
|
||||
with_locale_for(user) do
|
||||
localized_subject = localized(subject)
|
||||
|
||||
@@ -44,7 +45,6 @@ class AnnouncementMailer < ApplicationMailer
|
||||
locals = {
|
||||
body: localized(body),
|
||||
user:,
|
||||
salutation: user_salutation(user, salutation),
|
||||
header_summary: localized_subject,
|
||||
body_header: localized(body_header),
|
||||
body_subheader: localized(body_subheader)
|
||||
@@ -65,13 +65,4 @@ class AnnouncementMailer < ApplicationMailer
|
||||
input
|
||||
end
|
||||
end
|
||||
|
||||
def user_salutation(user, salutation)
|
||||
case salutation
|
||||
when :firstname
|
||||
I18n.t(:'mail.salutation', user: user.firstname)
|
||||
else
|
||||
salutation % { firstname: user.firstname, lastname: user.lastname, name: user.name }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,9 +37,19 @@ See COPYRIGHT and LICENSE files for more details.
|
||||
<div class="form--field"><%= setting_text_field :mail_from, size: 60, container_class: '-middle' %></div>
|
||||
<div class="form--field"><%= setting_check_box :bcc_recipients %></div>
|
||||
<div class="form--field"><%= setting_check_box :plain_text_mail %></div>
|
||||
<div class="form--field">
|
||||
<%= setting_select :emails_salutation,
|
||||
[
|
||||
[User.human_attribute_name(:firstname), :firstname],
|
||||
[t('mail.salutation_full_name'), :name],
|
||||
],
|
||||
container_class: '-middle' %>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<fieldset id="emails_decorators" class="form--fieldset"><legend class="form--fieldset-legend"><%= t(:setting_emails_header) %> & <%= t(:setting_emails_footer) %></legend>
|
||||
<fieldset id="emails_decorators" class="form--fieldset">
|
||||
<legend class="form--fieldset-legend"><%= t(:setting_emails_header) %>
|
||||
& <%= I18n.t(:setting_emails_footer) %></legend>
|
||||
<%= render Settings::TextSettingComponent.new(I18n.locale, name: "emails_header") %>
|
||||
<%= render Settings::TextSettingComponent.new(I18n.locale, name: "emails_footer") %>
|
||||
</fieldset>
|
||||
@@ -54,7 +64,7 @@ See COPYRIGHT and LICENSE files for more details.
|
||||
email_methods << :letter_opener if Rails.env.development?
|
||||
%>
|
||||
<%= content_tag :fieldset, id: "mail_configuration", class: "form--fieldset" do %>
|
||||
<legend class="form--fieldset-legend"><%=t(:text_setup_mail_configuration)%></legend>
|
||||
<legend class="form--fieldset-legend"><%= t(:text_setup_mail_configuration) %></legend>
|
||||
<div class="form--field"><%= setting_select(:email_delivery_method, email_methods, id: "email_delivery_method_switch", container_class: '-slim') %></div>
|
||||
<div id="email_delivery_method_smtp" class="email_delivery_method_settings">
|
||||
<div class="form--field"><%= setting_text_field :smtp_address, container_class: '-middle' %></div>
|
||||
@@ -70,7 +80,8 @@ See COPYRIGHT and LICENSE files for more details.
|
||||
<div class="form--field"><%= setting_text_field :sendmail_location %></div>
|
||||
</div>
|
||||
<div id="email_delivery_method_letter_opener" class="email_delivery_method_settings">
|
||||
<p>Letter opener is used to render emails as a file in your Rails tmp folder. Mails will automatically open in your browser if supported.</p>
|
||||
<p>Letter opener is used to render emails as a file in your Rails tmp folder. Mails will automatically open in
|
||||
your browser if supported.</p>
|
||||
</div>
|
||||
<% end unless OpenProject::Configuration['email_delivery_configuration'] == 'legacy' %>
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
<%= render partial: 'mailer/mailer_header',
|
||||
locals: {
|
||||
summary: header_summary,
|
||||
salutation: salutation,
|
||||
user: user
|
||||
} %>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= salutation %>
|
||||
<%= user_salutation(user) %>
|
||||
<%= header_summary %>
|
||||
<%= "-" * 100 %>
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
button_href: notifications_center_url,
|
||||
button_text: I18n.t(:'mail.notification.center'),
|
||||
user: @user,
|
||||
salutation: I18n.t(:'mail.salutation', user: @user.firstname)
|
||||
} %>
|
||||
|
||||
<% @aggregated_notifications.first(DigestMailer::MAX_SHOWN_WORK_PACKAGES).each do |work_package, notifications_by_work_package| %>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<tr>
|
||||
<td>
|
||||
<span style="font-size: 24px; color: #333333;">
|
||||
<%= salutation %>
|
||||
<%= user_salutation(user) %>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
|
||||
<%= render partial: 'mailer/mailer_header',
|
||||
locals: {
|
||||
user: @shared_with_user,
|
||||
summary:,
|
||||
button_href: shared_work_package_path(@work_package.id),
|
||||
button_text: I18n.t(:'mail.sharing.work_packages.open_work_package'),
|
||||
salutation: I18n.t(:'mail.salutation', user: @shared_with_user.firstname)
|
||||
} %>
|
||||
|
||||
<%= render layout: 'mailer/notification_row',
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
button_href: notifications_path(@work_package.id),
|
||||
button_text: I18n.t(:'mail.notification.see_in_center'),
|
||||
user: @user,
|
||||
salutation: I18n.t(:'mail.salutation', user: @user.firstname)
|
||||
} %>
|
||||
|
||||
<%= render layout: 'mailer/notification_row',
|
||||
|
||||
@@ -402,6 +402,10 @@ module Settings
|
||||
default: nil,
|
||||
env_alias: 'EMAIL_DELIVERY_METHOD'
|
||||
},
|
||||
emails_salutation: {
|
||||
allowed: %w[firstname name],
|
||||
default: :firstname
|
||||
},
|
||||
emails_footer: {
|
||||
default: {
|
||||
'en' => ''
|
||||
|
||||
@@ -2264,6 +2264,7 @@ en:
|
||||
see_in_center: 'See comment in notification center'
|
||||
settings: 'Change email settings'
|
||||
salutation: 'Hello %{user}'
|
||||
salutation_full_name: 'Full name'
|
||||
work_packages:
|
||||
created_at: 'Created at %{timestamp} by %{user} '
|
||||
login_to_see_all: 'Log in to see all notifications.'
|
||||
@@ -2747,6 +2748,7 @@ en:
|
||||
<a href="%{link}" target="_blank">%{link}</a>.
|
||||
setting_attachment_whitelist: "Attachment upload whitelist"
|
||||
setting_email_delivery_method: "Email delivery method"
|
||||
setting_emails_salutation: "Address user in emails with"
|
||||
setting_sendmail_location: "Location of the sendmail executable"
|
||||
setting_smtp_enable_starttls_auto: "Automatically use STARTTLS if available"
|
||||
setting_smtp_ssl: "Use SSL connection"
|
||||
|
||||
@@ -30,6 +30,7 @@ class MeetingMailer < UserMailer
|
||||
def invited(meeting, user, actor)
|
||||
@actor = actor
|
||||
@meeting = meeting
|
||||
@user = user
|
||||
|
||||
open_project_headers 'Project' => @meeting.project.identifier,
|
||||
'Meeting-Id' => @meeting.id
|
||||
@@ -42,6 +43,7 @@ class MeetingMailer < UserMailer
|
||||
|
||||
def rescheduled(meeting, user, actor, changes:)
|
||||
@actor = actor
|
||||
@user = user
|
||||
@meeting = meeting
|
||||
@changes = changes
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ See COPYRIGHT and LICENSE files for more details.
|
||||
<%= render layout: 'mailer/spacer_table' do %>
|
||||
<%= render partial: 'mailer/mailer_header',
|
||||
locals: {
|
||||
caption: I18n.t('meeting.email.invited.header', title: @meeting.title),
|
||||
subcaption: I18n.t('meeting.email.invited.summary', actor: @actor),
|
||||
user: @user,
|
||||
summary: I18n.t('meeting.email.invited.summary', title: @meeting.title, actor: @actor),
|
||||
bottom_spacing: false
|
||||
} %>
|
||||
|
||||
@@ -76,7 +76,7 @@ See COPYRIGHT and LICENSE files for more details.
|
||||
<%= @meeting.author %>
|
||||
</td>
|
||||
</tr>
|
||||
<% if @meeting.participants.any? %>
|
||||
<% if @meeting.participants.exists? %>
|
||||
<tr>
|
||||
<td style="<%= placeholder_text_styles(width: '30%') %>">
|
||||
<%= Meeting.human_attribute_name(:participants_invited) %>
|
||||
|
||||
@@ -30,7 +30,6 @@ See COPYRIGHT and LICENSE files for more details.
|
||||
<%= render layout: 'mailer/spacer_table' do %>
|
||||
<%= render partial: 'mailer/mailer_header',
|
||||
locals: {
|
||||
salutation: "#{@meeting.project.name}: #{@meeting.title}",
|
||||
summary: I18n.t('meeting.email.rescheduled.summary', title: @meeting.title, actor: @actor),
|
||||
bottom_spacing: false
|
||||
} %>
|
||||
|
||||
@@ -113,11 +113,9 @@ en:
|
||||
email:
|
||||
open_meeting_link: "Open meeting"
|
||||
invited:
|
||||
header: "Invitation to Meeting %{title}"
|
||||
summary: "%{actor} has sent you an invitation to participate."
|
||||
summary: "%{actor} has sent you an invitation for the meeting %{title}"
|
||||
rescheduled:
|
||||
header: "Meeting %{title} rescheduled by %{actor}"
|
||||
summary: "Meeting has been rescheduled by %{actor}"
|
||||
summary: "Meeting %{title} has been rescheduled by %{actor}"
|
||||
body: "The meeting %{title} has been rescheduled by %{actor}."
|
||||
old_date_time: "Old date/time"
|
||||
new_date_time: "New date/time"
|
||||
|
||||
@@ -59,22 +59,5 @@ RSpec.describe AnnouncementMailer do
|
||||
expect(mail.to)
|
||||
.to match_array [recipient.mail]
|
||||
end
|
||||
|
||||
context 'with custom salutation' do
|
||||
subject(:mail) do
|
||||
described_class.announce(recipient,
|
||||
subject: announcement_subject,
|
||||
salutation: "What's up %<name>s?",
|
||||
body: announcement_body)
|
||||
end
|
||||
|
||||
it 'includes the body' do
|
||||
expect(mail.body.encoded)
|
||||
.to include("What's up #{recipient.name}")
|
||||
|
||||
expect(mail.body.encoded)
|
||||
.not_to include("Hey #{recipient.name}!")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user