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