From 1c1a0322e36b3f8be47f937574f684f39b502462 Mon Sep 17 00:00:00 2001 From: Nick Recobra Date: Sun, 7 Aug 2011 13:28:15 +0400 Subject: [PATCH] Keeping ability to setup email frequency globally. --- app/controllers/apps_controller.rb | 2 +- app/models/app.rb | 2 +- app/views/apps/_fields.html.haml | 10 +++++----- config/config.example.yml | 12 ++++++------ config/initializers/_load_config.rb | 2 +- spec/controllers/apps_controller_spec.rb | 2 +- spec/factories/app_factories.rb | 1 - 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/controllers/apps_controller.rb b/app/controllers/apps_controller.rb index 9ccf6bf..7b8bd6d 100644 --- a/app/controllers/apps_controller.rb +++ b/app/controllers/apps_controller.rb @@ -85,7 +85,7 @@ class AppsController < ApplicationController if email_at_notices.any? params[:app][:email_at_notices] = email_at_notices else - default_array = params[:app][:email_at_notices] = Errbit::Config.default_email_at_notices + default_array = params[:app][:email_at_notices] = Errbit::Config.email_at_notices flash[:error] = "Couldn't parse your notification frequency. Value was reset to default (#{default_array.join(', ')})." end end diff --git a/app/models/app.rb b/app/models/app.rb index 9c9b06b..045fa63 100644 --- a/app/models/app.rb +++ b/app/models/app.rb @@ -8,7 +8,7 @@ class App field :resolve_errs_on_deploy, :type => Boolean, :default => false field :notify_on_errs, :type => Boolean, :default => true field :notify_on_deploys, :type => Boolean, :default => true - field :email_at_notices, :type => Array, :default => Errbit::Config.default_email_at_notices + field :email_at_notices, :type => Array, :default => Errbit::Config.email_at_notices # Some legacy apps may have sting as key instead of BSON::ObjectID identity :type => String diff --git a/app/views/apps/_fields.html.haml b/app/views/apps/_fields.html.haml index 84b9994..9542bdf 100644 --- a/app/views/apps/_fields.html.haml +++ b/app/views/apps/_fields.html.haml @@ -13,11 +13,11 @@ %div.checkbox = f.check_box :notify_on_errs = f.label :notify_on_errs, 'Notify on errors' - %div.email_at_notices_nested{:style => f.object.notify_on_errs ? '' : 'display: none;'} - .field-helpertext Send a notification every - -# Edit the email_at_notices array as a CSV string - = f.text_field :email_at_notices, :value => f.object.email_at_notices.join(", ") - .field-helpertext times an error occurs. (CSV) + - if Errbit::Config.per_app_email_at_notices + %div.email_at_notices_nested{:style => f.object.notify_on_errs ? '' : 'display: none;'} + .field-helpertext Send a notification every + = f.text_field :email_at_notices, :value => f.object.email_at_notices.join(", ") + .field-helpertext times an error occurs (comma separated). %div.checkbox = f.check_box :notify_on_deploys = f.label :notify_on_deploys, 'Notify on deploys' diff --git a/config/config.example.yml b/config/config.example.yml index d65495b..5f6f998 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -14,13 +14,13 @@ host: errbit.example.com # will be sent from. email_from: errbit@example.com -# Configure the default value for when emails are sent for an error. +# if you turn on this option, email_at_notices will be configured on per app basis +# at App edit page +per_app_email_at_notices: false + +# Configure when emails are sent for an error. # [1,3,7] = 1st, 3rd, and 7th occurence triggers # an email notification. -# Each app can be configured individually. -default_email_at_notices: [1, 10, 100] +email_at_notices: [1, 10, 100] -# Set to false to suppress confirmation when -# resolving errors. confirm_resolve_err: true - diff --git a/config/initializers/_load_config.rb b/config/initializers/_load_config.rb index 8e88013..d406ff0 100644 --- a/config/initializers/_load_config.rb +++ b/config/initializers/_load_config.rb @@ -4,7 +4,7 @@ if ENV['HEROKU'] Errbit::Config = OpenStruct.new Errbit::Config.host = ENV['ERRBIT_HOST'] Errbit::Config.email_from = ENV['ERRBIT_EMAIL_FROM'] - Errbit::Config.default_email_at_notices = [1,3,10] #ENV['ERRBIT_EMAIL_AT_NOTICES'] + Errbit::Config.email_at_notices = [1,3,10] #ENV['ERRBIT_EMAIL_AT_NOTICES'] Errbit::Application.config.action_mailer.smtp_settings = { :address => "smtp.sendgrid.net", :port => "25", diff --git a/spec/controllers/apps_controller_spec.rb b/spec/controllers/apps_controller_spec.rb index bb856b9..7c7f95d 100644 --- a/spec/controllers/apps_controller_spec.rb +++ b/spec/controllers/apps_controller_spec.rb @@ -252,7 +252,7 @@ describe AppsController do @app = Factory(:app, :email_at_notices => [1, 2, 3, 4]) put :update, :id => @app.id, :app => { :email_at_notices => 'asdf, -1,0,foobar,gd00,0,abc' } @app.reload - @app.email_at_notices.should == Errbit::Config.default_email_at_notices + @app.email_at_notices.should == Errbit::Config.email_at_notices end it "should display a message" do diff --git a/spec/factories/app_factories.rb b/spec/factories/app_factories.rb index a576d45..ba1b3c4 100644 --- a/spec/factories/app_factories.rb +++ b/spec/factories/app_factories.rb @@ -1,6 +1,5 @@ Factory.define(:app) do |p| p.name { Factory.next :app_name } - p.email_at_notices { [1, 10, 100] } end Factory.define(:app_with_watcher, :parent => :app) do |p| -- libgit2 0.21.2