Add 'staged' boolean to User

This commit is contained in:
Régis Hanol 2015-11-06 19:19:13 +01:00
parent 6b197179c9
commit acecfeb37f
5 changed files with 23 additions and 1 deletions

View File

@ -19,6 +19,9 @@ module Jobs
return skip(I18n.t("email_log.anonymous_user")) if @user.anonymous?
return skip(I18n.t("email_log.suspended_not_pm")) if @user.suspended? && args[:type] != :user_private_message
# ensure we *never* send a digest to a staged user
return if @user.staged && args[:type] == :digest
seen_recently = (@user.last_seen_at.present? && @user.last_seen_at > SiteSetting.email_time_window_mins.minutes.ago)
seen_recently = false if @user.email_always

View File

@ -15,7 +15,7 @@ module Jobs
def target_user_ids
# Users who want to receive emails and haven't been emailed in the last day
query = User.real
.where(email_digests: true, active: true)
.where(email_digests: true, active: true, staged: false)
.not_suspended
.where("COALESCE(last_emailed_at, '2010-01-01') <= CURRENT_TIMESTAMP - ('1 DAY'::INTERVAL * digest_after_days)")
.where("(COALESCE(last_seen_at, '2010-01-01') <= CURRENT_TIMESTAMP - ('1 DAY'::INTERVAL * digest_after_days)) AND

View File

@ -0,0 +1,5 @@
class AddStagedToUser < ActiveRecord::Migration
def change
add_column :users, :staged, :boolean, null: false, default: false
end
end

View File

@ -32,6 +32,14 @@ describe Jobs::EnqueueDigestEmails do
And { expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true) }
end
context 'staged users' do
let!(:staged_user) { Fabricate(:active_user, staged: true, last_emailed_at: 1.year.ago, last_seen_at: 1.year.ago) }
it "doesn't return staged users" do
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(staged_user.id)).to eq(false)
end
end
context 'recently emailed' do
let!(:user_emailed_recently) { Fabricate(:active_user, last_emailed_at: 6.days.ago) }

View File

@ -8,6 +8,7 @@ describe Jobs::UserEmail do
end
let(:user) { Fabricate(:user, last_seen_at: 11.minutes.ago ) }
let(:staged) { Fabricate(:user, staged: true, last_seen_at: 11.minutes.ago ) }
let(:suspended) { Fabricate(:user, last_seen_at: 10.minutes.ago, suspended_at: 5.minutes.ago, suspended_till: 7.days.from_now ) }
let(:anonymous) { Fabricate(:anonymous, last_seen_at: 11.minutes.ago ) }
let(:mailer) { Mail::Message.new(to: user.email) }
@ -29,6 +30,11 @@ describe Jobs::UserEmail do
Jobs::UserEmail.new.execute(type: :digest, user_id: 1234)
end
it "doesn't call the mailer when the user is staged" do
UserNotifications.expects(:digest).never
Jobs::UserEmail.new.execute(type: :digest, user_id: staged.id)
end
context 'to_address' do
it 'overwrites a to_address when present' do