From 89e060298326a809b37e306eed133d656b654061 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Wed, 1 Apr 2015 11:12:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=20observer,=20=E4=B8=80=E5=8F=A5=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD=E9=9A=90=E8=97=8F=E5=9C=A8=E5=88=AB?= =?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6=E9=87=8C=EF=BC=8C=E5=BE=88=E9=9A=BE?= =?UTF-8?q?=E6=B3=A8=E6=84=8F=E5=88=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/comment.rb | 7 +++++++ app/models/comment_observer.rb | 24 ------------------------ app/models/document.rb | 5 +++++ app/models/document_observer.rb | 22 ---------------------- app/models/forum.rb | 2 +- app/models/forum_observer.rb | 8 -------- app/models/memo.rb | 4 ++-- app/models/memo_observer.rb | 6 ------ app/models/message.rb | 8 +++++--- app/models/message_observer.rb | 22 ---------------------- app/models/news.rb | 11 ++++++----- app/models/news_observer.rb | 22 ---------------------- 12 files changed, 26 insertions(+), 115 deletions(-) delete mode 100644 app/models/comment_observer.rb delete mode 100644 app/models/document_observer.rb delete mode 100644 app/models/forum_observer.rb delete mode 100644 app/models/memo_observer.rb delete mode 100644 app/models/message_observer.rb delete mode 100644 app/models/news_observer.rb diff --git a/app/models/comment.rb b/app/models/comment.rb index 539c62e85..68ce73432 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/app/models/comment_observer.rb b/app/models/comment_observer.rb deleted file mode 100644 index ff5b31446..000000000 --- a/app/models/comment_observer.rb +++ /dev/null @@ -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 diff --git a/app/models/document.rb b/app/models/document.rb index 33ffdaa2f..c8e5f8a24 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -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 diff --git a/app/models/document_observer.rb b/app/models/document_observer.rb deleted file mode 100644 index 72516916c..000000000 --- a/app/models/document_observer.rb +++ /dev/null @@ -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 diff --git a/app/models/forum.rb b/app/models/forum.rb index 0e664fded..15d78ab24 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -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 diff --git a/app/models/forum_observer.rb b/app/models/forum_observer.rb deleted file mode 100644 index 6afcac824..000000000 --- a/app/models/forum_observer.rb +++ /dev/null @@ -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 diff --git a/app/models/memo.rb b/app/models/memo.rb index e3e66d251..456736f2e 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -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 diff --git a/app/models/memo_observer.rb b/app/models/memo_observer.rb deleted file mode 100644 index 621dcf3d8..000000000 --- a/app/models/memo_observer.rb +++ /dev/null @@ -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 diff --git a/app/models/message.rb b/app/models/message.rb index 85a87132d..5d0da8fc3 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -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 diff --git a/app/models/message_observer.rb b/app/models/message_observer.rb deleted file mode 100644 index 1f438f77a..000000000 --- a/app/models/message_observer.rb +++ /dev/null @@ -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 diff --git a/app/models/news.rb b/app/models/news.rb index d2547fc02..9b88209c4 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -45,11 +45,8 @@ 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 diff --git a/app/models/news_observer.rb b/app/models/news_observer.rb deleted file mode 100644 index 12258e7ca..000000000 --- a/app/models/news_observer.rb +++ /dev/null @@ -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