##// END OF EJS Templates
Adds email notifications support for news comments (#2074)....
Jean-Philippe Lang -
r4883:36009de154e0
parent child
Show More
@@ -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 # redMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
@@ -25,6 +25,8 class NewsController < ApplicationController
25 before_filter :find_optional_project, :only => :index
25 before_filter :find_optional_project, :only => :index
26 accept_key_auth :index
26 accept_key_auth :index
27
27
28 helper :watchers
29
28 def index
30 def index
29 case params[:format]
31 case params[:format]
30 when 'xml', 'json'
32 when 'xml', 'json'
@@ -1,5 +1,5
1 # redMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
@@ -148,6 +148,24 class Mailer < ActionMailer::Base
148 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
148 :news_url => url_for(:controller => 'news', :action => 'show', :id => news)
149 render_multipart('news_added', body)
149 render_multipart('news_added', body)
150 end
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 # Builds a tmail object used to email the recipients of the specified message that was posted.
170 # Builds a tmail object used to email the recipients of the specified message that was posted.
153 #
171 #
@@ -1,5 +1,5
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
@@ -28,6 +28,9 class News < ActiveRecord::Base
28 acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
28 acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
29 acts_as_activity_provider :find_options => {:include => [:project, :author]},
29 acts_as_activity_provider :find_options => {:include => [:project, :author]},
30 :author_key => :author_id
30 :author_key => :author_id
31 acts_as_watchable
32
33 after_create :add_author_as_watcher
31
34
32 named_scope :visible, lambda {|*args| {
35 named_scope :visible, lambda {|*args| {
33 :include => :project,
36 :include => :project,
@@ -42,4 +45,10 class News < ActiveRecord::Base
42 def self.latest(user = User.current, count = 5)
45 def self.latest(user = User.current, count = 5)
43 find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
46 find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
44 end
47 end
48
49 private
50
51 def add_author_as_watcher
52 Watcher.create(:watchable => self, :user => author)
53 end
45 end
54 end
@@ -1,4 +1,5
1 <div class="contextual">
1 <div class="contextual">
2 <%= watcher_tag(@news, User.current) %>
2 <%= link_to(l(:button_edit),
3 <%= link_to(l(:button_edit),
3 edit_news_path(@news),
4 edit_news_path(@news),
4 :class => 'icon icon-edit',
5 :class => 'icon icon-edit',
@@ -36,7 +36,7 Rails::Initializer.run do |config|
36
36
37 # Activate observers that should always be running
37 # Activate observers that should always be running
38 # config.active_record.observers = :cacher, :garbage_collector
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 # Make Active Record use UTC-base instead of local time
41 # Make Active Record use UTC-base instead of local time
42 # config.active_record.default_timezone = :utc
42 # config.active_record.default_timezone = :utc
@@ -537,6 +537,7 en:
537 label_news_latest: Latest news
537 label_news_latest: Latest news
538 label_news_view_all: View all news
538 label_news_view_all: View all news
539 label_news_added: News added
539 label_news_added: News added
540 label_news_comment_added: Comment added to a news
540 label_settings: Settings
541 label_settings: Settings
541 label_overview: Overview
542 label_overview: Overview
542 label_version: Version
543 label_version: Version
@@ -540,6 +540,7 fr:
540 label_news_latest: Dernières annonces
540 label_news_latest: Dernières annonces
541 label_news_view_all: Voir toutes les annonces
541 label_news_view_all: Voir toutes les annonces
542 label_news_added: Annonce ajoutée
542 label_news_added: Annonce ajoutée
543 label_news_comment_added: Commentaire ajouté à une annonce
543 label_settings: Configuration
544 label_settings: Configuration
544 label_overview: Aperçu
545 label_overview: Aperçu
545 label_version: Version
546 label_version: Version
@@ -14,6 +14,7 module Redmine
14 notifications << Notifiable.new('issue_status_updated', 'issue_updated')
14 notifications << Notifiable.new('issue_status_updated', 'issue_updated')
15 notifications << Notifiable.new('issue_priority_updated', 'issue_updated')
15 notifications << Notifiable.new('issue_priority_updated', 'issue_updated')
16 notifications << Notifiable.new('news_added')
16 notifications << Notifiable.new('news_added')
17 notifications << Notifiable.new('news_comment_added')
17 notifications << Notifiable.new('document_added')
18 notifications << Notifiable.new('document_added')
18 notifications << Notifiable.new('file_added')
19 notifications << Notifiable.new('file_added')
19 notifications << Notifiable.new('message_posted')
20 notifications << Notifiable.new('message_posted')
@@ -1,5 +1,5
1 # redMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
@@ -31,6 +31,15 class CommentTest < ActiveSupport::TestCase
31 @news.reload
31 @news.reload
32 assert_equal 2, @news.comments_count
32 assert_equal 2, @news.comments_count
33 end
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 def test_validate
44 def test_validate
36 comment = Comment.new(:commented => @news)
45 comment = Comment.new(:commented => @news)
@@ -1,5 +1,5
1 # redMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
@@ -22,9 +22,9 class Redmine::NotifiableTest < ActiveSupport::TestCase
22 end
22 end
23
23
24 def test_all
24 def test_all
25 assert_equal 11, Redmine::Notifiable.all.length
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 assert Redmine::Notifiable.all.collect(&:name).include?(notifiable), "missing #{notifiable}"
28 assert Redmine::Notifiable.all.collect(&:name).include?(notifiable), "missing #{notifiable}"
29 end
29 end
30 end
30 end
@@ -1,5 +1,5
1 # redMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
@@ -20,7 +20,7 require File.expand_path('../../test_helper', __FILE__)
20 class MailerTest < ActiveSupport::TestCase
20 class MailerTest < ActiveSupport::TestCase
21 include Redmine::I18n
21 include Redmine::I18n
22 include ActionController::Assertions::SelectorAssertions
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 def setup
25 def setup
26 ActionMailer::Base.deliveries.clear
26 ActionMailer::Base.deliveries.clear
@@ -295,6 +295,14 class MailerTest < ActiveSupport::TestCase
295 end
295 end
296 end
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 def test_message_posted
306 def test_message_posted
299 message = Message.find(:first)
307 message = Message.find(:first)
300 recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author}
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