diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 1cf92df..b38dd60 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -1,24 +1,25 @@ class Mailer < ActionMailer::Base default :from => Errbit::Config.email_from - + def err_notification(notice) @notice = notice @app = notice.err.app - + mail({ - :to => @app.watchers.map(&:address), + :to => @app.notification_recipients, :subject => "[#{@app.name}][#{@notice.err.environment}] #{@notice.err.message}" }) end - + def deploy_notification(deploy) @deploy = deploy @app = deploy.app - + mail({ - :to => @app.watchers.map(&:address), + :to => @app.notification_recipients, :subject => "[#{@app.name}] Deployed to #{@deploy.environment} by #{@deploy.username}" }) end - + end + diff --git a/app/models/app.rb b/app/models/app.rb index add9be7..de0b80d 100644 --- a/app/models/app.rb +++ b/app/models/app.rb @@ -6,6 +6,7 @@ class App field :api_key field :github_url field :resolve_errs_on_deploy, :type => Boolean, :default => false + field :notify_all_users, :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.email_at_notices @@ -74,6 +75,10 @@ class App issue_tracker && issue_tracker.issue_tracker_type != "none" && !issue_tracker.project_id.blank? end + def notification_recipients + notify_all_users ? User.all.map(&:email) : watchers.map(&:address) + end + protected def generate_api_key diff --git a/app/views/apps/_fields.html.haml b/app/views/apps/_fields.html.haml index c39e8bf..9ea0c80 100644 --- a/app/views/apps/_fields.html.haml +++ b/app/views/apps/_fields.html.haml @@ -23,11 +23,11 @@ = f.label :notify_on_deploys, 'Notify on deploys' %div.checkbox - = f.check_box :resolve_errs_on_deploy - = f.label :resolve_errs_on_deploy, 'Resolve errs on deploy' + = f.check_box :notify_all_users, 'data-hide-when-checked' => '.watchers.nested-wrapper' + = f.label :notify_all_users, 'Send notifications to all users' -%fieldset.nested-wrapper +%fieldset.watchers.nested-wrapper{:style => f.object.notify_all_users ? 'display: none;' : ''} %legend Watchers = f.fields_for :watchers do |w| %div.watcher.nested @@ -41,6 +41,10 @@ %div.watcher_params.email{:class => w.object.email.present? ? 'chosen' : nil} = w.text_field :email +%div.checkbox + = f.check_box :resolve_errs_on_deploy + = f.label :resolve_errs_on_deploy, 'Resolve errs on deploy' + %fieldset %legend Issue tracker = f.fields_for :issue_tracker do |w| diff --git a/spec/models/app_spec.rb b/spec/models/app_spec.rb index 90ed46f..bd1067c 100644 --- a/spec/models/app_spec.rb +++ b/spec/models/app_spec.rb @@ -1,21 +1,21 @@ require 'spec_helper' describe App do - + context 'validations' do it 'requires a name' do app = Factory.build(:app, :name => nil) app.should_not be_valid app.errors[:name].should include("can't be blank") end - + it 'requires unique names' do Factory(:app, :name => 'Errbit') app = Factory.build(:app, :name => 'Errbit') app.should_not be_valid app.errors[:name].should include('is already taken') end - + it 'requires unique api_keys' do Factory(:app, :api_key => 'APIKEY') app = Factory.build(:app, :api_key => 'APIKEY') @@ -23,7 +23,7 @@ describe App do app.errors[:api_key].should include('is already taken') end end - + context 'being created' do it 'generates a new api-key' do app = Factory.build(:app) @@ -31,18 +31,18 @@ describe App do app.save app.api_key.should_not be_nil end - + it 'generates a correct api-key' do app = Factory(:app) app.api_key.should match(/^[a-f0-9]{32}$/) end - + it 'is fine with blank github urls' do app = Factory.build(:app, :github_url => "") app.save app.github_url.should == "" end - + it 'does not touch https github urls' do app = Factory.build(:app, :github_url => "https://github.com/jdpace/errbit") app.save @@ -67,14 +67,14 @@ describe App do app.github_url.should == "https://github.com/jdpace/errbit" end end - + context '#github_url_to_file' do it 'resolves to full path to file' do app = Factory(:app, :github_url => "https://github.com/jdpace/errbit") app.github_url_to_file('/path/to/file').should == "https://github.com/jdpace/errbit/blob/master/path/to/file" end end - + context '#github_url?' do it 'is true when there is a github_url' do app = Factory(:app, :github_url => "https://github.com/jdpace/errbit") @@ -86,5 +86,18 @@ describe App do app.github_url?.should be_false end end - + + context "notification recipients" do + it "should send notices to either all users, or the configured watchers" do + @app = Factory(:app) + 3.times { Factory(:user) } + 5.times { Factory(:watcher, :app => @app) } + @app.notify_all_users = true + @app.notification_recipients.size.should == 3 + @app.notify_all_users = false + @app.notification_recipients.size.should == 5 + end + end + end + -- libgit2 0.21.2