2012-05-17 17:23:34 -04:00
|
|
|
class IssueObserver < ActiveRecord::Observer
|
|
|
|
cattr_accessor :current_user
|
|
|
|
|
|
|
|
def after_create(issue)
|
2012-06-26 14:47:25 -04:00
|
|
|
if issue.assignee && issue.assignee != current_user
|
|
|
|
Notify.new_issue_email(issue.id).deliver
|
|
|
|
end
|
2012-05-17 17:23:34 -04:00
|
|
|
end
|
|
|
|
|
2012-05-21 13:30:53 -04:00
|
|
|
def after_update(issue)
|
2012-05-20 14:25:34 -04:00
|
|
|
send_reassigned_email(issue) if issue.is_being_reassigned?
|
2012-05-20 15:06:13 -04:00
|
|
|
Note.create_status_change_note(issue, current_user, 'closed') if issue.is_being_closed?
|
2012-05-21 13:30:53 -04:00
|
|
|
Note.create_status_change_note(issue, current_user, 'reopened') if issue.is_being_reopened?
|
2012-05-20 14:25:34 -04:00
|
|
|
end
|
|
|
|
|
2012-06-20 21:23:05 -04:00
|
|
|
protected
|
|
|
|
|
2012-05-20 14:25:34 -04:00
|
|
|
def send_reassigned_email(issue)
|
2012-06-26 14:47:25 -04:00
|
|
|
recipient_ids = [issue.assignee_id, issue.assignee_id_was].keep_if {|id| id && id != current_user.id }
|
2012-05-17 17:23:34 -04:00
|
|
|
|
2012-05-20 14:25:34 -04:00
|
|
|
recipient_ids.each do |recipient_id|
|
2012-06-15 16:23:28 -04:00
|
|
|
Notify.reassigned_issue_email(recipient_id, issue.id, issue.assignee_id_was).deliver
|
2012-05-17 17:23:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|