diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 8f64b8c82a..069fed03af 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -61,7 +61,7 @@ def hidden_user_explanation locals: { name_to: info_request.user_name.html_safe, info_request: info_request, :reason => params[:reason], - info_request_url: 'http://' + AlaveteliConfiguration.domain + request_path(info_request), + info_request_url: request_link(request_path(info_request)), site_name: site_name.html_safe } end @@ -115,4 +115,14 @@ def ask_the_eu_link %q(Ask The EU) end + def request_link(request_path) + # https links in emails if forcing SSL + protocol = if AlaveteliConfiguration.force_ssl + "https://" + else + "http://" + end + "#{protocol}#{AlaveteliConfiguration.domain}#{request_path}" + end + end diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 9a2558e347..41a640b951 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -109,6 +109,26 @@ expect(response.body).to match(/Yours,\n\nThe A&B Test team/) end + describe 'constructing the request link' do + + it 'uses http if force_ssl is false' do + allow(AlaveteliConfiguration). + to receive(:force_ssl).and_return(false) + get :hidden_user_explanation, info_request_id: info_request.id + expect(response.body). + to match "http://test.host/request/#{info_request.url_title}" + end + + it 'uses https if force_ssl is true' do + allow(AlaveteliConfiguration). + to receive(:force_ssl).and_return(true) + get :hidden_user_explanation, info_request_id: info_request.id + expect(response.body). + to match "https://test.host/request/#{info_request.url_title}" + end + + end + end end