allow headers to be removed

This commit is contained in:
Lee Lawlor 2014-02-20 10:23:41 -05:00
parent 4cb1c95793
commit b8f2410d5f
2 changed files with 26 additions and 19 deletions

View File

@ -5,6 +5,7 @@ class ApplicationController < ActionController::Base
helper_method :current_user_session, :current_user, :logged_in?, :is_admin?, :get_header_value, :to_bytes helper_method :current_user_session, :current_user, :logged_in?, :is_admin?, :get_header_value, :to_bytes
protect_from_forgery protect_from_forgery
before_filter :allow_cross_domain_access, :set_variables before_filter :allow_cross_domain_access, :set_variables
after_filter :remove_headers
# responds with blank # responds with blank
def respond_with_blank def respond_with_blank
@ -53,6 +54,11 @@ class ApplicationController < ActionController::Base
private private
# remove headers if necessary
def remove_headers
response.headers.delete_if {|key| true} if params[:headers] == 'false'
end
# allow javascript requests from any domain # allow javascript requests from any domain
def allow_cross_domain_access def allow_cross_domain_access
response.headers['Access-Control-Allow-Origin'] = '*' response.headers['Access-Control-Allow-Origin'] = '*'

View File

@ -6,7 +6,7 @@ class PluginsController < ApplicationController
def check_permission def check_permission
@plugin = Plugin.find(params[:id]) @plugin = Plugin.find(params[:id])
if @plugin.user_id != current_user.id if @plugin.user_id != current_user.id
render :text=> "#{t(:permission)} #{t(:plugin)}", :layout => true render :text=> "#{t(:permission)} #{t(:plugin)}", :layout => true and return
return true return true
end end
return false return false
@ -20,7 +20,7 @@ class PluginsController < ApplicationController
def public_plugins def public_plugins
channel_id = params[:channel_id].to_i channel_id = params[:channel_id].to_i
return if channel_id.nil? return if channel_id.nil?
#private page should display all plugins #private page should display all plugins
#plugins = current_user.plugins.where("private_flag = true") #plugins = current_user.plugins.where("private_flag = true")
@plugin_windows = [] @plugin_windows = []
@ -28,7 +28,7 @@ class PluginsController < ApplicationController
plugins.each do |plugin| plugins.each do |plugin|
plugin.make_windows channel_id, api_domain #will only make the window the first time plugin.make_windows channel_id, api_domain #will only make the window the first time
@plugin_windows = @plugin_windows + plugin.public_dashboard_windows(channel_id) @plugin_windows = @plugin_windows + plugin.public_dashboard_windows(channel_id)
end end
respond_to do |format| respond_to do |format|
@ -39,7 +39,7 @@ class PluginsController < ApplicationController
def private_plugins def private_plugins
channel_id = params[:channel_id].to_i channel_id = params[:channel_id].to_i
return if channel_id.nil? return if channel_id.nil?
#private page should display all plugins #private page should display all plugins
@plugin_windows = [] @plugin_windows = []
@ -63,7 +63,7 @@ class PluginsController < ApplicationController
@plugin.user_id = current_user.id @plugin.user_id = current_user.id
@plugin.private_flag = true @plugin.private_flag = true
@plugin.save @plugin.save
# now that the plugin is saved, we can create the default name # now that the plugin is saved, we can create the default name
@plugin.name = "#{t(:plugin_default_name)} #{@plugin.id}" @plugin.name = "#{t(:plugin_default_name)} #{@plugin.id}"
@plugin.save @plugin.save
@ -81,11 +81,11 @@ class PluginsController < ApplicationController
end end
@output = @plugin.html.sub('%%PLUGIN_CSS%%', @plugin.css).sub('%%PLUGIN_JAVASCRIPT%%', @plugin.js) @output = @plugin.html.sub('%%PLUGIN_CSS%%', @plugin.css).sub('%%PLUGIN_JAVASCRIPT%%', @plugin.js)
if @plugin.private? if @plugin.private?
render :layout => false and return render :layout => false and return
else else
if request.url.include? api_domain if request.url.include? api_domain
render :layout => false and return render :layout => false and return
else else
protocol = ssl protocol = ssl
@ -93,27 +93,27 @@ class PluginsController < ApplicationController
redirect_to :host => host, redirect_to :host => host,
:protocol => protocol, :protocol => protocol,
:controller => "plugins", :controller => "plugins",
:action => "show", :action => "show",
:id => @plugin.id and return :id => @plugin.id and return
end end
end end
end end
def show_public def show_public
@plugin = Plugin.find(params[:id]) @plugin = Plugin.find(params[:id])
@output = @plugin.html.sub('%%PLUGIN_CSS%%', @plugin.css).sub('%%PLUGIN_JAVASCRIPT%%', @plugin.js) @output = @plugin.html.sub('%%PLUGIN_CSS%%', @plugin.css).sub('%%PLUGIN_JAVASCRIPT%%', @plugin.js)
if @plugin.private? if @plugin.private?
render :layout => false render :layout => false
else else
if request.url.include? 'api_domain' if request.url.include? 'api_domain'
render :layout => false render :layout => false
else else
redirect_to :host => api_domain, redirect_to :host => api_domain,
:controller => "plugins", :controller => "plugins",
:action => "show", :action => "show",
:id => @plugin.id :id => @plugin.id
end end
end end
@ -130,7 +130,7 @@ class PluginsController < ApplicationController
@plugin.update_attribute(:html,params[:plugin][:html]) @plugin.update_attribute(:html,params[:plugin][:html])
if @plugin.save if @plugin.save
@plugin.update_all_windows @plugin.update_all_windows
redirect_to plugins_path and return redirect_to plugins_path and return
end end
@ -159,3 +159,4 @@ class PluginsController < ApplicationController
redirect_to plugins_path redirect_to plugins_path
end end
end end