Commit f468e3c410eebf8eed31523647b4af78b3658b23
1 parent
623a401d
Exists in
master
and in
29 other branches
Use tokeninput to edit members whitelist
Showing
6 changed files
with
25 additions
and
9 deletions
Show diff stats
app/controllers/admin/features_controller.rb
@@ -51,4 +51,10 @@ class FeaturesController < AdminController | @@ -51,4 +51,10 @@ class FeaturesController < AdminController | ||
51 | redirect_to :action => 'manage_fields' | 51 | redirect_to :action => 'manage_fields' |
52 | end | 52 | end |
53 | 53 | ||
54 | + def search_members | ||
55 | + arg = params[:q].downcase | ||
56 | + result = environment.people.find(:all, :conditions => ['LOWER(name) LIKE ?', "%#{arg}%"]) | ||
57 | + render :text => prepare_to_token_input(result).to_json | ||
58 | + end | ||
59 | + | ||
54 | end | 60 | end |
app/helpers/token_helper.rb
@@ -18,6 +18,7 @@ module TokenHelper | @@ -18,6 +18,7 @@ module TokenHelper | ||
18 | options[:on_add] ||= 'null' | 18 | options[:on_add] ||= 'null' |
19 | options[:on_delete] ||= 'null' | 19 | options[:on_delete] ||= 'null' |
20 | options[:on_ready] ||= 'null' | 20 | options[:on_ready] ||= 'null' |
21 | + options[:query_param] ||= 'q' | ||
21 | 22 | ||
22 | result = text_field_tag(name, nil, text_field_options.merge(html_options.merge({:id => element_id}))) | 23 | result = text_field_tag(name, nil, text_field_options.merge(html_options.merge({:id => element_id}))) |
23 | result += javascript_tag("jQuery('##{element_id}') | 24 | result += javascript_tag("jQuery('##{element_id}') |
@@ -30,7 +31,7 @@ module TokenHelper | @@ -30,7 +31,7 @@ module TokenHelper | ||
30 | searchDelay: #{options[:search_delay].to_json}, | 31 | searchDelay: #{options[:search_delay].to_json}, |
31 | preventDuplicates: #{options[:prevent_duplicates].to_json}, | 32 | preventDuplicates: #{options[:prevent_duplicates].to_json}, |
32 | backspaceDeleteItem: #{options[:backspace_delete_item].to_json}, | 33 | backspaceDeleteItem: #{options[:backspace_delete_item].to_json}, |
33 | - queryParam: #{name.to_json}, | 34 | + queryParam: #{options[:query_param].to_json}, |
34 | tokenLimit: #{options[:token_limit].to_json}, | 35 | tokenLimit: #{options[:token_limit].to_json}, |
35 | onResult: #{options[:on_result]}, | 36 | onResult: #{options[:on_result]}, |
36 | onAdd: #{options[:on_add]}, | 37 | onAdd: #{options[:on_add]}, |
@@ -48,4 +49,4 @@ module TokenHelper | @@ -48,4 +49,4 @@ module TokenHelper | ||
48 | result | 49 | result |
49 | end | 50 | end |
50 | 51 | ||
51 | -end | ||
52 | \ No newline at end of file | 52 | \ No newline at end of file |
53 | +end |
app/models/environment.rb
@@ -298,11 +298,11 @@ class Environment < ActiveRecord::Base | @@ -298,11 +298,11 @@ class Environment < ActiveRecord::Base | ||
298 | settings_items :members_whitelist, :type => Array, :default => [] | 298 | settings_items :members_whitelist, :type => Array, :default => [] |
299 | 299 | ||
300 | def in_whitelist?(person) | 300 | def in_whitelist?(person) |
301 | - members_whitelist.include?(person.identifier) | 301 | + members_whitelist.include?(person.id) |
302 | end | 302 | end |
303 | 303 | ||
304 | def members_whitelist=(members) | 304 | def members_whitelist=(members) |
305 | - settings[:members_whitelist] = members.split(',').map(&:strip).reject(&:blank?) | 305 | + settings[:members_whitelist] = members.split(',').map(&:to_i) |
306 | end | 306 | end |
307 | 307 | ||
308 | def news_amount_by_folder=(amount) | 308 | def news_amount_by_folder=(amount) |
app/views/features/index.rhtml
@@ -38,8 +38,9 @@ Check all the features you want to enable for your environment, uncheck all the | @@ -38,8 +38,9 @@ Check all the features you want to enable for your environment, uncheck all the | ||
38 | <hr/> | 38 | <hr/> |
39 | 39 | ||
40 | <h3><%= _('Members Whitelist') %></h3> | 40 | <h3><%= _('Members Whitelist') %></h3> |
41 | - <div class="info"><%= _('Allow these people to access this environment (separate with commas):') %></div> | ||
42 | - <%= text_field :environment, :members_whitelist, :value => environment.members_whitelist.join(',') %> | 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}) %> | ||
43 | <hr/> | 44 | <hr/> |
44 | 45 | ||
45 | <div> | 46 | <div> |
test/functional/application_controller_test.rb
@@ -584,7 +584,7 @@ class ApplicationControllerTest < ActionController::TestCase | @@ -584,7 +584,7 @@ class ApplicationControllerTest < ActionController::TestCase | ||
584 | should 'do allow member in whitelist to access an environment' do | 584 | should 'do allow member in whitelist to access an environment' do |
585 | user = create_user | 585 | user = create_user |
586 | e = Environment.default | 586 | e = Environment.default |
587 | - e.members_whitelist = 'admin' | 587 | + e.members_whitelist = '1' |
588 | e.save! | 588 | e.save! |
589 | login_as(user.login) | 589 | login_as(user.login) |
590 | get :index | 590 | get :index |
@@ -594,7 +594,7 @@ class ApplicationControllerTest < ActionController::TestCase | @@ -594,7 +594,7 @@ class ApplicationControllerTest < ActionController::TestCase | ||
594 | should 'allow member in whitelist to access an environment' do | 594 | should 'allow member in whitelist to access an environment' do |
595 | user = create_user | 595 | user = create_user |
596 | e = Environment.default | 596 | e = Environment.default |
597 | - e.members_whitelist = user.person.identifier | 597 | + e.members_whitelist = "#{user.person.id}" |
598 | e.save! | 598 | e.save! |
599 | login_as(user.login) | 599 | login_as(user.login) |
600 | get :index | 600 | get :index |
@@ -613,7 +613,7 @@ class ApplicationControllerTest < ActionController::TestCase | @@ -613,7 +613,7 @@ class ApplicationControllerTest < ActionController::TestCase | ||
613 | 613 | ||
614 | should 'allow admin to access an environment' do | 614 | should 'allow admin to access an environment' do |
615 | e = Environment.default | 615 | e = Environment.default |
616 | - e.members_whitelist = 'ze' | 616 | + e.members_whitelist = '1' |
617 | e.save! | 617 | e.save! |
618 | login_as(create_admin_user(e)) | 618 | login_as(create_admin_user(e)) |
619 | get :index | 619 | get :index |
test/functional/features_controller_test.rb
@@ -154,4 +154,12 @@ class FeaturesControllerTest < ActionController::TestCase | @@ -154,4 +154,12 @@ class FeaturesControllerTest < ActionController::TestCase | ||
154 | assert_equal true, e.custom_community_fields['contact_person']['required'] | 154 | assert_equal true, e.custom_community_fields['contact_person']['required'] |
155 | end | 155 | end |
156 | 156 | ||
157 | + should 'search members' do | ||
158 | + uses_host 'anhetegua.net' | ||
159 | + person = fast_create(Person, :environment_id => Environment.find(2).id) | ||
160 | + xhr :get, :search_members, :q => person.name[0..2] | ||
161 | + json_response = ActiveSupport::JSON.decode(@response.body) | ||
162 | + assert_includes json_response, {"id"=>person.id, "name"=>person.name} | ||
163 | + end | ||
164 | + | ||
157 | end | 165 | end |