@@ -23,6 +23,12 class Mailer < ActionMailer::Base | |||||
23 | include ActionController::UrlWriter |
|
23 | include ActionController::UrlWriter | |
24 | include Redmine::I18n |
|
24 | include Redmine::I18n | |
25 |
|
25 | |||
|
26 | def self.default_url_options | |||
|
27 | h = Setting.host_name | |||
|
28 | h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank? | |||
|
29 | { :host => h, :protocol => Setting.protocol } | |||
|
30 | end | |||
|
31 | ||||
26 | def issue_add(issue) |
|
32 | def issue_add(issue) | |
27 | redmine_headers 'Project' => issue.project.identifier, |
|
33 | redmine_headers 'Project' => issue.project.identifier, | |
28 | 'Issue-Id' => issue.id, |
|
34 | 'Issue-Id' => issue.id, | |
@@ -213,12 +219,6 class Mailer < ActionMailer::Base | |||||
213 | set_language_if_valid Setting.default_language |
|
219 | set_language_if_valid Setting.default_language | |
214 | from Setting.mail_from |
|
220 | from Setting.mail_from | |
215 |
|
221 | |||
216 | # URL options |
|
|||
217 | h = Setting.host_name |
|
|||
218 | h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank? |
|
|||
219 | default_url_options[:host] = h |
|
|||
220 | default_url_options[:protocol] = Setting.protocol |
|
|||
221 |
|
||||
222 | # Common headers |
|
222 | # Common headers | |
223 | headers 'X-Mailer' => 'Redmine', |
|
223 | headers 'X-Mailer' => 'Redmine', | |
224 | 'X-Redmine-Host' => Setting.host_name, |
|
224 | 'X-Redmine-Host' => Setting.host_name, |
@@ -60,7 +60,6 module Redmine | |||||
60 | returning [] do |response| |
|
60 | returning [] do |response| | |
61 | hls = hook_listeners(hook) |
|
61 | hls = hook_listeners(hook) | |
62 | if hls.any? |
|
62 | if hls.any? | |
63 | default_url_options[:only_path] ||= true |
|
|||
64 | hls.each {|listener| response << listener.send(hook, context)} |
|
63 | hls.each {|listener| response << listener.send(hook, context)} | |
65 | end |
|
64 | end | |
66 | end |
|
65 | end | |
@@ -77,8 +76,9 module Redmine | |||||
77 | Redmine::Hook.add_listener(child) |
|
76 | Redmine::Hook.add_listener(child) | |
78 | super |
|
77 | super | |
79 | end |
|
78 | end | |
|
79 | ||||
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | # Listener class used for views hooks. |
|
82 | # Listener class used for views hooks. | |
83 | # Listeners that inherit this class will include various helpers by default. |
|
83 | # Listeners that inherit this class will include various helpers by default. | |
84 | class ViewListener < Listener |
|
84 | class ViewListener < Listener | |
@@ -96,6 +96,12 module Redmine | |||||
96 | include ActionController::UrlWriter |
|
96 | include ActionController::UrlWriter | |
97 | include ApplicationHelper |
|
97 | include ApplicationHelper | |
98 |
|
98 | |||
|
99 | # Default to creating links using only the path. Subclasses can | |||
|
100 | # change this default as needed | |||
|
101 | def self.default_url_options | |||
|
102 | {:only_path => true } | |||
|
103 | end | |||
|
104 | ||||
99 | # Helper method to directly render a partial using the context: |
|
105 | # Helper method to directly render a partial using the context: | |
100 | # |
|
106 | # | |
101 | # class MyHook < Redmine::Hook::ViewListener |
|
107 | # class MyHook < Redmine::Hook::ViewListener |
@@ -19,6 +19,8 require File.dirname(__FILE__) + '/../../../test_helper' | |||||
19 |
|
19 | |||
20 | class Redmine::Hook::ManagerTest < Test::Unit::TestCase |
|
20 | class Redmine::Hook::ManagerTest < Test::Unit::TestCase | |
21 |
|
21 | |||
|
22 | fixtures :issues | |||
|
23 | ||||
22 | # Some hooks that are manually registered in these tests |
|
24 | # Some hooks that are manually registered in these tests | |
23 | class TestHook < Redmine::Hook::ViewListener; end |
|
25 | class TestHook < Redmine::Hook::ViewListener; end | |
24 |
|
26 | |||
@@ -64,7 +66,6 class Redmine::Hook::ManagerTest < Test::Unit::TestCase | |||||
64 |
|
66 | |||
65 | def teardown |
|
67 | def teardown | |
66 | @hook_module.clear_listeners |
|
68 | @hook_module.clear_listeners | |
67 | @hook_module.default_url_options = { } |
|
|||
68 | end |
|
69 | end | |
69 |
|
70 | |||
70 | def test_clear_listeners |
|
71 | def test_clear_listeners | |
@@ -144,5 +145,22 class Redmine::Hook::ManagerTest < Test::Unit::TestCase | |||||
144 | assert_equal 'Test hook 1 listener. Test hook 2 listener.', |
|
145 | assert_equal 'Test hook 1 listener. Test hook 2 listener.', | |
145 | @view_hook_helper.call_hook(:view_layouts_base_html_head) |
|
146 | @view_hook_helper.call_hook(:view_layouts_base_html_head) | |
146 | end |
|
147 | end | |
|
148 | ||||
|
149 | def test_call_hook_should_not_change_the_default_url_for_email_notifications | |||
|
150 | issue = Issue.find(1) | |||
|
151 | ||||
|
152 | ActionMailer::Base.deliveries.clear | |||
|
153 | Mailer.deliver_issue_add(issue) | |||
|
154 | mail = ActionMailer::Base.deliveries.last | |||
|
155 | ||||
|
156 | @hook_module.add_listener(TestLinkToHook) | |||
|
157 | @hook_helper.call_hook(:view_layouts_base_html_head) | |||
|
158 | ||||
|
159 | ActionMailer::Base.deliveries.clear | |||
|
160 | Mailer.deliver_issue_add(issue) | |||
|
161 | mail2 = ActionMailer::Base.deliveries.last | |||
|
162 | ||||
|
163 | assert_equal mail.body, mail2.body | |||
|
164 | end | |||
147 | end |
|
165 | end | |
148 |
|
166 |
General Comments 0
You need to be logged in to leave comments.
Login now