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
|
|
|
|
|
2013-02-18 04:10:58 -05:00
|
|
|
def after_close(issue, transition)
|
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
|
|
|
|
2013-02-18 04:10:58 -05:00
|
|
|
create_note(issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
def after_reopen(issue, transition)
|
|
|
|
send_reassigned_email(issue) if issue.is_being_reassigned?
|
|
|
|
|
|
|
|
create_note(issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
def after_update(issue)
|
|
|
|
send_reassigned_email(issue) if issue.is_being_reassigned?
|
2012-05-20 14:25:34 -04:00
|
|
|
end
|
|
|
|
|
2012-06-20 21:23:05 -04:00
|
|
|
protected
|
|
|
|
|
2013-02-18 04:10:58 -05:00
|
|
|
def create_note(issue)
|
|
|
|
Note.create_status_change_note(issue, current_user, issue.state)
|
2013-01-16 19:05:44 -05:00
|
|
|
[issue.author, issue.assignee].compact.uniq.each do |recipient|
|
2013-02-18 04:10:58 -05:00
|
|
|
Notify.delay.issue_status_changed_email(recipient.id, issue.id, issue.state, current_user.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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
|