Unapproved users should not receive digest emails. Fixes #974

This commit is contained in:
Robin Ward 2013-06-06 11:45:18 -04:00
parent 207ad9049a
commit b062b4a98e
2 changed files with 29 additions and 5 deletions

View File

@ -11,11 +11,17 @@ module Jobs
def target_users
# Users who want to receive emails and haven't been emailed int he last day
User
.select(:id)
.where(email_digests: true)
.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)")
query = User.select(:id)
.where(email_digests: true)
.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)")
# If the site requires approval, make sure the user is approved
if SiteSetting.must_approve_users?
query = query.where("approved OR moderator OR admin")
end
query
end
end

View File

@ -14,6 +14,24 @@ describe Jobs::EnqueueDigestEmails do
end
end
context 'unapproved users' do
Given!(:unapproved_user) { Fabricate(:user, approved: false, last_emailed_at: 8.days.ago, last_seen_at: 10.days.ago) }
When { SiteSetting.stubs(:must_approve_users?).returns(true) }
Then { expect(Jobs::EnqueueDigestEmails.new.target_users.include?(unapproved_user)).to eq(false) }
# As a moderator
And { unapproved_user.update_column(:moderator, true) }
And { expect(Jobs::EnqueueDigestEmails.new.target_users.include?(unapproved_user)).to eq(true) }
# As an admin
And { unapproved_user.update_attributes(admin: true, moderator: false) }
And { expect(Jobs::EnqueueDigestEmails.new.target_users.include?(unapproved_user)).to eq(true) }
# As an approved user
And { unapproved_user.update_attributes(admin: false, moderator: false, approved: true ) }
And { expect(Jobs::EnqueueDigestEmails.new.target_users.include?(unapproved_user)).to eq(true) }
end
context 'recently emailed' do
let!(:user_emailed_recently) { Fabricate(:user, last_emailed_at: 6.days.ago) }