# * :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" +
)
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)
* 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"
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)
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'