邮件发送去除 observer, 一句代码的功能隐藏在别的文件里,很难注意到

This commit is contained in:
guange 2015-04-01 11:12:55 +08:00
parent 27e123f9fd
commit 89e0602983
12 changed files with 26 additions and 115 deletions

View File

@ -21,4 +21,11 @@ class Comment < ActiveRecord::Base
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
validates_presence_of :commented, :author, :comments
safe_attributes 'comments'
after_create :send_mail
def send_mail
if self.commented.is_a?(News) && Setting.notified_events.include?('news_comment_added')
Mailer.run.news_comment_added(self)
end
end
end

View File

@ -1,24 +0,0 @@
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class CommentObserver < ActiveRecord::Observer
def after_create(comment)
if comment.commented.is_a?(News) && Setting.notified_events.include?('news_comment_added')
Mailer.run.news_comment_added(comment)
end
end
end

View File

@ -24,6 +24,7 @@ class Document < ActiveRecord::Base
after_save :be_user_score # user_score
after_destroy :down_user_score
acts_as_attachable :delete_permission => :delete_documents
after_create :send_mail
# 被ForgeActivity虚拟关联
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
# end
@ -87,4 +88,8 @@ class Document < ActiveRecord::Base
:project_id => self.project_id)
end
def send_mail
Mailer.run.document_added(self) if Setting.notified_events.include?('document_added')
end
end

View File

@ -1,22 +0,0 @@
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class DocumentObserver < ActiveRecord::Observer
def after_create(document)
Mailer.run.document_added(document) if Setting.notified_events.include?('document_added')
end
end

View File

@ -20,7 +20,7 @@ class Forum < ActiveRecord::Base
after_destroy :delete_kindeditor_assets
acts_as_taggable
scope :by_join_date, order("created_at DESC")
#after_create :send_email
after_create :send_email
def reset_counters!
self.class.reset_counters!(id)
end

View File

@ -1,8 +0,0 @@
class ForumObserver < ActiveRecord::Observer
# def after_create(forum)
# Thread.start do
# Mailer.forum_add(forum).deliver if Setting.notified_events.include?('forum_add')
# end
#
# end
end

View File

@ -44,7 +44,7 @@ class Memo < ActiveRecord::Base
"parent_id",
"replies_count"
after_create :add_author_as_watcher, :reset_counters!, :sendmail
after_create :add_author_as_watcher, :reset_counters!, :send_mail
# after_update :update_memos_forum
after_destroy :reset_counters!,:delete_kindeditor_assets#,:down_user_score -- 公共区发帖暂不计入得分
# after_create :send_notification
@ -55,7 +55,7 @@ class Memo < ActiveRecord::Base
# includes(:forum => ).where()
# }
def sendmail
def send_mail
Mailer.run.forum_message_added(self) if Setting.notified_events.include?('forum_message_added')
end

View File

@ -1,6 +0,0 @@
class MemoObserver < ActiveRecord::Observer
def after_create(memo)
Mailer.run.forum_message_added(memo) if Setting.notified_events.include?('forum_message_added')
end
end

View File

@ -64,10 +64,8 @@ class Message < ActiveRecord::Base
after_update :update_messages_board
after_destroy :reset_counters!,:down_user_score
# fq
after_create :act_as_activity,:be_user_score,:act_as_forge_activity
after_create :act_as_activity,:be_user_score,:act_as_forge_activity, :send_mail
#before_save :be_user_score
# end
scope :visible, lambda {|*args|
includes(:board => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args))
@ -208,5 +206,9 @@ class Message < ActiveRecord::Base
end
end
def send_mail
Mailer.run.message_posted(self) if Setting.notified_events.include?('message_posted')
end
end

View File

@ -1,22 +0,0 @@
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class MessageObserver < ActiveRecord::Observer
def after_create(message)
Mailer.run.message_posted(message) if Setting.notified_events.include?('message_posted')
end
end

View File

@ -45,10 +45,7 @@ class News < ActiveRecord::Base
:author_key => :author_id
acts_as_watchable
after_create :add_author_as_watcher
# fq
after_create :act_as_activity,:act_as_forge_activity
# end
after_create :act_as_activity,:act_as_forge_activity,:add_author_as_watcher, :send_mail
scope :visible, lambda {|*args|
includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args))
@ -105,4 +102,8 @@ class News < ActiveRecord::Base
end
end
def send_mail
Mailer.run.news_added(news) if Setting.notified_events.include?('news_added')
end
end

View File

@ -1,22 +0,0 @@
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class NewsObserver < ActiveRecord::Observer
def after_create(news)
Mailer.run.news_added(news) if Setting.notified_events.include?('news_added')
end
end