##// 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 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 ApplicationHelper
20 20 helper IssuesHelper
21 21 helper CustomFieldsHelper
22 22
23 23 include ActionController::UrlWriter
24 24
25 25 def issue_add(issue)
26 26 recipients issue.recipients
27 27 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
28 28 body :issue => issue,
29 29 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
30 30 end
31 31
32 32 def issue_edit(journal)
33 33 issue = journal.journalized
34 issue.reload
34 35 recipients issue.recipients
35 36 # Watchers in cc
36 37 cc(issue.watcher_recipients - @recipients)
37 38 subject "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
38 39 body :issue => issue,
39 40 :journal => journal,
40 41 :issue_url => url_for(:controller => 'issues', :action => 'show', :id => issue)
41 42 end
42 43
43 44 def document_added(document)
44 45 recipients document.project.recipients
45 46 subject "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
46 47 body :document => document,
47 48 :document_url => url_for(:controller => 'documents', :action => 'show', :id => document)
48 49 end
49 50
50 51 def attachments_added(attachments)
51 52 container = attachments.first.container
52 53 added_to = ''
53 54 added_to_url = ''
54 55 case container.class.name
55 56 when 'Version'
56 57 added_to_url = url_for(:controller => 'projects', :action => 'list_files', :id => container.project_id)
57 58 added_to = "#{l(:label_version)}: #{container.name}"
58 59 when 'Document'
59 60 added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id)
60 61 added_to = "#{l(:label_document)}: #{container.title}"
61 62 end
62 63 recipients container.project.recipients
63 64 subject "[#{container.project.name}] #{l(:label_attachment_new)}"
64 65 body :attachments => attachments,
65 66 :added_to => added_to,
66 67 :added_to_url => added_to_url
67 68 end
68 69
69 70 def news_added(news)
70 71 recipients news.project.recipients
71 72 subject "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
72 73 body :news => news,
73 74 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
74 75 end
75 76
76 77 def message_posted(message, recipients)
77 78 recipients(recipients)
78 79 subject "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
79 80 body :message => message,
80 81 :message_url => url_for(:controller => 'messages', :action => 'show', :board_id => message.board_id, :id => message.root)
81 82 end
82 83
83 84 def account_information(user, password)
84 85 set_language_if_valid user.language
85 86 recipients user.mail
86 87 subject l(:mail_subject_register)
87 88 body :user => user,
88 89 :password => password,
89 90 :login_url => url_for(:controller => 'account', :action => 'login')
90 91 end
91 92
92 93 def account_activation_request(user)
93 94 # Send the email to all active administrators
94 95 recipients User.find_active(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
95 96 subject l(:mail_subject_account_activation_request)
96 97 body :user => user,
97 98 :url => url_for(:controller => 'users', :action => 'index', :status => User::STATUS_REGISTERED, :sort_key => 'created_on', :sort_order => 'desc')
98 99 end
99 100
100 101 def lost_password(token)
101 102 set_language_if_valid(token.user.language)
102 103 recipients token.user.mail
103 104 subject l(:mail_subject_lost_password)
104 105 body :token => token,
105 106 :url => url_for(:controller => 'account', :action => 'lost_password', :token => token.value)
106 107 end
107 108
108 109 def register(token)
109 110 set_language_if_valid(token.user.language)
110 111 recipients token.user.mail
111 112 subject l(:mail_subject_register)
112 113 body :token => token,
113 114 :url => url_for(:controller => 'account', :action => 'activate', :token => token.value)
114 115 end
115 116
116 117 def test(user)
117 118 set_language_if_valid(user.language)
118 119 recipients user.mail
119 120 subject 'Redmine test'
120 121 body :url => url_for(:controller => 'welcome')
121 122 end
122 123
123 124 private
124 125 def initialize_defaults(method_name)
125 126 super
126 127 set_language_if_valid Setting.default_language
127 128 from Setting.mail_from
128 129 default_url_options[:host] = Setting.host_name
129 130 default_url_options[:protocol] = Setting.protocol
130 131 end
131 132
132 133 # Overrides the create_mail method
133 134 def create_mail
134 135 # Removes the current user from the recipients and cc
135 136 # if he doesn't want to receive notifications about what he does
136 137 if User.current.pref[:no_self_notified]
137 138 recipients.delete(User.current.mail) if recipients
138 139 cc.delete(User.current.mail) if cc
139 140 end
140 141 # Blind carbon copy recipients
141 142 if Setting.bcc_recipients?
142 143 bcc([recipients, cc].flatten.compact.uniq)
143 144 recipients []
144 145 cc []
145 146 end
146 147 super
147 148 end
148 149
149 150 # Renders a message with the corresponding layout
150 151 def render_message(method_name, body)
151 152 layout = method_name.match(%r{text\.html\.(rhtml|rxml)}) ? 'layout.text.html.rhtml' : 'layout.text.plain.rhtml'
152 153 body[:content_for_layout] = render(:file => method_name, :body => body)
153 154 ActionView::Base.new(template_root, body, self).render(:file => "mailer/#{layout}")
154 155 end
155 156
156 157 # Makes partial rendering work with Rails 1.2 (retro-compatibility)
157 158 def self.controller_path
158 159 ''
159 160 end unless respond_to?('controller_path')
160 161 end
General Comments 0
You need to be logged in to leave comments. Login now