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
|
2013-01-09 00:44:05 -05:00
|
|
|
Notify.delay.new_issue_email(issue.id)
|
2012-06-26 14:47:25 -04:00
|
|
|
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-08-29 03:48:17 -04:00
|
|
|
|
2012-08-29 03:50:35 -04:00
|
|
|
status = nil
|
|
|
|
status = 'closed' if issue.is_being_closed?
|
|
|
|
status = 'reopened' if issue.is_being_reopened?
|
|
|
|
if status
|
2012-11-22 14:41:16 -05:00
|
|
|
Note.create_status_change_note(issue, current_user, status)
|
|
|
|
[issue.author, issue.assignee].compact.each do |recipient|
|
2013-01-09 00:44:05 -05:00
|
|
|
Notify.delay.issue_status_changed_email(recipient.id, issue.id, status, current_user.id)
|
2012-08-29 03:48:17 -04:00
|
|
|
end
|
|
|
|
end
|
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|
|
2013-01-09 00:44:05 -05:00
|
|
|
Notify.delay.reassigned_issue_email(recipient_id, issue.id, issue.assignee_id_was)
|
2012-05-17 17:23:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|