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

* Change email subject and summary text to include how many direct mentioned there have been * Move logo to the right side

Henriette Dargef388e941a9c2
diff --git a/app/helpers/mail_digest_helper.rb b/app/helpers/mail_digest_helper.rb
index e1151a59820..67bf356cb2f 100644
--- a/app/helpers/mail_digest_helper.rb
+++ b/app/helpers/mail_digest_helper.rb
@@ -29,15 +29,15 @@
#++
module MailDigestHelper
- def digest_summary_text(notification_count, wp_count)
- date = Time.parse(Setting.notification_email_digest_time)
-
- I18n.t(:'mail.digests.time_frame',
- time: Setting.notification_email_digest_time,
- weekday: day_name(date.wday),
- date: ::I18n.l(date.to_date, format: :long),
- number_unread: notification_count,
- number_work_packages: wp_count)
+ def digest_summary_text(notification_count, mentioned_count)
+ if mentioned_count > 0
+ I18n.t(:'mail.digests.summary_with_mentioned',
+ number_unread: notification_count,
+ number_mentioned: mentioned_count)
+ else
+ I18n.t(:'mail.digests.summary',
+ number_unread: notification_count)
+ end
end
def digest_notification_timestamp_text(notification, html: true, extended_text: false)
@@ -48,7 +48,7 @@ module MailDigestHelper
end
def digest_comment_text(notification)
- if notification.journal.notes.match(/<mention.*data-type="user".*>/)
+ if notification.reason_mail_digest === "mentioned"
sanitize I18n.t(:'mail.digests.work_packages.mentioned')
else
sanitize I18n.t(:'mail.digests.work_packages.comment_added')
@@ -63,7 +63,9 @@ module MailDigestHelper
sanitize(
"#{I18n.t(:"mail.digests.work_packages.#{value}")} #{I18n.t(:"mail.digests.work_packages.#{value}_at",
user: user,
- timestamp: journal.created_at.strftime(I18n.t(:'time.formats.time')))}"
+ timestamp: journal.created_at.strftime(
+ I18n.t(:'time.formats.time')
+ ))}"
)
else
sanitize(I18n.t(:"mail.digests.work_packages.#{value}_at",
diff --git a/app/mailers/digest_mailer.rb b/app/mailers/digest_mailer.rb
index 9c071553100..6562e205cc1 100644
--- a/app/mailers/digest_mailer.rb
+++ b/app/mailers/digest_mailer.rb
@@ -64,14 +64,40 @@ class DigestMailer < ApplicationMailer
.reverse
.group_by(&:resource)
+ @mentioned_count = @aggregated_notifications
+ .values
+ .flatten
+ .map(&:reason_mail_digest)
+ .compact
+ .count("mentioned")
+
return if @aggregated_notifications.empty?
+ project_count = @aggregated_notifications
+ .keys
+ .map(&:project_id)
+ .uniq
+ .size
+
with_locale_for(recipient) do
+ if @mentioned_count > 0
+ subject = I18n.t('mail.digests.work_packages.subject_with_mentioned',
+ instance_name: Setting.app_title,
+ notifications: notification_ids.size,
+ mentioned: @mentioned_count,
+ work_packages: @aggregated_notifications.size,
+ projects: project_count)
+ else
+
+ subject = I18n.t('mail.digests.work_packages.subject',
+ instance_name: Setting.app_title,
+ notifications: notification_ids.size,
+ work_packages: @aggregated_notifications.size,
+ projects: project_count)
+ end
+
mail to: recipient.mail,
- subject: I18n.t('mail.digests.work_packages.subject',
- instance_name: Setting.app_title,
- notifications: notification_ids.count,
- work_packages: @aggregated_notifications.count)
+ subject: subject
end
end
diff --git a/app/views/digest_mailer/work_packages.html.erb b/app/views/digest_mailer/work_packages.html.erb
index 4be207ef33f..359359556fa 100644
--- a/app/views/digest_mailer/work_packages.html.erb
+++ b/app/views/digest_mailer/work_packages.html.erb
@@ -1,6 +1,6 @@
<%= render partial: 'mailer/notification_mailer_header',
locals: {
- summary: digest_summary_text(@notification_ids.length, @aggregated_notifications.length)
+ summary: digest_summary_text(@notification_ids.length, @mentioned_count)
} %>
<% @aggregated_notifications.first(DigestMailer::MAX_SHOWN_WORK_PACKAGES).each do | work_package, notifications_by_work_package| %>
@@ -12,7 +12,7 @@
<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? %>
- <tr style="color: #878787; line-height: 20px; white-space: nowrap; font-size: 14px;">
+ <tr style="color: #878787; line-height: 20px; font-size: 14px;">
<td>
<%= digest_comment_text(notification) %>
<%= digest_notification_timestamp_text(notification) %>
@@ -46,7 +46,13 @@
</span>
<a
target="_blank"
- style="background-color: #D1E5F5; padding: 8px 12px; color: #1A67A3; border: 1px solid #1A67A3; border-radius: 16px; text-decoration: none; white-space: nowrap;">
+ style="background-color: #D1E5F5;
+ padding: 8px 12px;
+ color: #1A67A3;
+ border: 1px solid #1A67A3;
+ border-radius: 16px;
+ text-decoration: none;
+ white-space: nowrap;">
<%= I18n.t(:'mail.digests.work_packages.see_all') %>
</a>
<% end %>
diff --git a/app/views/digest_mailer/work_packages.text.erb b/app/views/digest_mailer/work_packages.text.erb
index 089a332c9f1..3681f7ed00f 100644
--- a/app/views/digest_mailer/work_packages.text.erb
+++ b/app/views/digest_mailer/work_packages.text.erb
@@ -1,5 +1,5 @@
<%= I18n.t(:'mail.salutation', user: @user.firstname) %>
-<%= digest_summary_text(@notification_ids.length, @aggregated_notifications.length) %>
+<%= digest_summary_text(@notification_ids.length, @mentioned_count) %>
<%= "-" * 100 %>
<% @aggregated_notifications.first(DigestMailer::MAX_SHOWN_WORK_PACKAGES).each do | work_package, notifications_by_work_package| %>
diff --git a/app/views/mailer/_notification_mailer_header.html.erb b/app/views/mailer/_notification_mailer_header.html.erb
index 6237f0abd03..56dcd3416e5 100644
--- a/app/views/mailer/_notification_mailer_header.html.erb
+++ b/app/views/mailer/_notification_mailer_header.html.erb
@@ -1,8 +1,5 @@
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="border-bottom: 1px solid #cccccc; margin-bottom: 32px;">
<tr>
- <td style="width: 82px; height: 82px; vertical-align: top;">
- <%= logo_tag({ alt: "#{Setting.app_title} #{I18n.t(:'mail.logo_alt_text')}", style: "height:82px;"}) %>
- </td>
<td width="100%" style="padding-top: 8px; padding-left: 12px;">
<table>
<tr>
@@ -26,5 +23,8 @@
</tr>
</table>
</td>
+ <td style="width: 96px; height: 96px; vertical-align: top;">
+ <%= logo_tag({ alt: "#{Setting.app_title} #{I18n.t(:'mail.logo_alt_text')}", style: "height: 96px;"}) %>
+ </td>
</tr>
-</table>
\ No newline at end of file
+</table>
diff --git a/app/views/mailer/_notification_row.html.erb b/app/views/mailer/_notification_row.html.erb
index dde1a237f0e..97554c930f2 100644
--- a/app/views/mailer/_notification_row.html.erb
+++ b/app/views/mailer/_notification_row.html.erb
@@ -19,8 +19,7 @@
</div>
</td>
<td width="100%" style="padding-left: 8px;
- font-weight: bold;
- color: #878787;">
+ color: #878787;">
#<%= work_package.id %> - <%= work_package.project %>
<% unique_reasons = unique_reasons_of_notifications(notifications_by_work_package) %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 092e2cd91b5..849a3c7e88e 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1967,7 +1967,8 @@ en:
mail:
actions: 'Actions'
digests:
- time_frame: "At %{time} on %{weekday}, %{date}, you have %{number_unread} unread notifications in %{number_work_packages} work packages"
+ summary: "You have %{number_unread} unread notifications"
+ summary_with_mentioned: "You have %{number_unread} unread notifications including %{number_mentioned} mentions"
work_packages:
comment_added: '<b>Comment</b> added'
created: 'Created'
@@ -1984,6 +1985,7 @@ en:
prefix: 'Received because of the notification setting: %{reason}'
see_all: 'See all'
subject: '%{instance_name} - %{notifications} unread notification(s) in %{work_packages} work package(s)'
+ subject_with_mentioned: '%{instance_name} - %{notifications} unread notification(s) including %{mentioned} mention(s) in %{work_packages} work package(s), in %{projects} projects'
updated: 'Updated'
updated_at: 'at %{timestamp} by %{user}'
logo_alt_text: 'Logo'
diff --git a/spec/mailers/digest_mailer_spec.rb b/spec/mailers/digest_mailer_spec.rb
index 357ceef6f91..3a6e7c8ccda 100644
--- a/spec/mailers/digest_mailer_spec.rb
+++ b/spec/mailers/digest_mailer_spec.rb
@@ -122,11 +122,11 @@ describe DigestMailer, type: :mailer do
expect(mail_body)
.to have_text(expected_notification_header, normalize_ws: true)
- expected_journal_text = "Comment added less than a minute ago by #{recipient.name}"
+ expected_journal_text = "Comment added at #{journal.created_at.strftime('%I:%M %p')} by #{recipient.name}"
expect(mail_body)
.to have_text(expected_journal_text, normalize_ws: true)
- expected_details_text = "Subject changed from old subject to new subject less than a minute ago by #{recipient.name}"
+ expected_details_text = "Subject changed from old subject to new subject at #{journal.created_at.strftime('%I:%M %p')} by #{recipient.name}"
expect(mail_body)
.to have_text(expected_details_text, normalize_ws: true)
end