Skip to content

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

Extract shared email parts into partials to make it easier to reuse them later

Henriette Darge51ec3c91c645
diff --git a/app/helpers/mail_digest_helper.rb b/app/helpers/mail_digest_helper.rb
index 2ac0d975226..1dc389bd5ce 100644
--- a/app/helpers/mail_digest_helper.rb
+++ b/app/helpers/mail_digest_helper.rb
@@ -29,8 +29,6 @@
#++
module MailDigestHelper
- include ::ColorsHelper
-
def digest_summary_text(notification_count, wp_count)
date = Time.parse(Setting.notification_email_digest_time)
@@ -57,31 +55,6 @@ module MailDigestHelper
end
end
- def email_image_tag(image, **options)
- attachments[image] = File.read(Rails.root.join("app/assets/images/#{image}"))
- image_tag attachments[image].url, **options
- end
-
- def unique_reasons_of_notifications(notifications)
- notifications
- .map(&:reason_mail_digest)
- .uniq
- end
-
- def notifications_path(id)
- notifications_center_url(['details', id, 'activity'])
- end
-
- def type_color(type, default_fallback)
- color_id = selected_color(type)
- color_id ? Color.find(color_id).hexcode : default_fallback
- end
-
- def status_colors(status)
- color_id = selected_color(status)
- Color.find(color_id).color_styles.map { |k, v| "#{k}:#{v};" }.join(' ') if color_id
- end
-
private
def timestamp_text(user, journal, extended)
diff --git a/app/helpers/mail_notification_helper.rb b/app/helpers/mail_notification_helper.rb
new file mode 100644
index 00000000000..b32bf04eae4
--- /dev/null
+++ b/app/helpers/mail_notification_helper.rb
@@ -0,0 +1,58 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+module MailNotificationHelper
+ include ::ColorsHelper
+
+ def email_image_tag(image, **options)
+ attachments[image] = File.read(Rails.root.join("app/assets/images/#{image}"))
+ image_tag attachments[image].url, **options
+ end
+
+ def unique_reasons_of_notifications(notifications)
+ notifications
+ .map(&:reason_mail_digest)
+ .uniq
+ end
+
+ def notifications_path(id)
+ notifications_center_url(['details', id, 'activity'])
+ end
+
+ def type_color(type, default_fallback)
+ color_id = selected_color(type)
+ color_id ? Color.find(color_id).hexcode : default_fallback
+ end
+
+ def status_colors(status)
+ color_id = selected_color(status)
+ Color.find(color_id).color_styles.map { |k, v| "#{k}:#{v};" }.join(' ') if color_id
+ end
+end
diff --git a/app/mailers/digest_mailer.rb b/app/mailers/digest_mailer.rb
index f11dcc44137..6648f6a3be6 100644
--- a/app/mailers/digest_mailer.rb
+++ b/app/mailers/digest_mailer.rb
@@ -37,7 +37,8 @@ class DigestMailer < ApplicationMailer
include OpenProject::TextFormatting
include Redmine::I18n
- helper :mail_digest
+ helper :mail_digest,
+ :mail_notification
MAX_SHOWN_WORK_PACKAGES = 15
diff --git a/app/views/digest_mailer/work_packages.html.erb b/app/views/digest_mailer/work_packages.html.erb
index 1397c7fa21c..c5ea948feba 100644
--- a/app/views/digest_mailer/work_packages.html.erb
+++ b/app/views/digest_mailer/work_packages.html.erb
@@ -1,93 +1,14 @@
-<table width="100%" border="0" cellpadding="0" cellspacing="0" style="border-bottom: 1px solid #cccccc; margin-bottom: 30px;">
- <tr>
- <td style="width: 82px; height: 82px; vertical-align: top;">
- <%= email_image_tag("logo_openproject_narrow.svg", alt: I18n.t(:'mail.logo_alt_text')) %>
- </td>
- <td width="100%" style="padding-top: 8px;">
- <table>
- <tr>
- <td style="font-size: 24px; color: #333333; padding-bottom: 5px;">
- <%= I18n.t(:'mail.digests.salutation', user: @user.firstname) %>
- </td>
- </tr>
- <tr>
- <td style="font-size:14px; color: #1A67A3; font-weight: bold; padding-bottom: 10px;">
- <%= digest_summary_text(@notification_ids.length, @aggregated_notifications.length) %>
- </td>
- </tr>
- <tr>
- <td style="padding: 10px 0 25px 0;">
- <a href="<%= notifications_center_url %>"
- target="_blank"
- style="background: #D1E5F5; padding: 8px 12px; color: #1A67A3; border: 1px solid #1A67A3; border-radius: 16px; text-decoration: none;">
- <%= I18n.t(:'mail.digests.center') %>
- </a>
- </td>
- </tr>
- </table>
- </td>
- </tr>
-</table>
+<%= render partial: 'mailer/notification_mailer_header',
+ locals: {
+ summary: digest_summary_text(@notification_ids.length, @aggregated_notifications.length)
+ } %>
<% @aggregated_notifications.first(DigestMailer::MAX_SHOWN_WORK_PACKAGES).each do | work_package, notifications_by_work_package| %>
- <a style="border: 1px solid #E0E0E0;
- margin-bottom: 15px;
- padding: 12px;
- border-radius: 10px;
- text-decoration: none;
- display: block;"
- href="<%= notifications_path(work_package.id) %>"
- target="_blank">
- <table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin-bottom: 10px; font-size: 12px;">
- <tr>
- <td style="color: #333333;
- background-color: #FFFFFF;
- <%= status_colors(work_package.status) %>
- white-space: nowrap;
- padding: 0 5px;">
- <%= work_package.status %>
- </td>
- <td style="padding-left: 5px;
- color: #878787;">
- #<%= work_package.id %>
- </td>
- <td style="white-space: nowrap;
- padding-left: 5px;
- color: #878787;">
- - <%= work_package.project %>
- </td>
- <td style="padding-left: 5px;
- color: #878787;
- white-space: nowrap;">
- <% unique_reasons = unique_reasons_of_notifications(notifications_by_work_package) %>
- <%= ' - ' unless unique_reasons.length === 1 && unique_reasons.first.nil? %>
- <% unique_reasons.each_with_index do |reason, index| %>
- <%= I18n.t(
- :"mail.digests.work_packages.reason.#{reason || :unknown}",
- default: '') %><%= ', ' unless unique_reasons.size-1 == index %>
- <% end %>
- </td>
- <td width="100%" style="text-align: right;">
- <span style="background-color: #00A3FF;
- color: white;
- border-radius: 8px;
- padding: 2px 7px;
- font-size: 10px;">
- <%= notifications_by_work_package.length %>
- </span>
- </td>
- </tr>
- </table>
- <table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin-bottom: 10px; font-size: 14px; font-weight: bold;">
- <tr>
- <td style="color: <%= type_color(work_package.type, '#333333') %>;">
- <%= work_package.type.to_s.upcase %>
- </td>
- <td width="100%" style="padding-left: 5px; color: #333333;">
- <%= work_package.subject %>
- </td>
- </tr>
- </table>
+ <%= render layout: 'mailer/notification_row',
+ locals: {
+ work_package: work_package,
+ notifications_by_work_package: notifications_by_work_package
+ } do %>
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-size: 12px;">
<% notifications_by_work_package.each do | notification | %>
<% if notification.journal.notes.present? %>
@@ -108,7 +29,7 @@
<% end %>
<% end %>
</table>
- </a>
+ <% end %>
<% end %>
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin: 30px 0;">
@@ -131,11 +52,7 @@
<% end %>
</td>
<td>
- <a href="<%= my_notifications_url %>"
- target="_blank"
- style="padding: 8px 12px; color: #333333; border: 1px solid #878787; border-radius: 16px; text-decoration: none; white-space: nowrap;">
- <%= I18n.t(:'mail.digests.settings') %>
- </a>
+ <%= render partial: 'mailer/notification_settings_button' %>
</td>
</tr>
</table>
diff --git a/app/views/mailer/_notification_mailer_header.html.erb b/app/views/mailer/_notification_mailer_header.html.erb
new file mode 100644
index 00000000000..459951821c9
--- /dev/null
+++ b/app/views/mailer/_notification_mailer_header.html.erb
@@ -0,0 +1,30 @@
+<table width="100%" border="0" cellpadding="0" cellspacing="0" style="border-bottom: 1px solid #cccccc; margin-bottom: 30px;">
+ <tr>
+ <td style="width: 82px; height: 82px; vertical-align: top;">
+ <%= email_image_tag("logo_openproject_narrow.svg", alt: I18n.t(:'mail.logo_alt_text')) %>
+ </td>
+ <td width="100%" style="padding-top: 8px;">
+ <table>
+ <tr>
+ <td style="font-size: 24px; color: #333333; padding-bottom: 5px;">
+ <%= I18n.t(:'mail.salutation', user: @user.firstname) %>
+ </td>
+ </tr>
+ <tr>
+ <td style="font-size:14px; color: #1A67A3; font-weight: bold; padding-bottom: 10px;">
+ <%= summary %>
+ </td>
+ </tr>
+ <tr>
+ <td style="padding: 10px 0 25px 0;">
+ <a href="<%= notifications_center_url %>"
+ target="_blank"
+ style="background: #D1E5F5; padding: 8px 12px; color: #1A67A3; border: 1px solid #1A67A3; border-radius: 16px; text-decoration: none;">
+ <%= I18n.t(:'mail.notification.center') %>
+ </a>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+</table>
\ No newline at end of file
diff --git a/app/views/mailer/_notification_row.html.erb b/app/views/mailer/_notification_row.html.erb
new file mode 100644
index 00000000000..8db6e76d7db
--- /dev/null
+++ b/app/views/mailer/_notification_row.html.erb
@@ -0,0 +1,61 @@
+<a style="border: 1px solid #E0E0E0;
+ margin-bottom: 15px;
+ padding: 12px;
+ border-radius: 10px;
+ text-decoration: none;
+ display: block;"
+ href="<%= notifications_path(work_package.id) %>"
+ target="_blank">
+ <table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin-bottom: 10px; font-size: 12px;">
+ <tr>
+ <td style="color: #333333;
+ background-color: #FFFFFF;
+ <%= status_colors(work_package.status) %>
+ white-space: nowrap;
+ padding: 0 5px;">
+ <%= work_package.status %>
+ </td>
+ <td style="padding-left: 5px;
+ color: #878787;">
+ #<%= work_package.id %>
+ </td>
+ <td style="white-space: nowrap;
+ padding-left: 5px;
+ color: #878787;">
+ - <%= work_package.project %>
+ </td>
+ <td style="padding-left: 5px;
+ color: #878787;
+ white-space: nowrap;">
+ <% unique_reasons = unique_reasons_of_notifications(notifications_by_work_package) %>
+ <%= ' - ' unless unique_reasons.length === 1 && unique_reasons.first.nil? %>
+ <% unique_reasons.each_with_index do |reason, index| %>
+ <%= I18n.t(
+ :"mail.digests.work_packages.reason.#{reason || :unknown}",
+ default: '') %><%= ', ' unless unique_reasons.size-1 == index %>
+ <% end %>
+ </td>
+ <td width="100%" style="text-align: right;">
+ <span style="background-color: #00A3FF;
+ color: white;
+ border-radius: 8px;
+ padding: 2px 7px;
+ font-size: 10px;">
+ <%= notifications_by_work_package.length %>
+ </span>
+ </td>
+ </tr>
+ </table>
+ <table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin-bottom: 10px; font-size: 14px; font-weight: bold;">
+ <tr>
+ <td style="color: <%= type_color(work_package.type, '#333333') %>;">
+ <%= work_package.type.to_s.upcase %>
+ </td>
+ <td width="100%" style="padding-left: 5px; color: #333333;">
+ <%= work_package.subject %>
+ </td>
+ </tr>
+ </table>
+
+ <%= yield %>
+</a>
\ No newline at end of file
diff --git a/app/views/mailer/_notification_settings_button.html.erb b/app/views/mailer/_notification_settings_button.html.erb
new file mode 100644
index 00000000000..a3d01ab38a3
--- /dev/null
+++ b/app/views/mailer/_notification_settings_button.html.erb
@@ -0,0 +1,5 @@
+<a href="<%= my_notifications_url %>"
+ target="_blank"
+ style="padding: 8px 12px; color: #333333; border: 1px solid #878787; border-radius: 16px; text-decoration: none; white-space: nowrap;">
+ <%= I18n.t(:'mail.notification.settings') %>
+</a>
\ No newline at end of file
diff --git a/config/locales/en.yml b/config/locales/en.yml
index e9d9abd7f7f..9248ddd8f55 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1967,9 +1967,6 @@ en:
mail:
actions: 'Actions'
digests:
- center: 'Notification center'
- salutation: 'Hey %{user}!'
- settings: 'Change email settings'
time_frame: "At %{time} on %{weekday}, %{date}, you have %{number_unread} unread notifications in %{number_work_packages} work packages"
work_packages:
comment_added: '<b>Comment</b> added'
@@ -1990,6 +1987,10 @@ en:
updated: 'Updated'
updated_at: '%{timestamp} ago by %{user}'
logo_alt_text: 'OpenProject Logo'
+ notification:
+ center: 'Notification center'
+ settings: 'Change email settings'
+ salutation: 'Hey %{user}!'
mail_body_account_activation_request: "A new user (%{value}) has registered. The account is pending your approval:"
mail_body_account_information: "Your account information"