diff --git a/app/settings.rb b/app/settings.rb index 50d47d34..12373380 100644 --- a/app/settings.rb +++ b/app/settings.rb @@ -247,6 +247,19 @@ post '/settings/change_email' do redirect '/settings#email' end +post '/settings/change_email_notification' do + require_login + + owner = current_site.owner + + owner.send_emails = params[:send_emails] + owner.send_comment_emails = params[:send_comment_emails] + owner.send_follow_emails = params[:send_follow_emails] + owner.save_changes validate: false + flash[:success] = 'Email notification settings have been updated.' + redirect '/settings#email' +end + post '/settings/create_child' do require_login diff --git a/models/site.rb b/models/site.rb index fecc404a..4bd2db29 100644 --- a/models/site.rb +++ b/models/site.rb @@ -733,7 +733,7 @@ class Site < Sequel::Model if can_email?(args[:col]) EmailWorker.perform_async({ from: FROM_EMAIL, - to: email, + to: owner.email, subject: args[:subject], body: args[:body] }) diff --git a/tests/acceptance/settings/account_tests.rb b/tests/acceptance/settings/account_tests.rb index fee6ca80..f9d419c7 100644 --- a/tests/acceptance/settings/account_tests.rb +++ b/tests/acceptance/settings/account_tests.rb @@ -48,6 +48,22 @@ describe 'site/settings' do @site.email.wont_equal @new_email EmailWorker.jobs.empty?.must_equal true end + + it 'should update email preferences' do + uncheck 'send_emails' + uncheck 'send_comment_emails' + uncheck 'send_follow_emails' + + @site.send_emails.must_equal true + @site.send_comment_emails.must_equal true + @site.send_follow_emails.must_equal true + + click_button 'Update Notification Settings' + @site.reload + @site.send_emails.must_equal false + @site.send_comment_emails.must_equal false + @site.send_follow_emails.must_equal false + end end describe 'change password' do diff --git a/views/settings/account/email.erb b/views/settings/account/email.erb index 13bd875b..dbf2a186 100644 --- a/views/settings/account/email.erb +++ b/views/settings/account/email.erb @@ -9,4 +9,43 @@