@@ -0,0 +1,38 | |||
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang | |
|
3 | # | |
|
4 | # This program is free software; you can redistribute it and/or | |
|
5 | # modify it under the terms of the GNU General Public License | |
|
6 | # as published by the Free Software Foundation; either version 2 | |
|
7 | # of the License, or (at your option) any later version. | |
|
8 | # | |
|
9 | # This program is distributed in the hope that it will be useful, | |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
12 | # GNU General Public License for more details. | |
|
13 | # | |
|
14 | # You should have received a copy of the GNU General Public License | |
|
15 | # along with this program; if not, write to the Free Software | |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
|
17 | ||
|
18 | module Redmine | |
|
19 | module Utils | |
|
20 | class << self | |
|
21 | # Returns the relative root url of the application | |
|
22 | def relative_url_root | |
|
23 | ActionController::Base.respond_to?('relative_url_root') ? | |
|
24 | ActionController::Base.relative_url_root.to_s : | |
|
25 | ActionController::AbstractRequest.relative_url_root.to_s | |
|
26 | end | |
|
27 | ||
|
28 | # Sets the relative root url of the application | |
|
29 | def relative_url_root=(arg) | |
|
30 | if ActionController::Base.respond_to?('relative_url_root=') | |
|
31 | ActionController::Base.relative_url_root=arg | |
|
32 | else | |
|
33 | ActionController::AbstractRequest.relative_url_root=arg | |
|
34 | end | |
|
35 | end | |
|
36 | end | |
|
37 | end | |
|
38 | end |
@@ -41,7 +41,7 class SettingsController < ApplicationController | |||
|
41 | 41 | @deliveries = ActionMailer::Base.perform_deliveries |
|
42 | 42 | |
|
43 | 43 | @guessed_host_and_path = request.host_with_port |
|
44 |
@guessed_host_and_path << ('/'+ |
|
|
44 | @guessed_host_and_path << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank? | |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | def plugin |
@@ -191,7 +191,7 class Mailer < ActionMailer::Base | |||
|
191 | 191 | |
|
192 | 192 | # URL options |
|
193 | 193 | h = Setting.host_name |
|
194 |
h = h.to_s.gsub(%r{\/.*$}, '') unless |
|
|
194 | h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank? | |
|
195 | 195 | default_url_options[:host] = h |
|
196 | 196 | default_url_options[:protocol] = Setting.protocol |
|
197 | 197 | |
@@ -226,7 +226,7 class Mailer < ActionMailer::Base | |||
|
226 | 226 | |
|
227 | 227 | # Renders a message with the corresponding layout |
|
228 | 228 | def render_message(method_name, body) |
|
229 | layout = method_name.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml' | |
|
229 | layout = method_name.to_s.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml' | |
|
230 | 230 | body[:content_for_layout] = render(:file => method_name, :body => body) |
|
231 | 231 | ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}", :use_full_path => true) |
|
232 | 232 | end |
@@ -21,8 +21,7 module Redmine | |||
|
21 | 21 | module Helper |
|
22 | 22 | def wikitoolbar_for(field_id) |
|
23 | 23 | # Is there a simple way to link to a public resource? |
|
24 | prefix = (ActionController::Base.respond_to?(:relative_url_root) ? ActionController::Base.relative_url_root : ActionController::AbstractRequest.relative_url_root) | |
|
25 | url = "#{prefix}/help/wiki_syntax.html" | |
|
24 | url = "#{Redmine::Utils.relative_url_root}/help/wiki_syntax.html" | |
|
26 | 25 | |
|
27 | 26 | help_link = l(:setting_text_formatting) + ': ' + |
|
28 | 27 | link_to(l(:label_help), url, |
@@ -40,11 +40,11 class MailerTest < Test::Unit::TestCase | |||
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def test_generated_links_with_prefix |
|
43 |
relative_url_root = |
|
|
43 | relative_url_root = Redmine::Utils.relative_url_root | |
|
44 | 44 | ActionMailer::Base.deliveries.clear |
|
45 | 45 | Setting.host_name = 'mydomain.foo/rdm' |
|
46 | 46 | Setting.protocol = 'http' |
|
47 |
|
|
|
47 | Redmine::Utils.relative_url_root = '/rdm' | |
|
48 | 48 | |
|
49 | 49 | journal = Journal.find(2) |
|
50 | 50 | assert Mailer.deliver_issue_edit(journal) |
@@ -60,15 +60,15 class MailerTest < Test::Unit::TestCase | |||
|
60 | 60 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/repositories/revision/ecookbook/2" class="changeset" title="This commit fixes #1, #2 and references #1 & #3">r2</a>') |
|
61 | 61 | ensure |
|
62 | 62 | # restore it |
|
63 |
|
|
|
63 | Redmine::Utils.relative_url_root = relative_url_root | |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | def test_generated_links_with_prefix_and_no_relative_url_root |
|
67 |
relative_url_root = |
|
|
67 | relative_url_root = Redmine::Utils.relative_url_root | |
|
68 | 68 | ActionMailer::Base.deliveries.clear |
|
69 | 69 | Setting.host_name = 'mydomain.foo/rdm' |
|
70 | 70 | Setting.protocol = 'http' |
|
71 |
|
|
|
71 | Redmine::Utils.relative_url_root = nil | |
|
72 | 72 | |
|
73 | 73 | journal = Journal.find(2) |
|
74 | 74 | assert Mailer.deliver_issue_edit(journal) |
@@ -84,7 +84,7 class MailerTest < Test::Unit::TestCase | |||
|
84 | 84 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/repositories/revision/ecookbook/2" class="changeset" title="This commit fixes #1, #2 and references #1 & #3">r2</a>') |
|
85 | 85 | ensure |
|
86 | 86 | # restore it |
|
87 |
|
|
|
87 | Redmine::Utils.relative_url_root = relative_url_root | |
|
88 | 88 | end |
|
89 | 89 | |
|
90 | 90 | def test_plain_text_mail |
General Comments 0
You need to be logged in to leave comments.
Login now