Commit 82ba86f13532bad12377fa07b0a0faa289067ce1
1 parent
20446fe0
Exists in
master
and in
29 other branches
invite-members: refactor friends search by usp_id
Removes the need of a hotspot to offer the possibility of searching members by usp_id on invite page. The previous hotspot to provide extra search fields was deemed too specific and complicated. Refactor from commits: 844304db138e2c7bb6234be39301f054b7a657cb 8470293887b42804d572dcffc5ee02af1a0d2ff6
Showing
6 changed files
with
15 additions
and
51 deletions
Show diff stats
app/controllers/public/invite_controller.rb
... | ... | @@ -7,6 +7,17 @@ class InviteController < PublicController |
7 | 7 | def invite_friends |
8 | 8 | @import_from = params[:import_from] || "manual" |
9 | 9 | @mail_template = params[:mail_template] || environment.invitation_mail_template(profile) |
10 | + | |
11 | + extra_labels = Profile::SEARCHABLE_FIELDS.keys - [:name, :identifier, :nickname] | |
12 | + labels = [ | |
13 | + _('Name'), | |
14 | + _('Username'), | |
15 | + _('Email'), | |
16 | + ] + extra_labels.map { |label| Profile.human_attribute_name(label) } | |
17 | + last = labels.pop | |
18 | + label = labels.join(', ') | |
19 | + @search_friend_fields = "#{label} #{_('or')} #{last}" | |
20 | + | |
10 | 21 | if request.post? |
11 | 22 | contact_list = ContactList.create |
12 | 23 | Delayed::Job.enqueue GetEmailContactsJob.new(@import_from, params[:login], params[:password], contact_list.id) if @import_from != 'manual' |
... | ... | @@ -73,12 +84,8 @@ class InviteController < PublicController |
73 | 84 | end |
74 | 85 | end |
75 | 86 | |
76 | - include InviteHelper | |
77 | - helper :invite | |
78 | - | |
79 | 87 | def search_friend |
80 | - fields = %w[name identifier email] + plugins_options.map {|field| field[:field].to_s } | |
81 | - render :text => find_by_contents(:people, environment.people.not_members_of(profile), params['q'], {:page => 1}, {:fields => fields, :joins => :user})[:results].map {|person| {:id => person.id, :name => person.name} }.to_json | |
88 | + render :text => find_by_contents(:people, environment.people.not_members_of(profile), params['q'], {:page => 1}, {:joins => :user})[:results].map {|person| {:id => person.id, :name => person.name} }.to_json | |
82 | 89 | end |
83 | 90 | |
84 | 91 | protected | ... | ... |
app/helpers/invite_helper.rb
1 | 1 | module InviteHelper |
2 | - def plugins_options | |
3 | - @plugins.dispatch(:search_friend_fields) | |
4 | - end | |
5 | - | |
6 | - def search_friend_fields | |
7 | - labels = [ | |
8 | - _('Name'), | |
9 | - _('Username'), | |
10 | - _('Email'), | |
11 | - ] + plugins_options.map { |options| options[:name] } | |
12 | - | |
13 | - last = labels.pop | |
14 | - label = labels.join(', ') | |
15 | - "#{label} #{_('or')} #{last}" | |
16 | - end | |
17 | 2 | end | ... | ... |
app/views/invite/invite_friends.rhtml
... | ... | @@ -10,7 +10,7 @@ |
10 | 10 | <% form_tag :action => 'invite_registered_friend' do %> |
11 | 11 | <% search_action = url_for(:action => 'search_friend') %> |
12 | 12 | <%= token_input_field_tag(:q, 'search-friends', search_action, |
13 | - { :hint_text => _('Type in your friend\'s ') + search_friend_fields, | |
13 | + { :hint_text => _('Type in your friend\'s ') + @search_friend_fields, | |
14 | 14 | :focus => false }) %> |
15 | 15 | |
16 | 16 | <% button_bar do %> | ... | ... |
lib/noosfero/plugin.rb
... | ... | @@ -437,12 +437,6 @@ class Noosfero::Plugin |
437 | 437 | nil |
438 | 438 | end |
439 | 439 | |
440 | - # -> Adds aditional fields for invite_friends search | |
441 | - # returns = [{:field => 'field1', :name => 'field 1 name'}, {...}] | |
442 | - def search_friend_fields | |
443 | - nil | |
444 | - end | |
445 | - | |
446 | 440 | # -> Adds additional blocks to profiles and environments. |
447 | 441 | # Your plugin must implements a class method called 'extra_blocks' |
448 | 442 | # that returns a hash with the following syntax. | ... | ... |
plugins/stoa/lib/ext/person.rb
1 | 1 | require_dependency 'person' |
2 | 2 | |
3 | 3 | class Person |
4 | + SEARCHABLE_FIELDS[:usp_id] = 5 | |
5 | + | |
4 | 6 | validates_uniqueness_of :usp_id, :allow_nil => true |
5 | 7 | settings_items :invitation_code |
6 | 8 | validate :usp_id_or_invitation, :if => lambda { |person| person.environment && person.environment.plugin_enabled?(StoaPlugin)} | ... | ... |
test/functional/invite_controller_test.rb
... | ... | @@ -269,30 +269,6 @@ class InviteControllerTest < ActionController::TestCase |
269 | 269 | assert_equal [{"name" => friend1.name, "id" => friend1.id}].to_json, @response.body |
270 | 270 | end |
271 | 271 | |
272 | - should 'search friends profiles by fields provided by plugins' do | |
273 | - class Plugin1 < Noosfero::Plugin | |
274 | - def search_friend_fields | |
275 | - [{:field => 'nickname'}, {:field => 'contact_phone'}] | |
276 | - end | |
277 | - end | |
278 | - | |
279 | - environment = Environment.default | |
280 | - environment.enable_plugin(Plugin1) | |
281 | - | |
282 | - friend1 = create_user('harry').person | |
283 | - friend2 = create_user('william').person | |
284 | - friend1.nickname = 'prince' | |
285 | - friend2.contact_phone = '2222' | |
286 | - friend1.save | |
287 | - friend2.save | |
288 | - | |
289 | - get :search_friend, :profile => profile.identifier, :q => 'prince' | |
290 | - assert_equal [{"name" => friend1.name, "id" => friend1.id}].to_json, @response.body | |
291 | - | |
292 | - get :search_friend, :profile => profile.identifier, :q => '222' | |
293 | - assert_equal [{"name" => friend2.name, "id" => friend2.id}].to_json, @response.body | |
294 | - end | |
295 | - | |
296 | 272 | should 'invite registered users through profile id' do |
297 | 273 | friend1 = create_user('testuser1').person |
298 | 274 | friend2 = create_user('testuser2').person | ... | ... |