-# redMine - project management software
-# Copyright (C) 2006 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011 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
before_filter :find_optional_project, :only => :index
accept_key_auth :index
+ helper :watchers
+
def index
case params[:format]
when 'xml', 'json'
--- /dev/null
+# Redmine - project management software
+# Copyright (C) 2006-2011 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.deliver_news_comment_added(comment)
+ end
+ end
+end
-# redMine - project management software
-# Copyright (C) 2006-2007 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011 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
:news_url => url_for(:controller => 'news', :action => 'show', :id => news)
render_multipart('news_added', body)
end
+
+ # Builds a tmail object used to email recipients of a news' project when a news comment is added.
+ #
+ # Example:
+ # news_comment_added(comment) => tmail object
+ # Mailer.news_comment_added(comment) => sends an email to the news' project recipients
+ def news_comment_added(comment)
+ news = comment.commented
+ redmine_headers 'Project' => news.project.identifier
+ message_id comment
+ recipients news.recipients
+ cc news.watcher_recipients
+ subject "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}"
+ body :news => news,
+ :comment => comment,
+ :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
+ render_multipart('news_comment_added', body)
+ end
# Builds a tmail object used to email the recipients of the specified message that was posted.
#
# Redmine - project management software
-# Copyright (C) 2006-2008 Jean-Philippe Lang
+# Copyright (C) 2006-2011 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
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
acts_as_activity_provider :find_options => {:include => [:project, :author]},
:author_key => :author_id
+ acts_as_watchable
+
+ after_create :add_author_as_watcher
named_scope :visible, lambda {|*args| {
:include => :project,
def self.latest(user = User.current, count = 5)
find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
end
+
+ private
+
+ def add_author_as_watcher
+ Watcher.create(:watchable => self, :user => author)
+ end
end
--- /dev/null
+<h1><%= link_to(h(@news.title), @news_url) %></h1>
+
+<p><%= l(:text_user_wrote, :value => h(@comment.author)) %></p>
+
+<%= textilizable @comment, :comments, :only_path => false %>
--- /dev/null
+<%= @news.title %>
+<%= @news_url %>
+
+<%= l(:text_user_wrote, :value => @comment.author) %>
+
+<%= @comment.comments %>
<div class="contextual">
+<%= watcher_tag(@news, User.current) %>
<%= link_to(l(:button_edit),
edit_news_path(@news),
:class => 'icon icon-edit',
# Activate observers that should always be running
# config.active_record.observers = :cacher, :garbage_collector
- config.active_record.observers = :message_observer, :issue_observer, :journal_observer, :news_observer, :document_observer, :wiki_content_observer
+ config.active_record.observers = :message_observer, :issue_observer, :journal_observer, :news_observer, :document_observer, :wiki_content_observer, :comment_observer
# Make Active Record use UTC-base instead of local time
# config.active_record.default_timezone = :utc
label_news_latest: Latest news
label_news_view_all: View all news
label_news_added: News added
+ label_news_comment_added: Comment added to a news
label_settings: Settings
label_overview: Overview
label_version: Version
label_news_latest: Dernières annonces
label_news_view_all: Voir toutes les annonces
label_news_added: Annonce ajoutée
+ label_news_comment_added: Commentaire ajouté à une annonce
label_settings: Configuration
label_overview: Aperçu
label_version: Version
notifications << Notifiable.new('issue_status_updated', 'issue_updated')
notifications << Notifiable.new('issue_priority_updated', 'issue_updated')
notifications << Notifiable.new('news_added')
+ notifications << Notifiable.new('news_comment_added')
notifications << Notifiable.new('document_added')
notifications << Notifiable.new('file_added')
notifications << Notifiable.new('message_posted')
-# redMine - project management software
-# Copyright (C) 2006-2007 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011 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
@news.reload
assert_equal 2, @news.comments_count
end
+
+ def test_create_should_send_notification
+ Setting.notified_events << 'news_comment_added'
+ Watcher.create!(:watchable => @news, :user => @jsmith)
+
+ assert_difference 'ActionMailer::Base.deliveries.size' do
+ Comment.create!(:commented => @news, :author => @jsmith, :comments => "my comment")
+ end
+ end
def test_validate
comment = Comment.new(:commented => @news)
-# redMine - project management software
-# Copyright (C) 2006-2008 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011 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
end
def test_all
- assert_equal 11, Redmine::Notifiable.all.length
+ assert_equal 12, Redmine::Notifiable.all.length
- %w(issue_added issue_updated issue_note_added issue_status_updated issue_priority_updated news_added document_added file_added message_posted wiki_content_added wiki_content_updated).each do |notifiable|
+ %w(issue_added issue_updated issue_note_added issue_status_updated issue_priority_updated news_added news_comment_added document_added file_added message_posted wiki_content_added wiki_content_updated).each do |notifiable|
assert Redmine::Notifiable.all.collect(&:name).include?(notifiable), "missing #{notifiable}"
end
end
-# redMine - project management software
-# Copyright (C) 2006-2007 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011 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
class MailerTest < ActiveSupport::TestCase
include Redmine::I18n
include ActionController::Assertions::SelectorAssertions
- fixtures :projects, :enabled_modules, :issues, :users, :members, :member_roles, :roles, :documents, :attachments, :news, :tokens, :journals, :journal_details, :changesets, :trackers, :issue_statuses, :enumerations, :messages, :boards, :repositories
+ fixtures :all
def setup
ActionMailer::Base.deliveries.clear
end
end
+ def test_news_comment_added
+ comment = Comment.find(2)
+ valid_languages.each do |lang|
+ Setting.default_language = lang.to_s
+ assert Mailer.deliver_news_comment_added(comment)
+ end
+ end
+
def test_message_posted
message = Message.find(:first)
recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}