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
|
2013-01-09 06:44:05 +01:00
|
|
|
Notify.delay.new_issue_email(issue.id)
|
2012-06-26 20:47:25 +02:00
|
|
|
end
|
2012-05-17 23:23:34 +02:00
|
|
|
end
|
|
|
|
|
2013-02-18 10:10:58 +01:00
|
|
|
def after_close(issue, transition)
|
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
|
|
|
|
2013-02-18 10:10:58 +01: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 20:25:34 +02:00
|
|
|
end
|
|
|
|
|
2012-06-21 03:23:05 +02:00
|
|
|
protected
|
|
|
|
|
2013-02-18 10:10:58 +01:00
|
|
|
def create_note(issue)
|
|
|
|
Note.create_status_change_note(issue, current_user, issue.state)
|
|
|
|
[issue.author, issue.assignee].compact.each do |recipient|
|
|
|
|
Notify.delay.issue_status_changed_email(recipient.id, issue.id, issue.state, current_user.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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|
|
2013-01-09 06:44:05 +01:00
|
|
|
Notify.delay.reassigned_issue_email(recipient_id, issue.id, issue.assignee_id_was)
|
2012-05-17 23:23:34 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|