Commit 448152ab944aa1c74d01d0717f10267a978c1c7c
1 parent
f7e630c4
Exists in
master
and in
4 other branches
Use NotificationService for observers pt1
Showing
3 changed files
with
13 additions
and
17 deletions
Show diff stats
app/observers/issue_observer.rb
... | ... | @@ -2,41 +2,33 @@ class IssueObserver < ActiveRecord::Observer |
2 | 2 | cattr_accessor :current_user |
3 | 3 | |
4 | 4 | def after_create(issue) |
5 | - if issue.assignee && issue.assignee != current_user | |
6 | - Notify.delay.new_issue_email(issue.id) | |
7 | - end | |
5 | + notification.new_issue(issue, current_user) | |
8 | 6 | end |
9 | 7 | |
10 | 8 | def after_close(issue, transition) |
11 | - send_reassigned_email(issue) if issue.is_being_reassigned? | |
9 | + notification.close_issue(issue, current_user) | |
12 | 10 | |
13 | 11 | create_note(issue) |
14 | 12 | end |
15 | 13 | |
16 | 14 | def after_reopen(issue, transition) |
17 | - send_reassigned_email(issue) if issue.is_being_reassigned? | |
18 | - | |
19 | 15 | create_note(issue) |
20 | 16 | end |
21 | 17 | |
22 | 18 | def after_update(issue) |
23 | - send_reassigned_email(issue) if issue.is_being_reassigned? | |
19 | + if issue.is_being_reassigned? | |
20 | + notification.reassigned_issue(issue, current_user) | |
21 | + end | |
24 | 22 | end |
25 | 23 | |
26 | 24 | protected |
27 | 25 | |
26 | + # Create issue note with service comment like 'Status changed to closed' | |
28 | 27 | def create_note(issue) |
29 | 28 | Note.create_status_change_note(issue, current_user, issue.state) |
30 | - [issue.author, issue.assignee].compact.uniq.each do |recipient| | |
31 | - Notify.delay.issue_status_changed_email(recipient.id, issue.id, issue.state, current_user.id) | |
32 | - end | |
33 | 29 | end |
34 | 30 | |
35 | - def send_reassigned_email(issue) | |
36 | - recipient_ids = [issue.assignee_id, issue.assignee_id_was].keep_if {|id| id && id != current_user.id } | |
37 | - | |
38 | - recipient_ids.each do |recipient_id| | |
39 | - Notify.delay.reassigned_issue_email(recipient_id, issue.id, issue.assignee_id_was) | |
40 | - end | |
31 | + def notification | |
32 | + NotificationService.new | |
41 | 33 | end |
42 | 34 | end | ... | ... |
app/observers/key_observer.rb
app/observers/note_observer.rb