Project

General

Profile

Patch #18983 ยป REMINDERS_VERSION.diff

Merul Patel, 2015-01-30 17:25

View differences:

app/models/mailer.rb (working copy)
319 319
  # * :tracker  => id of tracker for filtering issues (defaults to all trackers)
320 320
  # * :project  => id or identifier of project to process (defaults to all projects)
321 321
  # * :users    => array of user/group ids who should be reminded
322
  # * :version  => name of target version for filtering issues (defaults to none)
322 323
  def self.reminders(options={})
323 324
    days = options[:days] || 7
324 325
    project = options[:project] ? Project.find(options[:project]) : nil
325 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 328
    user_ids = options[:users]
327 329

  
328 330
    scope = Issue.open.where("#{Issue.table_name}.assigned_to_id IS NOT NULL" +
......
331 333
    )
332 334
    scope = scope.where(:assigned_to_id => user_ids) if user_ids.present?
333 335
    scope = scope.where(:project_id => project.id) if project
336
    scope = scope.where(:fixed_version_id => target_versions) unless target_versions.blank?
334 337
    scope = scope.where(:tracker_id => tracker.id) if tracker
335 338
    issues_by_assignee = scope.includes(:status, :assigned_to, :project, :tracker).
336 339
                              group_by(&:assigned_to)
lib/tasks/reminder.rake (working copy)
23 23
  * tracker  => id of tracker (defaults to all trackers)
24 24
  * project  => id or identifier of project (defaults to all projects)
25 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 28
Example:
28 29
  rake redmine:send_reminders days=7 users="1,23, 56" RAILS_ENV="production"
......
35 36
    options[:project] = ENV['project'] if ENV['project']
36 37
    options[:tracker] = ENV['tracker'].to_i if ENV['tracker']
37 38
    options[:users] = (ENV['users'] || '').split(',').each(&:strip!)
39
    options[:version] = ENV['version'] if ENV['version'] 
38 40

  
39 41
    Mailer.with_synched_deliveries do
40 42
      Mailer.reminders(options)
test/unit/mailer_test.rb (working copy)
633 633
    end
634 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 657
  def test_mailer_should_not_change_locale
637 658
    # Set current language to italian
638 659
    set_language_if_valid 'it'
    (1-1/1)