2012-05-17 23:23:34 +02:00
|
|
|
class IssueObserver < ActiveRecord::Observer
|
|
|
|
cattr_accessor :current_user
|
|
|
|
|
|
|
|
def after_create(issue)
|
2012-06-26 20:47:25 +02:00
|
|
|
if issue.assignee && issue.assignee != current_user
|
2012-11-22 20:41:16 +01:00
|
|
|
Notify.new_issue_email(issue.id).deliver
|
2012-06-26 20:47:25 +02:00
|
|
|
end
|
2012-05-17 23:23:34 +02:00
|
|
|
end
|
|
|
|
|
2012-05-21 19:30:53 +02:00
|
|
|
def after_update(issue)
|
2012-05-20 20:25:34 +02:00
|
|
|
send_reassigned_email(issue) if issue.is_being_reassigned?
|
2012-08-29 09:48:17 +02:00
|
|
|
|
2012-08-29 09:50:35 +02:00
|
|
|
status = nil
|
|
|
|
status = 'closed' if issue.is_being_closed?
|
|
|
|
status = 'reopened' if issue.is_being_reopened?
|
|
|
|
if status
|
2012-11-22 20:41:16 +01:00
|
|
|
Note.create_status_change_note(issue, current_user, status)
|
|
|
|
[issue.author, issue.assignee].compact.each do |recipient|
|
2012-08-29 09:50:35 +02:00
|
|
|
Notify.issue_status_changed_email(recipient.id, issue.id, status, current_user)
|
2012-08-29 09:48:17 +02:00
|
|
|
end
|
|
|
|
end
|
2012-05-20 20:25:34 +02:00
|
|
|
end
|
|
|
|
|
2012-06-21 03:23:05 +02:00
|
|
|
protected
|
|
|
|
|
2012-05-20 20:25:34 +02:00
|
|
|
def send_reassigned_email(issue)
|
2012-06-26 20:47:25 +02:00
|
|
|
recipient_ids = [issue.assignee_id, issue.assignee_id_was].keep_if {|id| id && id != current_user.id }
|
2012-05-17 23:23:34 +02:00
|
|
|
|
2012-05-20 20:25:34 +02:00
|
|
|
recipient_ids.each do |recipient_id|
|
2012-06-15 22:23:28 +02:00
|
|
|
Notify.reassigned_issue_email(recipient_id, issue.id, issue.assignee_id_was).deliver
|
2012-05-17 23:23:34 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|