diff --git a/app/assets/javascripts/discourse/models/composer.js.es6 b/app/assets/javascripts/discourse/models/composer.js.es6 index 1d5961bcd..366a55e73 100644 --- a/app/assets/javascripts/discourse/models/composer.js.es6 +++ b/app/assets/javascripts/discourse/models/composer.js.es6 @@ -431,6 +431,8 @@ const Composer = RestModel.extend({ if (!this.get('topic')) { this.set('topic', opts.post.get('topic')); } + } else { + this.set('post', null); } this.setProperties({ diff --git a/lib/post_creator.rb b/lib/post_creator.rb index faf713fbe..182cb0a36 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -56,6 +56,8 @@ class PostCreator @opts = opts || {} opts[:title] = pg_clean_up(opts[:title]) if opts[:title] && opts[:title].include?("\u0000") opts[:raw] = pg_clean_up(opts[:raw]) if opts[:raw] && opts[:raw].include?("\u0000") + opts.delete(:reply_to_post_number) unless opts[:topic_id] + @spam = false end diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index 0595a66e0..8ec10e457 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -38,27 +38,29 @@ describe PostCreator do expect { creator.create }.to raise_error(Discourse::InvalidAccess) end + context "reply to post number" do + it "omits reply to post number if received on a new topic" do + p = PostCreator.new(user, basic_topic_params.merge(reply_to_post_number: 3)).create + expect(p.reply_to_post_number).to be_nil + end + end context "invalid title" do - let(:creator_invalid_title) { PostCreator.new(user, basic_topic_params.merge(title: 'a')) } it "has errors" do creator_invalid_title.create expect(creator_invalid_title.errors).to be_present end - end context "invalid raw" do - let(:creator_invalid_raw) { PostCreator.new(user, basic_topic_params.merge(raw: '')) } it "has errors" do creator_invalid_raw.create expect(creator_invalid_raw.errors).to be_present end - end context "success" do diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 76e76f6f3..748cfca7c 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -618,7 +618,7 @@ describe PostsController do end it "passes reply_to_post_number through" do - xhr :post, :create, {raw: 'hello', reply_to_post_number: 6789} + xhr :post, :create, {raw: 'hello', reply_to_post_number: 6789, topic_id: 1234} expect(assigns(:manager_params)['reply_to_post_number']).to eq('6789') end @@ -678,7 +678,7 @@ describe PostsController do end it "ensures regular user cannot see the revisions" do - u = log_in(:user) + log_in(:user) xhr :get, :revisions, post_id: post_revision.post_id, revision: post_revision.number expect(response).to be_forbidden end @@ -831,7 +831,7 @@ describe PostsController do it "doesn't return secured categories for moderators if they don't have access" do user = Fabricate(:user) admin = Fabricate(:admin) - moderator = Fabricate(:moderator) + Fabricate(:moderator) group = Fabricate(:group) group.add(user) @@ -852,7 +852,7 @@ describe PostsController do it "doesn't return PMs for moderators" do user = Fabricate(:user) admin = Fabricate(:admin) - moderator = Fabricate(:moderator) + Fabricate(:moderator) pm_post = create_post(user: user, archetype: 'private_message', target_usernames: [admin.username]) PostDestroyer.new(admin, pm_post).destroy @@ -869,7 +869,7 @@ describe PostsController do user = Fabricate(:user) admin = Fabricate(:admin) - post_not_deleted = create_post(user: user) + create_post(user: user) post_deleted_by_user = create_post(user: user) post_deleted_by_admin = create_post(user: user)