gitlab-org--gitlab-foss/app/observers/issue_observer.rb

43 lines
1.1 KiB
Ruby
Raw Normal View History

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
Notify.delay.new_issue_email(issue.id)
2012-06-26 14:47:25 -04:00
end
end
2013-02-18 04:10:58 -05:00
def after_close(issue, transition)
send_reassigned_email(issue) if issue.is_being_reassigned?
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?
end
protected
2013-02-18 04:10:58 -05:00
def create_note(issue)
Note.create_status_change_note(issue, current_user, issue.state)
[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
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 }
recipient_ids.each do |recipient_id|
Notify.delay.reassigned_issue_email(recipient_id, issue.id, issue.assignee_id_was)
end
end
end