@@ -319,10 +319,12 class Mailer < ActionMailer::Base | |||||
319 | # * :tracker => id of tracker for filtering issues (defaults to all trackers) |
|
319 | # * :tracker => id of tracker for filtering issues (defaults to all trackers) | |
320 | # * :project => id or identifier of project to process (defaults to all projects) |
|
320 | # * :project => id or identifier of project to process (defaults to all projects) | |
321 | # * :users => array of user/group ids who should be reminded |
|
321 | # * :users => array of user/group ids who should be reminded | |
|
322 | # * :version => name of target version for filtering issues (defaults to none) | |||
322 | def self.reminders(options={}) |
|
323 | def self.reminders(options={}) | |
323 | days = options[:days] || 7 |
|
324 | days = options[:days] || 7 | |
324 | project = options[:project] ? Project.find(options[:project]) : nil |
|
325 | project = options[:project] ? Project.find(options[:project]) : nil | |
325 | tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil |
|
326 | tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil | |
|
327 | target_versions = options[:version] ? Version.where(name: options[:version]).select(:id).map(&:id) : nil | |||
326 | user_ids = options[:users] |
|
328 | user_ids = options[:users] | |
327 |
|
329 | |||
328 | scope = Issue.open.where("#{Issue.table_name}.assigned_to_id IS NOT NULL" + |
|
330 | scope = Issue.open.where("#{Issue.table_name}.assigned_to_id IS NOT NULL" + | |
@@ -331,6 +333,7 class Mailer < ActionMailer::Base | |||||
331 | ) |
|
333 | ) | |
332 | scope = scope.where(:assigned_to_id => user_ids) if user_ids.present? |
|
334 | scope = scope.where(:assigned_to_id => user_ids) if user_ids.present? | |
333 | scope = scope.where(:project_id => project.id) if project |
|
335 | scope = scope.where(:project_id => project.id) if project | |
|
336 | scope = scope.where(:fixed_version_id => target_versions) unless target_versions.blank? | |||
334 | scope = scope.where(:tracker_id => tracker.id) if tracker |
|
337 | scope = scope.where(:tracker_id => tracker.id) if tracker | |
335 | issues_by_assignee = scope.includes(:status, :assigned_to, :project, :tracker). |
|
338 | issues_by_assignee = scope.includes(:status, :assigned_to, :project, :tracker). | |
336 | group_by(&:assigned_to) |
|
339 | group_by(&:assigned_to) |
@@ -23,6 +23,7 Available options: | |||||
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/group ids who should be reminded |
|
25 | * users => comma separated list of user/group ids who should be reminded | |
|
26 | * version => name of target version for filtering issues (defaults to none) | |||
26 |
|
27 | |||
27 | Example: |
|
28 | Example: | |
28 | rake redmine:send_reminders days=7 users="1,23, 56" RAILS_ENV="production" |
|
29 | rake redmine:send_reminders days=7 users="1,23, 56" RAILS_ENV="production" | |
@@ -35,6 +36,7 namespace :redmine do | |||||
35 | options[:project] = ENV['project'] if ENV['project'] |
|
36 | options[:project] = ENV['project'] if ENV['project'] | |
36 | options[:tracker] = ENV['tracker'].to_i if ENV['tracker'] |
|
37 | options[:tracker] = ENV['tracker'].to_i if ENV['tracker'] | |
37 | options[:users] = (ENV['users'] || '').split(',').each(&:strip!) |
|
38 | options[:users] = (ENV['users'] || '').split(',').each(&:strip!) | |
|
39 | options[:version] = ENV['version'] if ENV['version'] | |||
38 |
|
40 | |||
39 | Mailer.with_synched_deliveries do |
|
41 | Mailer.with_synched_deliveries do | |
40 | Mailer.reminders(options) |
|
42 | Mailer.reminders(options) |
@@ -633,6 +633,27 class MailerTest < ActiveSupport::TestCase | |||||
633 | end |
|
633 | end | |
634 | end |
|
634 | end | |
635 |
|
635 | |||
|
636 | def test_reminders_for_versions | |||
|
637 | with_settings :default_language => 'en' do | |||
|
638 | Mailer.reminders(:days => 42, :users => ['3']) | |||
|
639 | assert_equal 1, ActionMailer::Base.deliveries.size | |||
|
640 | ||||
|
641 | ActionMailer::Base.deliveries.clear | |||
|
642 | Version.create!(name: 'Acme', project_id: 1, sharing: 'none') | |||
|
643 | Mailer.reminders(:days => 42, :users => ['3'], :version => 'Acme') | |||
|
644 | assert_equal 0, ActionMailer::Base.deliveries.size | |||
|
645 | Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, | |||
|
646 | :subject => 'Assigned to user', :assigned_to => User.find(3), | |||
|
647 | :due_date => 5.days.from_now, | |||
|
648 | :author_id => 2) | |||
|
649 | Mailer.reminders(:days => 42, :users => ['3'], :version => 'Acme') | |||
|
650 | assert_equal 1, ActionMailer::Base.deliveries.size | |||
|
651 | ||||
|
652 | mail = last_email | |||
|
653 | assert mail.bcc.include?('dlopper@somenet.foo') | |||
|
654 | end | |||
|
655 | end | |||
|
656 | ||||
636 | def test_mailer_should_not_change_locale |
|
657 | def test_mailer_should_not_change_locale | |
637 | # Set current language to italian |
|
658 | # Set current language to italian | |
638 | set_language_if_valid 'it' |
|
659 | set_language_if_valid 'it' |
General Comments 0
You need to be logged in to leave comments.
Login now