@@ -15,6 +15,8 | |||
|
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 'ar_condition' | |
|
19 | ||
|
18 | 20 | class Mailer < ActionMailer::Base |
|
19 | 21 | layout 'mailer' |
|
20 | 22 | helper :application |
@@ -306,13 +308,16 class Mailer < ActionMailer::Base | |||
|
306 | 308 | # * :days => how many days in the future to remind about (defaults to 7) |
|
307 | 309 | # * :tracker => id of tracker for filtering issues (defaults to all trackers) |
|
308 | 310 | # * :project => id or identifier of project to process (defaults to all projects) |
|
311 | # * :users => array of user ids who should be reminded | |
|
309 | 312 | def self.reminders(options={}) |
|
310 | 313 | days = options[:days] || 7 |
|
311 | 314 | project = options[:project] ? Project.find(options[:project]) : nil |
|
312 | 315 | tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil |
|
316 | user_ids = options[:users] | |
|
313 | 317 | |
|
314 | 318 | s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.due_date <= ?", false, days.day.from_now.to_date] |
|
315 | 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 | 321 | s << "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}" |
|
317 | 322 | s << "#{Issue.table_name}.project_id = #{project.id}" if project |
|
318 | 323 | s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker |
@@ -22,9 +22,10 Available options: | |||
|
22 | 22 | * days => number of days to remind about (defaults to 7) |
|
23 | 23 | * tracker => id of tracker (defaults to all trackers) |
|
24 | 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 | 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 | 29 | END_DESC |
|
29 | 30 | |
|
30 | 31 | namespace :redmine do |
@@ -33,6 +34,7 namespace :redmine do | |||
|
33 | 34 | options[:days] = ENV['days'].to_i if ENV['days'] |
|
34 | 35 | options[:project] = ENV['project'] if ENV['project'] |
|
35 | 36 | options[:tracker] = ENV['tracker'].to_i if ENV['tracker'] |
|
37 | options[:users] = (ENV['users'] || '').split(',').each(&:strip!) | |
|
36 | 38 | |
|
37 | 39 | Mailer.reminders(options) |
|
38 | 40 | end |
@@ -355,6 +355,16 class MailerTest < ActiveSupport::TestCase | |||
|
355 | 355 | assert_equal '1 issue(s) due in the next 42 days', mail.subject |
|
356 | 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 | 368 | def last_email |
|
359 | 369 | mail = ActionMailer::Base.deliveries.last |
|
360 | 370 | assert_not_nil mail |
General Comments 0
You need to be logged in to leave comments.
Login now