Commit f468e3c410eebf8eed31523647b4af78b3658b23
1 parent
623a401d
Exists in
master
and in
27 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 | 51 | redirect_to :action => 'manage_fields' |
| 52 | 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 | 60 | end | ... | ... |
app/helpers/token_helper.rb
| ... | ... | @@ -18,6 +18,7 @@ module TokenHelper |
| 18 | 18 | options[:on_add] ||= 'null' |
| 19 | 19 | options[:on_delete] ||= 'null' |
| 20 | 20 | options[:on_ready] ||= 'null' |
| 21 | + options[:query_param] ||= 'q' | |
| 21 | 22 | |
| 22 | 23 | result = text_field_tag(name, nil, text_field_options.merge(html_options.merge({:id => element_id}))) |
| 23 | 24 | result += javascript_tag("jQuery('##{element_id}') |
| ... | ... | @@ -30,7 +31,7 @@ module TokenHelper |
| 30 | 31 | searchDelay: #{options[:search_delay].to_json}, |
| 31 | 32 | preventDuplicates: #{options[:prevent_duplicates].to_json}, |
| 32 | 33 | backspaceDeleteItem: #{options[:backspace_delete_item].to_json}, |
| 33 | - queryParam: #{name.to_json}, | |
| 34 | + queryParam: #{options[:query_param].to_json}, | |
| 34 | 35 | tokenLimit: #{options[:token_limit].to_json}, |
| 35 | 36 | onResult: #{options[:on_result]}, |
| 36 | 37 | onAdd: #{options[:on_add]}, |
| ... | ... | @@ -48,4 +49,4 @@ module TokenHelper |
| 48 | 49 | result |
| 49 | 50 | end |
| 50 | 51 | |
| 51 | -end | |
| 52 | 52 | \ No newline at end of file |
| 53 | +end | ... | ... |
app/models/environment.rb
| ... | ... | @@ -298,11 +298,11 @@ class Environment < ActiveRecord::Base |
| 298 | 298 | settings_items :members_whitelist, :type => Array, :default => [] |
| 299 | 299 | |
| 300 | 300 | def in_whitelist?(person) |
| 301 | - members_whitelist.include?(person.identifier) | |
| 301 | + members_whitelist.include?(person.id) | |
| 302 | 302 | end |
| 303 | 303 | |
| 304 | 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 | 306 | end |
| 307 | 307 | |
| 308 | 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 | 38 | <hr/> |
| 39 | 39 | |
| 40 | 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 | 44 | <hr/> |
| 44 | 45 | |
| 45 | 46 | <div> | ... | ... |
test/functional/application_controller_test.rb
| ... | ... | @@ -584,7 +584,7 @@ class ApplicationControllerTest < ActionController::TestCase |
| 584 | 584 | should 'do allow member in whitelist to access an environment' do |
| 585 | 585 | user = create_user |
| 586 | 586 | e = Environment.default |
| 587 | - e.members_whitelist = 'admin' | |
| 587 | + e.members_whitelist = '1' | |
| 588 | 588 | e.save! |
| 589 | 589 | login_as(user.login) |
| 590 | 590 | get :index |
| ... | ... | @@ -594,7 +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 = user.person.identifier | |
| 597 | + e.members_whitelist = "#{user.person.id}" | |
| 598 | 598 | e.save! |
| 599 | 599 | login_as(user.login) |
| 600 | 600 | get :index |
| ... | ... | @@ -613,7 +613,7 @@ class ApplicationControllerTest < ActionController::TestCase |
| 613 | 613 | |
| 614 | 614 | should 'allow admin to access an environment' do |
| 615 | 615 | e = Environment.default |
| 616 | - e.members_whitelist = 'ze' | |
| 616 | + e.members_whitelist = '1' | |
| 617 | 617 | e.save! |
| 618 | 618 | login_as(create_admin_user(e)) |
| 619 | 619 | get :index | ... | ... |
test/functional/features_controller_test.rb
| ... | ... | @@ -154,4 +154,12 @@ class FeaturesControllerTest < ActionController::TestCase |
| 154 | 154 | assert_equal true, e.custom_community_fields['contact_person']['required'] |
| 155 | 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 | 165 | end | ... | ... |