mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FIX: digest emails should not include posts that are still in the edit grace period
This commit is contained in:
parent
89e919ec42
commit
94d8f6d734
5 changed files with 148 additions and 117 deletions
|
@ -99,6 +99,7 @@ class UserNotifications < ActionMailer::Base
|
||||||
.where('posts.post_type = ?', Post.types[:regular])
|
.where('posts.post_type = ?', Post.types[:regular])
|
||||||
.where('posts.deleted_at IS NULL AND posts.hidden = false AND posts.user_deleted = false')
|
.where('posts.deleted_at IS NULL AND posts.hidden = false AND posts.user_deleted = false')
|
||||||
.where("posts.post_number > ? AND posts.score > ?", 1, ScoreCalculator.default_score_weights[:like_score] * 5.0)
|
.where("posts.post_number > ? AND posts.score > ?", 1, ScoreCalculator.default_score_weights[:like_score] * 5.0)
|
||||||
|
.where('posts.created_at < ?', (SiteSetting.editing_grace_period || 0).seconds.ago)
|
||||||
.limit(SiteSetting.digest_posts)
|
.limit(SiteSetting.digest_posts)
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -337,6 +337,7 @@ class Topic < ActiveRecord::Base
|
||||||
.where(closed: false, archived: false)
|
.where(closed: false, archived: false)
|
||||||
.where("COALESCE(topic_users.notification_level, 1) <> ?", TopicUser.notification_levels[:muted])
|
.where("COALESCE(topic_users.notification_level, 1) <> ?", TopicUser.notification_levels[:muted])
|
||||||
.created_since(since)
|
.created_since(since)
|
||||||
|
.where('topics.created_at < ?', (SiteSetting.editing_grace_period || 0).seconds.ago)
|
||||||
.listable_topics
|
.listable_topics
|
||||||
.includes(:category)
|
.includes(:category)
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,10 @@ describe Jobs::UserEmail do
|
||||||
|
|
||||||
context "email_log" do
|
context "email_log" do
|
||||||
|
|
||||||
before { Fabricate(:post) }
|
before do
|
||||||
|
SiteSetting.editing_grace_period = 0
|
||||||
|
Fabricate(:post)
|
||||||
|
end
|
||||||
|
|
||||||
it "creates an email log when the mail is sent (via Email::Sender)" do
|
it "creates an email log when the mail is sent (via Email::Sender)" do
|
||||||
last_emailed_at = user.last_emailed_at
|
last_emailed_at = user.last_emailed_at
|
||||||
|
|
|
@ -106,7 +106,7 @@ describe UserNotifications do
|
||||||
context "with new topics" do
|
context "with new topics" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Fabricate(:topic, user: Fabricate(:coding_horror))
|
Fabricate(:topic, user: Fabricate(:coding_horror), created_at: 1.hour.ago)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "works" do
|
it "works" do
|
||||||
|
@ -127,8 +127,8 @@ describe UserNotifications do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "excludes deleted topics and their posts" do
|
it "excludes deleted topics and their posts" do
|
||||||
deleted = Fabricate(:topic, user: Fabricate(:user), title: "Delete this topic plz")
|
deleted = Fabricate(:topic, user: Fabricate(:user), title: "Delete this topic plz", created_at: 1.hour.ago)
|
||||||
post = Fabricate(:post, topic: deleted, score: 100.0, post_number: 2, raw: "Your wish is my command")
|
post = Fabricate(:post, topic: deleted, score: 100.0, post_number: 2, raw: "Your wish is my command", created_at: 1.hour.ago)
|
||||||
deleted.trash!
|
deleted.trash!
|
||||||
html = subject.html_part.body.to_s
|
html = subject.html_part.body.to_s
|
||||||
expect(html).to_not include deleted.title
|
expect(html).to_not include deleted.title
|
||||||
|
@ -136,10 +136,10 @@ describe UserNotifications do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "excludes whispers and other post types that don't belong" do
|
it "excludes whispers and other post types that don't belong" do
|
||||||
t = Fabricate(:topic, user: Fabricate(:user), title: "Who likes the same stuff I like?")
|
t = Fabricate(:topic, user: Fabricate(:user), title: "Who likes the same stuff I like?", created_at: 1.hour.ago)
|
||||||
whisper = Fabricate(:post, topic: t, score: 100.0, post_number: 2, raw: "You like weird stuff", post_type: Post.types[:whisper])
|
whisper = Fabricate(:post, topic: t, score: 100.0, post_number: 2, raw: "You like weird stuff", post_type: Post.types[:whisper], created_at: 1.hour.ago)
|
||||||
mod_action = Fabricate(:post, topic: t, score: 100.0, post_number: 3, raw: "This topic unlisted", post_type: Post.types[:moderator_action])
|
mod_action = Fabricate(:post, topic: t, score: 100.0, post_number: 3, raw: "This topic unlisted", post_type: Post.types[:moderator_action], created_at: 1.hour.ago)
|
||||||
small_action = Fabricate(:post, topic: t, score: 100.0, post_number: 4, raw: "A small action", post_type: Post.types[:small_action])
|
small_action = Fabricate(:post, topic: t, score: 100.0, post_number: 4, raw: "A small action", post_type: Post.types[:small_action], created_at: 1.hour.ago)
|
||||||
html = subject.html_part.body.to_s
|
html = subject.html_part.body.to_s
|
||||||
expect(html).to_not include whisper.raw
|
expect(html).to_not include whisper.raw
|
||||||
expect(html).to_not include mod_action.raw
|
expect(html).to_not include mod_action.raw
|
||||||
|
@ -147,16 +147,24 @@ describe UserNotifications do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "excludes deleted and hidden posts" do
|
it "excludes deleted and hidden posts" do
|
||||||
t = Fabricate(:topic, user: Fabricate(:user), title: "Post objectionable stuff here")
|
t = Fabricate(:topic, user: Fabricate(:user), title: "Post objectionable stuff here", created_at: 1.hour.ago)
|
||||||
deleted = Fabricate(:post, topic: t, score: 100.0, post_number: 2, raw: "This post is uncalled for", deleted_at: 5.minutes.ago)
|
deleted = Fabricate(:post, topic: t, score: 100.0, post_number: 2, raw: "This post is uncalled for", deleted_at: 5.minutes.ago, created_at: 1.hour.ago)
|
||||||
hidden = Fabricate(:post, topic: t, score: 100.0, post_number: 3, raw: "Try to find this post", hidden: true, hidden_at: 5.minutes.ago, hidden_reason_id: Post.hidden_reasons[:flagged_by_tl3_user])
|
hidden = Fabricate(:post, topic: t, score: 100.0, post_number: 3, raw: "Try to find this post", hidden: true, hidden_at: 5.minutes.ago, hidden_reason_id: Post.hidden_reasons[:flagged_by_tl3_user], created_at: 1.hour.ago)
|
||||||
user_deleted = Fabricate(:post, topic: t, score: 100.0, post_number: 4, raw: "I regret this post", user_deleted: true)
|
user_deleted = Fabricate(:post, topic: t, score: 100.0, post_number: 4, raw: "I regret this post", user_deleted: true, created_at: 1.hour.ago)
|
||||||
html = subject.html_part.body.to_s
|
html = subject.html_part.body.to_s
|
||||||
expect(html).to_not include deleted.raw
|
expect(html).to_not include deleted.raw
|
||||||
expect(html).to_not include hidden.raw
|
expect(html).to_not include hidden.raw
|
||||||
expect(html).to_not include user_deleted.raw
|
expect(html).to_not include user_deleted.raw
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "excludes posts that are newer than editing grace period" do
|
||||||
|
SiteSetting.editing_grace_period = 5.minutes
|
||||||
|
too_new = Fabricate(:topic, user: Fabricate(:user), title: "Oops I need to edit this", created_at: 1.minute.ago)
|
||||||
|
too_new_post = Fabricate(:post, user: too_new.user, topic: too_new, score: 100.0, post_number: 1, created_at: 1.minute.ago)
|
||||||
|
html = subject.html_part.body.to_s
|
||||||
|
expect(html).to_not include too_new.title
|
||||||
|
end
|
||||||
|
|
||||||
it "uses theme color" do
|
it "uses theme color" do
|
||||||
cs = Fabricate(:color_scheme, name: 'Fancy', color_scheme_colors: [
|
cs = Fabricate(:color_scheme, name: 'Fancy', color_scheme_colors: [
|
||||||
Fabricate(:color_scheme_color, name: 'header_primary', hex: 'F0F0F0'),
|
Fabricate(:color_scheme_color, name: 'header_primary', hex: 'F0F0F0'),
|
||||||
|
|
|
@ -1327,6 +1327,11 @@ describe Topic do
|
||||||
describe 'for_digest' do
|
describe 'for_digest' do
|
||||||
let(:user) { Fabricate.build(:user) }
|
let(:user) { Fabricate.build(:user) }
|
||||||
|
|
||||||
|
context "no edit grace period" do
|
||||||
|
before do
|
||||||
|
SiteSetting.editing_grace_period = 0
|
||||||
|
end
|
||||||
|
|
||||||
it "returns none when there are no topics" do
|
it "returns none when there are no topics" do
|
||||||
expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blank
|
expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blank
|
||||||
end
|
end
|
||||||
|
@ -1435,13 +1440,26 @@ describe Topic do
|
||||||
for_digest = Topic.for_digest(user, 1.year.ago, top_order: true).pluck(:id)
|
for_digest = Topic.for_digest(user, 1.year.ago, top_order: true).pluck(:id)
|
||||||
expect(for_digest).to eq([topics[2].id, topics[0].id, topics[1].id])
|
expect(for_digest).to eq([topics[2].id, topics[0].id, topics[1].id])
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with editing_grace_period" do
|
||||||
|
before do
|
||||||
|
SiteSetting.editing_grace_period = 5.minutes
|
||||||
|
end
|
||||||
|
|
||||||
|
it "excludes topics that are within the grace period" do
|
||||||
|
topic1 = Fabricate(:topic, created_at: 6.minutes.ago)
|
||||||
|
topic2 = Fabricate(:topic, created_at: 4.minutes.ago)
|
||||||
|
expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to eq([topic1])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'secured' do
|
describe 'secured' do
|
||||||
it 'can remove secure groups' do
|
it 'can remove secure groups' do
|
||||||
category = Fabricate(:category, read_restricted: true)
|
category = Fabricate(:category, read_restricted: true)
|
||||||
Fabricate(:topic, category: category)
|
Fabricate(:topic, category: category, created_at: 1.day.ago)
|
||||||
|
|
||||||
expect(Topic.secured(Guardian.new(nil)).count).to eq(0)
|
expect(Topic.secured(Guardian.new(nil)).count).to eq(0)
|
||||||
expect(Topic.secured(Guardian.new(Fabricate(:admin))).count).to eq(2)
|
expect(Topic.secured(Guardian.new(Fabricate(:admin))).count).to eq(2)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue