validates_presence_of :commented, :author, :comments
+ after_create :send_notification
+
safe_attributes 'comments'
+
+ private
+
+ def send_notification
+ if commented.is_a?(News) && Setting.notified_events.include?('news_comment_added')
+ Mailer.news_comment_added(self).deliver
+ end
+ end
end
+++ /dev/null
-# 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.news_comment_added(comment).deliver
- end
- end
-end
validates_presence_of :project, :title, :category
validates_length_of :title, :maximum => 60
+ after_create :send_notification
+
scope :visible, lambda {|*args|
includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_documents, *args))
}
end
@updated_on
end
+
+ private
+
+ def send_notification
+ if Setting.notified_events.include?('document_added')
+ Mailer.document_added(self).deliver
+ end
+ end
end
+++ /dev/null
-# 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.document_added(document).deliver if Setting.notified_events.include?('document_added')
- end
-end
# Should be after_create but would be called before previous after_save callbacks
after_save :after_create_from_copy
after_destroy :update_parent_attributes
+ after_create :send_notification
# Returns a SQL conditions string used to find all issues visible by the specified user
def self.visible_condition(user, options={})
end
end
+ def send_notification
+ if Setting.notified_events.include?('issue_added')
+ Mailer.deliver_issue_add(self)
+ end
+ end
+
# Query generator for selecting groups of issue counts for a project
# based on specific criteria
#
+++ /dev/null
-# 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 IssueObserver < ActiveRecord::Observer
- def after_create(issue)
- Mailer.deliver_issue_add(issue) if Setting.notified_events.include?('issue_added')
- end
-end
" (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
before_create :split_private_notes
+ after_create :send_notification
scope :visible, lambda {|*args|
user = args.shift || User.current
end
true
end
+
+ def send_notification
+ if notify? && (Setting.notified_events.include?('issue_updated') ||
+ (Setting.notified_events.include?('issue_note_added') && notes.present?) ||
+ (Setting.notified_events.include?('issue_status_updated') && new_status.present?) ||
+ (Setting.notified_events.include?('issue_priority_updated') && new_value_for('priority_id').present?)
+ )
+ Mailer.deliver_issue_edit(self)
+ end
+ end
end
+++ /dev/null
-# 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 JournalObserver < ActiveRecord::Observer
- def after_create(journal)
- if journal.notify? &&
- (Setting.notified_events.include?('issue_updated') ||
- (Setting.notified_events.include?('issue_note_added') && journal.notes.present?) ||
- (Setting.notified_events.include?('issue_status_updated') && journal.new_status.present?) ||
- (Setting.notified_events.include?('issue_priority_updated') && journal.new_value_for('priority_id').present?)
- )
- Mailer.deliver_issue_edit(journal)
- end
- end
-end
after_create :add_author_as_watcher, :reset_counters!
after_update :update_messages_board
after_destroy :reset_counters!
+ after_create :send_notification
scope :visible, lambda {|*args|
includes(:board => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args))
def add_author_as_watcher
Watcher.create(:watchable => self.root, :user => author)
end
+
+ def send_notification
+ if Setting.notified_events.include?('message_posted')
+ Mailer.message_posted(self).deliver
+ end
+ end
end
+++ /dev/null
-# 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.message_posted(message).deliver if Setting.notified_events.include?('message_posted')
- end
-end
acts_as_watchable
after_create :add_author_as_watcher
+ after_create :send_notification
scope :visible, lambda {|*args|
includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args))
def add_author_as_watcher
Watcher.create(:watchable => self, :user => author)
end
+
+ def send_notification
+ if Setting.notified_events.include?('news_added')
+ Mailer.news_added(self).deliver
+ end
+ end
end
+++ /dev/null
-# 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.news_added(news).deliver if Setting.notified_events.include?('news_added')
- end
-end
acts_as_versioned
+ after_save :send_notification
+
def visible?(user=User.current)
page.visible?(user)
end
end
end
end
+
+ private
+
+ def send_notification
+ # new_record? returns false in after_save callbacks
+ if id_changed?
+ if Setting.notified_events.include?('wiki_content_added')
+ Mailer.wiki_content_added(self).deliver
+ end
+ elsif text_changed?
+ if Setting.notified_events.include?('wiki_content_updated')
+ Mailer.wiki_content_updated(self).deliver
+ end
+ end
+ end
end
+++ /dev/null
-# 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 WikiContentObserver < ActiveRecord::Observer
- def after_create(wiki_content)
- Mailer.wiki_content_added(wiki_content).deliver if Setting.notified_events.include?('wiki_content_added')
- end
-
- def after_update(wiki_content)
- if wiki_content.text_changed?
- Mailer.wiki_content_updated(wiki_content).deliver if Setting.notified_events.include?('wiki_content_updated')
- end
- end
-end
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
- # Activate observers that should always be running.
- config.active_record.observers = :message_observer, :issue_observer, :journal_observer, :news_observer, :document_observer, :wiki_content_observer, :comment_observer
-
config.active_record.store_full_sti_class = true
config.active_record.default_timezone = :local
page = WikiPage.new(:wiki => @wiki, :title => "A new page")
page.content = WikiContent.new(:text => "Content text", :author => User.find(1), :comments => "My comment")
- with_settings :notified_events => %w(wiki_content_added) do
+ with_settings :default_language => 'en', :notified_events => %w(wiki_content_added) do
assert page.save
end
assert_equal 1, ActionMailer::Base.deliveries.size
+ assert_include 'wiki page has been added', mail_body(ActionMailer::Base.deliveries.last)
end
def test_update_should_be_versioned
end
assert_equal 1, ActionMailer::Base.deliveries.size
+ assert_include 'wiki page has been updated', mail_body(ActionMailer::Base.deliveries.last)
end
def test_fetch_history