Commit 448152ab944aa1c74d01d0717f10267a978c1c7c

Authored by Dmitriy Zaporozhets
1 parent f7e630c4

Use NotificationService for observers pt1

app/observers/issue_observer.rb
@@ -2,41 +2,33 @@ class IssueObserver < ActiveRecord::Observer @@ -2,41 +2,33 @@ class IssueObserver < ActiveRecord::Observer
2 cattr_accessor :current_user 2 cattr_accessor :current_user
3 3
4 def after_create(issue) 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 end 6 end
9 7
10 def after_close(issue, transition) 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 create_note(issue) 11 create_note(issue)
14 end 12 end
15 13
16 def after_reopen(issue, transition) 14 def after_reopen(issue, transition)
17 - send_reassigned_email(issue) if issue.is_being_reassigned?  
18 -  
19 create_note(issue) 15 create_note(issue)
20 end 16 end
21 17
22 def after_update(issue) 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 end 22 end
25 23
26 protected 24 protected
27 25
  26 + # Create issue note with service comment like 'Status changed to closed'
28 def create_note(issue) 27 def create_note(issue)
29 Note.create_status_change_note(issue, current_user, issue.state) 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 end 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 end 33 end
42 end 34 end
app/observers/key_observer.rb
@@ -9,7 +9,7 @@ class KeyObserver < ActiveRecord::Observer @@ -9,7 +9,7 @@ class KeyObserver < ActiveRecord::Observer
9 ) 9 )
10 10
11 # Notify about ssh key being added 11 # Notify about ssh key being added
12 - Notify.delay.new_ssh_key_email(key.id) if key.user 12 + NotificationService.new.new_key(key)
13 end 13 end
14 14
15 def after_destroy(key) 15 def after_destroy(key)
app/observers/note_observer.rb
@@ -35,4 +35,8 @@ class NoteObserver < ActiveRecord::Observer @@ -35,4 +35,8 @@ class NoteObserver < ActiveRecord::Observer
35 def team_without_note_author(note) 35 def team_without_note_author(note)
36 note.project.users.reject { |u| u.id == note.author.id } 36 note.project.users.reject { |u| u.id == note.author.id }
37 end 37 end
  38 +
  39 + def notification
  40 + NotificationService.new
  41 + end
38 end 42 end