From 14a2302f4c31e951f3b65d70edfb5d356a7d2c67 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 8 Jul 2014 09:36:10 -0300 Subject: [PATCH] Add a option to enable whitelist in the environment --- app/controllers/application_controller.rb | 2 +- app/models/environment.rb | 3 ++- app/views/features/index.rhtml | 12 +++++++++--- test/functional/application_controller_test.rb | 13 +++++++------ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f3712f7..68a2011 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base before_filter :verify_members_whitelist, :if => :user def verify_members_whitelist - render_access_denied unless user.is_admin? || environment.members_whitelist.blank? || environment.in_whitelist?(user) + render_access_denied unless user.is_admin? || environment.in_whitelist?(user) end def allow_cross_domain_access diff --git a/app/models/environment.rb b/app/models/environment.rb index bf26a35..da06096 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -295,10 +295,11 @@ class Environment < ActiveRecord::Base settings_items :access_control_allow_origin, :type => Array, :default => [] settings_items :access_control_allow_methods, :type => String + settings_items :members_whitelist_enabled, :type => :boolean, :default => false settings_items :members_whitelist, :type => Array, :default => [] def in_whitelist?(person) - members_whitelist.include?(person.id) + !members_whitelist_enabled || members_whitelist.include?(person.id) end def members_whitelist=(members) diff --git a/app/views/features/index.rhtml b/app/views/features/index.rhtml index 331c081..3438c01 100644 --- a/app/views/features/index.rhtml +++ b/app/views/features/index.rhtml @@ -38,9 +38,15 @@ Check all the features you want to enable for your environment, uncheck all the

<%= _('Members Whitelist') %>

-
<%= _('Allow these people to access this environment:') %>
- <% tokenized_members = prepare_to_token_input(environment.people.find(:all, :conditions => {:id => environment.members_whitelist})) %> - <%= token_input_field_tag('environment[members_whitelist]', 'search-members', {:action => 'search_members'}, {:focus => false, :hint_text => _('Type in a search term for a user'), :pre_populate => tokenized_members}) %> +
+ <%= check_box :environment, :members_whitelist_enabled %> + +
+
+
<%= _('Allow these people to access this environment:') %>
+ <% tokenized_members = prepare_to_token_input(environment.people.find(:all, :conditions => {:id => environment.members_whitelist})) %> + <%= token_input_field_tag('environment[members_whitelist]', 'search-members', {:action => 'search_members'}, {:focus => false, :hint_text => _('Type in a search term for a user'), :pre_populate => tokenized_members}) %> +

diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index 0e79b03..96d5334 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -581,10 +581,10 @@ class ApplicationControllerTest < ActionController::TestCase assert_redirected_to :controller => 'account', :action => 'login' end - should 'do allow member in whitelist to access an environment' do + should 'do not allow member not included in whitelist to access an environment' do user = create_user e = Environment.default - e.members_whitelist = '1' + e.members_whitelist_enabled = true e.save! login_as(user.login) get :index @@ -594,6 +594,7 @@ class ApplicationControllerTest < ActionController::TestCase should 'allow member in whitelist to access an environment' do user = create_user e = Environment.default + e.members_whitelist_enabled = true e.members_whitelist = "#{user.person.id}" e.save! login_as(user.login) @@ -601,19 +602,19 @@ class ApplicationControllerTest < ActionController::TestCase assert_response :success end - should 'allow members to access an environment if whitelist is blank' do + should 'allow members to access an environment if whitelist is disabled' do user = create_user e = Environment.default - e.members_whitelist = '' + e.members_whitelist_enabled = false e.save! login_as(user.login) get :index assert_response :success end - should 'allow admin to access an environment' do + should 'allow admin to access an environment if whitelist is enabled' do e = Environment.default - e.members_whitelist = '1' + e.members_whitelist_enabled = true e.save! login_as(create_admin_user(e)) get :index -- libgit2 0.21.2