diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 8f50b1b7b..6db5a997b 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -15,6 +15,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +require 'ar_condition' + class Mailer < ActionMailer::Base layout 'mailer' helper :application @@ -306,13 +308,16 @@ class Mailer < ActionMailer::Base # * :days => how many days in the future to remind about (defaults to 7) # * :tracker => id of tracker for filtering issues (defaults to all trackers) # * :project => id or identifier of project to process (defaults to all projects) + # * :users => array of user ids who should be reminded def self.reminders(options={}) days = options[:days] || 7 project = options[:project] ? Project.find(options[:project]) : nil tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil + user_ids = options[:users] s = ARCondition.new ["#{IssueStatus.table_name}.is_closed = ? AND #{Issue.table_name}.due_date <= ?", false, days.day.from_now.to_date] s << "#{Issue.table_name}.assigned_to_id IS NOT NULL" + s << ["#{Issue.table_name}.assigned_to_id IN (?)", user_ids] if user_ids.present? s << "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}" s << "#{Issue.table_name}.project_id = #{project.id}" if project s << "#{Issue.table_name}.tracker_id = #{tracker.id}" if tracker diff --git a/lib/tasks/reminder.rake b/lib/tasks/reminder.rake index 73844fb79..d11c7cebb 100644 --- a/lib/tasks/reminder.rake +++ b/lib/tasks/reminder.rake @@ -22,9 +22,10 @@ Available options: * days => number of days to remind about (defaults to 7) * tracker => id of tracker (defaults to all trackers) * project => id or identifier of project (defaults to all projects) + * users => comma separated list of user ids who should be reminded Example: - rake redmine:send_reminders days=7 RAILS_ENV="production" + rake redmine:send_reminders days=7 users="1,23, 56" RAILS_ENV="production" END_DESC namespace :redmine do @@ -33,6 +34,7 @@ namespace :redmine do options[:days] = ENV['days'].to_i if ENV['days'] options[:project] = ENV['project'] if ENV['project'] options[:tracker] = ENV['tracker'].to_i if ENV['tracker'] + options[:users] = (ENV['users'] || '').split(',').each(&:strip!) Mailer.reminders(options) end diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index a5932d325..77bcb36f6 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -355,6 +355,16 @@ class MailerTest < ActiveSupport::TestCase assert_equal '1 issue(s) due in the next 42 days', mail.subject end + def test_reminders_for_users + Mailer.reminders(:days => 42, :users => ['5']) + assert_equal 0, ActionMailer::Base.deliveries.size # No mail for dlopper + Mailer.reminders(:days => 42, :users => ['3']) + assert_equal 1, ActionMailer::Base.deliveries.size # No mail for dlopper + mail = ActionMailer::Base.deliveries.last + assert mail.bcc.include?('dlopper@somenet.foo') + assert mail.body.include?('Bug #3: Error 281 when updating a recipe') + end + def last_email mail = ActionMailer::Base.deliveries.last assert_not_nil mail