Skip to content

Commit

Permalink
第16回作業分
Browse files Browse the repository at this point in the history
  • Loading branch information
juno-nishizaki committed May 15, 2022
1 parent 089e4be commit e833363
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 6 deletions.
15 changes: 9 additions & 6 deletions app/models/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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)
redmine_headers 'Project' => issue.project.identifier,
'Issue-Tracker' => issue.tracker.name,
'Issue-Id' => issue.id,
Expand All @@ -81,6 +81,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 @@ -96,12 +97,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)
issue = journal.journalized
redmine_headers 'Project' => issue.project.identifier,
'Issue-Tracker' => issue.tracker.name,
Expand All @@ -116,6 +117,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 @@ -134,16 +136,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)
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 @@ -156,7 +159,7 @@ 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

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>
<%= @recipients.take(Setting.show_recipients_limit.to_i).map(&:name).join(', ') %><%= '...' if @recipients.size > Setting.show_recipients_limit.to_i %>
</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) %>
<%= @recipients.take(Setting.show_recipients_limit.to_i).map(&:name).join(', ') %><%= '...' if @recipients.size > Setting.show_recipients_limit.to_i %>
<% 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 @@ -506,6 +506,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 @@ -1232,6 +1234,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 @@ -903,6 +903,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 @@ -1265,6 +1266,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

0 comments on commit e833363

Please sign in to comment.