Project

General

Profile

Feature #21421 » 0008-Allow-overriding-of-originator-and-remote_ip-causing-a-s.patch

Jan from Planio www.plan.io, 2015-12-13 09:38

View differences:

app/controllers/account_controller.rb
message: :mail_body_security_notification_change,
field: :field_password,
title: :button_change_password,
remote_ip: request.remote_ip,
originator: @user,
url: {controller: 'my', action: 'password'}
).deliver
flash[:notice] = l(:notice_account_password_updated)
app/models/mailer.rb
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],
......
value: options[:value]
)
@title = options[:title] && l(options[:title])
@originator = options[:originator] || User.current
@remote_ip = options[:remote_ip] || @originator.remote_ip
@url = options[:url] && (options[:url].is_a?(Hash) ? url_for(options[:url]) : options[:url])
redmine_headers 'Sender' => @originator.login
mail :to => recipients,
:subject => l(:mail_subject_security_notification)
end
app/views/mailer/security_notification.html.erb
<%= 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/>
<p><%= l(:field_user) %>: <strong><%= @originator.login %></strong><br/>
<%= l(:field_remote_ip) %>: <strong><%= @remote_ip %></strong><br/>
<%= l(:label_date) %>: <strong><%= format_time Time.now, true, @user %></strong></p>
app/views/mailer/security_notification.text.erb
<%= @url || @title %>
<%= l(:field_user) %>: <%= User.current.login %>
<%= l(:field_remote_ip) %>: <%= User.current.remote_ip %>
<%= l(:field_user) %>: <%= @originator.login %>
<%= l(:field_remote_ip) %>: <%= @remote_ip %>
<%= l(:label_date) %>: <%= format_time Time.now, true, @user %>
test/unit/mailer_test.rb
end
end
def test_security_notification_with_overridden_originator_and_remote_ip
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, originator: User.find(2), remote_ip: '10.0.0.42').deliver
mail = last_email
assert_not_nil mail
assert_mail_body_match User.find(2).login, mail
assert_mail_body_match '10.0.0.42', 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
(9-9/9)