@@ -1,111 +1,112 | |||
|
1 | 1 | source 'https://rubygems.org' |
|
2 | 2 | |
|
3 | 3 | if Gem::Version.new(Bundler::VERSION) < Gem::Version.new('1.5.0') |
|
4 | 4 | abort "Redmine requires Bundler 1.5.0 or higher (you're using #{Bundler::VERSION}).\nPlease update with 'gem update bundler'." |
|
5 | 5 | end |
|
6 | 6 | |
|
7 | 7 | gem "rails", "4.2.4" |
|
8 | 8 | gem "jquery-rails", "~> 3.1.3" |
|
9 | 9 | gem "coderay", "~> 1.1.0" |
|
10 | 10 | gem "builder", ">= 3.0.4" |
|
11 | 11 | gem "request_store", "1.0.5" |
|
12 | 12 | gem "mime-types" |
|
13 | 13 | gem "protected_attributes" |
|
14 | 14 | gem "actionpack-action_caching" |
|
15 | 15 | gem "actionpack-xml_parser" |
|
16 | 16 | gem "loofah", "~> 2.0" |
|
17 | gem "roadie-rails" | |
|
17 | 18 | |
|
18 | 19 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem |
|
19 | 20 | gem 'tzinfo-data', platforms: [:mingw, :x64_mingw, :mswin, :jruby] |
|
20 | 21 | gem "rbpdf", "~> 1.18.6" |
|
21 | 22 | |
|
22 | 23 | # Optional gem for LDAP authentication |
|
23 | 24 | group :ldap do |
|
24 | 25 | gem "net-ldap", "~> 0.3.1" |
|
25 | 26 | end |
|
26 | 27 | |
|
27 | 28 | # Optional gem for OpenID authentication |
|
28 | 29 | group :openid do |
|
29 | 30 | gem "ruby-openid", "~> 2.3.0", :require => "openid" |
|
30 | 31 | gem "rack-openid" |
|
31 | 32 | end |
|
32 | 33 | |
|
33 | 34 | platforms :mri, :mingw, :x64_mingw do |
|
34 | 35 | # Optional gem for exporting the gantt to a PNG file, not supported with jruby |
|
35 | 36 | group :rmagick do |
|
36 | 37 | gem "rmagick", ">= 2.14.0" |
|
37 | 38 | end |
|
38 | 39 | |
|
39 | 40 | # Optional Markdown support, not for JRuby |
|
40 | 41 | group :markdown do |
|
41 | 42 | gem "redcarpet", "~> 3.3.2" |
|
42 | 43 | end |
|
43 | 44 | end |
|
44 | 45 | |
|
45 | 46 | platforms :jruby do |
|
46 | 47 | # jruby-openssl is bundled with JRuby 1.7.0 |
|
47 | 48 | gem "jruby-openssl" if Object.const_defined?(:JRUBY_VERSION) && JRUBY_VERSION < '1.7.0' |
|
48 | 49 | gem "activerecord-jdbc-adapter", "~> 1.3.2" |
|
49 | 50 | end |
|
50 | 51 | |
|
51 | 52 | # Include database gems for the adapters found in the database |
|
52 | 53 | # configuration file |
|
53 | 54 | require 'erb' |
|
54 | 55 | require 'yaml' |
|
55 | 56 | database_file = File.join(File.dirname(__FILE__), "config/database.yml") |
|
56 | 57 | if File.exist?(database_file) |
|
57 | 58 | database_config = YAML::load(ERB.new(IO.read(database_file)).result) |
|
58 | 59 | adapters = database_config.values.map {|c| c['adapter']}.compact.uniq |
|
59 | 60 | if adapters.any? |
|
60 | 61 | adapters.each do |adapter| |
|
61 | 62 | case adapter |
|
62 | 63 | when 'mysql2' |
|
63 | 64 | gem "mysql2", "~> 0.3.11", :platforms => [:mri, :mingw, :x64_mingw] |
|
64 | 65 | gem "activerecord-jdbcmysql-adapter", :platforms => :jruby |
|
65 | 66 | when 'mysql' |
|
66 | 67 | gem "activerecord-jdbcmysql-adapter", :platforms => :jruby |
|
67 | 68 | when /postgresql/ |
|
68 | 69 | gem "pg", "~> 0.18.1", :platforms => [:mri, :mingw, :x64_mingw] |
|
69 | 70 | gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby |
|
70 | 71 | when /sqlite3/ |
|
71 | 72 | gem "sqlite3", :platforms => [:mri, :mingw, :x64_mingw] |
|
72 | 73 | gem "jdbc-sqlite3", ">= 3.8.10.1", :platforms => :jruby |
|
73 | 74 | gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby |
|
74 | 75 | when /sqlserver/ |
|
75 | 76 | gem "tiny_tds", "~> 0.6.2", :platforms => [:mri, :mingw, :x64_mingw] |
|
76 | 77 | gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw, :x64_mingw] |
|
77 | 78 | else |
|
78 | 79 | warn("Unknown database adapter `#{adapter}` found in config/database.yml, use Gemfile.local to load your own database gems") |
|
79 | 80 | end |
|
80 | 81 | end |
|
81 | 82 | else |
|
82 | 83 | warn("No adapter found in config/database.yml, please configure it first") |
|
83 | 84 | end |
|
84 | 85 | else |
|
85 | 86 | warn("Please configure your config/database.yml first") |
|
86 | 87 | end |
|
87 | 88 | |
|
88 | 89 | group :development do |
|
89 | 90 | gem "rdoc", ">= 2.4.2" |
|
90 | 91 | gem "yard" |
|
91 | 92 | end |
|
92 | 93 | |
|
93 | 94 | group :test do |
|
94 | 95 | gem "minitest" |
|
95 | 96 | gem "rails-dom-testing" |
|
96 | 97 | gem "mocha" |
|
97 | 98 | gem "simplecov", "~> 0.9.1", :require => false |
|
98 | 99 | # For running UI tests |
|
99 | 100 | gem "capybara" |
|
100 | 101 | gem "selenium-webdriver" |
|
101 | 102 | end |
|
102 | 103 | |
|
103 | 104 | local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local") |
|
104 | 105 | if File.exists?(local_gemfile) |
|
105 | 106 | eval_gemfile local_gemfile |
|
106 | 107 | end |
|
107 | 108 | |
|
108 | 109 | # Load plugins' Gemfiles |
|
109 | 110 | Dir.glob File.expand_path("../plugins/*/{Gemfile,PluginGemfile}", __FILE__) do |file| |
|
110 | 111 | eval_gemfile file |
|
111 | 112 | end |
@@ -1,538 +1,541 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2015 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 | require 'roadie' | |
|
19 | ||
|
18 | 20 | class Mailer < ActionMailer::Base |
|
19 | 21 | layout 'mailer' |
|
20 | 22 | helper :application |
|
21 | 23 | helper :issues |
|
22 | 24 | helper :custom_fields |
|
23 | 25 | |
|
24 | 26 | include Redmine::I18n |
|
27 | include Roadie::Rails::Automatic | |
|
25 | 28 | |
|
26 | 29 | def self.default_url_options |
|
27 | 30 | options = {:protocol => Setting.protocol} |
|
28 | 31 | if Setting.host_name.to_s =~ /\A(https?\:\/\/)?(.+?)(\:(\d+))?(\/.+)?\z/i |
|
29 | 32 | host, port, prefix = $2, $4, $5 |
|
30 | 33 | options.merge!({ |
|
31 | 34 | :host => host, :port => port, :script_name => prefix |
|
32 | 35 | }) |
|
33 | 36 | else |
|
34 | 37 | options[:host] = Setting.host_name |
|
35 | 38 | end |
|
36 | 39 | options |
|
37 | 40 | end |
|
38 | 41 | |
|
39 | 42 | # Builds a mail for notifying to_users and cc_users about a new issue |
|
40 | 43 | def issue_add(issue, to_users, cc_users) |
|
41 | 44 | redmine_headers 'Project' => issue.project.identifier, |
|
42 | 45 | 'Issue-Id' => issue.id, |
|
43 | 46 | 'Issue-Author' => issue.author.login |
|
44 | 47 | redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to |
|
45 | 48 | message_id issue |
|
46 | 49 | references issue |
|
47 | 50 | @author = issue.author |
|
48 | 51 | @issue = issue |
|
49 | 52 | @users = to_users + cc_users |
|
50 | 53 | @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue) |
|
51 | 54 | mail :to => to_users, |
|
52 | 55 | :cc => cc_users, |
|
53 | 56 | :subject => "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}" |
|
54 | 57 | end |
|
55 | 58 | |
|
56 | 59 | # Notifies users about a new issue |
|
57 | 60 | def self.deliver_issue_add(issue) |
|
58 | 61 | to = issue.notified_users |
|
59 | 62 | cc = issue.notified_watchers - to |
|
60 | 63 | issue.each_notification(to + cc) do |users| |
|
61 | 64 | Mailer.issue_add(issue, to & users, cc & users).deliver |
|
62 | 65 | end |
|
63 | 66 | end |
|
64 | 67 | |
|
65 | 68 | # Builds a mail for notifying to_users and cc_users about an issue update |
|
66 | 69 | def issue_edit(journal, to_users, cc_users) |
|
67 | 70 | issue = journal.journalized |
|
68 | 71 | redmine_headers 'Project' => issue.project.identifier, |
|
69 | 72 | 'Issue-Id' => issue.id, |
|
70 | 73 | 'Issue-Author' => issue.author.login |
|
71 | 74 | redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to |
|
72 | 75 | message_id journal |
|
73 | 76 | references issue |
|
74 | 77 | @author = journal.user |
|
75 | 78 | s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] " |
|
76 | 79 | s << "(#{issue.status.name}) " if journal.new_value_for('status_id') |
|
77 | 80 | s << issue.subject |
|
78 | 81 | @issue = issue |
|
79 | 82 | @users = to_users + cc_users |
|
80 | 83 | @journal = journal |
|
81 | 84 | @journal_details = journal.visible_details(@users.first) |
|
82 | 85 | @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue, :anchor => "change-#{journal.id}") |
|
83 | 86 | mail :to => to_users, |
|
84 | 87 | :cc => cc_users, |
|
85 | 88 | :subject => s |
|
86 | 89 | end |
|
87 | 90 | |
|
88 | 91 | # Notifies users about an issue update |
|
89 | 92 | def self.deliver_issue_edit(journal) |
|
90 | 93 | issue = journal.journalized.reload |
|
91 | 94 | to = journal.notified_users |
|
92 | 95 | cc = journal.notified_watchers - to |
|
93 | 96 | journal.each_notification(to + cc) do |users| |
|
94 | 97 | issue.each_notification(users) do |users2| |
|
95 | 98 | Mailer.issue_edit(journal, to & users2, cc & users2).deliver |
|
96 | 99 | end |
|
97 | 100 | end |
|
98 | 101 | end |
|
99 | 102 | |
|
100 | 103 | def reminder(user, issues, days) |
|
101 | 104 | set_language_if_valid user.language |
|
102 | 105 | @issues = issues |
|
103 | 106 | @days = days |
|
104 | 107 | @issues_url = url_for(:controller => 'issues', :action => 'index', |
|
105 | 108 | :set_filter => 1, :assigned_to_id => user.id, |
|
106 | 109 | :sort => 'due_date:asc') |
|
107 | 110 | mail :to => user, |
|
108 | 111 | :subject => l(:mail_subject_reminder, :count => issues.size, :days => days) |
|
109 | 112 | end |
|
110 | 113 | |
|
111 | 114 | # Builds a Mail::Message object used to email users belonging to the added document's project. |
|
112 | 115 | # |
|
113 | 116 | # Example: |
|
114 | 117 | # document_added(document) => Mail::Message object |
|
115 | 118 | # Mailer.document_added(document).deliver => sends an email to the document's project recipients |
|
116 | 119 | def document_added(document) |
|
117 | 120 | redmine_headers 'Project' => document.project.identifier |
|
118 | 121 | @author = User.current |
|
119 | 122 | @document = document |
|
120 | 123 | @document_url = url_for(:controller => 'documents', :action => 'show', :id => document) |
|
121 | 124 | mail :to => document.notified_users, |
|
122 | 125 | :subject => "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}" |
|
123 | 126 | end |
|
124 | 127 | |
|
125 | 128 | # Builds a Mail::Message object used to email recipients of a project when an attachements are added. |
|
126 | 129 | # |
|
127 | 130 | # Example: |
|
128 | 131 | # attachments_added(attachments) => Mail::Message object |
|
129 | 132 | # Mailer.attachments_added(attachments).deliver => sends an email to the project's recipients |
|
130 | 133 | def attachments_added(attachments) |
|
131 | 134 | container = attachments.first.container |
|
132 | 135 | added_to = '' |
|
133 | 136 | added_to_url = '' |
|
134 | 137 | @author = attachments.first.author |
|
135 | 138 | case container.class.name |
|
136 | 139 | when 'Project' |
|
137 | 140 | added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container) |
|
138 | 141 | added_to = "#{l(:label_project)}: #{container}" |
|
139 | 142 | recipients = container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)} |
|
140 | 143 | when 'Version' |
|
141 | 144 | added_to_url = url_for(:controller => 'files', :action => 'index', :project_id => container.project) |
|
142 | 145 | added_to = "#{l(:label_version)}: #{container.name}" |
|
143 | 146 | recipients = container.project.notified_users.select {|user| user.allowed_to?(:view_files, container.project)} |
|
144 | 147 | when 'Document' |
|
145 | 148 | added_to_url = url_for(:controller => 'documents', :action => 'show', :id => container.id) |
|
146 | 149 | added_to = "#{l(:label_document)}: #{container.title}" |
|
147 | 150 | recipients = container.notified_users |
|
148 | 151 | end |
|
149 | 152 | redmine_headers 'Project' => container.project.identifier |
|
150 | 153 | @attachments = attachments |
|
151 | 154 | @added_to = added_to |
|
152 | 155 | @added_to_url = added_to_url |
|
153 | 156 | mail :to => recipients, |
|
154 | 157 | :subject => "[#{container.project.name}] #{l(:label_attachment_new)}" |
|
155 | 158 | end |
|
156 | 159 | |
|
157 | 160 | # Builds a Mail::Message object used to email recipients of a news' project when a news item is added. |
|
158 | 161 | # |
|
159 | 162 | # Example: |
|
160 | 163 | # news_added(news) => Mail::Message object |
|
161 | 164 | # Mailer.news_added(news).deliver => sends an email to the news' project recipients |
|
162 | 165 | def news_added(news) |
|
163 | 166 | redmine_headers 'Project' => news.project.identifier |
|
164 | 167 | @author = news.author |
|
165 | 168 | message_id news |
|
166 | 169 | references news |
|
167 | 170 | @news = news |
|
168 | 171 | @news_url = url_for(:controller => 'news', :action => 'show', :id => news) |
|
169 | 172 | mail :to => news.notified_users, |
|
170 | 173 | :cc => news.notified_watchers_for_added_news, |
|
171 | 174 | :subject => "[#{news.project.name}] #{l(:label_news)}: #{news.title}" |
|
172 | 175 | end |
|
173 | 176 | |
|
174 | 177 | # Builds a Mail::Message object used to email recipients of a news' project when a news comment is added. |
|
175 | 178 | # |
|
176 | 179 | # Example: |
|
177 | 180 | # news_comment_added(comment) => Mail::Message object |
|
178 | 181 | # Mailer.news_comment_added(comment) => sends an email to the news' project recipients |
|
179 | 182 | def news_comment_added(comment) |
|
180 | 183 | news = comment.commented |
|
181 | 184 | redmine_headers 'Project' => news.project.identifier |
|
182 | 185 | @author = comment.author |
|
183 | 186 | message_id comment |
|
184 | 187 | references news |
|
185 | 188 | @news = news |
|
186 | 189 | @comment = comment |
|
187 | 190 | @news_url = url_for(:controller => 'news', :action => 'show', :id => news) |
|
188 | 191 | mail :to => news.notified_users, |
|
189 | 192 | :cc => news.notified_watchers, |
|
190 | 193 | :subject => "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}" |
|
191 | 194 | end |
|
192 | 195 | |
|
193 | 196 | # Builds a Mail::Message object used to email the recipients of the specified message that was posted. |
|
194 | 197 | # |
|
195 | 198 | # Example: |
|
196 | 199 | # message_posted(message) => Mail::Message object |
|
197 | 200 | # Mailer.message_posted(message).deliver => sends an email to the recipients |
|
198 | 201 | def message_posted(message) |
|
199 | 202 | redmine_headers 'Project' => message.project.identifier, |
|
200 | 203 | 'Topic-Id' => (message.parent_id || message.id) |
|
201 | 204 | @author = message.author |
|
202 | 205 | message_id message |
|
203 | 206 | references message.root |
|
204 | 207 | recipients = message.notified_users |
|
205 | 208 | cc = ((message.root.notified_watchers + message.board.notified_watchers).uniq - recipients) |
|
206 | 209 | @message = message |
|
207 | 210 | @message_url = url_for(message.event_url) |
|
208 | 211 | mail :to => recipients, |
|
209 | 212 | :cc => cc, |
|
210 | 213 | :subject => "[#{message.board.project.name} - #{message.board.name} - msg#{message.root.id}] #{message.subject}" |
|
211 | 214 | end |
|
212 | 215 | |
|
213 | 216 | # Builds a Mail::Message object used to email the recipients of a project of the specified wiki content was added. |
|
214 | 217 | # |
|
215 | 218 | # Example: |
|
216 | 219 | # wiki_content_added(wiki_content) => Mail::Message object |
|
217 | 220 | # Mailer.wiki_content_added(wiki_content).deliver => sends an email to the project's recipients |
|
218 | 221 | def wiki_content_added(wiki_content) |
|
219 | 222 | redmine_headers 'Project' => wiki_content.project.identifier, |
|
220 | 223 | 'Wiki-Page-Id' => wiki_content.page.id |
|
221 | 224 | @author = wiki_content.author |
|
222 | 225 | message_id wiki_content |
|
223 | 226 | recipients = wiki_content.notified_users |
|
224 | 227 | cc = wiki_content.page.wiki.notified_watchers - recipients |
|
225 | 228 | @wiki_content = wiki_content |
|
226 | 229 | @wiki_content_url = url_for(:controller => 'wiki', :action => 'show', |
|
227 | 230 | :project_id => wiki_content.project, |
|
228 | 231 | :id => wiki_content.page.title) |
|
229 | 232 | mail :to => recipients, |
|
230 | 233 | :cc => cc, |
|
231 | 234 | :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_added, :id => wiki_content.page.pretty_title)}" |
|
232 | 235 | end |
|
233 | 236 | |
|
234 | 237 | # Builds a Mail::Message object used to email the recipients of a project of the specified wiki content was updated. |
|
235 | 238 | # |
|
236 | 239 | # Example: |
|
237 | 240 | # wiki_content_updated(wiki_content) => Mail::Message object |
|
238 | 241 | # Mailer.wiki_content_updated(wiki_content).deliver => sends an email to the project's recipients |
|
239 | 242 | def wiki_content_updated(wiki_content) |
|
240 | 243 | redmine_headers 'Project' => wiki_content.project.identifier, |
|
241 | 244 | 'Wiki-Page-Id' => wiki_content.page.id |
|
242 | 245 | @author = wiki_content.author |
|
243 | 246 | message_id wiki_content |
|
244 | 247 | recipients = wiki_content.notified_users |
|
245 | 248 | cc = wiki_content.page.wiki.notified_watchers + wiki_content.page.notified_watchers - recipients |
|
246 | 249 | @wiki_content = wiki_content |
|
247 | 250 | @wiki_content_url = url_for(:controller => 'wiki', :action => 'show', |
|
248 | 251 | :project_id => wiki_content.project, |
|
249 | 252 | :id => wiki_content.page.title) |
|
250 | 253 | @wiki_diff_url = url_for(:controller => 'wiki', :action => 'diff', |
|
251 | 254 | :project_id => wiki_content.project, :id => wiki_content.page.title, |
|
252 | 255 | :version => wiki_content.version) |
|
253 | 256 | mail :to => recipients, |
|
254 | 257 | :cc => cc, |
|
255 | 258 | :subject => "[#{wiki_content.project.name}] #{l(:mail_subject_wiki_content_updated, :id => wiki_content.page.pretty_title)}" |
|
256 | 259 | end |
|
257 | 260 | |
|
258 | 261 | # Builds a Mail::Message object used to email the specified user their account information. |
|
259 | 262 | # |
|
260 | 263 | # Example: |
|
261 | 264 | # account_information(user, password) => Mail::Message object |
|
262 | 265 | # Mailer.account_information(user, password).deliver => sends account information to the user |
|
263 | 266 | def account_information(user, password) |
|
264 | 267 | set_language_if_valid user.language |
|
265 | 268 | @user = user |
|
266 | 269 | @password = password |
|
267 | 270 | @login_url = url_for(:controller => 'account', :action => 'login') |
|
268 | 271 | mail :to => user.mail, |
|
269 | 272 | :subject => l(:mail_subject_register, Setting.app_title) |
|
270 | 273 | end |
|
271 | 274 | |
|
272 | 275 | # Builds a Mail::Message object used to email all active administrators of an account activation request. |
|
273 | 276 | # |
|
274 | 277 | # Example: |
|
275 | 278 | # account_activation_request(user) => Mail::Message object |
|
276 | 279 | # Mailer.account_activation_request(user).deliver => sends an email to all active administrators |
|
277 | 280 | def account_activation_request(user) |
|
278 | 281 | # Send the email to all active administrators |
|
279 | 282 | recipients = User.active.where(:admin => true) |
|
280 | 283 | @user = user |
|
281 | 284 | @url = url_for(:controller => 'users', :action => 'index', |
|
282 | 285 | :status => User::STATUS_REGISTERED, |
|
283 | 286 | :sort_key => 'created_on', :sort_order => 'desc') |
|
284 | 287 | mail :to => recipients, |
|
285 | 288 | :subject => l(:mail_subject_account_activation_request, Setting.app_title) |
|
286 | 289 | end |
|
287 | 290 | |
|
288 | 291 | # Builds a Mail::Message object used to email the specified user that their account was activated by an administrator. |
|
289 | 292 | # |
|
290 | 293 | # Example: |
|
291 | 294 | # account_activated(user) => Mail::Message object |
|
292 | 295 | # Mailer.account_activated(user).deliver => sends an email to the registered user |
|
293 | 296 | def account_activated(user) |
|
294 | 297 | set_language_if_valid user.language |
|
295 | 298 | @user = user |
|
296 | 299 | @login_url = url_for(:controller => 'account', :action => 'login') |
|
297 | 300 | mail :to => user.mail, |
|
298 | 301 | :subject => l(:mail_subject_register, Setting.app_title) |
|
299 | 302 | end |
|
300 | 303 | |
|
301 | 304 | def lost_password(token, recipient=nil) |
|
302 | 305 | set_language_if_valid(token.user.language) |
|
303 | 306 | recipient ||= token.user.mail |
|
304 | 307 | @token = token |
|
305 | 308 | @url = url_for(:controller => 'account', :action => 'lost_password', :token => token.value) |
|
306 | 309 | mail :to => recipient, |
|
307 | 310 | :subject => l(:mail_subject_lost_password, Setting.app_title) |
|
308 | 311 | end |
|
309 | 312 | |
|
310 | 313 | def register(token) |
|
311 | 314 | set_language_if_valid(token.user.language) |
|
312 | 315 | @token = token |
|
313 | 316 | @url = url_for(:controller => 'account', :action => 'activate', :token => token.value) |
|
314 | 317 | mail :to => token.user.mail, |
|
315 | 318 | :subject => l(:mail_subject_register, Setting.app_title) |
|
316 | 319 | end |
|
317 | 320 | |
|
318 | 321 | def test_email(user) |
|
319 | 322 | set_language_if_valid(user.language) |
|
320 | 323 | @url = url_for(:controller => 'welcome') |
|
321 | 324 | mail :to => user.mail, |
|
322 | 325 | :subject => 'Redmine test' |
|
323 | 326 | end |
|
324 | 327 | |
|
325 | 328 | # Sends reminders to issue assignees |
|
326 | 329 | # Available options: |
|
327 | 330 | # * :days => how many days in the future to remind about (defaults to 7) |
|
328 | 331 | # * :tracker => id of tracker for filtering issues (defaults to all trackers) |
|
329 | 332 | # * :project => id or identifier of project to process (defaults to all projects) |
|
330 | 333 | # * :users => array of user/group ids who should be reminded |
|
331 | 334 | # * :version => name of target version for filtering issues (defaults to none) |
|
332 | 335 | def self.reminders(options={}) |
|
333 | 336 | days = options[:days] || 7 |
|
334 | 337 | project = options[:project] ? Project.find(options[:project]) : nil |
|
335 | 338 | tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil |
|
336 | 339 | target_version_id = options[:version] ? Version.named(options[:version]).pluck(:id) : nil |
|
337 | 340 | if options[:version] && target_version_id.blank? |
|
338 | 341 | raise ActiveRecord::RecordNotFound.new("Couldn't find Version with named #{options[:version]}") |
|
339 | 342 | end |
|
340 | 343 | user_ids = options[:users] |
|
341 | 344 | |
|
342 | 345 | scope = Issue.open.where("#{Issue.table_name}.assigned_to_id IS NOT NULL" + |
|
343 | 346 | " AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}" + |
|
344 | 347 | " AND #{Issue.table_name}.due_date <= ?", days.day.from_now.to_date |
|
345 | 348 | ) |
|
346 | 349 | scope = scope.where(:assigned_to_id => user_ids) if user_ids.present? |
|
347 | 350 | scope = scope.where(:project_id => project.id) if project |
|
348 | 351 | scope = scope.where(:fixed_version_id => target_version_id) if target_version_id.present? |
|
349 | 352 | scope = scope.where(:tracker_id => tracker.id) if tracker |
|
350 | 353 | issues_by_assignee = scope.includes(:status, :assigned_to, :project, :tracker). |
|
351 | 354 | group_by(&:assigned_to) |
|
352 | 355 | issues_by_assignee.keys.each do |assignee| |
|
353 | 356 | if assignee.is_a?(Group) |
|
354 | 357 | assignee.users.each do |user| |
|
355 | 358 | issues_by_assignee[user] ||= [] |
|
356 | 359 | issues_by_assignee[user] += issues_by_assignee[assignee] |
|
357 | 360 | end |
|
358 | 361 | end |
|
359 | 362 | end |
|
360 | 363 | |
|
361 | 364 | issues_by_assignee.each do |assignee, issues| |
|
362 | 365 | reminder(assignee, issues, days).deliver if assignee.is_a?(User) && assignee.active? |
|
363 | 366 | end |
|
364 | 367 | end |
|
365 | 368 | |
|
366 | 369 | # Activates/desactivates email deliveries during +block+ |
|
367 | 370 | def self.with_deliveries(enabled = true, &block) |
|
368 | 371 | was_enabled = ActionMailer::Base.perform_deliveries |
|
369 | 372 | ActionMailer::Base.perform_deliveries = !!enabled |
|
370 | 373 | yield |
|
371 | 374 | ensure |
|
372 | 375 | ActionMailer::Base.perform_deliveries = was_enabled |
|
373 | 376 | end |
|
374 | 377 | |
|
375 | 378 | # Sends emails synchronously in the given block |
|
376 | 379 | def self.with_synched_deliveries(&block) |
|
377 | 380 | saved_method = ActionMailer::Base.delivery_method |
|
378 | 381 | if m = saved_method.to_s.match(%r{^async_(.+)$}) |
|
379 | 382 | synched_method = m[1] |
|
380 | 383 | ActionMailer::Base.delivery_method = synched_method.to_sym |
|
381 | 384 | ActionMailer::Base.send "#{synched_method}_settings=", ActionMailer::Base.send("async_#{synched_method}_settings") |
|
382 | 385 | end |
|
383 | 386 | yield |
|
384 | 387 | ensure |
|
385 | 388 | ActionMailer::Base.delivery_method = saved_method |
|
386 | 389 | end |
|
387 | 390 | |
|
388 | 391 | def mail(headers={}, &block) |
|
389 | 392 | headers.reverse_merge! 'X-Mailer' => 'Redmine', |
|
390 | 393 | 'X-Redmine-Host' => Setting.host_name, |
|
391 | 394 | 'X-Redmine-Site' => Setting.app_title, |
|
392 | 395 | 'X-Auto-Response-Suppress' => 'All', |
|
393 | 396 | 'Auto-Submitted' => 'auto-generated', |
|
394 | 397 | 'From' => Setting.mail_from, |
|
395 | 398 | 'List-Id' => "<#{Setting.mail_from.to_s.gsub('@', '.')}>" |
|
396 | 399 | |
|
397 | 400 | # Replaces users with their email addresses |
|
398 | 401 | [:to, :cc, :bcc].each do |key| |
|
399 | 402 | if headers[key].present? |
|
400 | 403 | headers[key] = self.class.email_addresses(headers[key]) |
|
401 | 404 | end |
|
402 | 405 | end |
|
403 | 406 | |
|
404 | 407 | # Removes the author from the recipients and cc |
|
405 | 408 | # if the author does not want to receive notifications |
|
406 | 409 | # about what the author do |
|
407 | 410 | if @author && @author.logged? && @author.pref.no_self_notified |
|
408 | 411 | addresses = @author.mails |
|
409 | 412 | headers[:to] -= addresses if headers[:to].is_a?(Array) |
|
410 | 413 | headers[:cc] -= addresses if headers[:cc].is_a?(Array) |
|
411 | 414 | end |
|
412 | 415 | |
|
413 | 416 | if @author && @author.logged? |
|
414 | 417 | redmine_headers 'Sender' => @author.login |
|
415 | 418 | end |
|
416 | 419 | |
|
417 | 420 | # Blind carbon copy recipients |
|
418 | 421 | if Setting.bcc_recipients? |
|
419 | 422 | headers[:bcc] = [headers[:to], headers[:cc]].flatten.uniq.reject(&:blank?) |
|
420 | 423 | headers[:to] = nil |
|
421 | 424 | headers[:cc] = nil |
|
422 | 425 | end |
|
423 | 426 | |
|
424 | 427 | if @message_id_object |
|
425 | 428 | headers[:message_id] = "<#{self.class.message_id_for(@message_id_object)}>" |
|
426 | 429 | end |
|
427 | 430 | if @references_objects |
|
428 | 431 | headers[:references] = @references_objects.collect {|o| "<#{self.class.references_for(o)}>"}.join(' ') |
|
429 | 432 | end |
|
430 | 433 | |
|
431 | 434 | m = if block_given? |
|
432 | 435 | super headers, &block |
|
433 | 436 | else |
|
434 | 437 | super headers do |format| |
|
435 | 438 | format.text |
|
436 | 439 | format.html unless Setting.plain_text_mail? |
|
437 | 440 | end |
|
438 | 441 | end |
|
439 | 442 | set_language_if_valid @initial_language |
|
440 | 443 | |
|
441 | 444 | m |
|
442 | 445 | end |
|
443 | 446 | |
|
444 | 447 | def initialize(*args) |
|
445 | 448 | @initial_language = current_language |
|
446 | 449 | set_language_if_valid Setting.default_language |
|
447 | 450 | super |
|
448 | 451 | end |
|
449 | 452 | |
|
450 | 453 | def self.deliver_mail(mail) |
|
451 | 454 | return false if mail.to.blank? && mail.cc.blank? && mail.bcc.blank? |
|
452 | 455 | begin |
|
453 | 456 | # Log errors when raise_delivery_errors is set to false, Rails does not |
|
454 | 457 | mail.raise_delivery_errors = true |
|
455 | 458 | super |
|
456 | 459 | rescue Exception => e |
|
457 | 460 | if ActionMailer::Base.raise_delivery_errors |
|
458 | 461 | raise e |
|
459 | 462 | else |
|
460 | 463 | Rails.logger.error "Email delivery error: #{e.message}" |
|
461 | 464 | end |
|
462 | 465 | end |
|
463 | 466 | end |
|
464 | 467 | |
|
465 | 468 | def self.method_missing(method, *args, &block) |
|
466 | 469 | if m = method.to_s.match(%r{^deliver_(.+)$}) |
|
467 | 470 | ActiveSupport::Deprecation.warn "Mailer.deliver_#{m[1]}(*args) is deprecated. Use Mailer.#{m[1]}(*args).deliver instead." |
|
468 | 471 | send(m[1], *args).deliver |
|
469 | 472 | else |
|
470 | 473 | super |
|
471 | 474 | end |
|
472 | 475 | end |
|
473 | 476 | |
|
474 | 477 | # Returns an array of email addresses to notify by |
|
475 | 478 | # replacing users in arg with their notified email addresses |
|
476 | 479 | # |
|
477 | 480 | # Example: |
|
478 | 481 | # Mailer.email_addresses(users) |
|
479 | 482 | # => ["foo@example.net", "bar@example.net"] |
|
480 | 483 | def self.email_addresses(arg) |
|
481 | 484 | arr = Array.wrap(arg) |
|
482 | 485 | mails = arr.reject {|a| a.is_a? Principal} |
|
483 | 486 | users = arr - mails |
|
484 | 487 | if users.any? |
|
485 | 488 | mails += EmailAddress. |
|
486 | 489 | where(:user_id => users.map(&:id)). |
|
487 | 490 | where("is_default = ? OR notify = ?", true, true). |
|
488 | 491 | pluck(:address) |
|
489 | 492 | end |
|
490 | 493 | mails |
|
491 | 494 | end |
|
492 | 495 | |
|
493 | 496 | private |
|
494 | 497 | |
|
495 | 498 | # Appends a Redmine header field (name is prepended with 'X-Redmine-') |
|
496 | 499 | def redmine_headers(h) |
|
497 | 500 | h.each { |k,v| headers["X-Redmine-#{k}"] = v.to_s } |
|
498 | 501 | end |
|
499 | 502 | |
|
500 | 503 | def self.token_for(object, rand=true) |
|
501 | 504 | timestamp = object.send(object.respond_to?(:created_on) ? :created_on : :updated_on) |
|
502 | 505 | hash = [ |
|
503 | 506 | "redmine", |
|
504 | 507 | "#{object.class.name.demodulize.underscore}-#{object.id}", |
|
505 | 508 | timestamp.strftime("%Y%m%d%H%M%S") |
|
506 | 509 | ] |
|
507 | 510 | if rand |
|
508 | 511 | hash << Redmine::Utils.random_hex(8) |
|
509 | 512 | end |
|
510 | 513 | host = Setting.mail_from.to_s.strip.gsub(%r{^.*@|>}, '') |
|
511 | 514 | host = "#{::Socket.gethostname}.redmine" if host.empty? |
|
512 | 515 | "#{hash.join('.')}@#{host}" |
|
513 | 516 | end |
|
514 | 517 | |
|
515 | 518 | # Returns a Message-Id for the given object |
|
516 | 519 | def self.message_id_for(object) |
|
517 | 520 | token_for(object, true) |
|
518 | 521 | end |
|
519 | 522 | |
|
520 | 523 | # Returns a uniq token for a given object referenced by all notifications |
|
521 | 524 | # related to this object |
|
522 | 525 | def self.references_for(object) |
|
523 | 526 | token_for(object, false) |
|
524 | 527 | end |
|
525 | 528 | |
|
526 | 529 | def message_id(object) |
|
527 | 530 | @message_id_object = object |
|
528 | 531 | end |
|
529 | 532 | |
|
530 | 533 | def references(object) |
|
531 | 534 | @references_objects ||= [] |
|
532 | 535 | @references_objects << object |
|
533 | 536 | end |
|
534 | 537 | |
|
535 | 538 | def mylogger |
|
536 | 539 | Rails.logger |
|
537 | 540 | end |
|
538 | 541 | end |
General Comments 0
You need to be logged in to leave comments.
Login now