From 84c83afd3508efb431b84236124f30411c5d81b1 Mon Sep 17 00:00:00 2001 From: Mudasir Raza Date: Thu, 17 Aug 2017 16:53:04 +0500 Subject: [PATCH] Allow optional import_mode param for posts in api (#4952) --- app/controllers/posts_controller.rb | 3 +++ spec/controllers/posts_controller_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index ca69ac2f14d..fa99d1f2d99 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -574,6 +574,9 @@ class PostsController < ApplicationController params[:skip_validations] = params[:skip_validations].to_s == "true" permitted << :skip_validations + params[:import_mode] = params[:import_mode].to_s == "true" + permitted << :import_mode + # We allow `embed_url` via the API permitted << :embed_url diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index c5ffb51252c..c068fa97540 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -631,6 +631,26 @@ describe PostsController do expect(response.body).to eq(original) end + + it 'allows to create posts in import_mode' do + NotificationEmailer.enable + post = Fabricate(:post) + user = Fabricate(:user) + master_key = ApiKey.create_master_key.key + + xhr :post, :create, {api_username: user.username, api_key: master_key, raw: 'this is test reply 1', topic_id: post.topic.id, reply_to_post_number: 1} + expect(response).to be_success + expect(post.topic.user.notifications.count).to eq(1) + post.topic.user.notifications.destroy_all + + xhr :post, :create, {api_username: user.username, api_key: master_key, raw: 'this is test reply 2', topic_id: post.topic.id, reply_to_post_number: 1, :import_mode => true} + expect(response).to be_success + expect(post.topic.user.notifications.count).to eq(0) + + xhr :post, :create, {api_username: user.username, api_key: master_key, raw: 'this is test reply 3', topic_id: post.topic.id, reply_to_post_number: 1, :import_mode => false} + expect(response).to be_success + expect(post.topic.user.notifications.count).to eq(1) + end end describe 'when logged in' do