Added a users options to the reminders email

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4167 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2010-09-20 23:17:51 +00:00
parent 55fbf6836b
commit 51359704a0
3 changed files with 18 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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