]> source.dussan.org Git - redmine.git/commitdiff
Added mail notification when a new message is posted in the forums.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 14 May 2007 17:03:59 +0000 (17:03 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 14 May 2007 17:03:59 +0000 (17:03 +0000)
Only users who "watch" the board receive notifications. To watch a board, go to the board and click on the "Watch" link.

Notifications are sent by MessageObserver observer.
GLoc was modified to use the mail template without language suffix when translated template (with language suffix) doesn't exist.
Usefull when there's no hard coded text in the mail tempate.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@531 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/mailer.rb
app/models/message_observer.rb [new file with mode: 0644]
app/views/mailer/message_posted.rhtml [new file with mode: 0644]
config/environment.rb
vendor/plugins/gloc-1.1.0/lib/gloc-rails.rb

index 5d835289aae962b2240a93b769fe5582dfcfcf23..41b5a329194b083337fd0d768feeab88acf25849 100644 (file)
@@ -87,4 +87,12 @@ class Mailer < ActionMailer::Base
     @subject        = l(:mail_subject_register)
     @body['token']  = token
   end
+  
+  def message_posted(message, recipients)
+    set_language_if_valid(Setting.default_language)
+    @recipients     = recipients
+    @from           = Setting.mail_from
+    @subject        = "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
+    @body['message'] = message
+  end
 end
diff --git a/app/models/message_observer.rb b/app/models/message_observer.rb
new file mode 100644 (file)
index 0000000..a3db7c8
--- /dev/null
@@ -0,0 +1,24 @@
+# redMine - project management software
+# Copyright (C) 2006-2007  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)
+    # send notification to board watchers
+    recipients = message.board.watcher_recipients
+    Mailer.deliver_message_posted(message, recipients) unless recipients.empty?
+  end
+end
diff --git a/app/views/mailer/message_posted.rhtml b/app/views/mailer/message_posted.rhtml
new file mode 100644 (file)
index 0000000..10b46c4
--- /dev/null
@@ -0,0 +1,4 @@
+<%= l(:field_author) %>: <%= @message.author.name %>
+<%= url_for :only_path => false, :host => Setting.host_name, :controller => 'messages', :action => 'show', :board_id => @message.board_id, :id => @message.root %>
+
+<%= @message.content %>
index e5e7d0e4b1c0c5f206f0ee7bb76db961b37196d6..7782e6ad6fc79d38527cdbcf1fbe61054e5ad4ef 100644 (file)
@@ -27,9 +27,10 @@ Rails::Initializer.run do |config|
   # Enable page/fragment caching by setting a file-based store
   # (remember to create the caching directory and make it readable to the application)
   # config.action_controller.fragment_cache_store = :file_store, "#{RAILS_ROOT}/cache"
-
+  
   # Activate observers that should always be running
   # config.active_record.observers = :cacher, :garbage_collector
+  config.active_record.observers = :message_observer
 
   # Make Active Record use UTC-base instead of local time
   # config.active_record.default_timezone = :utc
index 006d8976ab42f20a0b3eeb09ac7089bc2e62de38..8f201bcb89aa01ea1f53c3782b3db2ac699036fb 100644 (file)
@@ -92,7 +92,8 @@ module ActionMailer #:nodoc:
     private\r
     alias :render_message_without_gloc :render_message\r
     def render_message(method_name, body)\r
-      render_message_without_gloc("#{method_name}_#{current_language}", body)\r
+      template = File.exist?("#{template_path}/#{method_name}_#{current_language}.rhtml") ? "#{method_name}_#{current_language}" : "#{method_name}"\r
+      render_message_without_gloc(template, body)\r
     end\r
   end\r
 end\r