mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 21:43:46 +08:00
FIX: whitelist post_types used in context in email notifications
This commit is contained in:
parent
f77dfda097
commit
c740b42328
|
@ -186,11 +186,14 @@ class UserNotifications < ActionMailer::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_context_posts(post, topic_user)
|
def self.get_context_posts(post, topic_user)
|
||||||
|
allowed_post_types = [Post.types[:regular]]
|
||||||
|
allowed_post_types << Post.types[:whisper] if topic_user.try(:user).try(:staff?)
|
||||||
|
|
||||||
context_posts = Post.where(topic_id: post.topic_id)
|
context_posts = Post.where(topic_id: post.topic_id)
|
||||||
.where("post_number < ?", post.post_number)
|
.where("post_number < ?", post.post_number)
|
||||||
.where(user_deleted: false)
|
.where(user_deleted: false)
|
||||||
.where(hidden: false)
|
.where(hidden: false)
|
||||||
.where(post_type: Topic.visible_post_types)
|
.where(post_type: allowed_post_types)
|
||||||
.order('created_at desc')
|
.order('created_at desc')
|
||||||
.limit(SiteSetting.email_posts_context)
|
.limit(SiteSetting.email_posts_context)
|
||||||
|
|
||||||
|
|
|
@ -6,21 +6,20 @@ describe UserNotifications do
|
||||||
|
|
||||||
describe "#get_context_posts" do
|
describe "#get_context_posts" do
|
||||||
it "does not include hidden/deleted/user_deleted posts in context" do
|
it "does not include hidden/deleted/user_deleted posts in context" do
|
||||||
post = create_post
|
post1 = create_post
|
||||||
reply1 = create_post(topic: post.topic)
|
post2 = Fabricate(:post, topic: post1.topic, deleted_at: 1.day.ago)
|
||||||
reply2 = create_post(topic: post.topic)
|
post3 = Fabricate(:post, topic: post1.topic, user_deleted: true)
|
||||||
reply3 = create_post(topic: post.topic)
|
post4 = Fabricate(:post, topic: post1.topic, hidden: true)
|
||||||
reply4 = create_post(topic: post.topic)
|
post5 = Fabricate(:post, topic: post1.topic, post_type: Post.types[:moderator_action])
|
||||||
|
post6 = Fabricate(:post, topic: post1.topic, post_type: Post.types[:small_action])
|
||||||
|
post7 = Fabricate(:post, topic: post1.topic, post_type: Post.types[:whisper])
|
||||||
|
last = Fabricate(:post, topic: post1.topic)
|
||||||
|
|
||||||
reply1.trash!
|
# default is only post #1
|
||||||
|
expect(UserNotifications.get_context_posts(last, nil).count).to eq(1)
|
||||||
reply2.user_deleted = true
|
# staff members can also see the whisper
|
||||||
reply2.save
|
tu = TopicUser.new(topic: post1.topic, user: build(:moderator))
|
||||||
|
expect(UserNotifications.get_context_posts(last, tu).count).to eq(2)
|
||||||
reply3.hidden = true
|
|
||||||
reply3.save
|
|
||||||
|
|
||||||
expect(UserNotifications.get_context_posts(reply4, nil).count).to eq(1)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user