From 197a14a82e3e82bd0b5a057ffc397c1a81922453 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 9 Sep 2012 11:02:13 +0000 Subject: [PATCH] Fixed that the reminder email excludes issues assigned to groups (#11723). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10335 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/mailer.rb | 11 ++++++++++- lib/tasks/reminder.rake | 2 +- test/unit/mailer_test.rb | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 1f9a04af4..b8b2ac721 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -327,7 +327,7 @@ 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 + # * :users => array of user/group ids who should be reminded def self.reminders(options={}) days = options[:days] || 7 project = options[:project] ? Project.find(options[:project]) : nil @@ -343,6 +343,15 @@ class Mailer < ActionMailer::Base scope = scope.scoped(:conditions => {:tracker_id => tracker.id}) if tracker issues_by_assignee = scope.all(:include => [:status, :assigned_to, :project, :tracker]).group_by(&:assigned_to) + issues_by_assignee.keys.each do |assignee| + if assignee.is_a?(Group) + assignee.users.each do |user| + issues_by_assignee[user] ||= [] + issues_by_assignee[user] += issues_by_assignee[assignee] + end + end + end + issues_by_assignee.each do |assignee, issues| reminder(assignee, issues, days).deliver if assignee.is_a?(User) && assignee.active? end diff --git a/lib/tasks/reminder.rake b/lib/tasks/reminder.rake index f1d4619ca..ba1abd1da 100644 --- a/lib/tasks/reminder.rake +++ b/lib/tasks/reminder.rake @@ -22,7 +22,7 @@ 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 + * users => comma separated list of user/group ids who should be reminded Example: rake redmine:send_reminders days=7 users="1,23, 56" RAILS_ENV="production" diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb index e95aa449a..efde01f5c 100644 --- a/test/unit/mailer_test.rb +++ b/test/unit/mailer_test.rb @@ -508,6 +508,27 @@ class MailerTest < ActiveSupport::TestCase assert_mail_body_match 'Bug #3: Error 281 when updating a recipe', mail end + def test_reminder_should_include_issues_assigned_to_groups + with_settings :default_language => 'en' do + group = Group.generate! + group.users << User.find(2) + group.users << User.find(3) + + Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, + :subject => 'Assigned to group', :assigned_to => group, + :due_date => 5.days.from_now, + :author_id => 2) + ActionMailer::Base.deliveries.clear + + Mailer.reminders(:days => 7) + assert_equal 2, ActionMailer::Base.deliveries.size + assert_equal %w(dlopper@somenet.foo jsmith@somenet.foo), ActionMailer::Base.deliveries.map(&:bcc).flatten.sort + ActionMailer::Base.deliveries.each do |mail| + assert_mail_body_match 'Assigned to group', mail + end + end + end + def test_mailer_should_not_change_locale Setting.default_language = 'en' # Set current language to italian