issue_observer.rb 773 Bytes
Newer Older
Robb Kidd's avatar
Robb Kidd committed
1
2
3
4
class IssueObserver < ActiveRecord::Observer
  cattr_accessor :current_user

  def after_create(issue)
Robb Kidd's avatar
Robb Kidd committed
5
    Notify.new_issue_email(issue.id).deliver if issue.assignee != current_user
Robb Kidd's avatar
Robb Kidd committed
6
7
  end

8
  def after_update(issue)
9
    send_reassigned_email(issue) if issue.is_being_reassigned?
10
    Note.create_status_change_note(issue, current_user, 'closed') if issue.is_being_closed?
11
    Note.create_status_change_note(issue, current_user, 'reopened') if issue.is_being_reopened?
12
13
  end

14
15
  protected

16
17
  def send_reassigned_email(issue)
    recipient_ids = [issue.assignee_id, issue.assignee_id_was].keep_if {|id| id != current_user.id }
Robb Kidd's avatar
Robb Kidd committed
18

19
    recipient_ids.each do |recipient_id|
Robb Kidd's avatar
Robb Kidd committed
20
      Notify.reassigned_issue_email(recipient_id, issue.id, issue.assignee_id_was).deliver
Robb Kidd's avatar
Robb Kidd committed
21
22
23
    end
  end
end