]> source.dussan.org Git - redmine.git/commitdiff
Merged r17269 into 3.3-stable (#28302).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 7 Apr 2018 07:56:08 +0000 (07:56 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 7 Apr 2018 07:56:08 +0000 (07:56 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.3-stable@17271 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/account_controller.rb
app/models/mailer.rb
app/views/mailer/security_notification.html.erb
app/views/mailer/security_notification.text.erb
test/unit/mailer_test.rb

index 98ca2f5f5fa53b6c10393312a9161dad2b653538..81d6a581a527eefa4f0e0f5f683ae9008940bc04 100644 (file)
@@ -81,7 +81,7 @@ class AccountController < ApplicationController
         @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
         if @user.save
           @token.destroy
-          Mailer.password_updated(@user)
+          Mailer.password_updated(@user, { remote_ip: request.remote_ip })
           flash[:notice] = l(:notice_account_password_updated)
           redirect_to signin_path
           return
index f6b16b9f2fad90e782ddcaccfb738a5ebf8be055..1de0b90818b613204720d129a46defc8481c2652 100644 (file)
@@ -311,7 +311,7 @@ class Mailer < ActionMailer::Base
   end
 
   # Notifies user that his password was updated
-  def self.password_updated(user)
+  def self.password_updated(user, options={})
     # Don't send a notification to the dummy email address when changing the password
     # of the default admin account which is required after the first login
     # TODO: maybe not the best way to handle this
@@ -320,6 +320,8 @@ class Mailer < ActionMailer::Base
     Mailer.security_notification(user,
       message: :mail_body_password_updated,
       title: :button_change_password,
+      remote_ip: options[:remote_ip],
+      originator: user,
       url: {controller: 'my', action: 'password'}
     ).deliver
   end
@@ -333,7 +335,6 @@ class Mailer < ActionMailer::Base
   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],
@@ -341,7 +342,11 @@ class Mailer < ActionMailer::Base
       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
+    redmine_headers 'Url' => @url
     mail :to => recipients,
       :subject => "[#{Setting.app_title}] #{l(:mail_subject_security_notification)}"
   end
index 53bf0a0d5247e6f974c7bdf616a7f8dadae99a95..309e9437f5d3f2529dd4f9e9f7123b809b3fc415 100644 (file)
@@ -7,7 +7,7 @@
 <%= 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>
 
index 17fd6ef671d0ef3454403d32ca8bb428b077bd00..5be036b7a8dd08bf9f46f3d86cb6e2af6adc7941 100644 (file)
@@ -2,7 +2,7 @@
 
 <%= @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 %>
 
index 3ec758a9bd83dcc66ec40f75ffbf908312c8f42b..9a6e1a9c440506e062f97a27a9455245bf281a4e 100644 (file)
@@ -697,6 +697,23 @@ class MailerTest < ActiveSupport::TestCase
     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