Enhancement to reminder email rake task (patch attached) ยป more_field_notifications_trunk.diff
| app/models/mailer.rb (working copy) | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def reminder(user, issues, days)
|
||
|
def reminder(user, issues, days, cc_address='')
|
||
|
set_language_if_valid user.language
|
||
|
@issues = issues
|
||
|
@days = days
|
||
| ... | ... | |
|
:set_filter => 1, :assigned_to_id => user.id,
|
||
|
:sort => 'due_date:asc')
|
||
|
mail :to => user.mail,
|
||
|
:subject => l(:mail_subject_reminder, :count => issues.size, :days => days)
|
||
|
:cc => cc_address,
|
||
|
:subject => l(:mail_subject_reminder, :count => issues.size, :days => days )
|
||
|
end
|
||
|
# Builds a Mail::Message object used to email users belonging to the added document's project.
|
||
| ... | ... | |
|
# Sends reminders to issue assignees
|
||
|
# Available options:
|
||
|
# * :days => how many days in the future to remind about (defaults to 7)
|
||
|
# * :max_age => minutes to wait before reminding about issues (defaults to infinite)
|
||
|
# * :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
|
||
|
# * :users => array of user/group ids who should be reminded (default, all)
|
||
|
# * :cc => email address to cc on emails
|
||
|
# * :statuses => array of status names (defaults: all)
|
||
|
# * :priorities => array of issue priority names (default: all)
|
||
|
def self.reminders(options={})
|
||
|
days = options[:days] || 7
|
||
|
max_age = options[:max_age]
|
||
|
statuses = options[:statuses] || [:all]
|
||
|
priorities = options[:priorities] || [:all]
|
||
|
cc = options[:cc]
|
||
|
project = options[:project] ? Project.find(options[:project]) : nil
|
||
|
tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
|
||
|
user_ids = options[:users]
|
||
|
scope = Issue.open.where("#{Issue.table_name}.assigned_to_id IS NOT NULL" +
|
||
|
" AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}" +
|
||
|
" AND #{Issue.table_name}.due_date <= ?", days.day.from_now.to_date
|
||
|
" AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}"
|
||
|
)
|
||
|
scope = scope.where(["#{Issue.table_name}.updated_on <= ?", (-1 * max_age).minutes.from_now]) if max_age.to_i > 0
|
||
|
scope = scope.where(["#{Issue.table_name}.due_date <= ?", days.day.from_now.to_date]) if days.to_i > 0
|
||
|
scope = scope.where(:status_id => IssueStatus.where(:name => statuses).map(&:id)) unless statuses.include?(:all)
|
||
|
scope = scope.where(:priority_id => IssuePriority.where(:name => priorities).map(&:id)) unless priorities.include?(:all)
|
||
|
scope = scope.where(:assigned_to_id => user_ids) if user_ids.present?
|
||
|
scope = scope.where(:project_id => project.id) if project
|
||
|
scope = scope.where(["(#{Project.table_name}.id = ? OR #{Project.table_name}.parent_id = ?)",project.id, project.id]) if project
|
||
|
scope = scope.where(:tracker_id => tracker.id) if tracker
|
||
|
issues_by_assignee = scope.includes(:status, :assigned_to, :project, :tracker).all.group_by(&:assigned_to)
|
||
| ... | ... | |
|
end
|
||
|
issues_by_assignee.each do |assignee, issues|
|
||
|
reminder(assignee, issues, days).deliver if assignee.is_a?(User) && assignee.active?
|
||
|
reminder(assignee, issues, days, cc).deliver if assignee.is_a?(User) && assignee.active?
|
||
|
end
|
||
|
end
|
||
| lib/tasks/reminder.rake (working copy) | ||
|---|---|---|
|
task :send_reminders => :environment do
|
||
|
options = {}
|
||
|
options[:days] = ENV['days'].to_i if ENV['days']
|
||
|
options[:max_age] = ENV['max_age'].to_i if ENV['max_age']
|
||
|
options[:project] = ENV['project'] if ENV['project']
|
||
|
options[:tracker] = ENV['tracker'].to_i if ENV['tracker']
|
||
|
options[:users] = (ENV['users'] || '').split(',').each(&:strip!)
|
||
|
options[:priorities] = (ENV['priorities'] || '').split(',').each(&:strip!)
|
||
|
options[:statuses] = (ENV['statuses'] || '').split(',').each(&:strip!)
|
||
|
options[:cc] = ENV['cc'] if ENV['cc']
|
||
|
|
||
|
Mailer.with_synched_deliveries do
|
||
|
Mailer.reminders(options)
|
||
|
end
|
||