2012-10-09 18:25:29 -04:00
|
|
|
class NoteObserver < ActiveRecord::Observer
|
|
|
|
|
|
|
|
def after_create(note)
|
2012-10-13 16:46:27 -04:00
|
|
|
send_notify_mails(note)
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def send_notify_mails(note)
|
2012-10-09 18:25:29 -04:00
|
|
|
if note.notify
|
2012-10-13 16:46:27 -04:00
|
|
|
notify_team(note)
|
2012-10-09 18:25:29 -04:00
|
|
|
elsif note.notify_author
|
|
|
|
# Notify only author of resource
|
|
|
|
Notify.note_commit_email(note.commit_author.id, note.id).deliver
|
|
|
|
else
|
|
|
|
# Otherwise ignore it
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-13 16:46:27 -04:00
|
|
|
# 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 || "Wall"
|
|
|
|
notify_method = "note_#{noteable_type.underscore}_email".to_sym
|
2012-10-11 13:27:58 -04:00
|
|
|
|
|
|
|
if Notify.respond_to? notify_method
|
|
|
|
team_without_note_author(note).map do |u|
|
2012-10-13 16:46:27 -04:00
|
|
|
Notify.send(notify_method, u.id, note.id).deliver
|
2012-10-09 18:25:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def team_without_note_author(note)
|
|
|
|
note.project.users.reject { |u| u.id == note.author.id }
|
|
|
|
end
|
|
|
|
end
|