@@ -15,6 +15,8 | |||||
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 | require 'ar_condition' | |||
|
19 | ||||
18 | class Mailer < ActionMailer::Base |
|
20 | class Mailer < ActionMailer::Base | |
19 | layout 'mailer' |
|
21 | layout 'mailer' | |
20 | helper :application |
|
22 | helper :application | |
@@ -306,13 +308,16 class Mailer < ActionMailer::Base | |||||
306 | # * :days => how many days in the future to remind about (defaults to 7) |
|
308 | # * :days => how many days in the future to remind about (defaults to 7) | |
307 | # * :tracker => id of tracker for filtering issues (defaults to all trackers) |
|
309 | # * :tracker => id of tracker for filtering issues (defaults to all trackers) | |
308 | # * :project => id or identifier of project to process (defaults to all projects) |
|
310 | # * :project => id or identifier of project to process (defaults to all projects) | |
|
311 | # * :users => array of user ids who should be reminded | |||
309 | def self.reminders(options={}) |
|
312 | def self.reminders(options={}) | |
310 | days = options[:days] || 7 |
|
313 | days = options[:days] || 7 | |
311 | project = options[:project] ? Project.find(options[:project]) : nil |
|
314 | project = options[:project] ? Project.find(options[:project]) : nil | |
312 | tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil |
|
315 | tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil | |
|
316 | user_ids = options[:users] | |||
313 |
|
317 | |||
314 | s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.due_date <= ?", false, days.day.from_now.to_date] |
|
318 | s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.due_date <= ?", false, days.day.from_now.to_date] | |
315 | s << "#{Issue.table_name}.assigned_to_id IS NOT NULL" |
|
319 | s << "#{Issue.table_name}.assigned_to_id IS NOT NULL" | |
|
320 | s << ["#{Issue.table_name}.assigned_to_id IN (?)", user_ids] if user_ids.present? | |||
316 | s << "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}" |
|
321 | s << "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}" | |
317 | s << "#{Issue.table_name}.project_id = #{project.id}" if project |
|
322 | s << "#{Issue.table_name}.project_id = #{project.id}" if project | |
318 | s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker |
|
323 | s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker |
@@ -22,9 +22,10 Available options: | |||||
22 | * days => number of days to remind about (defaults to 7) |
|
22 | * days => number of days to remind about (defaults to 7) | |
23 | * tracker => id of tracker (defaults to all trackers) |
|
23 | * tracker => id of tracker (defaults to all trackers) | |
24 | * project => id or identifier of project (defaults to all projects) |
|
24 | * project => id or identifier of project (defaults to all projects) | |
|
25 | * users => comma separated list of user ids who should be reminded | |||
25 |
|
26 | |||
26 | Example: |
|
27 | Example: | |
27 | rake redmine:send_reminders days=7 RAILS_ENV="production" |
|
28 | rake redmine:send_reminders days=7 users="1,23, 56" RAILS_ENV="production" | |
28 | END_DESC |
|
29 | END_DESC | |
29 |
|
30 | |||
30 | namespace :redmine do |
|
31 | namespace :redmine do | |
@@ -33,6 +34,7 namespace :redmine do | |||||
33 | options[:days] = ENV['days'].to_i if ENV['days'] |
|
34 | options[:days] = ENV['days'].to_i if ENV['days'] | |
34 | options[:project] = ENV['project'] if ENV['project'] |
|
35 | options[:project] = ENV['project'] if ENV['project'] | |
35 | options[:tracker] = ENV['tracker'].to_i if ENV['tracker'] |
|
36 | options[:tracker] = ENV['tracker'].to_i if ENV['tracker'] | |
|
37 | options[:users] = (ENV['users'] || '').split(',').each(&:strip!) | |||
36 |
|
38 | |||
37 | Mailer.reminders(options) |
|
39 | Mailer.reminders(options) | |
38 | end |
|
40 | end |
@@ -355,6 +355,16 class MailerTest < ActiveSupport::TestCase | |||||
355 | assert_equal '1 issue(s) due in the next 42 days', mail.subject |
|
355 | assert_equal '1 issue(s) due in the next 42 days', mail.subject | |
356 | end |
|
356 | end | |
357 |
|
357 | |||
|
358 | def test_reminders_for_users | |||
|
359 | Mailer.reminders(:days => 42, :users => ['5']) | |||
|
360 | assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper | |||
|
361 | Mailer.reminders(:days => 42, :users => ['3']) | |||
|
362 | assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper | |||
|
363 | mail = ActionMailer::Base.deliveries.last | |||
|
364 | assert mail.bcc.include?('dlopper@somenet.foo') | |||
|
365 | assert mail.body.include?('Bug #3: Error 281 when updating a recipe') | |||
|
366 | end | |||
|
367 | ||||
358 | def last_email |
|
368 | def last_email | |
359 | mail = ActionMailer::Base.deliveries.last |
|
369 | mail = ActionMailer::Base.deliveries.last | |
360 | assert_not_nil mail |
|
370 | assert_not_nil mail |
General Comments 0
You need to be logged in to leave comments.
Login now