aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/widgets_controller.rb8
-rw-r--r--config/general.yml-example8
-rw-r--r--lib/configuration.rb1
-rw-r--r--spec/controllers/widgets_controller_spec.rb33
4 files changed, 49 insertions, 1 deletions
diff --git a/app/controllers/widgets_controller.rb b/app/controllers/widgets_controller.rb
index bdbabeac4..017d3a77f 100644
--- a/app/controllers/widgets_controller.rb
+++ b/app/controllers/widgets_controller.rb
@@ -8,7 +8,7 @@ require 'securerandom'
class WidgetsController < ApplicationController
- before_filter :find_info_request
+ before_filter :check_widget_config, :find_info_request
def show
medium_cache
@@ -40,4 +40,10 @@ class WidgetsController < ApplicationController
@info_request = InfoRequest.find(params[:request_id])
end
+ def check_widget_config
+ unless AlaveteliConfiguration::enable_widgets
+ raise ActiveRecord::RecordNotFound.new("Page not enabled")
+ end
+ end
+
end
diff --git a/config/general.yml-example b/config/general.yml-example
index 88d89958d..df140136c 100644
--- a/config/general.yml-example
+++ b/config/general.yml-example
@@ -802,3 +802,11 @@ RESPONSIVE_STYLING: true
# ---
PRODUCTION_MAILER_DELIVERY_METHOD: sendmail
+# If ENABLE_WIDGETS is set to true, Alaveteli will allow the embedding of a
+# 'widget' linking to a request on other sites. This widget will record
+# how many people click on an 'I also want to know' button.
+#
+# ENABLE_WIDGETS - Boolean (default: false)
+#
+# ---
+ENABLE_WIDGETS: false
diff --git a/lib/configuration.rb b/lib/configuration.rb
index 7921b93fa..c983152e0 100644
--- a/lib/configuration.rb
+++ b/lib/configuration.rb
@@ -32,6 +32,7 @@ module AlaveteliConfiguration
:DISABLE_EMERGENCY_USER => false,
:DOMAIN => 'localhost:3000',
:DONATION_URL => '',
+ :ENABLE_WIDGETS => false,
:EXCEPTION_NOTIFICATIONS_FROM => '',
:EXCEPTION_NOTIFICATIONS_TO => '',
:FORCE_REGISTRATION_ON_NEW_REQUEST => false,
diff --git a/spec/controllers/widgets_controller_spec.rb b/spec/controllers/widgets_controller_spec.rb
index e60f1b3cb..28f6c1904 100644
--- a/spec/controllers/widgets_controller_spec.rb
+++ b/spec/controllers/widgets_controller_spec.rb
@@ -9,6 +9,7 @@ describe WidgetsController do
before do
@info_request = FactoryGirl.create(:info_request)
+ AlaveteliConfiguration.stub!(:enable_widgets).and_return(true)
end
it 'should render the widget template' do
@@ -45,6 +46,16 @@ describe WidgetsController do
end
+ context 'when widgets are not enabled' do
+
+ it 'should return a 404' do
+ AlaveteliConfiguration.stub!(:enable_widgets).and_return(false)
+ lambda{ get :show, :request_id => @info_request.id }.should
+ raise_error(ActiveRecord::RecordNotFound)
+ end
+
+ end
+
end
@@ -52,6 +63,7 @@ describe WidgetsController do
before do
@info_request = FactoryGirl.create(:info_request)
+ AlaveteliConfiguration.stub!(:enable_widgets).and_return(true)
end
it 'should render the create widget template' do
@@ -64,12 +76,23 @@ describe WidgetsController do
assigns[:info_request].should == @info_request
end
+ context 'when widgets are not enabled' do
+
+ it 'should return a 404' do
+ AlaveteliConfiguration.stub!(:enable_widgets).and_return(false)
+ lambda{ get :new, :request_id => @info_request.id }.should
+ raise_error(ActiveRecord::RecordNotFound)
+ end
+
+ end
+
end
describe :update do
before do
@info_request = FactoryGirl.create(:info_request)
+ AlaveteliConfiguration.stub!(:enable_widgets).and_return(true)
end
it 'should find the info request' do
@@ -105,6 +128,16 @@ describe WidgetsController do
end
+ context 'when widgets are not enabled' do
+
+ it 'should raise ActiveRecord::RecordNotFound' do
+ AlaveteliConfiguration.stub!(:enable_widgets).and_return(false)
+ lambda{ get :update, :request_id => @info_request.id }.should
+ raise_error(ActiveRecord::RecordNotFound)
+ end
+
+ end
+
end
end