summaryrefslogtreecommitdiff
path: root/app/observers
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-26 09:47:40 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-26 10:48:06 +0200
commit448152ab944aa1c74d01d0717f10267a978c1c7c (patch)
treeced0d29f3100450e51f814dc085ddc37d4b28a5e /app/observers
parentf7e630c4528d0561466ede42d5e4820aa8b4d267 (diff)
downloadgitlab-ce-448152ab944aa1c74d01d0717f10267a978c1c7c.tar.gz
Use NotificationService for observers pt1
Diffstat (limited to 'app/observers')
-rw-r--r--app/observers/issue_observer.rb24
-rw-r--r--app/observers/key_observer.rb2
-rw-r--r--app/observers/note_observer.rb4
3 files changed, 13 insertions, 17 deletions
diff --git a/app/observers/issue_observer.rb b/app/observers/issue_observer.rb
index 29e24040378..7e8e9ccd490 100644
--- a/app/observers/issue_observer.rb
+++ b/app/observers/issue_observer.rb
@@ -2,41 +2,33 @@ class IssueObserver < ActiveRecord::Observer
cattr_accessor :current_user
def after_create(issue)
- if issue.assignee && issue.assignee != current_user
- Notify.delay.new_issue_email(issue.id)
- end
+ notification.new_issue(issue, current_user)
end
def after_close(issue, transition)
- send_reassigned_email(issue) if issue.is_being_reassigned?
+ notification.close_issue(issue, current_user)
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?
+ if issue.is_being_reassigned?
+ notification.reassigned_issue(issue, current_user)
+ end
end
protected
+ # Create issue note with service comment like 'Status changed to closed'
def create_note(issue)
Note.create_status_change_note(issue, current_user, issue.state)
- [issue.author, issue.assignee].compact.uniq.each do |recipient|
- Notify.delay.issue_status_changed_email(recipient.id, issue.id, issue.state, current_user.id)
- end
end
- def send_reassigned_email(issue)
- 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
+ def notification
+ NotificationService.new
end
end
diff --git a/app/observers/key_observer.rb b/app/observers/key_observer.rb
index 0bc71a663e8..2a69b876920 100644
--- a/app/observers/key_observer.rb
+++ b/app/observers/key_observer.rb
@@ -9,7 +9,7 @@ class KeyObserver < ActiveRecord::Observer
)
# Notify about ssh key being added
- Notify.delay.new_ssh_key_email(key.id) if key.user
+ NotificationService.new.new_key(key)
end
def after_destroy(key)
diff --git a/app/observers/note_observer.rb b/app/observers/note_observer.rb
index 0f820a263b3..1c3c1ad31cf 100644
--- a/app/observers/note_observer.rb
+++ b/app/observers/note_observer.rb
@@ -35,4 +35,8 @@ class NoteObserver < ActiveRecord::Observer
def team_without_note_author(note)
note.project.users.reject { |u| u.id == note.author.id }
end
+
+ def notification
+ NotificationService.new
+ end
end