@@ -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 |
@@ -1,59 +1,59 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class SettingsController < ApplicationController |
|
19 | 19 | before_filter :require_admin |
|
20 | 20 | |
|
21 | 21 | def index |
|
22 | 22 | edit |
|
23 | 23 | render :action => 'edit' |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | def edit |
|
27 | 27 | @notifiables = %w(issue_added issue_updated news_added document_added file_added message_posted) |
|
28 | 28 | if request.post? && params[:settings] && params[:settings].is_a?(Hash) |
|
29 | 29 | settings = (params[:settings] || {}).dup.symbolize_keys |
|
30 | 30 | settings.each do |name, value| |
|
31 | 31 | # remove blank values in array settings |
|
32 | 32 | value.delete_if {|v| v.blank? } if value.is_a?(Array) |
|
33 | 33 | Setting[name] = value |
|
34 | 34 | end |
|
35 | 35 | flash[:notice] = l(:notice_successful_update) |
|
36 | 36 | redirect_to :action => 'edit', :tab => params[:tab] |
|
37 | 37 | return |
|
38 | 38 | end |
|
39 | 39 | @options = {} |
|
40 | 40 | @options[:user_format] = User::USER_FORMATS.keys.collect {|f| [User.current.name(f), f.to_s] } |
|
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 |
|
48 | 48 | @plugin = Redmine::Plugin.find(params[:id]) |
|
49 | 49 | if request.post? |
|
50 | 50 | Setting["plugin_#{@plugin.id}"] = params[:settings] |
|
51 | 51 | flash[:notice] = l(:notice_successful_update) |
|
52 | 52 | redirect_to :action => 'plugin', :id => @plugin.id |
|
53 | 53 | end |
|
54 | 54 | @partial = @plugin.settings[:partial] |
|
55 | 55 | @settings = Setting["plugin_#{@plugin.id}"] |
|
56 | 56 | rescue Redmine::PluginNotFound |
|
57 | 57 | render_404 |
|
58 | 58 | end |
|
59 | 59 | end |
@@ -1,253 +1,253 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Mailer < ActionMailer::Base |
|
19 | 19 | helper :application |
|
20 | 20 | helper :issues |
|
21 | 21 | helper :custom_fields |
|
22 | 22 | |
|
23 | 23 | include ActionController::UrlWriter |
|
24 | 24 | |
|
25 | 25 | def issue_add(issue) |
|
26 | 26 | redmine_headers 'Project' => issue.project.identifier, |
|
27 | 27 | 'Issue-Id' => issue.id, |
|
28 | 28 | 'Issue-Author' => issue.author.login |
|
29 | 29 | redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to |
|
30 | 30 | recipients issue.recipients |
|
31 | 31 | cc(issue.watcher_recipients - @recipients) |
|
32 | 32 | subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}" |
|
33 | 33 | body :issue => issue, |
|
34 | 34 | :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue) |
|
35 | 35 | end |
|
36 | 36 | |
|
37 | 37 | def issue_edit(journal) |
|
38 | 38 | issue = journal.journalized |
|
39 | 39 | redmine_headers 'Project' => issue.project.identifier, |
|
40 | 40 | 'Issue-Id' => issue.id, |
|
41 | 41 | 'Issue-Author' => issue.author.login |
|
42 | 42 | redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to |
|
43 | 43 | @author = journal.user |
|
44 | 44 | recipients issue.recipients |
|
45 | 45 | # Watchers in cc |
|
46 | 46 | cc(issue.watcher_recipients - @recipients) |
|
47 | 47 | s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] " |
|
48 | 48 | s << "(#{issue.status.name}) " if journal.new_value_for('status_id') |
|
49 | 49 | s << issue.subject |
|
50 | 50 | subject s |
|
51 | 51 | body :issue => issue, |
|
52 | 52 | :journal => journal, |
|
53 | 53 | :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue) |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | def reminder(user, issues, days) |
|
57 | 57 | set_language_if_valid user.language |
|
58 | 58 | recipients user.mail |
|
59 | 59 | subject l(:mail_subject_reminder, issues.size) |
|
60 | 60 | body :issues => issues, |
|
61 | 61 | :days => days, |
|
62 | 62 | :issues_url => url_for(:controller => 'issues', :action => 'index', :set_filter => 1, :assigned_to_id => user.id, :sort_key => 'due_date', :sort_order => 'asc') |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | def document_added(document) |
|
66 | 66 | redmine_headers 'Project' => document.project.identifier |
|
67 | 67 | recipients document.project.recipients |
|
68 | 68 | subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" |
|
69 | 69 | body :document => document, |
|
70 | 70 | :document_url => url_for(:controller => 'documents', :action => 'show', :id => document) |
|
71 | 71 | end |
|
72 | 72 | |
|
73 | 73 | def attachments_added(attachments) |
|
74 | 74 | container = attachments.first.container |
|
75 | 75 | added_to = '' |
|
76 | 76 | added_to_url = '' |
|
77 | 77 | case container.class.name |
|
78 | 78 | when 'Project' |
|
79 | 79 | added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container) |
|
80 | 80 | added_to = "#{l(:label_project)}: #{container}" |
|
81 | 81 | when 'Version' |
|
82 | 82 | added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id) |
|
83 | 83 | added_to = "#{l(:label_version)}: #{container.name}" |
|
84 | 84 | when 'Document' |
|
85 | 85 | added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id) |
|
86 | 86 | added_to = "#{l(:label_document)}: #{container.title}" |
|
87 | 87 | end |
|
88 | 88 | redmine_headers 'Project' => container.project.identifier |
|
89 | 89 | recipients container.project.recipients |
|
90 | 90 | subject "[#{container.project.name}] #{l(:label_attachment_new)}" |
|
91 | 91 | body :attachments => attachments, |
|
92 | 92 | :added_to => added_to, |
|
93 | 93 | :added_to_url => added_to_url |
|
94 | 94 | end |
|
95 | 95 | |
|
96 | 96 | def news_added(news) |
|
97 | 97 | redmine_headers 'Project' => news.project.identifier |
|
98 | 98 | recipients news.project.recipients |
|
99 | 99 | subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}" |
|
100 | 100 | body :news => news, |
|
101 | 101 | :news_url => url_for(:controller => 'news', :action => 'show', :id => news) |
|
102 | 102 | end |
|
103 | 103 | |
|
104 | 104 | def message_posted(message, recipients) |
|
105 | 105 | redmine_headers 'Project' => message.project.identifier, |
|
106 | 106 | 'Topic-Id' => (message.parent_id || message.id) |
|
107 | 107 | recipients(recipients) |
|
108 | 108 | subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}" |
|
109 | 109 | body :message => message, |
|
110 | 110 | :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root) |
|
111 | 111 | end |
|
112 | 112 | |
|
113 | 113 | def account_information(user, password) |
|
114 | 114 | set_language_if_valid user.language |
|
115 | 115 | recipients user.mail |
|
116 | 116 | subject l(:mail_subject_register, Setting.app_title) |
|
117 | 117 | body :user => user, |
|
118 | 118 | :password => password, |
|
119 | 119 | :login_url => url_for(:controller => 'account', :action => 'login') |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | def account_activation_request(user) |
|
123 | 123 | # Send the email to all active administrators |
|
124 | 124 | recipients User.active.find(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact |
|
125 | 125 | subject l(:mail_subject_account_activation_request, Setting.app_title) |
|
126 | 126 | body :user => user, |
|
127 | 127 | :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc') |
|
128 | 128 | end |
|
129 | 129 | |
|
130 | 130 | def lost_password(token) |
|
131 | 131 | set_language_if_valid(token.user.language) |
|
132 | 132 | recipients token.user.mail |
|
133 | 133 | subject l(:mail_subject_lost_password, Setting.app_title) |
|
134 | 134 | body :token => token, |
|
135 | 135 | :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value) |
|
136 | 136 | end |
|
137 | 137 | |
|
138 | 138 | def register(token) |
|
139 | 139 | set_language_if_valid(token.user.language) |
|
140 | 140 | recipients token.user.mail |
|
141 | 141 | subject l(:mail_subject_register, Setting.app_title) |
|
142 | 142 | body :token => token, |
|
143 | 143 | :url => url_for(:controller => 'account', :action => 'activate', :token => token.value) |
|
144 | 144 | end |
|
145 | 145 | |
|
146 | 146 | def test(user) |
|
147 | 147 | set_language_if_valid(user.language) |
|
148 | 148 | recipients user.mail |
|
149 | 149 | subject 'Redmine test' |
|
150 | 150 | body :url => url_for(:controller => 'welcome') |
|
151 | 151 | end |
|
152 | 152 | |
|
153 | 153 | # Overrides default deliver! method to prevent from sending an email |
|
154 | 154 | # with no recipient, cc or bcc |
|
155 | 155 | def deliver!(mail = @mail) |
|
156 | 156 | return false if (recipients.nil? || recipients.empty?) && |
|
157 | 157 | (cc.nil? || cc.empty?) && |
|
158 | 158 | (bcc.nil? || bcc.empty?) |
|
159 | 159 | super |
|
160 | 160 | end |
|
161 | 161 | |
|
162 | 162 | # Sends reminders to issue assignees |
|
163 | 163 | # Available options: |
|
164 | 164 | # * :days => how many days in the future to remind about (defaults to 7) |
|
165 | 165 | # * :tracker => id of tracker for filtering issues (defaults to all trackers) |
|
166 | 166 | # * :project => id or identifier of project to process (defaults to all projects) |
|
167 | 167 | def self.reminders(options={}) |
|
168 | 168 | days = options[:days] || 7 |
|
169 | 169 | project = options[:project] ? Project.find(options[:project]) : nil |
|
170 | 170 | tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil |
|
171 | 171 | |
|
172 | 172 | s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.due_date <= ?", false, days.day.from_now.to_date] |
|
173 | 173 | s << "#{Issue.table_name}.assigned_to_id IS NOT NULL" |
|
174 | 174 | s << "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}" |
|
175 | 175 | s << "#{Issue.table_name}.project_id = #{project.id}" if project |
|
176 | 176 | s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker |
|
177 | 177 | |
|
178 | 178 | issues_by_assignee = Issue.find(:all, :include => [:status, :assigned_to, :project, :tracker], |
|
179 | 179 | :conditions => s.conditions |
|
180 | 180 | ).group_by(&:assigned_to) |
|
181 | 181 | issues_by_assignee.each do |assignee, issues| |
|
182 | 182 | deliver_reminder(assignee, issues, days) unless assignee.nil? |
|
183 | 183 | end |
|
184 | 184 | end |
|
185 | 185 | |
|
186 | 186 | private |
|
187 | 187 | def initialize_defaults(method_name) |
|
188 | 188 | super |
|
189 | 189 | set_language_if_valid Setting.default_language |
|
190 | 190 | from Setting.mail_from |
|
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 | |
|
198 | 198 | # Common headers |
|
199 | 199 | headers 'X-Mailer' => 'Redmine', |
|
200 | 200 | 'X-Redmine-Host' => Setting.host_name, |
|
201 | 201 | 'X-Redmine-Site' => Setting.app_title |
|
202 | 202 | end |
|
203 | 203 | |
|
204 | 204 | # Appends a Redmine header field (name is prepended with 'X-Redmine-') |
|
205 | 205 | def redmine_headers(h) |
|
206 | 206 | h.each { |k,v| headers["X-Redmine-#{k}"] = v } |
|
207 | 207 | end |
|
208 | 208 | |
|
209 | 209 | # Overrides the create_mail method |
|
210 | 210 | def create_mail |
|
211 | 211 | # Removes the current user from the recipients and cc |
|
212 | 212 | # if he doesn't want to receive notifications about what he does |
|
213 | 213 | @author ||= User.current |
|
214 | 214 | if @author.pref[:no_self_notified] |
|
215 | 215 | recipients.delete(@author.mail) if recipients |
|
216 | 216 | cc.delete(@author.mail) if cc |
|
217 | 217 | end |
|
218 | 218 | # Blind carbon copy recipients |
|
219 | 219 | if Setting.bcc_recipients? |
|
220 | 220 | bcc([recipients, cc].flatten.compact.uniq) |
|
221 | 221 | recipients [] |
|
222 | 222 | cc [] |
|
223 | 223 | end |
|
224 | 224 | super |
|
225 | 225 | end |
|
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 |
|
233 | 233 | |
|
234 | 234 | # for the case of plain text only |
|
235 | 235 | def body(*params) |
|
236 | 236 | value = super(*params) |
|
237 | 237 | if Setting.plain_text_mail? |
|
238 | 238 | templates = Dir.glob("#{template_path}/#{@template}.text.plain.{rhtml,erb}") |
|
239 | 239 | unless String === @body or templates.empty? |
|
240 | 240 | template = File.basename(templates.first) |
|
241 | 241 | @body[:content_for_layout] = render(:file => template, :body => @body) |
|
242 | 242 | @body = ActionView::Base.new(template_root, @body, self).render(:file => "mailer/layout.text.plain.rhtml", :use_full_path => true) |
|
243 | 243 | return @body |
|
244 | 244 | end |
|
245 | 245 | end |
|
246 | 246 | return value |
|
247 | 247 | end |
|
248 | 248 | |
|
249 | 249 | # Makes partial rendering work with Rails 1.2 (retro-compatibility) |
|
250 | 250 | def self.controller_path |
|
251 | 251 | '' |
|
252 | 252 | end unless respond_to?('controller_path') |
|
253 | 253 | end |
@@ -1,47 +1,46 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | module Redmine |
|
19 | 19 | module WikiFormatting |
|
20 | 20 | module Textile |
|
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, |
|
29 | 28 | :onclick => "window.open(\"#{ url }\", \"\", \"resizable=yes, location=no, width=300, height=640, menubar=no, status=no, scrollbars=yes\"); return false;") |
|
30 | 29 | |
|
31 | 30 | javascript_include_tag('jstoolbar/jstoolbar') + |
|
32 | 31 | javascript_include_tag('jstoolbar/textile') + |
|
33 | 32 | javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language}") + |
|
34 | 33 | javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.setHelpLink('#{help_link}'); toolbar.draw();") |
|
35 | 34 | end |
|
36 | 35 | |
|
37 | 36 | def initial_page_content(page) |
|
38 | 37 | "h1. #{@page.pretty_title}" |
|
39 | 38 | end |
|
40 | 39 | |
|
41 | 40 | def heads_for_wiki_formatter |
|
42 | 41 | stylesheet_link_tag 'jstoolbar' |
|
43 | 42 | end |
|
44 | 43 | end |
|
45 | 44 | end |
|
46 | 45 | end |
|
47 | 46 | end |
@@ -1,186 +1,186 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | |
|
20 | 20 | class MailerTest < Test::Unit::TestCase |
|
21 | 21 | fixtures :projects, :issues, :users, :members, :documents, :attachments, :news, :tokens, :journals, :journal_details, :changesets, :trackers, :issue_statuses, :enumerations, :messages, :boards, :repositories |
|
22 | 22 | |
|
23 | 23 | def test_generated_links_in_emails |
|
24 | 24 | ActionMailer::Base.deliveries.clear |
|
25 | 25 | Setting.host_name = 'mydomain.foo' |
|
26 | 26 | Setting.protocol = 'https' |
|
27 | 27 | |
|
28 | 28 | journal = Journal.find(2) |
|
29 | 29 | assert Mailer.deliver_issue_edit(journal) |
|
30 | 30 | |
|
31 | 31 | mail = ActionMailer::Base.deliveries.last |
|
32 | 32 | assert_kind_of TMail::Mail, mail |
|
33 | 33 | # link to the main ticket |
|
34 | 34 | assert mail.body.include?('<a href="https://mydomain.foo/issues/show/1">Bug #1: Can\'t print recipes</a>') |
|
35 | 35 | |
|
36 | 36 | # link to a referenced ticket |
|
37 | 37 | assert mail.body.include?('<a href="https://mydomain.foo/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>') |
|
38 | 38 | # link to a changeset |
|
39 | 39 | assert mail.body.include?('<a href="https://mydomain.foo/repositories/revision/ecookbook/2" class="changeset" title="This commit fixes #1, #2 and references #1 & #3">r2</a>') |
|
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) |
|
51 | 51 | |
|
52 | 52 | mail = ActionMailer::Base.deliveries.last |
|
53 | 53 | assert_kind_of TMail::Mail, mail |
|
54 | 54 | # link to the main ticket |
|
55 | 55 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/1">Bug #1: Can\'t print recipes</a>') |
|
56 | 56 | |
|
57 | 57 | # link to a referenced ticket |
|
58 | 58 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>') |
|
59 | 59 | # link to a changeset |
|
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) |
|
75 | 75 | |
|
76 | 76 | mail = ActionMailer::Base.deliveries.last |
|
77 | 77 | assert_kind_of TMail::Mail, mail |
|
78 | 78 | # link to the main ticket |
|
79 | 79 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/1">Bug #1: Can\'t print recipes</a>') |
|
80 | 80 | |
|
81 | 81 | # link to a referenced ticket |
|
82 | 82 | assert mail.body.include?('<a href="http://mydomain.foo/rdm/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>') |
|
83 | 83 | # link to a changeset |
|
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 |
|
91 | 91 | Setting.plain_text_mail = 1 |
|
92 | 92 | journal = Journal.find(2) |
|
93 | 93 | Mailer.deliver_issue_edit(journal) |
|
94 | 94 | mail = ActionMailer::Base.deliveries.last |
|
95 | 95 | assert !mail.body.include?('<a href="https://mydomain.foo/issues/show/1">Bug #1: Can\'t print recipes</a>') |
|
96 | 96 | end |
|
97 | 97 | |
|
98 | 98 | |
|
99 | 99 | |
|
100 | 100 | # test mailer methods for each language |
|
101 | 101 | def test_issue_add |
|
102 | 102 | issue = Issue.find(1) |
|
103 | 103 | GLoc.valid_languages.each do |lang| |
|
104 | 104 | Setting.default_language = lang.to_s |
|
105 | 105 | assert Mailer.deliver_issue_add(issue) |
|
106 | 106 | end |
|
107 | 107 | end |
|
108 | 108 | |
|
109 | 109 | def test_issue_edit |
|
110 | 110 | journal = Journal.find(1) |
|
111 | 111 | GLoc.valid_languages.each do |lang| |
|
112 | 112 | Setting.default_language = lang.to_s |
|
113 | 113 | assert Mailer.deliver_issue_edit(journal) |
|
114 | 114 | end |
|
115 | 115 | end |
|
116 | 116 | |
|
117 | 117 | def test_document_added |
|
118 | 118 | document = Document.find(1) |
|
119 | 119 | GLoc.valid_languages.each do |lang| |
|
120 | 120 | Setting.default_language = lang.to_s |
|
121 | 121 | assert Mailer.deliver_document_added(document) |
|
122 | 122 | end |
|
123 | 123 | end |
|
124 | 124 | |
|
125 | 125 | def test_attachments_added |
|
126 | 126 | attachements = [ Attachment.find_by_container_type('Document') ] |
|
127 | 127 | GLoc.valid_languages.each do |lang| |
|
128 | 128 | Setting.default_language = lang.to_s |
|
129 | 129 | assert Mailer.deliver_attachments_added(attachements) |
|
130 | 130 | end |
|
131 | 131 | end |
|
132 | 132 | |
|
133 | 133 | def test_news_added |
|
134 | 134 | news = News.find(:first) |
|
135 | 135 | GLoc.valid_languages.each do |lang| |
|
136 | 136 | Setting.default_language = lang.to_s |
|
137 | 137 | assert Mailer.deliver_news_added(news) |
|
138 | 138 | end |
|
139 | 139 | end |
|
140 | 140 | |
|
141 | 141 | def test_message_posted |
|
142 | 142 | message = Message.find(:first) |
|
143 | 143 | recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} |
|
144 | 144 | recipients = recipients.compact.uniq |
|
145 | 145 | GLoc.valid_languages.each do |lang| |
|
146 | 146 | Setting.default_language = lang.to_s |
|
147 | 147 | assert Mailer.deliver_message_posted(message, recipients) |
|
148 | 148 | end |
|
149 | 149 | end |
|
150 | 150 | |
|
151 | 151 | def test_account_information |
|
152 | 152 | user = User.find(:first) |
|
153 | 153 | GLoc.valid_languages.each do |lang| |
|
154 | 154 | user.update_attribute :language, lang.to_s |
|
155 | 155 | user.reload |
|
156 | 156 | assert Mailer.deliver_account_information(user, 'pAsswORd') |
|
157 | 157 | end |
|
158 | 158 | end |
|
159 | 159 | |
|
160 | 160 | def test_lost_password |
|
161 | 161 | token = Token.find(2) |
|
162 | 162 | GLoc.valid_languages.each do |lang| |
|
163 | 163 | token.user.update_attribute :language, lang.to_s |
|
164 | 164 | token.reload |
|
165 | 165 | assert Mailer.deliver_lost_password(token) |
|
166 | 166 | end |
|
167 | 167 | end |
|
168 | 168 | |
|
169 | 169 | def test_register |
|
170 | 170 | token = Token.find(1) |
|
171 | 171 | GLoc.valid_languages.each do |lang| |
|
172 | 172 | token.user.update_attribute :language, lang.to_s |
|
173 | 173 | token.reload |
|
174 | 174 | assert Mailer.deliver_register(token) |
|
175 | 175 | end |
|
176 | 176 | end |
|
177 | 177 | |
|
178 | 178 | def test_reminders |
|
179 | 179 | ActionMailer::Base.deliveries.clear |
|
180 | 180 | Mailer.reminders(:days => 42) |
|
181 | 181 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
182 | 182 | mail = ActionMailer::Base.deliveries.last |
|
183 | 183 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
184 | 184 | assert mail.body.include?('Bug #3: Error 281 when updating a recipe') |
|
185 | 185 | end |
|
186 | 186 | end |
General Comments 0
You need to be logged in to leave comments.
Login now