summaryrefslogtreecommitdiff
path: root/app/observers
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-26 17:51:06 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-26 17:51:06 +0200
commit6abf58466fc47a7efd86a03c5b0b3878edfbce36 (patch)
tree791f03d51ddebbab7a07fbf6df59102f23ec968c /app/observers
parentf93c4dc0d83dd40452d40447a62cd68a08e24b09 (diff)
downloadgitlab-ce-6abf58466fc47a7efd86a03c5b0b3878edfbce36.tar.gz
Move new_note email logic to NotificationService
Diffstat (limited to 'app/observers')
-rw-r--r--app/observers/note_observer.rb33
-rw-r--r--app/observers/user_observer.rb7
2 files changed, 6 insertions, 34 deletions
diff --git a/app/observers/note_observer.rb b/app/observers/note_observer.rb
index 1c3c1ad31cf..944c68393ab 100644
--- a/app/observers/note_observer.rb
+++ b/app/observers/note_observer.rb
@@ -1,41 +1,10 @@
class NoteObserver < ActiveRecord::Observer
def after_create(note)
- send_notify_mails(note)
+ notification.new_note(note)
end
protected
- def send_notify_mails(note)
- if note.notify
- notify_team(note)
- elsif note.notify_author
- # Notify only author of resource
- if note.commit_author
- Notify.delay.note_commit_email(note.commit_author.id, note.id)
- end
- else
- # Otherwise ignore it
- nil
- end
- end
-
- # Notifies the whole team except the author of note
- def notify_team(note)
- # Note: wall posts are not "attached" to anything, so fall back to "Wall"
- noteable_type = note.noteable_type.presence || "Wall"
- notify_method = "note_#{noteable_type.underscore}_email".to_sym
-
- if Notify.respond_to? notify_method
- team_without_note_author(note).map do |u|
- Notify.delay.send(notify_method, u.id, note.id)
- end
- end
- end
-
- def team_without_note_author(note)
- note.project.users.reject { |u| u.id == note.author.id }
- end
-
def notification
NotificationService.new
end
diff --git a/app/observers/user_observer.rb b/app/observers/user_observer.rb
index 6c461e07865..7ce3be0c654 100644
--- a/app/observers/user_observer.rb
+++ b/app/observers/user_observer.rb
@@ -2,8 +2,7 @@ class UserObserver < ActiveRecord::Observer
def after_create(user)
log_info("User \"#{user.name}\" (#{user.email}) was created")
- # Dont email omniauth created users
- Notify.delay.new_user_email(user.id, user.password) unless user.extern_uid?
+ notification.new_user(user)
end
def after_destroy user
@@ -25,4 +24,8 @@ class UserObserver < ActiveRecord::Observer
def log_info message
Gitlab::AppLogger.info message
end
+
+ def notification
+ NotificationService.new
+ end
end