A platform for community discussion. Free, open, simple.
FIX: Check post visibility before allowing comment creation (#38348)
Osama Sayeghd2ecf316fa75
diff --git a/plugins/discourse-post-voting/app/controllers/post_voting/comments_controller.rb b/plugins/discourse-post-voting/app/controllers/post_voting/comments_controller.rbindex 35d127d241d..60d2aa4aafa 100644--- a/plugins/discourse-post-voting/app/controllers/post_voting/comments_controller.rb+++ b/plugins/discourse-post-voting/app/controllers/post_voting/comments_controller.rb@@ -26,6 +26,8 @@ module PostVotingenddef create+ @guardian.ensure_can_see!(@post)+raise Discourse::InvalidAccess if [email protected]_create_post_on_topic?(@post.topic)comment =diff --git a/plugins/discourse-post-voting/spec/requests/post_voting/comments_controller_spec.rb b/plugins/discourse-post-voting/spec/requests/post_voting/comments_controller_spec.rbindex 51fd9660c7e..e129acddb0c 100644--- a/plugins/discourse-post-voting/spec/requests/post_voting/comments_controller_spec.rb+++ b/plugins/discourse-post-voting/spec/requests/post_voting/comments_controller_spec.rb@@ -69,6 +69,18 @@ RSpec.describe PostVoting::CommentsController doexpect(response.status).to eq(403)end+ it "returns 403 when user cannot see the post (e.g. whisper)" do+ whisper_post = Fabricate(:post, topic: topic, post_type: Post.types[:whisper], user: admin)++ post "/post_voting/comments.json",+ params: {+ post_id: whisper_post.id,+ raw: "this is some content",+ }++ expect(response.status).to eq(403)+ end+it "returns the right response when post_id is invalid" dopost "/post_voting/comments.json", params: { post_id: -999_999, raw: "this is some content" }