Support for creating embedded topics via API

This commit is contained in:
Robin Ward 2014-04-03 14:42:26 -04:00
parent ecf211aa3f
commit dbab628e16
3 changed files with 26 additions and 1 deletions

View File

@ -256,6 +256,9 @@ class PostsController < ApplicationController
# php seems to be sending this incorrectly, don't fight with it # php seems to be sending this incorrectly, don't fight with it
params[:skip_validations] = params[:skip_validations].to_s == "true" params[:skip_validations] = params[:skip_validations].to_s == "true"
permitted << :skip_validations permitted << :skip_validations
# We allow `embed_url` via the API
permitted << :embed_url
end end
params.require(:raw) params.require(:raw)

View File

@ -64,6 +64,7 @@ class PostCreator
track_topic track_topic
update_topic_stats update_topic_stats
update_user_counts update_user_counts
create_embedded_topic
publish publish
ensure_in_allowed_users if guardian.is_staff? ensure_in_allowed_users if guardian.is_staff?
@ -82,7 +83,6 @@ class PostCreator
@post @post
end end
def self.create(user, opts) def self.create(user, opts)
PostCreator.new(user, opts).create PostCreator.new(user, opts).create
end end
@ -110,6 +110,14 @@ class PostCreator
protected protected
# You can supply an `embed_url` for a post to set up the embedded relationship.
# This is used by the wp-discourse plugin to associate a remote post with a
# discourse post.
def create_embedded_topic
return unless @opts[:embed_url].present?
TopicEmbed.create!(topic_id: @post.topic_id, post_id: @post.id, embed_url: @opts[:embed_url])
end
def handle_spam def handle_spam
if @spam if @spam
GroupMessage.create( Group[:moderators].name, GroupMessage.create( Group[:moderators].name,

View File

@ -420,5 +420,19 @@ describe PostCreator do
end end
end end
describe "embed_url" do
let(:embed_url) { "http://eviltrout.com/stupid-url" }
it "creates the topic_embed record" do
creator = PostCreator.new(user,
embed_url: embed_url,
title: 'Reviews of Science Ovens',
raw: 'Did you know that you can use microwaves to cook your dinner? Science!')
post = creator.create
TopicEmbed.where(embed_url: embed_url).exists?.should be_true
end
end
end end