diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index fb6465bb3..f667fbd51 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -154,7 +154,7 @@ class TopicsController < ApplicationController def posts params.require(:topic_id) - params.require(:post_ids) + params.permit(:post_ids) @topic_view = TopicView.new(params[:topic_id], current_user, post_ids: params[:post_ids]) render_json_dump(TopicViewPostsSerializer.new(@topic_view, scope: guardian, root: false, include_raw: !!params[:include_raw])) diff --git a/config/routes.rb b/config/routes.rb index 55c54e7d0..1e52cb382 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -544,7 +544,7 @@ Discourse::Application.routes.draw do get "t/:slug/:topic_id" => "topics#show", constraints: {topic_id: /\d+/} get "t/:slug/:topic_id/:post_number" => "topics#show", constraints: {topic_id: /\d+/, post_number: /\d+/} get "t/:slug/:topic_id/last" => "topics#show", post_number: 99999999, constraints: {topic_id: /\d+/} - get "t/:topic_id/posts" => "topics#posts", constraints: {topic_id: /\d+/} + get "t/:topic_id/posts" => "topics#posts", constraints: {topic_id: /\d+/}, format: :json post "t/:topic_id/timings" => "topics#timings", constraints: {topic_id: /\d+/} post "t/:topic_id/invite" => "topics#invite", constraints: {topic_id: /\d+/} post "t/:topic_id/move-posts" => "topics#move_posts", constraints: {topic_id: /\d+/} diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index d06b4ff1c..4a82c8074 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -813,6 +813,16 @@ describe TopicsController do end end + describe '#posts' do + let(:topic) { Fabricate(:post).topic } + + it 'returns first posts of the topic' do + get :posts, topic_id: topic.id, format: :json + expect(response).to be_success + expect(response.content_type).to eq('application/json') + end + end + describe '#feed' do let(:topic) { Fabricate(:post).topic }