Commit 444059a16ace054d94c38435dfab05fae27220a1
Committed by
Daniela Feitosa
1 parent
b37c7bda
Exists in
master
and in
29 other branches
Notify exceptions by email
- new config entry 'exception_recipients' in noosfero.yml (ActionItem1808)
Showing
6 changed files
with
57 additions
and
3 deletions
Show diff stats
INSTALL
| @@ -215,6 +215,24 @@ At this point you have a functional Noosfero installation running, the only | @@ -215,6 +215,24 @@ At this point you have a functional Noosfero installation running, the only | ||
| 215 | thing left is to configure your webserver as a reverse proxy to pass requests | 215 | thing left is to configure your webserver as a reverse proxy to pass requests |
| 216 | to them. | 216 | to them. |
| 217 | 217 | ||
| 218 | +Enabling exception notifications | ||
| 219 | +================================ | ||
| 220 | + | ||
| 221 | +This is an optional step. You will need it only if you want to receive e-mail | ||
| 222 | +notifications when some exception occurs on Noosfero. | ||
| 223 | + | ||
| 224 | +First, install this version of the gem. | ||
| 225 | +Others versions may not be compatible with Noosfero: | ||
| 226 | + | ||
| 227 | +# gem install exception_notification -v 1.0.20090728 | ||
| 228 | + | ||
| 229 | +You can configure the e-mails that will receive the notifications. | ||
| 230 | +Change the file config/noosfero.yml as the following example, replacing the | ||
| 231 | +e-mails by real ones: | ||
| 232 | + | ||
| 233 | + production: | ||
| 234 | + exception_recipients: [admin@example.com, you@example.com] | ||
| 235 | + | ||
| 218 | ================== | 236 | ================== |
| 219 | Apache instalation | 237 | Apache instalation |
| 220 | ================== | 238 | ================== |
| @@ -224,7 +242,7 @@ Apache instalation | @@ -224,7 +242,7 @@ Apache instalation | ||
| 224 | Apache configuration | 242 | Apache configuration |
| 225 | -------------------- | 243 | -------------------- |
| 226 | 244 | ||
| 227 | -Firts you have to enable the following some apache modules: | 245 | +First you have to enable the following some apache modules: |
| 228 | 246 | ||
| 229 | deflate | 247 | deflate |
| 230 | expires | 248 | expires |
| @@ -0,0 +1,7 @@ | @@ -0,0 +1,7 @@ | ||
| 1 | +unless NOOSFERO_CONF['exception_recipients'].blank? | ||
| 2 | + require 'exception_notification.rb' | ||
| 3 | + ExceptionNotifier.sender_address = "noreply@#{Environment.default.default_hostname}" | ||
| 4 | + ExceptionNotifier.email_prefix = "[Noosfero ERROR] " | ||
| 5 | + ExceptionNotifier.exception_recipients = NOOSFERO_CONF['exception_recipients'] | ||
| 6 | + ActionController::Base.send :include, ExceptionNotifiable | ||
| 7 | +end |
config/initializers/load_config.rb
config/noosfero.yml.dist
| @@ -7,6 +7,7 @@ development: | @@ -7,6 +7,7 @@ development: | ||
| 7 | addthis_options: favorites, email, digg, delicious, technorati, slashdot, twitter, more | 7 | addthis_options: favorites, email, digg, delicious, technorati, slashdot, twitter, more |
| 8 | gravatar: wavatar | 8 | gravatar: wavatar |
| 9 | googlemaps_initial_zoom: 4 | 9 | googlemaps_initial_zoom: 4 |
| 10 | + exception_recipients: [admin@example.com] | ||
| 10 | 11 | ||
| 11 | test: | 12 | test: |
| 12 | 13 |
| @@ -0,0 +1,28 @@ | @@ -0,0 +1,28 @@ | ||
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | +require 'account_controller' | ||
| 3 | +require 'exception_notification.rb' | ||
| 4 | +ActionController::Base.send :include, ExceptionNotifiable | ||
| 5 | +ExceptionNotifier.exception_recipients = ['admin@example.com', 'user@example.com'] | ||
| 6 | + | ||
| 7 | +class ExceptionNotificationTest < ActionController::IntegrationTest | ||
| 8 | + def setup | ||
| 9 | + ActionMailer::Base.delivery_method = :test | ||
| 10 | + ActionMailer::Base.perform_deliveries = true | ||
| 11 | + ActionMailer::Base.deliveries = [] | ||
| 12 | + AccountController.any_instance.stubs(:signup).raises(RuntimeError) | ||
| 13 | + AccountController.any_instance.stubs(:local_request?).returns(false) | ||
| 14 | + AccountController.any_instance.stubs(:consider_all_requests_local).returns(false) | ||
| 15 | + end | ||
| 16 | + | ||
| 17 | + should 'deliver mail notification about exceptions' do | ||
| 18 | + assert_difference ActionMailer::Base.deliveries, :size do | ||
| 19 | + get '/account/signup' | ||
| 20 | + end | ||
| 21 | + end | ||
| 22 | + | ||
| 23 | + should 'deliver mails to addresses listed in Noosfero configuration noosfero.yml' do | ||
| 24 | + get '/account/signup' | ||
| 25 | + assert_includes ActionMailer::Base.deliveries.map(&:to).flatten, 'admin@example.com' | ||
| 26 | + assert_includes ActionMailer::Base.deliveries.map(&:to).flatten, 'user@example.com' | ||
| 27 | + end | ||
| 28 | +end |