issue_observer.rb 997 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)
randx's avatar
randx committed
5
    if issue.assignee && issue.assignee != current_user
6
      Notify.delay.new_issue_email(issue.id)
randx's avatar
randx committed
7
    end
Robb Kidd's avatar
Robb Kidd committed
8
9
  end

10
  def after_update(issue)
11
    send_reassigned_email(issue) if issue.is_being_reassigned?
12

13
14
15
16
    status = nil
    status = 'closed' if issue.is_being_closed?
    status = 'reopened' if issue.is_being_reopened?
    if status
17
18
      Note.create_status_change_note(issue, current_user, status)
      [issue.author, issue.assignee].compact.each do |recipient|
19
        Notify.delay.issue_status_changed_email(recipient.id, issue.id, status, current_user.id)
20
21
      end
    end
22
23
  end

24
25
  protected

26
  def send_reassigned_email(issue)
randx's avatar
randx committed
27
    recipient_ids = [issue.assignee_id, issue.assignee_id_was].keep_if {|id| id && id != current_user.id }
Robb Kidd's avatar
Robb Kidd committed
28

29
    recipient_ids.each do |recipient_id|
30
      Notify.delay.reassigned_issue_email(recipient_id, issue.id, issue.assignee_id_was)
Robb Kidd's avatar
Robb Kidd committed
31
32
33
    end
  end
end