diff --git a/ruby/lib/jam_ruby/lib/email_new_musician_match.rb b/ruby/lib/jam_ruby/lib/email_new_musician_match.rb index d5369f65e..e8be9c41e 100644 --- a/ruby/lib/jam_ruby/lib/email_new_musician_match.rb +++ b/ruby/lib/jam_ruby/lib/email_new_musician_match.rb @@ -33,7 +33,6 @@ module JamRuby end begin - recipients = User.where("users.subscribe_email = ? AND users.subscribe_email_for_user_match = ? AND NOT COALESCE(users.user_match_email_sent_at, ?) > ?", @@ -41,12 +40,17 @@ module JamRuby CASE WHEN users.email IN ('#{PRIORITY_RECIPIENTS.map {|str| "\"#{str}\""}.join(',')}') THEN 0 ELSE 1 END, last_active_at DESC").select("users.*, GREATEST(updated_at, last_jam_updated_at) AS last_active_at").limit(LIMIT) + + # If the flag is set to send user match email only to jamkazam team + if Rails.application.config.send_user_match_mail_only_to_jamkazam_team + recipients = recipients.where(email: PRIORITY_RECIPIENTS) + end AdminMailer.ugly({to: APP_CONFIG.user_match_monitoring_email, subject:"Weekly user match email sending job started.", body: "#{email_sending.sent_user_ids.any?? "This job is resuming. It was originally started at #{email_sending.created_at} and has been sent to #{email_sending.sent_user_ids.size} user(s) so far." : "This job was started at #{email_sending.created_at}" }. It will send to total of #{ recipients.size } users."}).deliver_now - recipients.find_each do |user| + recipients.find_each do |user| ip_address = user.last_jam_addr.blank?? '127.0.0.1' : IPAddr.new(user.last_jam_addr, Socket::AF_INET).to_s matched_musician_data = [] diff --git a/ruby/spec/jam_ruby/lib/email_new_musician_match_spec.rb b/ruby/spec/jam_ruby/lib/email_new_musician_match_spec.rb index 56eca0494..5ce5de145 100644 --- a/ruby/spec/jam_ruby/lib/email_new_musician_match_spec.rb +++ b/ruby/spec/jam_ruby/lib/email_new_musician_match_spec.rb @@ -23,6 +23,7 @@ describe EmailNewMusicianMatch do ActionMailer::Base.deliveries = [] User.delete_all allow(JamRuby::MusicianFilter).to receive(:filter).and_return(search_result) + Rails.application.config.send_user_match_mail_only_to_jamkazam_team = false end after(:each) do @@ -46,6 +47,14 @@ describe EmailNewMusicianMatch do JamRuby::EmailNewMusicianMatch.send_new_musicians end + it "delivers only to priority recipients" do + Rails.application.config.send_user_match_mail_only_to_jamkazam_team = true + allow(UserMailer).to receive(:new_musicians_match).and_return(mail) + expect(mail).to receive(:deliver_now).exactly(1).times #only to the priority user seth@jamkazam + JamRuby::EmailNewMusicianMatch.send_new_musicians + end + + xit "delivers to priority recipients first" do JamRuby::EmailNewMusicianMatch.send_new_musicians raise ActionMailer::Base.deliveries.map{|d| d['to'].to_s }.inspect #.include?("seth@example.com").should be_truthy diff --git a/web/config/application.rb b/web/config/application.rb index 0aa9e312c..d43bbd722 100644 --- a/web/config/application.rb +++ b/web/config/application.rb @@ -518,5 +518,6 @@ if defined?(Bundler) config.manual_override_installer_ends_with = "JamKazam-1.0.3776.dmg" config.spa_origin = "http://beta.jamkazam.local:4000" config.user_match_monitoring_email = "user_match_monitoring_email@jamkazam.com" + config.send_user_match_mail_only_to_jamkazam_team = true end end diff --git a/web/config/environments/development.rb b/web/config/environments/development.rb index 0c8e8bd91..0b38cafbb 100644 --- a/web/config/environments/development.rb +++ b/web/config/environments/development.rb @@ -125,4 +125,6 @@ SampleApp::Application.configure do config.action_controller.asset_host = 'http://localhost:3000' config.action_mailer.asset_host = config.action_controller.asset_host + + config.send_user_match_mail_only_to_jamkazam_team = false end