Add embed/info endpoint for TopicEmbed queries

This commit is contained in:
Jude Aakjaer
2015-05-06 01:00:31 +00:00
parent 83efde79f0
commit 9cca510944
5 changed files with 70 additions and 1 deletions

View File

@ -1,6 +1,8 @@
class EmbedController < ApplicationController
skip_before_filter :check_xhr, :preload_json, :verify_authenticity_token
before_filter :ensure_embeddable
before_filter :ensure_embeddable, except: [ :info ]
before_filter :ensure_api_request, only: [ :info ]
layout 'embed'
@ -35,6 +37,15 @@ class EmbedController < ApplicationController
discourse_expires_in 1.minute
end
def info
embed_url = params.require(:embed_url)
@topic_embed = TopicEmbed.where(embed_url: embed_url).first
raise Discourse::NotFound if @topic_embed.nil?
render_serialized(@topic_embed, TopicEmbedSerializer, root: false)
end
def count
embed_urls = params[:embed_url]
by_url = {}
@ -55,6 +66,10 @@ class EmbedController < ApplicationController
private
def ensure_api_request
raise Discourse::InvalidAccess.new('api key not set') if !is_api?
end
def ensure_embeddable
if !(Rails.env.development? && current_user.try(:admin?))