From 8a0e121f29318da3bb7fda8a282974835d9d45ec Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Tue, 6 Jan 2015 19:45:38 -0800 Subject: [PATCH] email notifications management --- app/settings.rb | 13 ++++++++ models/site.rb | 2 +- tests/acceptance/settings/account_tests.rb | 16 +++++++++ views/settings/account/email.erb | 39 ++++++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) 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 @@
+ + +

Email Notification Settings

+
+ <%== csrf_token_input_html %> + +

+ Receive Emails: + + + checked + <% end %> + > +

+ +

+ Receive Comment Emails: + + + checked + <% end %> + > +

+ +

+ Receive Follow Emails: + + + checked + <% end %> + > +

+ +
+ +
\ No newline at end of file