Add 'staged' boolean to User
This commit is contained in:
parent
6b197179c9
commit
acecfeb37f
|
@ -19,6 +19,9 @@ module Jobs
|
||||||
return skip(I18n.t("email_log.anonymous_user")) if @user.anonymous?
|
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
|
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 = (@user.last_seen_at.present? && @user.last_seen_at > SiteSetting.email_time_window_mins.minutes.ago)
|
||||||
seen_recently = false if @user.email_always
|
seen_recently = false if @user.email_always
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ module Jobs
|
||||||
def target_user_ids
|
def target_user_ids
|
||||||
# Users who want to receive emails and haven't been emailed in the last day
|
# Users who want to receive emails and haven't been emailed in the last day
|
||||||
query = User.real
|
query = User.real
|
||||||
.where(email_digests: true, active: true)
|
.where(email_digests: true, active: true, staged: false)
|
||||||
.not_suspended
|
.not_suspended
|
||||||
.where("COALESCE(last_emailed_at, '2010-01-01') <= CURRENT_TIMESTAMP - ('1 DAY'::INTERVAL * digest_after_days)")
|
.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
|
.where("(COALESCE(last_seen_at, '2010-01-01') <= CURRENT_TIMESTAMP - ('1 DAY'::INTERVAL * digest_after_days)) AND
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddStagedToUser < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :users, :staged, :boolean, null: false, default: false
|
||||||
|
end
|
||||||
|
end
|
|
@ -32,6 +32,14 @@ describe Jobs::EnqueueDigestEmails do
|
||||||
And { expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true) }
|
And { expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true) }
|
||||||
end
|
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
|
context 'recently emailed' do
|
||||||
let!(:user_emailed_recently) { Fabricate(:active_user, last_emailed_at: 6.days.ago) }
|
let!(:user_emailed_recently) { Fabricate(:active_user, last_emailed_at: 6.days.ago) }
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ describe Jobs::UserEmail do
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:user) { Fabricate(:user, last_seen_at: 11.minutes.ago ) }
|
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(: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(:anonymous) { Fabricate(:anonymous, last_seen_at: 11.minutes.ago ) }
|
||||||
let(:mailer) { Mail::Message.new(to: user.email) }
|
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)
|
Jobs::UserEmail.new.execute(type: :digest, user_id: 1234)
|
||||||
end
|
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
|
context 'to_address' do
|
||||||
it 'overwrites a to_address when present' do
|
it 'overwrites a to_address when present' do
|
||||||
|
|
Loading…
Reference in New Issue