From e94920a5ff5aff6ef7bb23f8852ee119f8fdca53 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 7 Feb 2015 07:56:58 +0000 Subject: [PATCH] Allow filtering of Redmine Reminders by Version (#18983). Patch by Merul Patel. git-svn-id: http://svn.redmine.org/redmine/trunk@13964 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/mailer.rb | 3 +++ lib/tasks/reminder.rake | 2 ++ test/unit/mailer_test.rb | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/app/models/mailer.rb b/app/models/mailer.rb index f6312e073..026ff7c18 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -319,10 +319,12 @@ class Mailer < ActionMailer::Base # * :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/group ids who should be reminded + # * :version => name of target version for filtering issues (defaults to none) def self.reminders(options={}) days = options[:days] || 7 project = options[:project] ? Project.find(options[:project]) : nil tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil + target_versions = options[:version] ? Version.where(name: options[:version]).select(:id).map(&:id) : nil user_ids = options[:users] scope = Issue.open.where("#{Issue.table_name}.assigned_to_id IS NOT NULL" + @@ -331,6 +333,7 @@ class Mailer < ActionMailer::Base ) scope = scope.where(:assigned_to_id => user_ids) if user_ids.present? scope = scope.where(:project_id => project.id) if project + scope = scope.where(:fixed_version_id => target_versions) unless target_versions.blank? scope = scope.where(:tracker_id => tracker.id) if tracker issues_by_assignee = scope.includes(:status, :assigned_to, :project, :tracker). group_by(&:assigned_to) diff --git a/lib/tasks/reminder.rake b/lib/tasks/reminder.rake index 289c8b11a..38072978f 100644 --- a/lib/tasks/reminder.rake +++ b/lib/tasks/reminder.rake @@ -23,6 +23,7 @@ Available options: * tracker => id of tracker (defaults to all trackers) * project => id or identifier of project (defaults to all projects) * users => comma separated list of user/group ids who should be reminded + * version => name of target version for filtering issues (defaults to none) Example: rake redmine:send_reminders days=7 users="1,23, 56" RAILS_ENV="production" @@ -35,6 +36,7 @@ namespace :redmine do options[:project] = ENV['project'] if ENV['project'] options[:tracker] = ENV['tracker'].to_i if ENV['tracker'] options[:users] = (ENV['users'] || '').split(',').each(&:strip!) + options[:version] = ENV['version'] if ENV['version'] Mailer.with_synched_deliveries do Mailer.reminders(options) diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index c5df3e684..9594d8e72 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -633,6 +633,27 @@ class MailerTest < ActiveSupport::TestCase end end + def test_reminders_for_versions + with_settings :default_language => 'en' do + Mailer.reminders(:days => 42, :users => ['3']) + assert_equal 1, ActionMailer::Base.deliveries.size + + ActionMailer::Base.deliveries.clear + Version.create!(name: 'Acme', project_id: 1, sharing: 'none') + Mailer.reminders(:days => 42, :users => ['3'], :version => 'Acme') + assert_equal 0, ActionMailer::Base.deliveries.size + Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, + :subject => 'Assigned to user', :assigned_to => User.find(3), + :due_date => 5.days.from_now, + :author_id => 2) + Mailer.reminders(:days => 42, :users => ['3'], :version => 'Acme') + assert_equal 1, ActionMailer::Base.deliveries.size + + mail = last_email + assert mail.bcc.include?('dlopper@somenet.foo') + end + end + def test_mailer_should_not_change_locale # Set current language to italian set_language_if_valid 'it' -- 2.39.5