Commit 14a2302f4c31e951f3b65d70edfb5d356a7d2c67
1 parent
f468e3c4
Exists in
master
and in
29 other branches
Add a option to enable whitelist in the environment
Showing
4 changed files
with
19 additions
and
11 deletions
Show diff stats
app/controllers/application_controller.rb
| ... | ... | @@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base |
| 8 | 8 | before_filter :verify_members_whitelist, :if => :user |
| 9 | 9 | |
| 10 | 10 | def verify_members_whitelist |
| 11 | - render_access_denied unless user.is_admin? || environment.members_whitelist.blank? || environment.in_whitelist?(user) | |
| 11 | + render_access_denied unless user.is_admin? || environment.in_whitelist?(user) | |
| 12 | 12 | end |
| 13 | 13 | |
| 14 | 14 | def allow_cross_domain_access | ... | ... |
app/models/environment.rb
| ... | ... | @@ -295,10 +295,11 @@ class Environment < ActiveRecord::Base |
| 295 | 295 | settings_items :access_control_allow_origin, :type => Array, :default => [] |
| 296 | 296 | settings_items :access_control_allow_methods, :type => String |
| 297 | 297 | |
| 298 | + settings_items :members_whitelist_enabled, :type => :boolean, :default => false | |
| 298 | 299 | settings_items :members_whitelist, :type => Array, :default => [] |
| 299 | 300 | |
| 300 | 301 | def in_whitelist?(person) |
| 301 | - members_whitelist.include?(person.id) | |
| 302 | + !members_whitelist_enabled || members_whitelist.include?(person.id) | |
| 302 | 303 | end |
| 303 | 304 | |
| 304 | 305 | def members_whitelist=(members) | ... | ... |
app/views/features/index.rhtml
| ... | ... | @@ -38,9 +38,15 @@ Check all the features you want to enable for your environment, uncheck all the |
| 38 | 38 | <hr/> |
| 39 | 39 | |
| 40 | 40 | <h3><%= _('Members Whitelist') %></h3> |
| 41 | - <div class="info"><%= _('Allow these people to access this environment:') %></div> | |
| 42 | - <% tokenized_members = prepare_to_token_input(environment.people.find(:all, :conditions => {:id => environment.members_whitelist})) %> | |
| 43 | - <%= 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}) %> | |
| 41 | + <div class="option"> | |
| 42 | + <%= check_box :environment, :members_whitelist_enabled %> | |
| 43 | + <label><%= _('Enable whitelist') %></label> | |
| 44 | + </div> | |
| 45 | + <div class="input"> | |
| 46 | + <div class="info"><%= _('Allow these people to access this environment:') %></div> | |
| 47 | + <% tokenized_members = prepare_to_token_input(environment.people.find(:all, :conditions => {:id => environment.members_whitelist})) %> | |
| 48 | + <%= 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}) %> | |
| 49 | + </div> | |
| 44 | 50 | <hr/> |
| 45 | 51 | |
| 46 | 52 | <div> | ... | ... |
test/functional/application_controller_test.rb
| ... | ... | @@ -581,10 +581,10 @@ class ApplicationControllerTest < ActionController::TestCase |
| 581 | 581 | assert_redirected_to :controller => 'account', :action => 'login' |
| 582 | 582 | end |
| 583 | 583 | |
| 584 | - should 'do allow member in whitelist to access an environment' do | |
| 584 | + should 'do not allow member not included in whitelist to access an environment' do | |
| 585 | 585 | user = create_user |
| 586 | 586 | e = Environment.default |
| 587 | - e.members_whitelist = '1' | |
| 587 | + e.members_whitelist_enabled = true | |
| 588 | 588 | e.save! |
| 589 | 589 | login_as(user.login) |
| 590 | 590 | get :index |
| ... | ... | @@ -594,6 +594,7 @@ class ApplicationControllerTest < ActionController::TestCase |
| 594 | 594 | should 'allow member in whitelist to access an environment' do |
| 595 | 595 | user = create_user |
| 596 | 596 | e = Environment.default |
| 597 | + e.members_whitelist_enabled = true | |
| 597 | 598 | e.members_whitelist = "#{user.person.id}" |
| 598 | 599 | e.save! |
| 599 | 600 | login_as(user.login) |
| ... | ... | @@ -601,19 +602,19 @@ class ApplicationControllerTest < ActionController::TestCase |
| 601 | 602 | assert_response :success |
| 602 | 603 | end |
| 603 | 604 | |
| 604 | - should 'allow members to access an environment if whitelist is blank' do | |
| 605 | + should 'allow members to access an environment if whitelist is disabled' do | |
| 605 | 606 | user = create_user |
| 606 | 607 | e = Environment.default |
| 607 | - e.members_whitelist = '' | |
| 608 | + e.members_whitelist_enabled = false | |
| 608 | 609 | e.save! |
| 609 | 610 | login_as(user.login) |
| 610 | 611 | get :index |
| 611 | 612 | assert_response :success |
| 612 | 613 | end |
| 613 | 614 | |
| 614 | - should 'allow admin to access an environment' do | |
| 615 | + should 'allow admin to access an environment if whitelist is enabled' do | |
| 615 | 616 | e = Environment.default |
| 616 | - e.members_whitelist = '1' | |
| 617 | + e.members_whitelist_enabled = true | |
| 617 | 618 | e.save! |
| 618 | 619 | login_as(create_admin_user(e)) |
| 619 | 620 | get :index | ... | ... |