From eac829000154a8d3b8031281b236a0a60a0e7857 Mon Sep 17 00:00:00 2001 From: shawn-higgins1 <23224097+shawn-higgins1@users.noreply.github.com> Date: Wed, 22 May 2019 13:38:34 -0400 Subject: [PATCH] GRN2-148: Always check that email notifications are enabled before sending an email (#539) * Always check that email notificatiosn are enabled before sending an email * Fix tests * Fix formating * Change to hardcoding the validation --- app/controllers/concerns/emailer.rb | 8 ++++++++ spec/controllers/admins_controller_spec.rb | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/app/controllers/concerns/emailer.rb b/app/controllers/concerns/emailer.rb index e67325b3..617819be 100644 --- a/app/controllers/concerns/emailer.rb +++ b/app/controllers/concerns/emailer.rb @@ -21,12 +21,16 @@ module Emailer # Sends account activation email. def send_activation_email(user) + return unless Rails.configuration.enable_email_verification + @user = user UserMailer.verify_email(@user, user_verification_link, logo_image, user_color).deliver end # Sends password reset email. def send_password_reset_email(user) + return unless Rails.configuration.enable_email_verification + @user = user UserMailer.password_reset(@user, reset_link, logo_image, user_color).deliver_now end @@ -41,11 +45,15 @@ module Emailer # Sends inivitation to join def send_invitation_email(name, email, token) + return unless Rails.configuration.enable_email_verification + @token = token UserMailer.invite_email(name, email, invitation_link, logo_image, user_color).deliver_now end def send_user_approved_email(user) + return unless Rails.configuration.enable_email_verification + UserMailer.approve_user(user, root_url, logo_image, user_color).deliver_now end diff --git a/spec/controllers/admins_controller_spec.rb b/spec/controllers/admins_controller_spec.rb index 05eac84a..3d1ba995 100644 --- a/spec/controllers/admins_controller_spec.rb +++ b/spec/controllers/admins_controller_spec.rb @@ -26,6 +26,10 @@ describe AdminsController, type: :controller do end describe "User Roles" do + before do + allow(Rails.configuration).to receive(:enable_email_verification).and_return(true) + end + context "GET #index" do it "renders a 404 if a user tries to acccess it" do @request.session[:user_id] = @user.id