Commit abde92102fb7bfdd9e350b3a0aa10b03d8630a12
1 parent
d4f22713
Exists in
master
and in
22 other branches
Added an option to make a environment private
Showing
3 changed files
with
14 additions
and
1 deletions
Show diff stats
app/controllers/application_controller.rb
@@ -4,6 +4,7 @@ class ApplicationController < ActionController::Base | @@ -4,6 +4,7 @@ class ApplicationController < ActionController::Base | ||
4 | before_filter :detect_stuff_by_domain | 4 | before_filter :detect_stuff_by_domain |
5 | before_filter :init_noosfero_plugins_controller_filters | 5 | before_filter :init_noosfero_plugins_controller_filters |
6 | before_filter :allow_cross_domain_access | 6 | before_filter :allow_cross_domain_access |
7 | + before_filter :login_required, :if => :private_environment? | ||
7 | 8 | ||
8 | def allow_cross_domain_access | 9 | def allow_cross_domain_access |
9 | origin = request.headers['Origin'] | 10 | origin = request.headers['Origin'] |
@@ -190,4 +191,8 @@ class ApplicationController < ActionController::Base | @@ -190,4 +191,8 @@ class ApplicationController < ActionController::Base | ||
190 | {:results => scope.paginate(paginate_options)} | 191 | {:results => scope.paginate(paginate_options)} |
191 | end | 192 | end |
192 | 193 | ||
194 | + def private_environment? | ||
195 | + @environment.enabled?(:restrict_to_members) | ||
196 | + end | ||
197 | + | ||
193 | end | 198 | end |
app/models/environment.rb
@@ -130,7 +130,8 @@ class Environment < ActiveRecord::Base | @@ -130,7 +130,8 @@ class Environment < ActiveRecord::Base | ||
130 | 'send_welcome_email_to_new_users' => _('Send welcome e-mail to new users'), | 130 | 'send_welcome_email_to_new_users' => _('Send welcome e-mail to new users'), |
131 | 'allow_change_of_redirection_after_login' => _('Allow users to set the page to redirect after login'), | 131 | 'allow_change_of_redirection_after_login' => _('Allow users to set the page to redirect after login'), |
132 | 'display_my_communities_on_user_menu' => _('Display on menu the list of communities the user can manage'), | 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 | end | 136 | end |
136 | 137 |
test/functional/application_controller_test.rb
@@ -574,4 +574,11 @@ class ApplicationControllerTest < ActionController::TestCase | @@ -574,4 +574,11 @@ class ApplicationControllerTest < ActionController::TestCase | ||
574 | assert_no_tag :tag => 'meta', :attributes => { :property => 'article:published_time' } | 574 | assert_no_tag :tag => 'meta', :attributes => { :property => 'article:published_time' } |
575 | assert_no_tag :tag => 'meta', :attributes => { :property => 'og:image' } | 575 | assert_no_tag :tag => 'meta', :attributes => { :property => 'og:image' } |
576 | end | 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 | end | 584 | end |