@@ -1,86 +1,86 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 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 AdminController < ApplicationController |
|
19 | 19 | layout 'admin' |
|
20 | 20 | menu_item :projects, :only => :projects |
|
21 | 21 | menu_item :plugins, :only => :plugins |
|
22 | 22 | menu_item :info, :only => :info |
|
23 | 23 | |
|
24 | 24 | before_filter :require_admin |
|
25 | 25 | helper :sort |
|
26 | 26 | include SortHelper |
|
27 | 27 | |
|
28 | 28 | def index |
|
29 | 29 | @no_configuration_data = Redmine::DefaultData::Loader::no_data? |
|
30 | 30 | end |
|
31 | 31 | |
|
32 | 32 | def projects |
|
33 | 33 | @status = params[:status] || 1 |
|
34 | 34 | |
|
35 | 35 | scope = Project.status(@status) |
|
36 | 36 | scope = scope.like(params[:name]) if params[:name].present? |
|
37 | 37 | |
|
38 | 38 | @projects = scope.all(:order => 'lft') |
|
39 | 39 | |
|
40 | 40 | render :action => "projects", :layout => false if request.xhr? |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | 43 | def plugins |
|
44 | 44 | @plugins = Redmine::Plugin.all |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | # Loads the default configuration |
|
48 | 48 | # (roles, trackers, statuses, workflow, enumerations) |
|
49 | 49 | def default_configuration |
|
50 | 50 | if request.post? |
|
51 | 51 | begin |
|
52 | 52 | Redmine::DefaultData::Loader::load(params[:lang]) |
|
53 | 53 | flash[:notice] = l(:notice_default_data_loaded) |
|
54 | 54 | rescue Exception => e |
|
55 | 55 | flash[:error] = l(:error_can_t_load_default_data, e.message) |
|
56 | 56 | end |
|
57 | 57 | end |
|
58 | 58 | redirect_to :action => 'index' |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | def test_email |
|
62 | 62 | raise_delivery_errors = ActionMailer::Base.raise_delivery_errors |
|
63 | 63 | # Force ActionMailer to raise delivery errors so we can catch it |
|
64 | 64 | ActionMailer::Base.raise_delivery_errors = true |
|
65 | 65 | begin |
|
66 | @test = Mailer.deliver_test(User.current) | |
|
66 | @test = Mailer.deliver_test_email(User.current) | |
|
67 | 67 | flash[:notice] = l(:notice_email_sent, User.current.mail) |
|
68 | 68 | rescue Exception => e |
|
69 | 69 | flash[:error] = l(:notice_email_error, e.message) |
|
70 | 70 | end |
|
71 | 71 | ActionMailer::Base.raise_delivery_errors = raise_delivery_errors |
|
72 | 72 | redirect_to :controller => 'settings', :action => 'edit', :tab => 'notifications' |
|
73 | 73 | end |
|
74 | 74 | |
|
75 | 75 | def info |
|
76 | 76 | @db_adapter_name = ActiveRecord::Base.connection.adapter_name |
|
77 | 77 | @checklist = [ |
|
78 | 78 | [:text_default_administrator_account_changed, |
|
79 | 79 | User.find(:first, |
|
80 | 80 | :conditions => ["login=? and hashed_password=?", 'admin', User.hash_password('admin')]).nil?], |
|
81 | 81 | [:text_file_repository_writable, File.writable?(Attachment.storage_path)], |
|
82 | 82 | [:text_plugin_assets_writable, File.writable?(Redmine::Plugin.public_directory)], |
|
83 | 83 | [:text_rmagick_available, Object.const_defined?(:Magick)] |
|
84 | 84 | ] |
|
85 | 85 | end |
|
86 | 86 | end |
@@ -1,477 +1,477 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 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 | layout 'mailer' |
|
20 | 20 | helper :application |
|
21 | 21 | helper :issues |
|
22 | 22 | helper :custom_fields |
|
23 | 23 | |
|
24 | 24 | include ActionController::UrlWriter |
|
25 | 25 | include Redmine::I18n |
|
26 | 26 | |
|
27 | 27 | def self.default_url_options |
|
28 | 28 | h = Setting.host_name |
|
29 | 29 | h = h.to_s.gsub(%r{\/.*$}, '') unless Redmine::Utils.relative_url_root.blank? |
|
30 | 30 | { :host => h, :protocol => Setting.protocol } |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | # Builds a tmail object used to email recipients of the added issue. |
|
34 | 34 | # |
|
35 | 35 | # Example: |
|
36 | 36 | # issue_add(issue) => tmail object |
|
37 | 37 | # Mailer.deliver_issue_add(issue) => sends an email to issue recipients |
|
38 | 38 | def issue_add(issue) |
|
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 | message_id issue |
|
44 | 44 | @author = issue.author |
|
45 | 45 | recipients issue.recipients |
|
46 | 46 | cc(issue.watcher_recipients - @recipients) |
|
47 | 47 | subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}" |
|
48 | 48 | body :issue => issue, |
|
49 | 49 | :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue) |
|
50 | 50 | render_multipart('issue_add', body) |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | # Builds a tmail object used to email recipients of the edited issue. |
|
54 | 54 | # |
|
55 | 55 | # Example: |
|
56 | 56 | # issue_edit(journal) => tmail object |
|
57 | 57 | # Mailer.deliver_issue_edit(journal) => sends an email to issue recipients |
|
58 | 58 | def issue_edit(journal) |
|
59 | 59 | issue = journal.journalized.reload |
|
60 | 60 | redmine_headers 'Project' => issue.project.identifier, |
|
61 | 61 | 'Issue-Id' => issue.id, |
|
62 | 62 | 'Issue-Author' => issue.author.login |
|
63 | 63 | redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to |
|
64 | 64 | message_id journal |
|
65 | 65 | references issue |
|
66 | 66 | @author = journal.user |
|
67 | 67 | recipients issue.recipients |
|
68 | 68 | # Watchers in cc |
|
69 | 69 | cc(issue.watcher_recipients - @recipients) |
|
70 | 70 | s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] " |
|
71 | 71 | s << "(#{issue.status.name}) " if journal.new_value_for('status_id') |
|
72 | 72 | s << issue.subject |
|
73 | 73 | subject s |
|
74 | 74 | body :issue => issue, |
|
75 | 75 | :journal => journal, |
|
76 | 76 | :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}") |
|
77 | 77 | |
|
78 | 78 | render_multipart('issue_edit', body) |
|
79 | 79 | end |
|
80 | 80 | |
|
81 | 81 | def reminder(user, issues, days) |
|
82 | 82 | set_language_if_valid user.language |
|
83 | 83 | recipients user.mail |
|
84 | 84 | subject l(:mail_subject_reminder, :count => issues.size, :days => days) |
|
85 | 85 | body :issues => issues, |
|
86 | 86 | :days => days, |
|
87 | 87 | :issues_url => url_for(:controller => 'issues', :action => 'index', |
|
88 | 88 | :set_filter => 1, :assigned_to_id => user.id, |
|
89 | 89 | :sort => 'due_date:asc') |
|
90 | 90 | render_multipart('reminder', body) |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | # Builds a tmail object used to email users belonging to the added document's project. |
|
94 | 94 | # |
|
95 | 95 | # Example: |
|
96 | 96 | # document_added(document) => tmail object |
|
97 | 97 | # Mailer.deliver_document_added(document) => sends an email to the document's project recipients |
|
98 | 98 | def document_added(document) |
|
99 | 99 | redmine_headers 'Project' => document.project.identifier |
|
100 | 100 | recipients document.recipients |
|
101 | 101 | subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" |
|
102 | 102 | body :document => document, |
|
103 | 103 | :document_url => url_for(:controller => 'documents', :action => 'show', :id => document) |
|
104 | 104 | render_multipart('document_added', body) |
|
105 | 105 | end |
|
106 | 106 | |
|
107 | 107 | # Builds a tmail object used to email recipients of a project when an attachements are added. |
|
108 | 108 | # |
|
109 | 109 | # Example: |
|
110 | 110 | # attachments_added(attachments) => tmail object |
|
111 | 111 | # Mailer.deliver_attachments_added(attachments) => sends an email to the project's recipients |
|
112 | 112 | def attachments_added(attachments) |
|
113 | 113 | container = attachments.first.container |
|
114 | 114 | added_to = '' |
|
115 | 115 | added_to_url = '' |
|
116 | 116 | case container.class.name |
|
117 | 117 | when 'Project' |
|
118 | 118 | added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container) |
|
119 | 119 | added_to = "#{l(:label_project)}: #{container}" |
|
120 | 120 | recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail} |
|
121 | 121 | when 'Version' |
|
122 | 122 | added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container.project) |
|
123 | 123 | added_to = "#{l(:label_version)}: #{container.name}" |
|
124 | 124 | recipients container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)}.collect {|u| u.mail} |
|
125 | 125 | when 'Document' |
|
126 | 126 | added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id) |
|
127 | 127 | added_to = "#{l(:label_document)}: #{container.title}" |
|
128 | 128 | recipients container.recipients |
|
129 | 129 | end |
|
130 | 130 | redmine_headers 'Project' => container.project.identifier |
|
131 | 131 | subject "[#{container.project.name}] #{l(:label_attachment_new)}" |
|
132 | 132 | body :attachments => attachments, |
|
133 | 133 | :added_to => added_to, |
|
134 | 134 | :added_to_url => added_to_url |
|
135 | 135 | render_multipart('attachments_added', body) |
|
136 | 136 | end |
|
137 | 137 | |
|
138 | 138 | # Builds a tmail object used to email recipients of a news' project when a news item is added. |
|
139 | 139 | # |
|
140 | 140 | # Example: |
|
141 | 141 | # news_added(news) => tmail object |
|
142 | 142 | # Mailer.deliver_news_added(news) => sends an email to the news' project recipients |
|
143 | 143 | def news_added(news) |
|
144 | 144 | redmine_headers 'Project' => news.project.identifier |
|
145 | 145 | message_id news |
|
146 | 146 | recipients news.recipients |
|
147 | 147 | subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}" |
|
148 | 148 | body :news => news, |
|
149 | 149 | :news_url => url_for(:controller => 'news', :action => 'show', :id => news) |
|
150 | 150 | render_multipart('news_added', body) |
|
151 | 151 | end |
|
152 | 152 | |
|
153 | 153 | # Builds a tmail object used to email recipients of a news' project when a news comment is added. |
|
154 | 154 | # |
|
155 | 155 | # Example: |
|
156 | 156 | # news_comment_added(comment) => tmail object |
|
157 | 157 | # Mailer.news_comment_added(comment) => sends an email to the news' project recipients |
|
158 | 158 | def news_comment_added(comment) |
|
159 | 159 | news = comment.commented |
|
160 | 160 | redmine_headers 'Project' => news.project.identifier |
|
161 | 161 | message_id comment |
|
162 | 162 | recipients news.recipients |
|
163 | 163 | cc news.watcher_recipients |
|
164 | 164 | subject "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}" |
|
165 | 165 | body :news => news, |
|
166 | 166 | :comment => comment, |
|
167 | 167 | :news_url => url_for(:controller => 'news', :action => 'show', :id => news) |
|
168 | 168 | render_multipart('news_comment_added', body) |
|
169 | 169 | end |
|
170 | 170 | |
|
171 | 171 | # Builds a tmail object used to email the recipients of the specified message that was posted. |
|
172 | 172 | # |
|
173 | 173 | # Example: |
|
174 | 174 | # message_posted(message) => tmail object |
|
175 | 175 | # Mailer.deliver_message_posted(message) => sends an email to the recipients |
|
176 | 176 | def message_posted(message) |
|
177 | 177 | redmine_headers 'Project' => message.project.identifier, |
|
178 | 178 | 'Topic-Id' => (message.parent_id || message.id) |
|
179 | 179 | message_id message |
|
180 | 180 | references message.parent unless message.parent.nil? |
|
181 | 181 | recipients(message.recipients) |
|
182 | 182 | cc((message.root.watcher_recipients + message.board.watcher_recipients).uniq - @recipients) |
|
183 | 183 | subject "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}" |
|
184 | 184 | body :message => message, |
|
185 | 185 | :message_url => url_for(message.event_url) |
|
186 | 186 | render_multipart('message_posted', body) |
|
187 | 187 | end |
|
188 | 188 | |
|
189 | 189 | # Builds a tmail object used to email the recipients of a project of the specified wiki content was added. |
|
190 | 190 | # |
|
191 | 191 | # Example: |
|
192 | 192 | # wiki_content_added(wiki_content) => tmail object |
|
193 | 193 | # Mailer.deliver_wiki_content_added(wiki_content) => sends an email to the project's recipients |
|
194 | 194 | def wiki_content_added(wiki_content) |
|
195 | 195 | redmine_headers 'Project' => wiki_content.project.identifier, |
|
196 | 196 | 'Wiki-Page-Id' => wiki_content.page.id |
|
197 | 197 | message_id wiki_content |
|
198 | 198 | recipients wiki_content.recipients |
|
199 | 199 | cc(wiki_content.page.wiki.watcher_recipients - recipients) |
|
200 | 200 | subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :id => wiki_content.page.pretty_title)}" |
|
201 | 201 | body :wiki_content => wiki_content, |
|
202 | 202 | :wiki_content_url => url_for(:controller => 'wiki', :action => 'show', |
|
203 | 203 | :project_id => wiki_content.project, |
|
204 | 204 | :id => wiki_content.page.title) |
|
205 | 205 | render_multipart('wiki_content_added', body) |
|
206 | 206 | end |
|
207 | 207 | |
|
208 | 208 | # Builds a tmail object used to email the recipients of a project of the specified wiki content was updated. |
|
209 | 209 | # |
|
210 | 210 | # Example: |
|
211 | 211 | # wiki_content_updated(wiki_content) => tmail object |
|
212 | 212 | # Mailer.deliver_wiki_content_updated(wiki_content) => sends an email to the project's recipients |
|
213 | 213 | def wiki_content_updated(wiki_content) |
|
214 | 214 | redmine_headers 'Project' => wiki_content.project.identifier, |
|
215 | 215 | 'Wiki-Page-Id' => wiki_content.page.id |
|
216 | 216 | message_id wiki_content |
|
217 | 217 | recipients wiki_content.recipients |
|
218 | 218 | cc(wiki_content.page.wiki.watcher_recipients + wiki_content.page.watcher_recipients - recipients) |
|
219 | 219 | subject "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :id => wiki_content.page.pretty_title)}" |
|
220 | 220 | body :wiki_content => wiki_content, |
|
221 | 221 | :wiki_content_url => url_for(:controller => 'wiki', :action => 'show', |
|
222 | 222 | :project_id => wiki_content.project, |
|
223 | 223 | :id => wiki_content.page.title), |
|
224 | 224 | :wiki_diff_url => url_for(:controller => 'wiki', :action => 'diff', |
|
225 | 225 | :project_id => wiki_content.project, :id => wiki_content.page.title, |
|
226 | 226 | :version => wiki_content.version) |
|
227 | 227 | render_multipart('wiki_content_updated', body) |
|
228 | 228 | end |
|
229 | 229 | |
|
230 | 230 | # Builds a tmail object used to email the specified user their account information. |
|
231 | 231 | # |
|
232 | 232 | # Example: |
|
233 | 233 | # account_information(user, password) => tmail object |
|
234 | 234 | # Mailer.deliver_account_information(user, password) => sends account information to the user |
|
235 | 235 | def account_information(user, password) |
|
236 | 236 | set_language_if_valid user.language |
|
237 | 237 | recipients user.mail |
|
238 | 238 | subject l(:mail_subject_register, Setting.app_title) |
|
239 | 239 | body :user => user, |
|
240 | 240 | :password => password, |
|
241 | 241 | :login_url => url_for(:controller => 'account', :action => 'login') |
|
242 | 242 | render_multipart('account_information', body) |
|
243 | 243 | end |
|
244 | 244 | |
|
245 | 245 | # Builds a tmail object used to email all active administrators of an account activation request. |
|
246 | 246 | # |
|
247 | 247 | # Example: |
|
248 | 248 | # account_activation_request(user) => tmail object |
|
249 | 249 | # Mailer.deliver_account_activation_request(user)=> sends an email to all active administrators |
|
250 | 250 | def account_activation_request(user) |
|
251 | 251 | # Send the email to all active administrators |
|
252 | 252 | recipients User.active.find(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact |
|
253 | 253 | subject l(:mail_subject_account_activation_request, Setting.app_title) |
|
254 | 254 | body :user => user, |
|
255 | 255 | :url => url_for(:controller => 'users', :action => 'index', |
|
256 | 256 | :status => User::STATUS_REGISTERED, |
|
257 | 257 | :sort_key => 'created_on', :sort_order => 'desc') |
|
258 | 258 | render_multipart('account_activation_request', body) |
|
259 | 259 | end |
|
260 | 260 | |
|
261 | 261 | # Builds a tmail object used to email the specified user that their account was activated by an administrator. |
|
262 | 262 | # |
|
263 | 263 | # Example: |
|
264 | 264 | # account_activated(user) => tmail object |
|
265 | 265 | # Mailer.deliver_account_activated(user) => sends an email to the registered user |
|
266 | 266 | def account_activated(user) |
|
267 | 267 | set_language_if_valid user.language |
|
268 | 268 | recipients user.mail |
|
269 | 269 | subject l(:mail_subject_register, Setting.app_title) |
|
270 | 270 | body :user => user, |
|
271 | 271 | :login_url => url_for(:controller => 'account', :action => 'login') |
|
272 | 272 | render_multipart('account_activated', body) |
|
273 | 273 | end |
|
274 | 274 | |
|
275 | 275 | def lost_password(token) |
|
276 | 276 | set_language_if_valid(token.user.language) |
|
277 | 277 | recipients token.user.mail |
|
278 | 278 | subject l(:mail_subject_lost_password, Setting.app_title) |
|
279 | 279 | body :token => token, |
|
280 | 280 | :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value) |
|
281 | 281 | render_multipart('lost_password', body) |
|
282 | 282 | end |
|
283 | 283 | |
|
284 | 284 | def register(token) |
|
285 | 285 | set_language_if_valid(token.user.language) |
|
286 | 286 | recipients token.user.mail |
|
287 | 287 | subject l(:mail_subject_register, Setting.app_title) |
|
288 | 288 | body :token => token, |
|
289 | 289 | :url => url_for(:controller => 'account', :action => 'activate', :token => token.value) |
|
290 | 290 | render_multipart('register', body) |
|
291 | 291 | end |
|
292 | 292 | |
|
293 | def test(user) | |
|
293 | def test_email(user) | |
|
294 | 294 | set_language_if_valid(user.language) |
|
295 | 295 | recipients user.mail |
|
296 | 296 | subject 'Redmine test' |
|
297 | 297 | body :url => url_for(:controller => 'welcome') |
|
298 | render_multipart('test', body) | |
|
298 | render_multipart('test_email', body) | |
|
299 | 299 | end |
|
300 | 300 | |
|
301 | 301 | # Overrides default deliver! method to prevent from sending an email |
|
302 | 302 | # with no recipient, cc or bcc |
|
303 | 303 | def deliver!(mail = @mail) |
|
304 | 304 | set_language_if_valid @initial_language |
|
305 | 305 | return false if (recipients.nil? || recipients.empty?) && |
|
306 | 306 | (cc.nil? || cc.empty?) && |
|
307 | 307 | (bcc.nil? || bcc.empty?) |
|
308 | 308 | |
|
309 | 309 | # Set Message-Id and References |
|
310 | 310 | if @message_id_object |
|
311 | 311 | mail.message_id = self.class.message_id_for(@message_id_object) |
|
312 | 312 | end |
|
313 | 313 | if @references_objects |
|
314 | 314 | mail.references = @references_objects.collect {|o| self.class.message_id_for(o)} |
|
315 | 315 | end |
|
316 | 316 | |
|
317 | 317 | # Log errors when raise_delivery_errors is set to false, Rails does not |
|
318 | 318 | raise_errors = self.class.raise_delivery_errors |
|
319 | 319 | self.class.raise_delivery_errors = true |
|
320 | 320 | begin |
|
321 | 321 | return super(mail) |
|
322 | 322 | rescue Exception => e |
|
323 | 323 | if raise_errors |
|
324 | 324 | raise e |
|
325 | 325 | elsif mylogger |
|
326 | 326 | mylogger.error "The following error occured while sending email notification: \"#{e.message}\". Check your configuration in config/configuration.yml." |
|
327 | 327 | end |
|
328 | 328 | ensure |
|
329 | 329 | self.class.raise_delivery_errors = raise_errors |
|
330 | 330 | end |
|
331 | 331 | end |
|
332 | 332 | |
|
333 | 333 | # Sends reminders to issue assignees |
|
334 | 334 | # Available options: |
|
335 | 335 | # * :days => how many days in the future to remind about (defaults to 7) |
|
336 | 336 | # * :tracker => id of tracker for filtering issues (defaults to all trackers) |
|
337 | 337 | # * :project => id or identifier of project to process (defaults to all projects) |
|
338 | 338 | # * :users => array of user ids who should be reminded |
|
339 | 339 | def self.reminders(options={}) |
|
340 | 340 | days = options[:days] || 7 |
|
341 | 341 | project = options[:project] ? Project.find(options[:project]) : nil |
|
342 | 342 | tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil |
|
343 | 343 | user_ids = options[:users] |
|
344 | 344 | |
|
345 | 345 | scope = Issue.open.scoped(:conditions => ["#{Issue.table_name}.assigned_to_id IS NOT NULL" + |
|
346 | 346 | " AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}" + |
|
347 | 347 | " AND #{Issue.table_name}.due_date <= ?", days.day.from_now.to_date] |
|
348 | 348 | ) |
|
349 | 349 | scope = scope.scoped(:conditions => {:assigned_to_id => user_ids}) if user_ids.present? |
|
350 | 350 | scope = scope.scoped(:conditions => {:project_id => project.id}) if project |
|
351 | 351 | scope = scope.scoped(:conditions => {:tracker_id => tracker.id}) if tracker |
|
352 | 352 | |
|
353 | 353 | issues_by_assignee = scope.all(:include => [:status, :assigned_to, :project, :tracker]).group_by(&:assigned_to) |
|
354 | 354 | issues_by_assignee.each do |assignee, issues| |
|
355 | 355 | deliver_reminder(assignee, issues, days) if assignee && assignee.active? |
|
356 | 356 | end |
|
357 | 357 | end |
|
358 | 358 | |
|
359 | 359 | # Activates/desactivates email deliveries during +block+ |
|
360 | 360 | def self.with_deliveries(enabled = true, &block) |
|
361 | 361 | was_enabled = ActionMailer::Base.perform_deliveries |
|
362 | 362 | ActionMailer::Base.perform_deliveries = !!enabled |
|
363 | 363 | yield |
|
364 | 364 | ensure |
|
365 | 365 | ActionMailer::Base.perform_deliveries = was_enabled |
|
366 | 366 | end |
|
367 | 367 | |
|
368 | 368 | private |
|
369 | 369 | def initialize_defaults(method_name) |
|
370 | 370 | super |
|
371 | 371 | @initial_language = current_language |
|
372 | 372 | set_language_if_valid Setting.default_language |
|
373 | 373 | from Setting.mail_from |
|
374 | 374 | |
|
375 | 375 | # Common headers |
|
376 | 376 | headers 'X-Mailer' => 'Redmine', |
|
377 | 377 | 'X-Redmine-Host' => Setting.host_name, |
|
378 | 378 | 'X-Redmine-Site' => Setting.app_title, |
|
379 | 379 | 'X-Auto-Response-Suppress' => 'OOF', |
|
380 | 380 | 'Auto-Submitted' => 'auto-generated' |
|
381 | 381 | end |
|
382 | 382 | |
|
383 | 383 | # Appends a Redmine header field (name is prepended with 'X-Redmine-') |
|
384 | 384 | def redmine_headers(h) |
|
385 | 385 | h.each { |k,v| headers["X-Redmine-#{k}"] = v.to_s } |
|
386 | 386 | end |
|
387 | 387 | |
|
388 | 388 | # Overrides the create_mail method |
|
389 | 389 | def create_mail |
|
390 | 390 | # Removes the current user from the recipients and cc |
|
391 | 391 | # if he doesn't want to receive notifications about what he does |
|
392 | 392 | @author ||= User.current |
|
393 | 393 | if @author.pref[:no_self_notified] |
|
394 | 394 | recipients.delete(@author.mail) if recipients |
|
395 | 395 | cc.delete(@author.mail) if cc |
|
396 | 396 | end |
|
397 | 397 | |
|
398 | 398 | if @author.logged? |
|
399 | 399 | redmine_headers 'Sender' => @author.login |
|
400 | 400 | end |
|
401 | 401 | |
|
402 | 402 | notified_users = [recipients, cc].flatten.compact.uniq |
|
403 | 403 | # Rails would log recipients only, not cc and bcc |
|
404 | 404 | mylogger.info "Sending email notification to: #{notified_users.join(', ')}" if mylogger |
|
405 | 405 | |
|
406 | 406 | # Blind carbon copy recipients |
|
407 | 407 | if Setting.bcc_recipients? |
|
408 | 408 | bcc(notified_users) |
|
409 | 409 | recipients [] |
|
410 | 410 | cc [] |
|
411 | 411 | end |
|
412 | 412 | super |
|
413 | 413 | end |
|
414 | 414 | |
|
415 | 415 | # Rails 2.3 has problems rendering implicit multipart messages with |
|
416 | 416 | # layouts so this method will wrap an multipart messages with |
|
417 | 417 | # explicit parts. |
|
418 | 418 | # |
|
419 | 419 | # https://rails.lighthouseapp.com/projects/8994/tickets/2338-actionmailer-mailer-views-and-content-type |
|
420 | 420 | # https://rails.lighthouseapp.com/projects/8994/tickets/1799-actionmailer-doesnt-set-template_format-when-rendering-layouts |
|
421 | 421 | |
|
422 | 422 | def render_multipart(method_name, body) |
|
423 | 423 | if Setting.plain_text_mail? |
|
424 | 424 | content_type "text/plain" |
|
425 | 425 | body render(:file => "#{method_name}.text.erb", |
|
426 | 426 | :body => body, |
|
427 | 427 | :layout => 'mailer.text.erb') |
|
428 | 428 | else |
|
429 | 429 | content_type "multipart/alternative" |
|
430 | 430 | part :content_type => "text/plain", |
|
431 | 431 | :body => render(:file => "#{method_name}.text.erb", |
|
432 | 432 | :body => body, :layout => 'mailer.text.erb') |
|
433 | 433 | part :content_type => "text/html", |
|
434 | 434 | :body => render_message("#{method_name}.html.erb", body) |
|
435 | 435 | end |
|
436 | 436 | end |
|
437 | 437 | |
|
438 | 438 | # Makes partial rendering work with Rails 1.2 (retro-compatibility) |
|
439 | 439 | def self.controller_path |
|
440 | 440 | '' |
|
441 | 441 | end unless respond_to?('controller_path') |
|
442 | 442 | |
|
443 | 443 | # Returns a predictable Message-Id for the given object |
|
444 | 444 | def self.message_id_for(object) |
|
445 | 445 | # id + timestamp should reduce the odds of a collision |
|
446 | 446 | # as far as we don't send multiple emails for the same object |
|
447 | 447 | timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on) |
|
448 | 448 | hash = "redmine.#{object.class.name.demodulize.underscore}-#{object.id}.#{timestamp.strftime("%Y%m%d%H%M%S")}" |
|
449 | 449 | host = Setting.mail_from.to_s.gsub(%r{^.*@}, '') |
|
450 | 450 | host = "#{::Socket.gethostname}.redmine" if host.empty? |
|
451 | 451 | "<#{hash}@#{host}>" |
|
452 | 452 | end |
|
453 | 453 | |
|
454 | 454 | private |
|
455 | 455 | |
|
456 | 456 | def message_id(object) |
|
457 | 457 | @message_id_object = object |
|
458 | 458 | end |
|
459 | 459 | |
|
460 | 460 | def references(object) |
|
461 | 461 | @references_objects ||= [] |
|
462 | 462 | @references_objects << object |
|
463 | 463 | end |
|
464 | 464 | |
|
465 | 465 | def mylogger |
|
466 | 466 | Rails.logger |
|
467 | 467 | end |
|
468 | 468 | end |
|
469 | 469 | |
|
470 | 470 | # Patch TMail so that message_id is not overwritten |
|
471 | 471 | module TMail |
|
472 | 472 | class Mail |
|
473 | 473 | def add_message_id( fqdn = nil ) |
|
474 | 474 | self.message_id ||= ::TMail::new_message_id(fqdn) |
|
475 | 475 | end |
|
476 | 476 | end |
|
477 | 477 | end |
|
1 | NO CONTENT: file renamed from app/views/mailer/test.html.erb to app/views/mailer/test_email.html.erb |
|
1 | NO CONTENT: file renamed from app/views/mailer/test.text.erb to app/views/mailer/test_email.text.erb |
@@ -1,186 +1,186 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 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 | namespace :redmine do |
|
19 | 19 | namespace :email do |
|
20 | 20 | |
|
21 | 21 | desc <<-END_DESC |
|
22 | 22 | Read an email from standard input. |
|
23 | 23 | |
|
24 | 24 | General options: |
|
25 | 25 | unknown_user=ACTION how to handle emails from an unknown user |
|
26 | 26 | ACTION can be one of the following values: |
|
27 | 27 | ignore: email is ignored (default) |
|
28 | 28 | accept: accept as anonymous user |
|
29 | 29 | create: create a user account |
|
30 | 30 | no_permission_check=1 disable permission checking when receiving |
|
31 | 31 | the email |
|
32 | 32 | |
|
33 | 33 | Issue attributes control options: |
|
34 | 34 | project=PROJECT identifier of the target project |
|
35 | 35 | status=STATUS name of the target status |
|
36 | 36 | tracker=TRACKER name of the target tracker |
|
37 | 37 | category=CATEGORY name of the target category |
|
38 | 38 | priority=PRIORITY name of the target priority |
|
39 | 39 | allow_override=ATTRS allow email content to override attributes |
|
40 | 40 | specified by previous options |
|
41 | 41 | ATTRS is a comma separated list of attributes |
|
42 | 42 | |
|
43 | 43 | Examples: |
|
44 | 44 | # No project specified. Emails MUST contain the 'Project' keyword: |
|
45 | 45 | rake redmine:email:read RAILS_ENV="production" < raw_email |
|
46 | 46 | |
|
47 | 47 | # Fixed project and default tracker specified, but emails can override |
|
48 | 48 | # both tracker and priority attributes: |
|
49 | 49 | rake redmine:email:read RAILS_ENV="production" \\ |
|
50 | 50 | project=foo \\ |
|
51 | 51 | tracker=bug \\ |
|
52 | 52 | allow_override=tracker,priority < raw_email |
|
53 | 53 | END_DESC |
|
54 | 54 | |
|
55 | 55 | task :read => :environment do |
|
56 | 56 | options = { :issue => {} } |
|
57 | 57 | %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] } |
|
58 | 58 | options[:allow_override] = ENV['allow_override'] if ENV['allow_override'] |
|
59 | 59 | options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user'] |
|
60 | 60 | options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check'] |
|
61 | 61 | |
|
62 | 62 | MailHandler.receive(STDIN.read, options) |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | desc <<-END_DESC |
|
66 | 66 | Read emails from an IMAP server. |
|
67 | 67 | |
|
68 | 68 | General options: |
|
69 | 69 | unknown_user=ACTION how to handle emails from an unknown user |
|
70 | 70 | ACTION can be one of the following values: |
|
71 | 71 | ignore: email is ignored (default) |
|
72 | 72 | accept: accept as anonymous user |
|
73 | 73 | create: create a user account |
|
74 | 74 | no_permission_check=1 disable permission checking when receiving |
|
75 | 75 | the email |
|
76 | 76 | |
|
77 | 77 | Available IMAP options: |
|
78 | 78 | host=HOST IMAP server host (default: 127.0.0.1) |
|
79 | 79 | port=PORT IMAP server port (default: 143) |
|
80 | 80 | ssl=SSL Use SSL? (default: false) |
|
81 | 81 | username=USERNAME IMAP account |
|
82 | 82 | password=PASSWORD IMAP password |
|
83 | 83 | folder=FOLDER IMAP folder to read (default: INBOX) |
|
84 | 84 | |
|
85 | 85 | Issue attributes control options: |
|
86 | 86 | project=PROJECT identifier of the target project |
|
87 | 87 | status=STATUS name of the target status |
|
88 | 88 | tracker=TRACKER name of the target tracker |
|
89 | 89 | category=CATEGORY name of the target category |
|
90 | 90 | priority=PRIORITY name of the target priority |
|
91 | 91 | allow_override=ATTRS allow email content to override attributes |
|
92 | 92 | specified by previous options |
|
93 | 93 | ATTRS is a comma separated list of attributes |
|
94 | 94 | |
|
95 | 95 | Processed emails control options: |
|
96 | 96 | move_on_success=MAILBOX move emails that were successfully received |
|
97 | 97 | to MAILBOX instead of deleting them |
|
98 | 98 | move_on_failure=MAILBOX move emails that were ignored to MAILBOX |
|
99 | 99 | |
|
100 | 100 | Examples: |
|
101 | 101 | # No project specified. Emails MUST contain the 'Project' keyword: |
|
102 | 102 | |
|
103 | 103 | rake redmine:email:receive_imap RAILS_ENV="production" \\ |
|
104 | 104 | host=imap.foo.bar username=redmine@example.net password=xxx |
|
105 | 105 | |
|
106 | 106 | |
|
107 | 107 | # Fixed project and default tracker specified, but emails can override |
|
108 | 108 | # both tracker and priority attributes: |
|
109 | 109 | |
|
110 | 110 | rake redmine:email:receive_imap RAILS_ENV="production" \\ |
|
111 | 111 | host=imap.foo.bar username=redmine@example.net password=xxx ssl=1 \\ |
|
112 | 112 | project=foo \\ |
|
113 | 113 | tracker=bug \\ |
|
114 | 114 | allow_override=tracker,priority |
|
115 | 115 | END_DESC |
|
116 | 116 | |
|
117 | 117 | task :receive_imap => :environment do |
|
118 | 118 | imap_options = {:host => ENV['host'], |
|
119 | 119 | :port => ENV['port'], |
|
120 | 120 | :ssl => ENV['ssl'], |
|
121 | 121 | :username => ENV['username'], |
|
122 | 122 | :password => ENV['password'], |
|
123 | 123 | :folder => ENV['folder'], |
|
124 | 124 | :move_on_success => ENV['move_on_success'], |
|
125 | 125 | :move_on_failure => ENV['move_on_failure']} |
|
126 | 126 | |
|
127 | 127 | options = { :issue => {} } |
|
128 | 128 | %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] } |
|
129 | 129 | options[:allow_override] = ENV['allow_override'] if ENV['allow_override'] |
|
130 | 130 | options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user'] |
|
131 | 131 | options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check'] |
|
132 | 132 | |
|
133 | 133 | Redmine::IMAP.check(imap_options, options) |
|
134 | 134 | end |
|
135 | 135 | |
|
136 | 136 | desc <<-END_DESC |
|
137 | 137 | Read emails from an POP3 server. |
|
138 | 138 | |
|
139 | 139 | Available POP3 options: |
|
140 | 140 | host=HOST POP3 server host (default: 127.0.0.1) |
|
141 | 141 | port=PORT POP3 server port (default: 110) |
|
142 | 142 | username=USERNAME POP3 account |
|
143 | 143 | password=PASSWORD POP3 password |
|
144 | 144 | apop=1 use APOP authentication (default: false) |
|
145 | 145 | delete_unprocessed=1 delete messages that could not be processed |
|
146 | 146 | successfully from the server (default |
|
147 | 147 | behaviour is to leave them on the server) |
|
148 | 148 | |
|
149 | 149 | See redmine:email:receive_imap for more options and examples. |
|
150 | 150 | END_DESC |
|
151 | 151 | |
|
152 | 152 | task :receive_pop3 => :environment do |
|
153 | 153 | pop_options = {:host => ENV['host'], |
|
154 | 154 | :port => ENV['port'], |
|
155 | 155 | :apop => ENV['apop'], |
|
156 | 156 | :username => ENV['username'], |
|
157 | 157 | :password => ENV['password'], |
|
158 | 158 | :delete_unprocessed => ENV['delete_unprocessed']} |
|
159 | 159 | |
|
160 | 160 | options = { :issue => {} } |
|
161 | 161 | %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] } |
|
162 | 162 | options[:allow_override] = ENV['allow_override'] if ENV['allow_override'] |
|
163 | 163 | options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user'] |
|
164 | 164 | options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check'] |
|
165 | 165 | |
|
166 | 166 | Redmine::POP3.check(pop_options, options) |
|
167 | 167 | end |
|
168 | 168 | |
|
169 | 169 | desc "Send a test email to the user with the provided login name" |
|
170 | 170 | task :test, [:login] => :environment do |task, args| |
|
171 | 171 | include Redmine::I18n |
|
172 | 172 | abort l(:notice_email_error, "Please include the user login to test with. Example: rake redmine:email:test[login]") if args[:login].blank? |
|
173 | 173 | |
|
174 | 174 | user = User.find_by_login(args[:login]) |
|
175 | 175 | abort l(:notice_email_error, "User #{args[:login]} not found") unless user && user.logged? |
|
176 | 176 | |
|
177 | 177 | ActionMailer::Base.raise_delivery_errors = true |
|
178 | 178 | begin |
|
179 | Mailer.deliver_test(User.current) | |
|
179 | Mailer.deliver_test_email(User.current) | |
|
180 | 180 | puts l(:notice_email_sent, user.mail) |
|
181 | 181 | rescue Exception => e |
|
182 | 182 | abort l(:notice_email_error, e.message) |
|
183 | 183 | end |
|
184 | 184 | end |
|
185 | 185 | end |
|
186 | 186 | end |
@@ -1,157 +1,157 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 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.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | require 'admin_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class AdminController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class AdminControllerTest < ActionController::TestCase |
|
25 | 25 | fixtures :projects, :users, :roles |
|
26 | 26 | |
|
27 | 27 | def setup |
|
28 | 28 | @controller = AdminController.new |
|
29 | 29 | @request = ActionController::TestRequest.new |
|
30 | 30 | @response = ActionController::TestResponse.new |
|
31 | 31 | User.current = nil |
|
32 | 32 | @request.session[:user_id] = 1 # admin |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | def test_index |
|
36 | 36 | get :index |
|
37 | 37 | assert_no_tag :tag => 'div', |
|
38 | 38 | :attributes => { :class => /nodata/ } |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def test_index_with_no_configuration_data |
|
42 | 42 | delete_configuration_data |
|
43 | 43 | get :index |
|
44 | 44 | assert_tag :tag => 'div', |
|
45 | 45 | :attributes => { :class => /nodata/ } |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | def test_projects |
|
49 | 49 | get :projects |
|
50 | 50 | assert_response :success |
|
51 | 51 | assert_template 'projects' |
|
52 | 52 | assert_not_nil assigns(:projects) |
|
53 | 53 | # active projects only |
|
54 | 54 | assert_nil assigns(:projects).detect {|u| !u.active?} |
|
55 | 55 | end |
|
56 | 56 | |
|
57 | 57 | def test_projects_with_status_filter |
|
58 | 58 | get :projects, :status => 1 |
|
59 | 59 | assert_response :success |
|
60 | 60 | assert_template 'projects' |
|
61 | 61 | assert_not_nil assigns(:projects) |
|
62 | 62 | # active projects only |
|
63 | 63 | assert_nil assigns(:projects).detect {|u| !u.active?} |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | def test_projects_with_name_filter |
|
67 | 67 | get :projects, :name => 'store', :status => '' |
|
68 | 68 | assert_response :success |
|
69 | 69 | assert_template 'projects' |
|
70 | 70 | projects = assigns(:projects) |
|
71 | 71 | assert_not_nil projects |
|
72 | 72 | assert_equal 1, projects.size |
|
73 | 73 | assert_equal 'OnlineStore', projects.first.name |
|
74 | 74 | end |
|
75 | 75 | |
|
76 | 76 | def test_load_default_configuration_data |
|
77 | 77 | delete_configuration_data |
|
78 | 78 | post :default_configuration, :lang => 'fr' |
|
79 | 79 | assert_response :redirect |
|
80 | 80 | assert_nil flash[:error] |
|
81 | 81 | assert IssueStatus.find_by_name('Nouveau') |
|
82 | 82 | end |
|
83 | 83 | |
|
84 | 84 | def test_test_email |
|
85 | 85 | get :test_email |
|
86 | 86 | assert_redirected_to '/settings/edit?tab=notifications' |
|
87 | 87 | mail = ActionMailer::Base.deliveries.last |
|
88 | 88 | assert_not_nil mail |
|
89 | 89 | user = User.find(1) |
|
90 | 90 | assert_equal [user.mail], mail.bcc |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | def test_test_email_failure_should_display_the_error |
|
94 | Mailer.stubs(:deliver_test).raises(Exception, 'Some error message') | |
|
94 | Mailer.stubs(:deliver_test_email).raises(Exception, 'Some error message') | |
|
95 | 95 | get :test_email |
|
96 | 96 | assert_redirected_to '/settings/edit?tab=notifications' |
|
97 | 97 | assert_match /Some error message/, flash[:error] |
|
98 | 98 | end |
|
99 | 99 | |
|
100 | 100 | def test_no_plugins |
|
101 | 101 | Redmine::Plugin.clear |
|
102 | 102 | |
|
103 | 103 | get :plugins |
|
104 | 104 | assert_response :success |
|
105 | 105 | assert_template 'plugins' |
|
106 | 106 | end |
|
107 | 107 | |
|
108 | 108 | def test_plugins |
|
109 | 109 | # Register a few plugins |
|
110 | 110 | Redmine::Plugin.register :foo do |
|
111 | 111 | name 'Foo plugin' |
|
112 | 112 | author 'John Smith' |
|
113 | 113 | description 'This is a test plugin' |
|
114 | 114 | version '0.0.1' |
|
115 | 115 | settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'foo/settings' |
|
116 | 116 | end |
|
117 | 117 | Redmine::Plugin.register :bar do |
|
118 | 118 | end |
|
119 | 119 | |
|
120 | 120 | get :plugins |
|
121 | 121 | assert_response :success |
|
122 | 122 | assert_template 'plugins' |
|
123 | 123 | |
|
124 | 124 | assert_tag :td, :child => { :tag => 'span', :content => 'Foo plugin' } |
|
125 | 125 | assert_tag :td, :child => { :tag => 'span', :content => 'Bar' } |
|
126 | 126 | end |
|
127 | 127 | |
|
128 | 128 | def test_info |
|
129 | 129 | get :info |
|
130 | 130 | assert_response :success |
|
131 | 131 | assert_template 'info' |
|
132 | 132 | end |
|
133 | 133 | |
|
134 | 134 | def test_admin_menu_plugin_extension |
|
135 | 135 | Redmine::MenuManager.map :admin_menu do |menu| |
|
136 | 136 | menu.push :test_admin_menu_plugin_extension, '/foo/bar', :caption => 'Test' |
|
137 | 137 | end |
|
138 | 138 | |
|
139 | 139 | get :index |
|
140 | 140 | assert_response :success |
|
141 | 141 | assert_tag :a, :attributes => { :href => '/foo/bar' }, |
|
142 | 142 | :content => 'Test' |
|
143 | 143 | |
|
144 | 144 | Redmine::MenuManager.map :admin_menu do |menu| |
|
145 | 145 | menu.delete :test_admin_menu_plugin_extension |
|
146 | 146 | end |
|
147 | 147 | end |
|
148 | 148 | |
|
149 | 149 | private |
|
150 | 150 | |
|
151 | 151 | def delete_configuration_data |
|
152 | 152 | Role.delete_all('builtin = 0') |
|
153 | 153 | Tracker.delete_all |
|
154 | 154 | IssueStatus.delete_all |
|
155 | 155 | Enumeration.delete_all |
|
156 | 156 | end |
|
157 | 157 | end |
@@ -1,550 +1,550 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 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.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class MailerTest < ActiveSupport::TestCase |
|
21 | 21 | include Redmine::I18n |
|
22 | 22 | include ActionController::Assertions::SelectorAssertions |
|
23 | 23 | fixtures :projects, :enabled_modules, :issues, :users, :members, |
|
24 | 24 | :member_roles, :roles, :documents, :attachments, :news, |
|
25 | 25 | :tokens, :journals, :journal_details, :changesets, :trackers, |
|
26 | 26 | :issue_statuses, :enumerations, :messages, :boards, :repositories, |
|
27 | 27 | :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, |
|
28 | 28 | :versions, |
|
29 | 29 | :comments |
|
30 | 30 | |
|
31 | 31 | def setup |
|
32 | 32 | ActionMailer::Base.deliveries.clear |
|
33 | 33 | Setting.host_name = 'mydomain.foo' |
|
34 | 34 | Setting.protocol = 'http' |
|
35 | 35 | Setting.plain_text_mail = '0' |
|
36 | 36 | end |
|
37 | 37 | |
|
38 | 38 | def test_generated_links_in_emails |
|
39 | 39 | Setting.default_language = 'en' |
|
40 | 40 | Setting.host_name = 'mydomain.foo' |
|
41 | 41 | Setting.protocol = 'https' |
|
42 | 42 | |
|
43 | 43 | journal = Journal.find(3) |
|
44 | 44 | assert Mailer.deliver_issue_edit(journal) |
|
45 | 45 | |
|
46 | 46 | mail = last_email |
|
47 | 47 | assert_not_nil mail |
|
48 | 48 | |
|
49 | 49 | assert_select_email do |
|
50 | 50 | # link to the main ticket |
|
51 | 51 | assert_select 'a[href=?]', |
|
52 | 52 | 'https://mydomain.foo/issues/2#change-3', |
|
53 | 53 | :text => 'Feature request #2: Add ingredients categories' |
|
54 | 54 | # link to a referenced ticket |
|
55 | 55 | assert_select 'a[href=?][title=?]', |
|
56 | 56 | 'https://mydomain.foo/issues/1', |
|
57 | 57 | 'Can\'t print recipes (New)', |
|
58 | 58 | :text => '#1' |
|
59 | 59 | # link to a changeset |
|
60 | 60 | assert_select 'a[href=?][title=?]', |
|
61 | 61 | 'https://mydomain.foo/projects/ecookbook/repository/revisions/2', |
|
62 | 62 | 'This commit fixes #1, #2 and references #1 & #3', |
|
63 | 63 | :text => 'r2' |
|
64 | 64 | # link to a description diff |
|
65 | 65 | assert_select 'a[href=?][title=?]', |
|
66 | 66 | 'https://mydomain.foo/journals/diff/3?detail_id=4', |
|
67 | 67 | 'View differences', |
|
68 | 68 | :text => 'diff' |
|
69 | 69 | # link to an attachment |
|
70 | 70 | assert_select 'a[href=?]', |
|
71 | 71 | 'https://mydomain.foo/attachments/download/4/source.rb', |
|
72 | 72 | :text => 'source.rb' |
|
73 | 73 | end |
|
74 | 74 | end |
|
75 | 75 | |
|
76 | 76 | def test_generated_links_with_prefix |
|
77 | 77 | Setting.default_language = 'en' |
|
78 | 78 | relative_url_root = Redmine::Utils.relative_url_root |
|
79 | 79 | Setting.host_name = 'mydomain.foo/rdm' |
|
80 | 80 | Setting.protocol = 'http' |
|
81 | 81 | Redmine::Utils.relative_url_root = '/rdm' |
|
82 | 82 | |
|
83 | 83 | journal = Journal.find(3) |
|
84 | 84 | assert Mailer.deliver_issue_edit(journal) |
|
85 | 85 | |
|
86 | 86 | mail = last_email |
|
87 | 87 | assert_not_nil mail |
|
88 | 88 | |
|
89 | 89 | assert_select_email do |
|
90 | 90 | # link to the main ticket |
|
91 | 91 | assert_select 'a[href=?]', |
|
92 | 92 | 'http://mydomain.foo/rdm/issues/2#change-3', |
|
93 | 93 | :text => 'Feature request #2: Add ingredients categories' |
|
94 | 94 | # link to a referenced ticket |
|
95 | 95 | assert_select 'a[href=?][title=?]', |
|
96 | 96 | 'http://mydomain.foo/rdm/issues/1', |
|
97 | 97 | 'Can\'t print recipes (New)', |
|
98 | 98 | :text => '#1' |
|
99 | 99 | # link to a changeset |
|
100 | 100 | assert_select 'a[href=?][title=?]', |
|
101 | 101 | 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2', |
|
102 | 102 | 'This commit fixes #1, #2 and references #1 & #3', |
|
103 | 103 | :text => 'r2' |
|
104 | 104 | # link to a description diff |
|
105 | 105 | assert_select 'a[href=?][title=?]', |
|
106 | 106 | 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4', |
|
107 | 107 | 'View differences', |
|
108 | 108 | :text => 'diff' |
|
109 | 109 | # link to an attachment |
|
110 | 110 | assert_select 'a[href=?]', |
|
111 | 111 | 'http://mydomain.foo/rdm/attachments/download/4/source.rb', |
|
112 | 112 | :text => 'source.rb' |
|
113 | 113 | end |
|
114 | 114 | ensure |
|
115 | 115 | # restore it |
|
116 | 116 | Redmine::Utils.relative_url_root = relative_url_root |
|
117 | 117 | end |
|
118 | 118 | |
|
119 | 119 | def test_generated_links_with_prefix_and_no_relative_url_root |
|
120 | 120 | Setting.default_language = 'en' |
|
121 | 121 | relative_url_root = Redmine::Utils.relative_url_root |
|
122 | 122 | Setting.host_name = 'mydomain.foo/rdm' |
|
123 | 123 | Setting.protocol = 'http' |
|
124 | 124 | Redmine::Utils.relative_url_root = nil |
|
125 | 125 | |
|
126 | 126 | journal = Journal.find(3) |
|
127 | 127 | assert Mailer.deliver_issue_edit(journal) |
|
128 | 128 | |
|
129 | 129 | mail = last_email |
|
130 | 130 | assert_not_nil mail |
|
131 | 131 | |
|
132 | 132 | assert_select_email do |
|
133 | 133 | # link to the main ticket |
|
134 | 134 | assert_select 'a[href=?]', |
|
135 | 135 | 'http://mydomain.foo/rdm/issues/2#change-3', |
|
136 | 136 | :text => 'Feature request #2: Add ingredients categories' |
|
137 | 137 | # link to a referenced ticket |
|
138 | 138 | assert_select 'a[href=?][title=?]', |
|
139 | 139 | 'http://mydomain.foo/rdm/issues/1', |
|
140 | 140 | 'Can\'t print recipes (New)', |
|
141 | 141 | :text => '#1' |
|
142 | 142 | # link to a changeset |
|
143 | 143 | assert_select 'a[href=?][title=?]', |
|
144 | 144 | 'http://mydomain.foo/rdm/projects/ecookbook/repository/revisions/2', |
|
145 | 145 | 'This commit fixes #1, #2 and references #1 & #3', |
|
146 | 146 | :text => 'r2' |
|
147 | 147 | # link to a description diff |
|
148 | 148 | assert_select 'a[href=?][title=?]', |
|
149 | 149 | 'http://mydomain.foo/rdm/journals/diff/3?detail_id=4', |
|
150 | 150 | 'View differences', |
|
151 | 151 | :text => 'diff' |
|
152 | 152 | # link to an attachment |
|
153 | 153 | assert_select 'a[href=?]', |
|
154 | 154 | 'http://mydomain.foo/rdm/attachments/download/4/source.rb', |
|
155 | 155 | :text => 'source.rb' |
|
156 | 156 | end |
|
157 | 157 | ensure |
|
158 | 158 | # restore it |
|
159 | 159 | Redmine::Utils.relative_url_root = relative_url_root |
|
160 | 160 | end |
|
161 | 161 | |
|
162 | 162 | def test_email_headers |
|
163 | 163 | issue = Issue.find(1) |
|
164 | 164 | Mailer.deliver_issue_add(issue) |
|
165 | 165 | mail = last_email |
|
166 | 166 | assert_not_nil mail |
|
167 | 167 | assert_equal 'OOF', mail.header_string('X-Auto-Response-Suppress') |
|
168 | 168 | assert_equal 'auto-generated', mail.header_string('Auto-Submitted') |
|
169 | 169 | end |
|
170 | 170 | |
|
171 | 171 | def test_email_headers_should_include_sender |
|
172 | 172 | issue = Issue.find(1) |
|
173 | 173 | Mailer.deliver_issue_add(issue) |
|
174 | 174 | mail = last_email |
|
175 | 175 | assert_equal issue.author.login, mail.header_string('X-Redmine-Sender') |
|
176 | 176 | end |
|
177 | 177 | |
|
178 | 178 | def test_plain_text_mail |
|
179 | 179 | Setting.plain_text_mail = 1 |
|
180 | 180 | journal = Journal.find(2) |
|
181 | 181 | Mailer.deliver_issue_edit(journal) |
|
182 | 182 | mail = last_email |
|
183 | 183 | assert_equal "text/plain", mail.content_type |
|
184 | 184 | assert_equal 0, mail.parts.size |
|
185 | 185 | assert !mail.encoded.include?('href') |
|
186 | 186 | end |
|
187 | 187 | |
|
188 | 188 | def test_html_mail |
|
189 | 189 | Setting.plain_text_mail = 0 |
|
190 | 190 | journal = Journal.find(2) |
|
191 | 191 | Mailer.deliver_issue_edit(journal) |
|
192 | 192 | mail = last_email |
|
193 | 193 | assert_equal 2, mail.parts.size |
|
194 | 194 | assert mail.encoded.include?('href') |
|
195 | 195 | end |
|
196 | 196 | |
|
197 | 197 | def test_from_header |
|
198 | 198 | with_settings :mail_from => 'redmine@example.net' do |
|
199 | Mailer.deliver_test(User.find(1)) | |
|
199 | Mailer.deliver_test_email(User.find(1)) | |
|
200 | 200 | end |
|
201 | 201 | mail = last_email |
|
202 | 202 | assert_equal 'redmine@example.net', mail.from_addrs.first.address |
|
203 | 203 | end |
|
204 | 204 | |
|
205 | 205 | def test_from_header_with_phrase |
|
206 | 206 | with_settings :mail_from => 'Redmine app <redmine@example.net>' do |
|
207 | Mailer.deliver_test(User.find(1)) | |
|
207 | Mailer.deliver_test_email(User.find(1)) | |
|
208 | 208 | end |
|
209 | 209 | mail = last_email |
|
210 | 210 | assert_equal 'redmine@example.net', mail.from_addrs.first.address |
|
211 | 211 | assert_equal 'Redmine app', mail.from_addrs.first.name |
|
212 | 212 | end |
|
213 | 213 | |
|
214 | 214 | def test_should_not_send_email_without_recipient |
|
215 | 215 | news = News.find(:first) |
|
216 | 216 | user = news.author |
|
217 | 217 | # Remove members except news author |
|
218 | 218 | news.project.memberships.each {|m| m.destroy unless m.user == user} |
|
219 | 219 | |
|
220 | 220 | user.pref[:no_self_notified] = false |
|
221 | 221 | user.pref.save |
|
222 | 222 | User.current = user |
|
223 | 223 | Mailer.deliver_news_added(news.reload) |
|
224 | 224 | assert_equal 1, last_email.bcc.size |
|
225 | 225 | |
|
226 | 226 | # nobody to notify |
|
227 | 227 | user.pref[:no_self_notified] = true |
|
228 | 228 | user.pref.save |
|
229 | 229 | User.current = user |
|
230 | 230 | ActionMailer::Base.deliveries.clear |
|
231 | 231 | Mailer.deliver_news_added(news.reload) |
|
232 | 232 | assert ActionMailer::Base.deliveries.empty? |
|
233 | 233 | end |
|
234 | 234 | |
|
235 | 235 | def test_issue_add_message_id |
|
236 | 236 | issue = Issue.find(1) |
|
237 | 237 | Mailer.deliver_issue_add(issue) |
|
238 | 238 | mail = last_email |
|
239 | 239 | assert_equal Mailer.message_id_for(issue), mail.message_id |
|
240 | 240 | assert_nil mail.references |
|
241 | 241 | end |
|
242 | 242 | |
|
243 | 243 | def test_issue_edit_message_id |
|
244 | 244 | journal = Journal.find(1) |
|
245 | 245 | Mailer.deliver_issue_edit(journal) |
|
246 | 246 | mail = last_email |
|
247 | 247 | assert_equal Mailer.message_id_for(journal), mail.message_id |
|
248 | 248 | assert_equal Mailer.message_id_for(journal.issue), mail.references.first.to_s |
|
249 | 249 | assert_select_email do |
|
250 | 250 | # link to the update |
|
251 | 251 | assert_select "a[href=?]", |
|
252 | 252 | "http://mydomain.foo/issues/#{journal.journalized_id}#change-#{journal.id}" |
|
253 | 253 | end |
|
254 | 254 | end |
|
255 | 255 | |
|
256 | 256 | def test_message_posted_message_id |
|
257 | 257 | message = Message.find(1) |
|
258 | 258 | Mailer.deliver_message_posted(message) |
|
259 | 259 | mail = last_email |
|
260 | 260 | assert_equal Mailer.message_id_for(message), mail.message_id |
|
261 | 261 | assert_nil mail.references |
|
262 | 262 | assert_select_email do |
|
263 | 263 | # link to the message |
|
264 | 264 | assert_select "a[href=?]", |
|
265 | 265 | "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.id}", |
|
266 | 266 | :text => message.subject |
|
267 | 267 | end |
|
268 | 268 | end |
|
269 | 269 | |
|
270 | 270 | def test_reply_posted_message_id |
|
271 | 271 | message = Message.find(3) |
|
272 | 272 | Mailer.deliver_message_posted(message) |
|
273 | 273 | mail = last_email |
|
274 | 274 | assert_equal Mailer.message_id_for(message), mail.message_id |
|
275 | 275 | assert_equal Mailer.message_id_for(message.parent), mail.references.first.to_s |
|
276 | 276 | assert_select_email do |
|
277 | 277 | # link to the reply |
|
278 | 278 | assert_select "a[href=?]", |
|
279 | 279 | "http://mydomain.foo/boards/#{message.board.id}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", |
|
280 | 280 | :text => message.subject |
|
281 | 281 | end |
|
282 | 282 | end |
|
283 | 283 | |
|
284 | 284 | context("#issue_add") do |
|
285 | 285 | setup do |
|
286 | 286 | ActionMailer::Base.deliveries.clear |
|
287 | 287 | Setting.bcc_recipients = '1' |
|
288 | 288 | @issue = Issue.find(1) |
|
289 | 289 | end |
|
290 | 290 | |
|
291 | 291 | should "notify project members" do |
|
292 | 292 | assert Mailer.deliver_issue_add(@issue) |
|
293 | 293 | assert last_email.bcc.include?('dlopper@somenet.foo') |
|
294 | 294 | end |
|
295 | 295 | |
|
296 | 296 | should "not notify project members that are not allow to view the issue" do |
|
297 | 297 | Role.find(2).remove_permission!(:view_issues) |
|
298 | 298 | assert Mailer.deliver_issue_add(@issue) |
|
299 | 299 | assert !last_email.bcc.include?('dlopper@somenet.foo') |
|
300 | 300 | end |
|
301 | 301 | |
|
302 | 302 | should "notify issue watchers" do |
|
303 | 303 | user = User.find(9) |
|
304 | 304 | # minimal email notification options |
|
305 | 305 | user.pref[:no_self_notified] = '1' |
|
306 | 306 | user.pref.save |
|
307 | 307 | user.mail_notification = false |
|
308 | 308 | user.save |
|
309 | 309 | |
|
310 | 310 | Watcher.create!(:watchable => @issue, :user => user) |
|
311 | 311 | assert Mailer.deliver_issue_add(@issue) |
|
312 | 312 | assert last_email.bcc.include?(user.mail) |
|
313 | 313 | end |
|
314 | 314 | |
|
315 | 315 | should "not notify watchers not allowed to view the issue" do |
|
316 | 316 | user = User.find(9) |
|
317 | 317 | Watcher.create!(:watchable => @issue, :user => user) |
|
318 | 318 | Role.non_member.remove_permission!(:view_issues) |
|
319 | 319 | assert Mailer.deliver_issue_add(@issue) |
|
320 | 320 | assert !last_email.bcc.include?(user.mail) |
|
321 | 321 | end |
|
322 | 322 | end |
|
323 | 323 | |
|
324 | 324 | # test mailer methods for each language |
|
325 | 325 | def test_issue_add |
|
326 | 326 | issue = Issue.find(1) |
|
327 | 327 | valid_languages.each do |lang| |
|
328 | 328 | Setting.default_language = lang.to_s |
|
329 | 329 | assert Mailer.deliver_issue_add(issue) |
|
330 | 330 | end |
|
331 | 331 | end |
|
332 | 332 | |
|
333 | 333 | def test_issue_edit |
|
334 | 334 | journal = Journal.find(1) |
|
335 | 335 | valid_languages.each do |lang| |
|
336 | 336 | Setting.default_language = lang.to_s |
|
337 | 337 | assert Mailer.deliver_issue_edit(journal) |
|
338 | 338 | end |
|
339 | 339 | end |
|
340 | 340 | |
|
341 | 341 | def test_document_added |
|
342 | 342 | document = Document.find(1) |
|
343 | 343 | valid_languages.each do |lang| |
|
344 | 344 | Setting.default_language = lang.to_s |
|
345 | 345 | assert Mailer.deliver_document_added(document) |
|
346 | 346 | end |
|
347 | 347 | end |
|
348 | 348 | |
|
349 | 349 | def test_attachments_added |
|
350 | 350 | attachements = [ Attachment.find_by_container_type('Document') ] |
|
351 | 351 | valid_languages.each do |lang| |
|
352 | 352 | Setting.default_language = lang.to_s |
|
353 | 353 | assert Mailer.deliver_attachments_added(attachements) |
|
354 | 354 | end |
|
355 | 355 | end |
|
356 | 356 | |
|
357 | 357 | def test_version_file_added |
|
358 | 358 | attachements = [ Attachment.find_by_container_type('Version') ] |
|
359 | 359 | assert Mailer.deliver_attachments_added(attachements) |
|
360 | 360 | assert_not_nil last_email.bcc |
|
361 | 361 | assert last_email.bcc.any? |
|
362 | 362 | assert_select_email do |
|
363 | 363 | assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" |
|
364 | 364 | end |
|
365 | 365 | end |
|
366 | 366 | |
|
367 | 367 | def test_project_file_added |
|
368 | 368 | attachements = [ Attachment.find_by_container_type('Project') ] |
|
369 | 369 | assert Mailer.deliver_attachments_added(attachements) |
|
370 | 370 | assert_not_nil last_email.bcc |
|
371 | 371 | assert last_email.bcc.any? |
|
372 | 372 | assert_select_email do |
|
373 | 373 | assert_select "a[href=?]", "http://mydomain.foo/projects/ecookbook/files" |
|
374 | 374 | end |
|
375 | 375 | end |
|
376 | 376 | |
|
377 | 377 | def test_news_added |
|
378 | 378 | news = News.find(:first) |
|
379 | 379 | valid_languages.each do |lang| |
|
380 | 380 | Setting.default_language = lang.to_s |
|
381 | 381 | assert Mailer.deliver_news_added(news) |
|
382 | 382 | end |
|
383 | 383 | end |
|
384 | 384 | |
|
385 | 385 | def test_news_comment_added |
|
386 | 386 | comment = Comment.find(2) |
|
387 | 387 | valid_languages.each do |lang| |
|
388 | 388 | Setting.default_language = lang.to_s |
|
389 | 389 | assert Mailer.deliver_news_comment_added(comment) |
|
390 | 390 | end |
|
391 | 391 | end |
|
392 | 392 | |
|
393 | 393 | def test_message_posted |
|
394 | 394 | message = Message.find(:first) |
|
395 | 395 | recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} |
|
396 | 396 | recipients = recipients.compact.uniq |
|
397 | 397 | valid_languages.each do |lang| |
|
398 | 398 | Setting.default_language = lang.to_s |
|
399 | 399 | assert Mailer.deliver_message_posted(message) |
|
400 | 400 | end |
|
401 | 401 | end |
|
402 | 402 | |
|
403 | 403 | def test_wiki_content_added |
|
404 | 404 | content = WikiContent.find(1) |
|
405 | 405 | valid_languages.each do |lang| |
|
406 | 406 | Setting.default_language = lang.to_s |
|
407 | 407 | assert_difference 'ActionMailer::Base.deliveries.size' do |
|
408 | 408 | assert Mailer.deliver_wiki_content_added(content) |
|
409 | 409 | end |
|
410 | 410 | end |
|
411 | 411 | end |
|
412 | 412 | |
|
413 | 413 | def test_wiki_content_updated |
|
414 | 414 | content = WikiContent.find(1) |
|
415 | 415 | valid_languages.each do |lang| |
|
416 | 416 | Setting.default_language = lang.to_s |
|
417 | 417 | assert_difference 'ActionMailer::Base.deliveries.size' do |
|
418 | 418 | assert Mailer.deliver_wiki_content_updated(content) |
|
419 | 419 | end |
|
420 | 420 | end |
|
421 | 421 | end |
|
422 | 422 | |
|
423 | 423 | def test_account_information |
|
424 | 424 | user = User.find(2) |
|
425 | 425 | valid_languages.each do |lang| |
|
426 | 426 | user.update_attribute :language, lang.to_s |
|
427 | 427 | user.reload |
|
428 | 428 | assert Mailer.deliver_account_information(user, 'pAsswORd') |
|
429 | 429 | end |
|
430 | 430 | end |
|
431 | 431 | |
|
432 | 432 | def test_lost_password |
|
433 | 433 | token = Token.find(2) |
|
434 | 434 | valid_languages.each do |lang| |
|
435 | 435 | token.user.update_attribute :language, lang.to_s |
|
436 | 436 | token.reload |
|
437 | 437 | assert Mailer.deliver_lost_password(token) |
|
438 | 438 | end |
|
439 | 439 | end |
|
440 | 440 | |
|
441 | 441 | def test_register |
|
442 | 442 | token = Token.find(1) |
|
443 | 443 | Setting.host_name = 'redmine.foo' |
|
444 | 444 | Setting.protocol = 'https' |
|
445 | 445 | |
|
446 | 446 | valid_languages.each do |lang| |
|
447 | 447 | token.user.update_attribute :language, lang.to_s |
|
448 | 448 | token.reload |
|
449 | 449 | ActionMailer::Base.deliveries.clear |
|
450 | 450 | assert Mailer.deliver_register(token) |
|
451 | 451 | mail = last_email |
|
452 | 452 | assert_select_email do |
|
453 | 453 | assert_select "a[href=?]", |
|
454 | 454 | "https://redmine.foo/account/activate?token=#{token.value}", |
|
455 | 455 | :text => "https://redmine.foo/account/activate?token=#{token.value}" |
|
456 | 456 | end |
|
457 | 457 | end |
|
458 | 458 | end |
|
459 | 459 | |
|
460 | 460 | def test_test |
|
461 | 461 | user = User.find(1) |
|
462 | 462 | valid_languages.each do |lang| |
|
463 | 463 | user.update_attribute :language, lang.to_s |
|
464 | assert Mailer.deliver_test(user) | |
|
464 | assert Mailer.deliver_test_email(user) | |
|
465 | 465 | end |
|
466 | 466 | end |
|
467 | 467 | |
|
468 | 468 | def test_reminders |
|
469 | 469 | Mailer.reminders(:days => 42) |
|
470 | 470 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
471 | 471 | mail = last_email |
|
472 | 472 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
473 | 473 | assert mail.body.include?('Bug #3: Error 281 when updating a recipe') |
|
474 | 474 | assert_equal '1 issue(s) due in the next 42 days', mail.subject |
|
475 | 475 | end |
|
476 | 476 | |
|
477 | 477 | def test_reminders_should_not_include_closed_issues |
|
478 | 478 | with_settings :default_language => 'en' do |
|
479 | 479 | Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5, |
|
480 | 480 | :subject => 'Closed issue', :assigned_to_id => 3, |
|
481 | 481 | :due_date => 5.days.from_now, |
|
482 | 482 | :author_id => 2) |
|
483 | 483 | ActionMailer::Base.deliveries.clear |
|
484 | 484 | |
|
485 | 485 | Mailer.reminders(:days => 42) |
|
486 | 486 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
487 | 487 | mail = last_email |
|
488 | 488 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
489 | 489 | assert !mail.body.include?('Closed issue') |
|
490 | 490 | end |
|
491 | 491 | end |
|
492 | 492 | |
|
493 | 493 | def test_reminders_for_users |
|
494 | 494 | Mailer.reminders(:days => 42, :users => ['5']) |
|
495 | 495 | assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper |
|
496 | 496 | Mailer.reminders(:days => 42, :users => ['3']) |
|
497 | 497 | assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper |
|
498 | 498 | mail = last_email |
|
499 | 499 | assert mail.bcc.include?('dlopper@somenet.foo') |
|
500 | 500 | assert mail.body.include?('Bug #3: Error 281 when updating a recipe') |
|
501 | 501 | end |
|
502 | 502 | |
|
503 | 503 | def last_email |
|
504 | 504 | mail = ActionMailer::Base.deliveries.last |
|
505 | 505 | assert_not_nil mail |
|
506 | 506 | |
|
507 | 507 | end |
|
508 | 508 | |
|
509 | 509 | def test_mailer_should_not_change_locale |
|
510 | 510 | Setting.default_language = 'en' |
|
511 | 511 | # Set current language to italian |
|
512 | 512 | set_language_if_valid 'it' |
|
513 | 513 | # Send an email to a french user |
|
514 | 514 | user = User.find(1) |
|
515 | 515 | user.language = 'fr' |
|
516 | 516 | Mailer.deliver_account_activated(user) |
|
517 | 517 | mail = last_email |
|
518 | 518 | assert mail.body.include?('Votre compte') |
|
519 | 519 | |
|
520 | 520 | assert_equal :it, current_language |
|
521 | 521 | end |
|
522 | 522 | |
|
523 | 523 | def test_with_deliveries_off |
|
524 | 524 | Mailer.with_deliveries false do |
|
525 | Mailer.deliver_test(User.find(1)) | |
|
525 | Mailer.deliver_test_email(User.find(1)) | |
|
526 | 526 | end |
|
527 | 527 | assert ActionMailer::Base.deliveries.empty? |
|
528 | 528 | # should restore perform_deliveries |
|
529 | 529 | assert ActionMailer::Base.perform_deliveries |
|
530 | 530 | end |
|
531 | 531 | |
|
532 | 532 | def test_tmail_to_header_field_should_not_include_blank_lines |
|
533 | 533 | mail = TMail::Mail.new |
|
534 | 534 | mail.to = ["a.user@example.com", "v.user2@example.com", "e.smith@example.com", "info@example.com", "v.pupkin@example.com", |
|
535 | 535 | "b.user@example.com", "w.user2@example.com", "f.smith@example.com", "info2@example.com", "w.pupkin@example.com"] |
|
536 | 536 | |
|
537 | 537 | assert !mail.encoded.strip.split("\r\n").detect(&:blank?), "#{mail.encoded} malformed" |
|
538 | 538 | end |
|
539 | 539 | |
|
540 | 540 | def test_layout_should_include_the_emails_header |
|
541 | 541 | with_settings :emails_header => "*Header content*" do |
|
542 | assert Mailer.deliver_test(User.find(1)) | |
|
542 | assert Mailer.deliver_test_email(User.find(1)) | |
|
543 | 543 | assert_select_email do |
|
544 | 544 | assert_select ".header" do |
|
545 | 545 | assert_select "strong", :text => "Header content" |
|
546 | 546 | end |
|
547 | 547 | end |
|
548 | 548 | end |
|
549 | 549 | end |
|
550 | 550 | end |
General Comments 0
You need to be logged in to leave comments.
Login now