diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-05-14 17:03:59 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-05-14 17:03:59 +0000 |
commit | 7ca7e4bad5037067c1a8cd653eed095372e7f772 (patch) | |
tree | 64d867e8daaebf1364ab1b0293ed3e88638effc0 | |
parent | bca5bd9c62769ca85f00259ac0e9a3c4538f7051 (diff) | |
download | redmine-7ca7e4bad5037067c1a8cd653eed095372e7f772.tar.gz redmine-7ca7e4bad5037067c1a8cd653eed095372e7f772.zip |
Added mail notification when a new message is posted in the forums.
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
-rw-r--r-- | app/models/mailer.rb | 8 | ||||
-rw-r--r-- | app/models/message_observer.rb | 24 | ||||
-rw-r--r-- | app/views/mailer/message_posted.rhtml | 4 | ||||
-rw-r--r-- | config/environment.rb | 3 | ||||
-rw-r--r-- | vendor/plugins/gloc-1.1.0/lib/gloc-rails.rb | 3 |
5 files changed, 40 insertions, 2 deletions
diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 5d835289a..41b5a3291 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -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 index 000000000..a3db7c867 --- /dev/null +++ b/app/models/message_observer.rb @@ -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 index 000000000..10b46c41e --- /dev/null +++ b/app/views/mailer/message_posted.rhtml @@ -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 %> diff --git a/config/environment.rb b/config/environment.rb index e5e7d0e4b..7782e6ad6 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -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 diff --git a/vendor/plugins/gloc-1.1.0/lib/gloc-rails.rb b/vendor/plugins/gloc-1.1.0/lib/gloc-rails.rb index 006d8976a..8f201bcb8 100644 --- a/vendor/plugins/gloc-1.1.0/lib/gloc-rails.rb +++ b/vendor/plugins/gloc-1.1.0/lib/gloc-rails.rb @@ -92,7 +92,8 @@ module ActionMailer #:nodoc: private
alias :render_message_without_gloc :render_message
def render_message(method_name, body)
- render_message_without_gloc("#{method_name}_#{current_language}", body)
+ template = File.exist?("#{template_path}/#{method_name}_#{current_language}.rhtml") ? "#{method_name}_#{current_language}" : "#{method_name}"
+ render_message_without_gloc(template, body)
end
end
end
|