##// END OF EJS Templates
Fixed: when changing the status of an issue, the email subject contains the previous status of the issue....
Jean-Philippe Lang -
r1064:1535ac122053
parent child
Show More
@@ -1,160 +1,161
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class Mailer < ActionMailer::Base
18 class Mailer < ActionMailer::Base
19 helper ApplicationHelper
19 helper ApplicationHelper
20 helper IssuesHelper
20 helper IssuesHelper
21 helper CustomFieldsHelper
21 helper CustomFieldsHelper
22
22
23 include ActionController::UrlWriter
23 include ActionController::UrlWriter
24
24
25 def issue_add(issue)
25 def issue_add(issue)
26 recipients issue.recipients
26 recipients issue.recipients
27 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
27 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
28 body :issue => issue,
28 body :issue => issue,
29 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
29 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
30 end
30 end
31
31
32 def issue_edit(journal)
32 def issue_edit(journal)
33 issue = journal.journalized
33 issue = journal.journalized
34 issue.reload
34 recipients issue.recipients
35 recipients issue.recipients
35 # Watchers in cc
36 # Watchers in cc
36 cc(issue.watcher_recipients - @recipients)
37 cc(issue.watcher_recipients - @recipients)
37 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
38 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
38 body :issue => issue,
39 body :issue => issue,
39 :journal => journal,
40 :journal => journal,
40 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
41 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
41 end
42 end
42
43
43 def document_added(document)
44 def document_added(document)
44 recipients document.project.recipients
45 recipients document.project.recipients
45 subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
46 subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
46 body :document => document,
47 body :document => document,
47 :document_url => url_for(:controller => 'documents', :action => 'show', :id => document)
48 :document_url => url_for(:controller => 'documents', :action => 'show', :id => document)
48 end
49 end
49
50
50 def attachments_added(attachments)
51 def attachments_added(attachments)
51 container = attachments.first.container
52 container = attachments.first.container
52 added_to = ''
53 added_to = ''
53 added_to_url = ''
54 added_to_url = ''
54 case container.class.name
55 case container.class.name
55 when 'Version'
56 when 'Version'
56 added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id)
57 added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id)
57 added_to = "#{l(:label_version)}: #{container.name}"
58 added_to = "#{l(:label_version)}: #{container.name}"
58 when 'Document'
59 when 'Document'
59 added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
60 added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
60 added_to = "#{l(:label_document)}: #{container.title}"
61 added_to = "#{l(:label_document)}: #{container.title}"
61 end
62 end
62 recipients container.project.recipients
63 recipients container.project.recipients
63 subject "[#{container.project.name}] #{l(:label_attachment_new)}"
64 subject "[#{container.project.name}] #{l(:label_attachment_new)}"
64 body :attachments => attachments,
65 body :attachments => attachments,
65 :added_to => added_to,
66 :added_to => added_to,
66 :added_to_url => added_to_url
67 :added_to_url => added_to_url
67 end
68 end
68
69
69 def news_added(news)
70 def news_added(news)
70 recipients news.project.recipients
71 recipients news.project.recipients
71 subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
72 subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
72 body :news => news,
73 body :news => news,
73 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
74 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
74 end
75 end
75
76
76 def message_posted(message, recipients)
77 def message_posted(message, recipients)
77 recipients(recipients)
78 recipients(recipients)
78 subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
79 subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
79 body :message => message,
80 body :message => message,
80 :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root)
81 :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root)
81 end
82 end
82
83
83 def account_information(user, password)
84 def account_information(user, password)
84 set_language_if_valid user.language
85 set_language_if_valid user.language
85 recipients user.mail
86 recipients user.mail
86 subject l(:mail_subject_register)
87 subject l(:mail_subject_register)
87 body :user => user,
88 body :user => user,
88 :password => password,
89 :password => password,
89 :login_url => url_for(:controller => 'account', :action => 'login')
90 :login_url => url_for(:controller => 'account', :action => 'login')
90 end
91 end
91
92
92 def account_activation_request(user)
93 def account_activation_request(user)
93 # Send the email to all active administrators
94 # Send the email to all active administrators
94 recipients User.find_active(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
95 recipients User.find_active(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
95 subject l(:mail_subject_account_activation_request)
96 subject l(:mail_subject_account_activation_request)
96 body :user => user,
97 body :user => user,
97 :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
98 :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
98 end
99 end
99
100
100 def lost_password(token)
101 def lost_password(token)
101 set_language_if_valid(token.user.language)
102 set_language_if_valid(token.user.language)
102 recipients token.user.mail
103 recipients token.user.mail
103 subject l(:mail_subject_lost_password)
104 subject l(:mail_subject_lost_password)
104 body :token => token,
105 body :token => token,
105 :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
106 :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
106 end
107 end
107
108
108 def register(token)
109 def register(token)
109 set_language_if_valid(token.user.language)
110 set_language_if_valid(token.user.language)
110 recipients token.user.mail
111 recipients token.user.mail
111 subject l(:mail_subject_register)
112 subject l(:mail_subject_register)
112 body :token => token,
113 body :token => token,
113 :url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
114 :url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
114 end
115 end
115
116
116 def test(user)
117 def test(user)
117 set_language_if_valid(user.language)
118 set_language_if_valid(user.language)
118 recipients user.mail
119 recipients user.mail
119 subject 'Redmine test'
120 subject 'Redmine test'
120 body :url => url_for(:controller => 'welcome')
121 body :url => url_for(:controller => 'welcome')
121 end
122 end
122
123
123 private
124 private
124 def initialize_defaults(method_name)
125 def initialize_defaults(method_name)
125 super
126 super
126 set_language_if_valid Setting.default_language
127 set_language_if_valid Setting.default_language
127 from Setting.mail_from
128 from Setting.mail_from
128 default_url_options[:host] = Setting.host_name
129 default_url_options[:host] = Setting.host_name
129 default_url_options[:protocol] = Setting.protocol
130 default_url_options[:protocol] = Setting.protocol
130 end
131 end
131
132
132 # Overrides the create_mail method
133 # Overrides the create_mail method
133 def create_mail
134 def create_mail
134 # Removes the current user from the recipients and cc
135 # Removes the current user from the recipients and cc
135 # if he doesn't want to receive notifications about what he does
136 # if he doesn't want to receive notifications about what he does
136 if User.current.pref[:no_self_notified]
137 if User.current.pref[:no_self_notified]
137 recipients.delete(User.current.mail) if recipients
138 recipients.delete(User.current.mail) if recipients
138 cc.delete(User.current.mail) if cc
139 cc.delete(User.current.mail) if cc
139 end
140 end
140 # Blind carbon copy recipients
141 # Blind carbon copy recipients
141 if Setting.bcc_recipients?
142 if Setting.bcc_recipients?
142 bcc([recipients, cc].flatten.compact.uniq)
143 bcc([recipients, cc].flatten.compact.uniq)
143 recipients []
144 recipients []
144 cc []
145 cc []
145 end
146 end
146 super
147 super
147 end
148 end
148
149
149 # Renders a message with the corresponding layout
150 # Renders a message with the corresponding layout
150 def render_message(method_name, body)
151 def render_message(method_name, body)
151 layout = method_name.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml'
152 layout = method_name.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml'
152 body[:content_for_layout] = render(:file => method_name, :body => body)
153 body[:content_for_layout] = render(:file => method_name, :body => body)
153 ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}")
154 ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}")
154 end
155 end
155
156
156 # Makes partial rendering work with Rails 1.2 (retro-compatibility)
157 # Makes partial rendering work with Rails 1.2 (retro-compatibility)
157 def self.controller_path
158 def self.controller_path
158 ''
159 ''
159 end unless respond_to?('controller_path')
160 end unless respond_to?('controller_path')
160 end
161 end
General Comments 0
You need to be logged in to leave comments. Login now