Commit abde92102fb7bfdd9e350b3a0aa10b03d8630a12

Authored by Victor Costa
1 parent d4f22713

Added an option to make a environment private

app/controllers/application_controller.rb
... ... @@ -4,6 +4,7 @@ class ApplicationController < ActionController::Base
4 4 before_filter :detect_stuff_by_domain
5 5 before_filter :init_noosfero_plugins_controller_filters
6 6 before_filter :allow_cross_domain_access
  7 + before_filter :login_required, :if => :private_environment?
7 8  
8 9 def allow_cross_domain_access
9 10 origin = request.headers['Origin']
... ... @@ -190,4 +191,8 @@ class ApplicationController < ActionController::Base
190 191 {:results => scope.paginate(paginate_options)}
191 192 end
192 193  
  194 + def private_environment?
  195 + @environment.enabled?(:restrict_to_members)
  196 + end
  197 +
193 198 end
... ...
app/models/environment.rb
... ... @@ -130,7 +130,8 @@ class Environment < ActiveRecord::Base
130 130 'send_welcome_email_to_new_users' => _('Send welcome e-mail to new users'),
131 131 'allow_change_of_redirection_after_login' => _('Allow users to set the page to redirect after login'),
132 132 'display_my_communities_on_user_menu' => _('Display on menu the list of communities the user can manage'),
133   - 'display_my_enterprises_on_user_menu' => _('Display on menu the list of enterprises the user can manage')
  133 + 'display_my_enterprises_on_user_menu' => _('Display on menu the list of enterprises the user can manage'),
  134 + 'restrict_to_members' => _('Show content only to members')
134 135 }
135 136 end
136 137  
... ...
test/functional/application_controller_test.rb
... ... @@ -574,4 +574,11 @@ class ApplicationControllerTest < ActionController::TestCase
574 574 assert_no_tag :tag => 'meta', :attributes => { :property => 'article:published_time' }
575 575 assert_no_tag :tag => 'meta', :attributes => { :property => 'og:image' }
576 576 end
  577 +
  578 + should 'redirect to login if environment is restrict to members' do
  579 + Environment.default.enable(:restrict_to_members)
  580 + get :index
  581 + assert_redirected_to :controller => 'account', :action => 'login'
  582 + end
  583 +
577 584 end
... ...