Skip to content

[WIP] Task/66 #73

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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions app/helpers/mailer_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

# Redmine - project management software
# Copyright (C) 2006-2022 Jean-Philippe Lang
#
# 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.

module MailerHelper
def show_recipients(recipients)
recipients.take(Setting.show_recipients_limit.to_i).map(&:name).join(', ') + (recipients.size > Setting.show_recipients_limit.to_i ? '...' : '')
end
end
61 changes: 37 additions & 24 deletions app/models/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Mailer < ActionMailer::Base
helper :application
helper :issues
helper :custom_fields
helper :mailer

include Redmine::I18n
include Roadie::Rails::Automatic
Expand Down Expand Up @@ -70,7 +71,7 @@ def self.default_url_options
end

# Builds a mail for notifying user about a new issue
def issue_add(user, issue)
def issue_add(user, issue, recipients=nil)
redmine_headers 'Project' => issue.project.identifier,
'Issue-Tracker' => issue.tracker.name,
'Issue-Id' => issue.id,
Expand All @@ -82,6 +83,7 @@ def issue_add(user, issue)
@author = issue.author
@issue = issue
@user = user
@recipients = recipients
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue)
subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]"
subject += " (#{issue.status.name})" if Setting.show_status_changes_in_mail_subject?
Expand All @@ -97,12 +99,12 @@ def issue_add(user, issue)
def self.deliver_issue_add(issue)
users = issue.notified_users | issue.notified_watchers | issue.notified_mentions
users.each do |user|
issue_add(user, issue).deliver_later
issue_add(user, issue, users).deliver_later
end
end

# Builds a mail for notifying user about an issue update
def issue_edit(user, journal)
def issue_edit(user, journal, recipients=nil)
issue = journal.journalized
redmine_headers 'Project' => issue.project.identifier,
'Issue-Tracker' => issue.tracker.name,
Expand All @@ -118,6 +120,7 @@ def issue_edit(user, journal)
s += issue.subject
@issue = issue
@user = user
@recipients = recipients
@journal = journal
@journal_details = journal.visible_details
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}")
Expand All @@ -136,16 +139,17 @@ def self.deliver_issue_edit(journal)
journal.notes? || journal.visible_details(user).any?
end
users.each do |user|
issue_edit(user, journal).deliver_later
issue_edit(user, journal, users).deliver_later
end
end

# Builds a mail to user about a new document.
def document_added(user, document, author)
def document_added(user, document, author, recipients=nil)
redmine_headers 'Project' => document.project.identifier
@author = author
@document = document
@user = user
@recipients = recipients
@document_url = url_for(:controller => 'documents', :action => 'show', :id => document)
mail :to => user,
:subject => "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
Expand All @@ -158,12 +162,12 @@ def document_added(user, document, author)
def self.deliver_document_added(document, author)
users = document.notified_users
users.each do |user|
document_added(user, document, author).deliver_later
document_added(user, document, author, users).deliver_later
end
end

# Builds a mail to user about new attachements.
def attachments_added(user, attachments)
def attachments_added(user, attachments, recipients=nil)
container = attachments.first.container
added_to = ''
added_to_url = ''
Expand All @@ -182,6 +186,7 @@ def attachments_added(user, attachments)
redmine_headers 'Project' => container.project.identifier
@attachments = attachments
@user = user
@recipients = recipients
@added_to = added_to
@added_to_url = added_to_url
mail :to => user,
Expand All @@ -202,18 +207,19 @@ def self.deliver_attachments_added(attachments)
end

users.each do |user|
attachments_added(user, attachments).deliver_later
attachments_added(user, attachments, users).deliver_later
end
end

# Builds a mail to user about a new news.
def news_added(user, news)
def news_added(user, news, recipients=nil)
redmine_headers 'Project' => news.project.identifier
@author = news.author
message_id news
references news
@news = news
@user = user
@recipients = recipients
@news_url = url_for(:controller => 'news', :action => 'show', :id => news)
mail :to => user,
:subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
Expand All @@ -226,12 +232,12 @@ def news_added(user, news)
def self.deliver_news_added(news)
users = news.notified_users | news.notified_watchers_for_added_news
users.each do |user|
news_added(user, news).deliver_later
news_added(user, news, users).deliver_later
end
end

# Builds a mail to user about a new news comment.
def news_comment_added(user, comment)
def news_comment_added(user, comment, recipients=nil)
news = comment.commented
redmine_headers 'Project' => news.project.identifier
@author = comment.author
Expand All @@ -240,6 +246,7 @@ def news_comment_added(user, comment)
@news = news
@comment = comment
@user = user
@recipients = recipients
@news_url = url_for(:controller => 'news', :action => 'show', :id => news)
mail :to => user,
:subject => "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}"
Expand All @@ -253,19 +260,20 @@ def self.deliver_news_comment_added(comment)
news = comment.commented
users = news.notified_users | news.notified_watchers
users.each do |user|
news_comment_added(user, comment).deliver_later
news_comment_added(user, comment, users).deliver_later
end
end

# Builds a mail to user about a new message.
def message_posted(user, message)
def message_posted(user, message, recipients=nil)
redmine_headers 'Project' => message.project.identifier,
'Topic-Id' => (message.parent_id || message.id)
@author = message.author
message_id message
references message.root
@message = message
@user = user
@recipients = recipients
@message_url = url_for(message.event_url)
mail :to => user,
:subject => "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}"
Expand All @@ -281,18 +289,19 @@ def self.deliver_message_posted(message)
users |= message.board.notified_watchers

users.each do |user|
message_posted(user, message).deliver_later
message_posted(user, message, users).deliver_later
end
end

# Builds a mail to user about a new wiki content.
def wiki_content_added(user, wiki_content)
def wiki_content_added(user, wiki_content, recipients=nil)
redmine_headers 'Project' => wiki_content.project.identifier,
'Wiki-Page-Id' => wiki_content.page.id
@author = wiki_content.author
message_id wiki_content
@wiki_content = wiki_content
@user = user
@recipients = recipients
@wiki_content_url = url_for(:controller => 'wiki', :action => 'show',
:project_id => wiki_content.project,
:id => wiki_content.page.title)
Expand All @@ -310,18 +319,19 @@ def wiki_content_added(user, wiki_content)
def self.deliver_wiki_content_added(wiki_content)
users = wiki_content.notified_users | wiki_content.page.wiki.notified_watchers | wiki_content.notified_mentions
users.each do |user|
wiki_content_added(user, wiki_content).deliver_later
wiki_content_added(user, wiki_content, users).deliver_later
end
end

# Builds a mail to user about an update of the specified wiki content.
def wiki_content_updated(user, wiki_content)
def wiki_content_updated(user, wiki_content, recipients=nil)
redmine_headers 'Project' => wiki_content.project.identifier,
'Wiki-Page-Id' => wiki_content.page.id
@author = wiki_content.author
message_id wiki_content
@wiki_content = wiki_content
@user = user
@recipients = recipients
@wiki_content_url =
url_for(:controller => 'wiki', :action => 'show',
:project_id => wiki_content.project,
Expand All @@ -348,7 +358,7 @@ def self.deliver_wiki_content_updated(wiki_content)
users |= wiki_content.notified_mentions

users.each do |user|
wiki_content_updated(user, wiki_content).deliver_later
wiki_content_updated(user, wiki_content, users).deliver_later
end
end

Expand All @@ -367,8 +377,9 @@ def self.deliver_account_information(user, password)
end

# Builds a mail to user about an account activation request.
def account_activation_request(user, new_user)
def account_activation_request(user, new_user, recipients=nil)
@new_user = new_user
@recipients = recipients
@url = url_for(:controller => 'users', :action => 'index',
:status => User::STATUS_REGISTERED,
:sort_key => 'created_on', :sort_order => 'desc')
Expand All @@ -385,7 +396,7 @@ def self.deliver_account_activation_request(new_user)
# Send the email to all active administrators
users = User.active.where(:admin => true)
users.each do |user|
account_activation_request(user, new_user).deliver_later
account_activation_request(user, new_user, users.to_a).deliver_later
end
end

Expand Down Expand Up @@ -469,7 +480,8 @@ def self.deliver_register(user, token)
# field: :field_mail,
# value: address
# ) => Mail::Message object
def security_notification(user, sender, options={})
def security_notification(user, sender, options={}, recipients=nil)
@recipients = recipients
@sender = sender
redmine_headers 'Sender' => sender.login
@message =
Expand Down Expand Up @@ -506,12 +518,13 @@ def self.deliver_security_notification(users, sender, options={})
options[:remote_ip] ||= sender.remote_ip

Array.wrap(users).each do |user|
security_notification(user, sender, options).deliver_later
security_notification(user, sender, options, users).deliver_later
end
end

# Build a mail to user about application settings changes made by sender.
def settings_updated(user, sender, changes, options={})
def settings_updated(user, sender, changes, options={}, recipients=nil)
@recipients = recipients
@sender = sender
redmine_headers 'Sender' => sender.login
@changes = changes
Expand All @@ -538,7 +551,7 @@ def self.deliver_settings_updated(sender, changes, options={})

users = User.active.where(admin: true).to_a
users.each do |user|
settings_updated(user, sender, changes, options).deliver_later
settings_updated(user, sender, changes, options, users).deliver_later
end
end

Expand Down
11 changes: 11 additions & 0 deletions app/views/layouts/mailer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ span.footer {
font-size: 0.8em;
font-style: italic;
}
span.recipients {
font-size: 0.8em;
font-style: italic;
color: #959595;
}
blockquote { font-style: italic; border-left: 3px solid #e0e0e0; padding-left: 0.6em; margin-left: 0;}
blockquote blockquote { margin-left: 0;}
pre, code {font-family: Consolas, Menlo, "Liberation Mono", Courier, monospace;}
Expand Down Expand Up @@ -78,5 +83,11 @@ table, td, th {
<% if Setting.emails_footer.present? -%>
<span class="footer"><%= Redmine::WikiFormatting.to_html(Setting.text_formatting, Setting.emails_footer).html_safe %></span>
<% end -%>
<% if Setting.show_recipients_in_mail_footer? && @recipients.present? %>
<span class="recipients">
<%= l(:text_sent_email_to_recipients) %><br>
<%= show_recipients @recipients %>
</span>
<% end %>
</body>
</html>
5 changes: 5 additions & 0 deletions app/views/layouts/mailer.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
--
<%= Setting.emails_footer %>
<% end -%>
<% if Setting.show_recipients_in_mail_footer? && @recipients.present? %>

<%= l(:text_sent_email_to_recipients) %>
<%= show_recipients @recipients %>
<% end -%>
4 changes: 4 additions & 0 deletions app/views/settings/_notifications.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<p><%= setting_check_box :plain_text_mail %></p>

<p><%= setting_check_box :show_status_changes_in_mail_subject %></p>

<p><%= setting_check_box :show_recipients_in_mail_footer, :data => {:enables => '#settings_show_recipients_limit'} %></p>

<p><%= setting_text_field :show_recipients_limit, :size => 6%></p>
</div>

<fieldset class="box" id="notified_events"><legend><%=l(:text_select_mail_notifications)%></legend>
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ en:
setting_timelog_max_hours_per_day: Maximum hours that can be logged per day and user
setting_timelog_accept_future_dates: Accept time logs on future dates
setting_show_status_changes_in_mail_subject: Show status changes in issue mail notifications subject
setting_show_recipients_in_mail_footer: Show recipients in mail notifications footer
setting_show_recipients_limit: Maximum number of recipients in mail notifications footer
setting_project_list_defaults: Projects list defaults
setting_twofa: Two-factor authentication

Expand Down Expand Up @@ -1259,6 +1261,7 @@ en:
text_issues_ref_in_commit_messages: Referencing and fixing issues in commit messages
text_issue_added: "Issue %{id} has been reported by %{author}."
text_issue_updated: "Issue %{id} has been updated by %{author}."
text_sent_email_to_recipients: The following recipients have also received this email.
text_wiki_destroy_confirmation: Are you sure you want to delete this wiki and all its content?
text_issue_category_destroy_question: "Some issues (%{count}) are assigned to this category. What do you want to do?"
text_issue_category_destroy_assignments: Remove category assignments
Expand Down
3 changes: 3 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ ja:
text_issues_ref_in_commit_messages: コミットメッセージ内でチケットの参照/修正
text_issue_added: "チケット %{id} を %{author} さんが作成しました。"
text_issue_updated: "チケット %{id} を %{author} さんが更新しました。"
text_sent_email_to_recipients: 次のユーザーにもこのメールを送信しました。
text_wiki_destroy_confirmation: 本当にこのwikiとその内容のすべてを削除しますか?
text_issue_category_destroy_question: "%{count}件のチケットがこのカテゴリに割り当てられています。"
text_issue_category_destroy_assignments: カテゴリの割り当てを削除する
Expand Down Expand Up @@ -1260,6 +1261,8 @@ ja:
text_status_no_workflow: このステータスはどのトラッカーのワークフローでも使われていません
setting_mail_handler_preferred_body_part: マルチパート (HTML) メールの優先パート
setting_show_status_changes_in_mail_subject: 通知メールの題名にステータス変更の情報を挿入
setting_show_recipients_in_mail_footer: 通知メールのフッタに受信者の情報を挿入
setting_show_recipients_limit: 通知メールのフッタに挿入される受信者数の上限
label_inherited_from_parent_project: 親プロジェクトから継承
label_inherited_from_group: グループ %{name} から継承
label_trackers_description: トラッカーの説明
Expand Down
5 changes: 5 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,8 @@ timelog_accept_future_dates:
default: 1
show_status_changes_in_mail_subject:
default: 1
show_recipients_in_mail_footer:
default: 0
show_recipients_limit:
format: int
default: 15
Loading