A platform for community discussion. Free, open, simple.
SECURITY: Filter whisper posts from private-posts feed
Joffrey JAFFEUXd2f317271ad7
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rbindex 3ae2609759c..325a7dc6cff 100644--- a/app/controllers/posts_controller.rb+++ b/app/controllers/posts_controller.rb@@ -63,6 +63,7 @@ class PostsController < ApplicationControllerposts =Post.private_posts+ .where(post_type: Topic.visible_post_types(current_user)).order(id: :desc).includes(topic: :category).includes(user: %i[primary_group flair_group])diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rbindex 3455928d266..0d5c1f15b04 100644--- a/spec/requests/posts_controller_spec.rb+++ b/spec/requests/posts_controller_spec.rb@@ -3208,6 +3208,23 @@ RSpec.describe PostsController doexpect(post_ids).to eq([post_id])end+ it "does not include whisper posts for non-whisperer users" do+ sign_in(user)++ pm = Fabricate(:private_message_topic, recipient: user)+ regular_post = Fabricate(:post, topic: pm)+ whisper_post = Fabricate(:post, topic: pm, post_type: Post.types[:whisper])++ get "/private-posts.json"+ expect(response.status).to eq(200)++ json = response.parsed_body+ post_ids = json["private_posts"].map { |p| p["id"] }++ expect(post_ids).to include(regular_post.id)+ expect(post_ids).to_not include(whisper_post.id)+ end+it "returns private posts for json" dosign_in(admin)