@@ -0,0 +1,24 | |||
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | # | |
|
4 | # This program is free software; you can redistribute it and/or | |
|
5 | # modify it under the terms of the GNU General Public License | |
|
6 | # as published by the Free Software Foundation; either version 2 | |
|
7 | # of the License, or (at your option) any later version. | |
|
8 | # | |
|
9 | # This program is distributed in the hope that it will be useful, | |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
12 | # GNU General Public License for more details. | |
|
13 | # | |
|
14 | # You should have received a copy of the GNU General Public License | |
|
15 | # along with this program; if not, write to the Free Software | |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
|
17 | ||
|
18 | class CommentObserver < ActiveRecord::Observer | |
|
19 | def after_create(comment) | |
|
20 | if comment.commented.is_a?(News) && Setting.notified_events.include?('news_comment_added') | |
|
21 | Mailer.deliver_news_comment_added(comment) | |
|
22 | end | |
|
23 | end | |
|
24 | end |
@@ -0,0 +1,5 | |||
|
1 | <h1><%= link_to(h(@news.title), @news_url) %></h1> | |
|
2 | ||
|
3 | <p><%= l(:text_user_wrote, :value => h(@comment.author)) %></p> | |
|
4 | ||
|
5 | <%= textilizable @comment, :comments, :only_path => false %> |
@@ -0,0 +1,6 | |||
|
1 | <%= @news.title %> | |
|
2 | <%= @news_url %> | |
|
3 | ||
|
4 | <%= l(:text_user_wrote, :value => @comment.author) %> | |
|
5 | ||
|
6 | <%= @comment.comments %> |
@@ -1,5 +1,5 | |||
|
1 |
# |
|
|
2 | # Copyright (C) 2006 Jean-Philippe Lang | |
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
@@ -25,6 +25,8 class NewsController < ApplicationController | |||
|
25 | 25 | before_filter :find_optional_project, :only => :index |
|
26 | 26 | accept_key_auth :index |
|
27 | 27 | |
|
28 | helper :watchers | |
|
29 | ||
|
28 | 30 | def index |
|
29 | 31 | case params[:format] |
|
30 | 32 | when 'xml', 'json' |
@@ -1,5 +1,5 | |||
|
1 |
# |
|
|
2 |
# Copyright (C) 2006-20 |
|
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
@@ -148,6 +148,24 class Mailer < ActionMailer::Base | |||
|
148 | 148 | :news_url => url_for(:controller => 'news', :action => 'show', :id => news) |
|
149 | 149 | render_multipart('news_added', body) |
|
150 | 150 | end |
|
151 | ||
|
152 | # Builds a tmail object used to email recipients of a news' project when a news comment is added. | |
|
153 | # | |
|
154 | # Example: | |
|
155 | # news_comment_added(comment) => tmail object | |
|
156 | # Mailer.news_comment_added(comment) => sends an email to the news' project recipients | |
|
157 | def news_comment_added(comment) | |
|
158 | news = comment.commented | |
|
159 | redmine_headers 'Project' => news.project.identifier | |
|
160 | message_id comment | |
|
161 | recipients news.recipients | |
|
162 | cc news.watcher_recipients | |
|
163 | subject "Re: [#{news.project.name}] #{l(:label_news)}: #{news.title}" | |
|
164 | body :news => news, | |
|
165 | :comment => comment, | |
|
166 | :news_url => url_for(:controller => 'news', :action => 'show', :id => news) | |
|
167 | render_multipart('news_comment_added', body) | |
|
168 | end | |
|
151 | 169 | |
|
152 | 170 | # Builds a tmail object used to email the recipients of the specified message that was posted. |
|
153 | 171 | # |
@@ -1,5 +1,5 | |||
|
1 | 1 | # Redmine - project management software |
|
2 |
# Copyright (C) 2006-20 |
|
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
@@ -28,6 +28,9 class News < ActiveRecord::Base | |||
|
28 | 28 | acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}} |
|
29 | 29 | acts_as_activity_provider :find_options => {:include => [:project, :author]}, |
|
30 | 30 | :author_key => :author_id |
|
31 | acts_as_watchable | |
|
32 | ||
|
33 | after_create :add_author_as_watcher | |
|
31 | 34 | |
|
32 | 35 | named_scope :visible, lambda {|*args| { |
|
33 | 36 | :include => :project, |
@@ -42,4 +45,10 class News < ActiveRecord::Base | |||
|
42 | 45 | def self.latest(user = User.current, count = 5) |
|
43 | 46 | find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC") |
|
44 | 47 | end |
|
48 | ||
|
49 | private | |
|
50 | ||
|
51 | def add_author_as_watcher | |
|
52 | Watcher.create(:watchable => self, :user => author) | |
|
53 | end | |
|
45 | 54 | end |
@@ -1,4 +1,5 | |||
|
1 | 1 | <div class="contextual"> |
|
2 | <%= watcher_tag(@news, User.current) %> | |
|
2 | 3 | <%= link_to(l(:button_edit), |
|
3 | 4 | edit_news_path(@news), |
|
4 | 5 | :class => 'icon icon-edit', |
@@ -36,7 +36,7 Rails::Initializer.run do |config| | |||
|
36 | 36 | |
|
37 | 37 | # Activate observers that should always be running |
|
38 | 38 | # config.active_record.observers = :cacher, :garbage_collector |
|
39 | config.active_record.observers = :message_observer, :issue_observer, :journal_observer, :news_observer, :document_observer, :wiki_content_observer | |
|
39 | config.active_record.observers = :message_observer, :issue_observer, :journal_observer, :news_observer, :document_observer, :wiki_content_observer, :comment_observer | |
|
40 | 40 | |
|
41 | 41 | # Make Active Record use UTC-base instead of local time |
|
42 | 42 | # config.active_record.default_timezone = :utc |
@@ -537,6 +537,7 en: | |||
|
537 | 537 | label_news_latest: Latest news |
|
538 | 538 | label_news_view_all: View all news |
|
539 | 539 | label_news_added: News added |
|
540 | label_news_comment_added: Comment added to a news | |
|
540 | 541 | label_settings: Settings |
|
541 | 542 | label_overview: Overview |
|
542 | 543 | label_version: Version |
@@ -540,6 +540,7 fr: | |||
|
540 | 540 | label_news_latest: Dernières annonces |
|
541 | 541 | label_news_view_all: Voir toutes les annonces |
|
542 | 542 | label_news_added: Annonce ajoutée |
|
543 | label_news_comment_added: Commentaire ajouté à une annonce | |
|
543 | 544 | label_settings: Configuration |
|
544 | 545 | label_overview: Aperçu |
|
545 | 546 | label_version: Version |
@@ -14,6 +14,7 module Redmine | |||
|
14 | 14 | notifications << Notifiable.new('issue_status_updated', 'issue_updated') |
|
15 | 15 | notifications << Notifiable.new('issue_priority_updated', 'issue_updated') |
|
16 | 16 | notifications << Notifiable.new('news_added') |
|
17 | notifications << Notifiable.new('news_comment_added') | |
|
17 | 18 | notifications << Notifiable.new('document_added') |
|
18 | 19 | notifications << Notifiable.new('file_added') |
|
19 | 20 | notifications << Notifiable.new('message_posted') |
@@ -1,5 +1,5 | |||
|
1 |
# |
|
|
2 |
# Copyright (C) 2006-20 |
|
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
@@ -31,6 +31,15 class CommentTest < ActiveSupport::TestCase | |||
|
31 | 31 | @news.reload |
|
32 | 32 | assert_equal 2, @news.comments_count |
|
33 | 33 | end |
|
34 | ||
|
35 | def test_create_should_send_notification | |
|
36 | Setting.notified_events << 'news_comment_added' | |
|
37 | Watcher.create!(:watchable => @news, :user => @jsmith) | |
|
38 | ||
|
39 | assert_difference 'ActionMailer::Base.deliveries.size' do | |
|
40 | Comment.create!(:commented => @news, :author => @jsmith, :comments => "my comment") | |
|
41 | end | |
|
42 | end | |
|
34 | 43 | |
|
35 | 44 | def test_validate |
|
36 | 45 | comment = Comment.new(:commented => @news) |
@@ -1,5 +1,5 | |||
|
1 |
# |
|
|
2 |
# Copyright (C) 2006-20 |
|
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
@@ -22,9 +22,9 class Redmine::NotifiableTest < ActiveSupport::TestCase | |||
|
22 | 22 | end |
|
23 | 23 | |
|
24 | 24 | def test_all |
|
25 |
assert_equal 1 |
|
|
25 | assert_equal 12, Redmine::Notifiable.all.length | |
|
26 | 26 | |
|
27 | %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| | |
|
27 | %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| | |
|
28 | 28 | assert Redmine::Notifiable.all.collect(&:name).include?(notifiable), "missing #{notifiable}" |
|
29 | 29 | end |
|
30 | 30 | end |
@@ -1,5 +1,5 | |||
|
1 |
# |
|
|
2 |
# Copyright (C) 2006-20 |
|
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
@@ -20,7 +20,7 require File.expand_path('../../test_helper', __FILE__) | |||
|
20 | 20 | class MailerTest < ActiveSupport::TestCase |
|
21 | 21 | include Redmine::I18n |
|
22 | 22 | include ActionController::Assertions::SelectorAssertions |
|
23 | 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 | |
|
23 | fixtures :all | |
|
24 | 24 | |
|
25 | 25 | def setup |
|
26 | 26 | ActionMailer::Base.deliveries.clear |
@@ -295,6 +295,14 class MailerTest < ActiveSupport::TestCase | |||
|
295 | 295 | end |
|
296 | 296 | end |
|
297 | 297 | |
|
298 | def test_news_comment_added | |
|
299 | comment = Comment.find(2) | |
|
300 | valid_languages.each do |lang| | |
|
301 | Setting.default_language = lang.to_s | |
|
302 | assert Mailer.deliver_news_comment_added(comment) | |
|
303 | end | |
|
304 | end | |
|
305 | ||
|
298 | 306 | def test_message_posted |
|
299 | 307 | message = Message.find(:first) |
|
300 | 308 | recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author} |
General Comments 0
You need to be logged in to leave comments.
Login now