Merge pull request #3130 from techAPJ/master

FEATURE: suppress digest emails for users not seen on the site for more ...
This commit is contained in:
Robin Ward 2015-01-26 13:12:47 -05:00
commit 51827b06ac
4 changed files with 11 additions and 7 deletions

View file

@ -16,8 +16,8 @@ module Jobs
.where(email_digests: true, active: true)
.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)) OR
email_always")
.where("(COALESCE(last_seen_at, '2010-01-01') <= CURRENT_TIMESTAMP - ('1 DAY'::INTERVAL * digest_after_days)) AND
COALESCE(last_seen_at, '2010-01-01') >= CURRENT_TIMESTAMP - ('1 DAY'::INTERVAL * #{SiteSetting.suppress_digest_email_after_days})")
# If the site requires approval, make sure the user is approved
if SiteSetting.must_approve_users?

View file

@ -990,6 +990,7 @@ en:
digest_topics: "The maximum number of topics to display in the email digest."
digest_min_excerpt_length: "Minimum post excerpt in the email digest, in characters."
default_digest_email_frequency: "How often users receive digest emails by default. They can change this setting in their preferences."
suppress_digest_email_after_days: "Suppress digest emails for users not seen on the site for more than (n) days."
default_external_links_in_new_tab: "Open external links in a new tab. Users can change this in their preferences."
detect_custom_avatars: "Whether or not to check that users have uploaded custom avatars."

View file

@ -408,6 +408,7 @@ email:
default_digest_email_frequency:
default: 7
enum: 'DigestEmailSiteSetting'
suppress_digest_email_after_days: 365
email_custom_headers: 'Auto-Submitted: auto-generated'
email_subject: '[%{site_name}] %{optional_pm}%{optional_cat}%{topic_title}'
reply_by_email_enabled: false

View file

@ -65,15 +65,18 @@ describe Jobs::EnqueueDigestEmails do
user = user_visited_this_week
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user.id)).to eq(false)
end
end
it "does return users who have been emailed recently but have email_always set" do
user = user_visited_this_week_email_always
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user.id)).to eq(true)
context 'visited the site a year ago' do
let!(:user_visited_a_year_ago) { Fabricate(:active_user, last_seen_at: 370.days.ago) }
it "doesn't return the user who have not visited the site for more than 365 days" do
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user_visited_a_year_ago.id)).to eq(false)
end
end
context 'regular users' do
let!(:user) { Fabricate(:active_user) }
let!(:user) { Fabricate(:active_user, last_seen_at: 360.days.ago) }
it "returns the user" do
expect(Jobs::EnqueueDigestEmails.new.target_user_ids).to eq([user.id])
@ -99,4 +102,3 @@ describe Jobs::EnqueueDigestEmails do
end