From abde92102fb7bfdd9e350b3a0aa10b03d8630a12 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Fri, 4 Jul 2014 11:59:48 -0300 Subject: [PATCH] Added an option to make a environment private --- app/controllers/application_controller.rb | 5 +++++ app/models/environment.rb | 3 ++- test/functional/application_controller_test.rb | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6e1f0f8..20d58bf 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,6 +4,7 @@ class ApplicationController < ActionController::Base before_filter :detect_stuff_by_domain before_filter :init_noosfero_plugins_controller_filters before_filter :allow_cross_domain_access + before_filter :login_required, :if => :private_environment? def allow_cross_domain_access origin = request.headers['Origin'] @@ -190,4 +191,8 @@ class ApplicationController < ActionController::Base {:results => scope.paginate(paginate_options)} end + def private_environment? + @environment.enabled?(:restrict_to_members) + end + end diff --git a/app/models/environment.rb b/app/models/environment.rb index d57ecc2..7d64472 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -130,7 +130,8 @@ class Environment < ActiveRecord::Base 'send_welcome_email_to_new_users' => _('Send welcome e-mail to new users'), 'allow_change_of_redirection_after_login' => _('Allow users to set the page to redirect after login'), 'display_my_communities_on_user_menu' => _('Display on menu the list of communities the user can manage'), - 'display_my_enterprises_on_user_menu' => _('Display on menu the list of enterprises the user can manage') + 'display_my_enterprises_on_user_menu' => _('Display on menu the list of enterprises the user can manage'), + 'restrict_to_members' => _('Show content only to members') } end diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index f7f4108..cd612c1 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -574,4 +574,11 @@ class ApplicationControllerTest < ActionController::TestCase assert_no_tag :tag => 'meta', :attributes => { :property => 'article:published_time' } assert_no_tag :tag => 'meta', :attributes => { :property => 'og:image' } end + + should 'redirect to login if environment is restrict to members' do + Environment.default.enable(:restrict_to_members) + get :index + assert_redirected_to :controller => 'account', :action => 'login' + end + end -- libgit2 0.21.2