Feature #21421 » 0002-Add-Mailer-security_notification.patch
| app/models/mailer.rb | ||
|---|---|---|
|
:subject => l(:mail_subject_register, Setting.app_title)
|
||
|
end
|
||
|
def security_notification(recipients, options={})
|
||
|
redmine_headers 'Sender' => User.current.login
|
||
|
@user = Array(recipients).detect{|r| r.is_a? User }
|
||
|
set_language_if_valid(@user.try :language)
|
||
|
@message = l(options[:message],
|
||
|
field: (options[:field] && l(options[:field])),
|
||
|
value: options[:value]
|
||
|
)
|
||
|
@title = options[:title] && l(options[:title])
|
||
|
@url = options[:url] && (options[:url].is_a?(Hash) ? url_for(options[:url]) : options[:url])
|
||
|
mail :to => recipients,
|
||
|
:subject => l(:mail_subject_security_notification)
|
||
|
end
|
||
|
def test_email(user)
|
||
|
set_language_if_valid(user.language)
|
||
|
@url = url_for(:controller => 'welcome')
|
||
| app/views/mailer/security_notification.html.erb | ||
|---|---|---|
|
<p><%= @message %><br />
|
||
|
<% if @url && @title -%>
|
||
|
<%= link_to @title, @url -%>
|
||
|
<% elsif @url -%>
|
||
|
<%= link_to @url -%>
|
||
|
<% elsif @title -%>
|
||
|
<%= content_tag :h1, @title -%>
|
||
|
<% end %></p>
|
||
|
<p><%= l(:field_user) %>: <strong><%= User.current.login %></strong><br/>
|
||
|
<%= l(:field_remote_ip) %>: <strong><%= User.current.remote_ip %></strong><br/>
|
||
|
<%= l(:label_date) %>: <strong><%= format_time Time.now, true, @user %></strong></p>
|
||
| app/views/mailer/security_notification.text.erb | ||
|---|---|---|
|
<%= @message %>
|
||
|
<%= @url || @title %>
|
||
|
<%= l(:field_user) %>: <%= User.current.login %>
|
||
|
<%= l(:field_remote_ip) %>: <%= User.current.remote_ip %>
|
||
|
<%= l(:label_date) %>: <%= format_time Time.now, true, @user %>
|
||
| config/locales/de.yml | ||
|---|---|---|
|
mail_subject_reminder: "%{count} Tickets müssen in den nächsten %{days} Tagen abgegeben werden"
|
||
|
mail_subject_wiki_content_added: "Wiki-Seite '%{id}' hinzugefügt"
|
||
|
mail_subject_wiki_content_updated: "Wiki-Seite '%{id}' erfolgreich aktualisiert"
|
||
|
mail_subject_security_notification: "Sicherheitshinweis"
|
||
|
mail_body_security_notification_change: "%{field} wurde geändert."
|
||
|
mail_body_security_notification_change_to: "%{field} wurde geändert zu %{value}."
|
||
|
mail_body_security_notification_add: "%{field} %{value} wurde hinzugefügt."
|
||
|
mail_body_security_notification_remove: "%{field} %{value} wurde entfernt."
|
||
|
notice_account_activated: Ihr Konto ist aktiviert. Sie können sich jetzt anmelden.
|
||
|
notice_account_deleted: Ihr Benutzerkonto wurde unwiderruflich gelöscht.
|
||
| config/locales/en.yml | ||
|---|---|---|
|
mail_body_wiki_content_added: "The '%{id}' wiki page has been added by %{author}."
|
||
|
mail_subject_wiki_content_updated: "'%{id}' wiki page has been updated"
|
||
|
mail_body_wiki_content_updated: "The '%{id}' wiki page has been updated by %{author}."
|
||
|
mail_subject_security_notification: "Security notification"
|
||
|
mail_body_security_notification_change: "%{field} was changed."
|
||
|
mail_body_security_notification_change_to: "%{field} was changed to %{value}."
|
||
|
mail_body_security_notification_add: "%{field} %{value} was added."
|
||
|
mail_body_security_notification_remove: "%{field} %{value} was removed."
|
||
|
field_name: Name
|
||
|
field_description: Description
|
||
| test/unit/mailer_test.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def test_security_notification
|
||
|
set_language_if_valid User.find(1).language
|
||
|
with_settings :emails_footer => "footer without link" do
|
||
|
User.current.remote_ip = '192.168.1.1'
|
||
|
assert Mailer.security_notification(User.find(1), message: :notice_account_password_updated).deliver
|
||
|
mail = last_email
|
||
|
assert_not_nil mail
|
||
|
assert_mail_body_match '192.168.1.1', mail
|
||
|
assert_mail_body_match I18n.t(:notice_account_password_updated), mail
|
||
|
assert_select_email do
|
||
|
assert_select "h1", false
|
||
|
assert_select "a", false
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def test_security_notification_should_include_title
|
||
|
set_language_if_valid User.find(2).language
|
||
|
with_settings :emails_footer => "footer without link" do
|
||
|
assert Mailer.security_notification(User.find(2),
|
||
|
message: :notice_account_password_updated,
|
||
|
title: :label_my_account
|
||
|
).deliver
|
||
|
assert_select_email do
|
||
|
assert_select "a", false
|
||
|
assert_select "h1", :text => I18n.t(:label_my_account)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def test_security_notification_should_include_link
|
||
|
set_language_if_valid User.find(3).language
|
||
|
with_settings :emails_footer => "footer without link" do
|
||
|
assert Mailer.security_notification(User.find(3),
|
||
|
message: :notice_account_password_updated,
|
||
|
title: :label_my_account,
|
||
|
url: {controller: 'my', action: 'account'}
|
||
|
).deliver
|
||
|
assert_select_email do
|
||
|
assert_select "h1", false
|
||
|
assert_select 'a[href=?]', 'http://mydomain.foo/my/account', :text => I18n.t(:label_my_account)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def test_mailer_should_not_change_locale
|
||
|
# Set current language to italian
|
||
|
set_language_if_valid 'it'
|
||