Project

General

Profile

Enhancement to reminder email rake task (patch attached) ยป more_field_notifications_trunk.diff

Brad Langhorst, 2013-09-18 06:38

View differences:

app/models/mailer.rb (working copy)
88 88
    end
89 89
  end
90 90

  
91
  def reminder(user, issues, days)
91
  def reminder(user, issues, days, cc_address='')
92 92
    set_language_if_valid user.language
93 93
    @issues = issues
94 94
    @days = days
......
96 96
                                :set_filter => 1, :assigned_to_id => user.id,
97 97
                                :sort => 'due_date:asc')
98 98
    mail :to => user.mail,
99
      :subject => l(:mail_subject_reminder, :count => issues.size, :days => days)
99
      :cc => cc_address,
100
      :subject => l(:mail_subject_reminder, :count => issues.size, :days => days )
100 101
  end
101 102

  
102 103
  # Builds a Mail::Message object used to email users belonging to the added document's project.
......
314 315
  # Sends reminders to issue assignees
315 316
  # Available options:
316 317
  # * :days     => how many days in the future to remind about (defaults to 7)
318
  # * :max_age  => minutes to wait before reminding about issues (defaults to infinite)
317 319
  # * :tracker  => id of tracker for filtering issues (defaults to all trackers)
318 320
  # * :project  => id or identifier of project to process (defaults to all projects)
319
  # * :users    => array of user/group ids who should be reminded
321
  # * :users    => array of user/group ids who should be reminded (default, all)
322
  # * :cc       => email address to cc on emails
323
  # * :statuses   => array of status names (defaults: all)
324
  # * :priorities => array of issue priority names (default: all)
325

  
320 326
  def self.reminders(options={})
321 327
    days = options[:days] || 7
328
    max_age = options[:max_age]
329
    statuses = options[:statuses] || [:all]
330
    priorities = options[:priorities] || [:all]
331
    cc = options[:cc]
322 332
    project = options[:project] ? Project.find(options[:project]) : nil
323 333
    tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
324 334
    user_ids = options[:users]
325 335

  
326 336
    scope = Issue.open.where("#{Issue.table_name}.assigned_to_id IS NOT NULL" +
327
      " AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}" +
328
      " AND #{Issue.table_name}.due_date <= ?", days.day.from_now.to_date
337
      " AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}"
329 338
    )
339

  
340
    scope = scope.where(["#{Issue.table_name}.updated_on <= ?", (-1 * max_age).minutes.from_now]) if max_age.to_i > 0
341
    scope = scope.where(["#{Issue.table_name}.due_date <= ?", days.day.from_now.to_date]) if days.to_i > 0
342
    scope = scope.where(:status_id => IssueStatus.where(:name => statuses).map(&:id)) unless statuses.include?(:all)
343
    scope = scope.where(:priority_id => IssuePriority.where(:name => priorities).map(&:id)) unless priorities.include?(:all)
330 344
    scope = scope.where(:assigned_to_id => user_ids) if user_ids.present?
331
    scope = scope.where(:project_id => project.id) if project
345
    scope = scope.where(["(#{Project.table_name}.id = ? OR #{Project.table_name}.parent_id = ?)",project.id, project.id]) if project
332 346
    scope = scope.where(:tracker_id => tracker.id) if tracker
333 347

  
334 348
    issues_by_assignee = scope.includes(:status, :assigned_to, :project, :tracker).all.group_by(&:assigned_to)
......
342 356
    end
343 357

  
344 358
    issues_by_assignee.each do |assignee, issues|
345
      reminder(assignee, issues, days).deliver if assignee.is_a?(User) && assignee.active?
359
      reminder(assignee, issues, days, cc).deliver if assignee.is_a?(User) && assignee.active?
346 360
    end
347 361
  end
348 362

  
lib/tasks/reminder.rake (working copy)
32 32
  task :send_reminders => :environment do
33 33
    options = {}
34 34
    options[:days] = ENV['days'].to_i if ENV['days']
35
    options[:max_age] = ENV['max_age'].to_i if ENV['max_age']
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[:priorities] = (ENV['priorities'] || '').split(',').each(&:strip!)
40
    options[:statuses] = (ENV['statuses'] || '').split(',').each(&:strip!)
41
    options[:cc] = ENV['cc'] if ENV['cc']
38 42

  
43
    
39 44
    Mailer.with_synched_deliveries do
40 45
      Mailer.reminders(options)
41 46
    end
    (1-1/1)