/
question_mailer.rb
68 lines (55 loc) · 2.63 KB
/
question_mailer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class QuestionMailer < Mailer
unloadable
def asked_question(journal)
question = journal.question
subject "[Question #{question.issue.project.name} ##{question.issue.id}] #{question.issue.subject}"
recipients question.assigned_to.mail unless question.assigned_to.nil?
@from = "#{question.author.name} (Redmine) <#{Setting.mail_from}>" unless question.author.nil?
redmine_headers 'Issue-Id' => question.issue.id
redmine_headers 'Question-Asked' => question.author.login if question.author.present?
redmine_headers 'Question-Assigned-To' => question.assigned_to.login if question.assigned_to.present?
body({
:question => question,
:issue => question.issue,
:journal => journal,
:issue_url => url_for(:controller => 'issues', :action => 'show', :id => question.issue)
})
RAILS_DEFAULT_LOGGER.debug 'Sending QuestionMailer#asked_question'
render_multipart('asked_question', body)
end
def answered_question(question, closing_journal)
subject "[Answered #{question.issue.project.name} ##{question.issue.id}] #{question.issue.subject}"
recipients question.author.mail unless question.author.nil?
@from = "#{question.assigned_to.name} (Redmine) <#{Setting.mail_from}>" unless question.assigned_to.nil?
redmine_headers 'Issue-Id' => question.issue.id
redmine_headers 'Question-Answer' => "#{question.issue.id}-#{closing_journal.id}"
body({
:question => question,
:issue => question.issue,
:journal => closing_journal,
:issue_url => url_for(:controller => 'issues', :action => 'show', :id => question.issue)
})
RAILS_DEFAULT_LOGGER.debug 'Sending QuestionMailer#answered_question'
render_multipart('answered_question', body)
end
# Creates an email with a list of issues that have open questions
# assigned to the user
def question_reminder(user, issues)
redmine_headers 'Type' => "Question"
set_language_if_valid user.language
recipients user.mail
subject l(:question_reminder_subject, :count => issues.size)
body :issues => issues,
:issues_url => url_for(:controller => 'questions', :action => 'my_issue_filter')
render_multipart('question_reminder', body)
end
# Send email reminders to users who have open questions.
def self.question_reminders
open_questions_by_assignee = Question.opened.all(:order => 'id desc').group_by(&:assigned_to)
open_questions_by_assignee.each do |assignee, questions|
next unless assignee.present?
issues = questions.collect {|q| q.issue.visible?(assignee) ? q.issue : nil }.compact.uniq
deliver_question_reminder(assignee, issues)
end
end
end