OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Store salutation as setting to make it reusable
Oliver Güntherfeb3edff1371
diff --git a/app/helpers/mail_layout_helper.rb b/app/helpers/mail_layout_helper.rbindex 766621c13a0..532894e838b 100644--- a/app/helpers/mail_layout_helper.rb+++ b/app/helpers/mail_layout_helper.rb@@ -68,4 +68,13 @@ module MailLayoutHelpercontent_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+ endenddiff --git a/app/mailers/announcement_mailer.rb b/app/mailers/announcement_mailer.rbindex 023febaa34f..52ddaf86956 100644--- a/app/mailers/announcement_mailer.rb+++ b/app/mailers/announcement_mailer.rb@@ -33,9 +33,10 @@class AnnouncementMailer < ApplicationMailerinclude OpenProject::StaticRouting::UrlHelpersinclude 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) dolocalized_subject = localized(subject)@@ -44,7 +45,6 @@ class AnnouncementMailer < ApplicationMailerlocals = {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 < ApplicationMailerinputendend-- 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- endenddiff --git a/app/views/admin/settings/mail_notifications_settings/show.html.erb b/app/views/admin/settings/mail_notifications_settings/show.html.erbindex 4e275a2dce8..bb12727c4d8 100644--- a/app/views/admin/settings/mail_notifications_settings/show.html.erb+++ b/app/views/admin/settings/mail_notifications_settings/show.html.erb@@ -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' %>diff --git a/app/views/announcement_mailer/announce.html.erb b/app/views/announcement_mailer/announce.html.erbindex 0a814918708..824b9cbb073 100644--- a/app/views/announcement_mailer/announce.html.erb+++ b/app/views/announcement_mailer/announce.html.erb@@ -2,7 +2,6 @@<%= render partial: 'mailer/mailer_header',locals: {summary: header_summary,- salutation: salutation,user: user} %>diff --git a/app/views/announcement_mailer/announce.text.erb b/app/views/announcement_mailer/announce.text.erbindex ae763a29f2f..bee2004dc04 100644--- a/app/views/announcement_mailer/announce.text.erb+++ b/app/views/announcement_mailer/announce.text.erb@@ -1,4 +1,4 @@-<%= salutation %>+<%= user_salutation(user) %><%= header_summary %><%= "-" * 100 %>diff --git a/app/views/digest_mailer/work_packages.html.erb b/app/views/digest_mailer/work_packages.html.erbindex e78a53f9e5c..38b35e85a5d 100644--- a/app/views/digest_mailer/work_packages.html.erb+++ b/app/views/digest_mailer/work_packages.html.erb@@ -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| %>diff --git a/app/views/mailer/_mailer_header.html.erb b/app/views/mailer/_mailer_header.html.erbindex 5500a9eb31b..3859afc37b8 100644--- a/app/views/mailer/_mailer_header.html.erb+++ b/app/views/mailer/_mailer_header.html.erb@@ -8,7 +8,7 @@<tr><td><span style="font-size: 24px; color: #333333;">- <%= salutation %>+ <%= user_salutation(user) %></span></td></tr>diff --git a/app/views/sharing_mailer/shared_work_package.html.erb b/app/views/sharing_mailer/shared_work_package.html.erbindex f48c31c372d..d29a6556309 100644--- a/app/views/sharing_mailer/shared_work_package.html.erb+++ b/app/views/sharing_mailer/shared_work_package.html.erb@@ -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',diff --git a/app/views/work_package_mailer/mentioned.html.erb b/app/views/work_package_mailer/mentioned.html.erbindex 8b51803494c..3f4a333d98b 100644--- a/app/views/work_package_mailer/mentioned.html.erb+++ b/app/views/work_package_mailer/mentioned.html.erb@@ -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',diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex b06c3294130..a15f4bd4848 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -402,6 +402,10 @@ module Settingsdefault: nil,env_alias: 'EMAIL_DELIVERY_METHOD'},+ emails_salutation: {+ allowed: %w[firstname name],+ default: :firstname+ },emails_footer: {default: {'en' => ''diff --git a/config/locales/en.yml b/config/locales/en.ymlindex b4edbd1044f..150d0a84596 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -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"diff --git a/modules/meeting/app/mailers/meeting_mailer.rb b/modules/meeting/app/mailers/meeting_mailer.rbindex 716c97083c6..dc649ccf9f0 100644--- a/modules/meeting/app/mailers/meeting_mailer.rb+++ b/modules/meeting/app/mailers/meeting_mailer.rb@@ -30,6 +30,7 @@ class MeetingMailer < UserMailerdef invited(meeting, user, actor)@actor = actor@meeting = meeting+ @user = useropen_project_headers 'Project' => @meeting.project.identifier,'Meeting-Id' => @meeting.id@@ -42,6 +43,7 @@ class MeetingMailer < UserMailerdef rescheduled(meeting, user, actor, changes:)@actor = actor+ @user = user@meeting = meeting@changes = changesdiff --git a/modules/meeting/app/views/meeting_mailer/invited.html.erb b/modules/meeting/app/views/meeting_mailer/invited.html.erbindex bcfa91daeaf..bc294af3326 100644--- a/modules/meeting/app/views/meeting_mailer/invited.html.erb+++ b/modules/meeting/app/views/meeting_mailer/invited.html.erb@@ -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) %>diff --git a/modules/meeting/app/views/meeting_mailer/rescheduled.html.erb b/modules/meeting/app/views/meeting_mailer/rescheduled.html.erbindex 97a6bb5a9e1..c152dd3c8f1 100644--- a/modules/meeting/app/views/meeting_mailer/rescheduled.html.erb+++ b/modules/meeting/app/views/meeting_mailer/rescheduled.html.erb@@ -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} %>diff --git a/modules/meeting/config/locales/en.yml b/modules/meeting/config/locales/en.ymlindex e8c4ae14dfb..74f6af3d9fb 100644--- a/modules/meeting/config/locales/en.yml+++ b/modules/meeting/config/locales/en.yml@@ -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"diff --git a/spec/mailers/announcement_mailer_spec.rb b/spec/mailers/announcement_mailer_spec.rbindex fe20ba08332..a9fbc9f9e42 100644--- a/spec/mailers/announcement_mailer_spec.rb+++ b/spec/mailers/announcement_mailer_spec.rb@@ -59,22 +59,5 @@ RSpec.describe AnnouncementMailer doexpect(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- endendend