Add framing of /donate and /btn
This commit is contained in:
parent
a69c5256a4
commit
63c40ccba7
3 changed files with 37 additions and 0 deletions
16
app/controllers/concerns/controllers/x_frame.rb
Normal file
16
app/controllers/concerns/controllers/x_frame.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
||||||
|
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
||||||
|
module Controllers::XFrame
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
private
|
||||||
|
|
||||||
|
# allows the page to be put in a frame, i.e. remove the X-Frame-Options header
|
||||||
|
def allow_framing
|
||||||
|
response.headers.delete('X-Frame-Options') if response.headers.has_key?('X-Frame-Options')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -5,11 +5,15 @@
|
||||||
class NonprofitsController < ApplicationController
|
class NonprofitsController < ApplicationController
|
||||||
include Controllers::Nonprofit::Current
|
include Controllers::Nonprofit::Current
|
||||||
include Controllers::Nonprofit::Authorization
|
include Controllers::Nonprofit::Authorization
|
||||||
|
include Controllers::XFrame
|
||||||
|
|
||||||
helper_method :current_nonprofit_user?
|
helper_method :current_nonprofit_user?
|
||||||
before_action :authenticate_nonprofit_user!, only: %i[dashboard dashboard_metrics dashboard_todos payment_history profile_todos recurring_donation_stats update verify_identity]
|
before_action :authenticate_nonprofit_user!, only: %i[dashboard dashboard_metrics dashboard_todos payment_history profile_todos recurring_donation_stats update verify_identity]
|
||||||
before_action :authenticate_super_admin!, if: proc {|c| ( c.action_name == "destroy") || (c.action_name == "show" && !current_nonprofit.published) }
|
before_action :authenticate_super_admin!, if: proc {|c| ( c.action_name == "destroy") || (c.action_name == "show" && !current_nonprofit.published) }
|
||||||
|
|
||||||
|
# we have to allow nonprofits/:id/donation and nonprofits/:id/btn to be framed
|
||||||
|
after_action :allow_framing, only: %i[donate btn]
|
||||||
|
|
||||||
# get /nonprofits/:id
|
# get /nonprofits/:id
|
||||||
# get /:state_code/:city/:name
|
# get /:state_code/:city/:name
|
||||||
def show
|
def show
|
||||||
|
|
|
@ -76,4 +76,21 @@ describe NonprofitsController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#donate' do
|
||||||
|
let(:nonprofit) { force_create(:nm_justice) }
|
||||||
|
it 'allows being put into a frame by not setting X-Frame-Options header' do
|
||||||
|
get :donate, params: {id: nonprofit.id}
|
||||||
|
expect(response.headers).to_not include 'X-Frame-Options'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#btn' do
|
||||||
|
let(:nonprofit) { force_create(:nm_justice) }
|
||||||
|
it 'allows being put into a frame by not setting X-Frame-Options header' do
|
||||||
|
get :btn, params: {id: nonprofit.id}
|
||||||
|
expect(response.headers).to_not include 'X-Frame-Options'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue