Compare View
Commits (2)
-
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
3 changed files
Show diff stats
app/controllers/public/search_controller.rb
... | ... | @@ -154,7 +154,7 @@ class SearchController < PublicController |
154 | 154 | render :text => find_suggestions(normalize_term(params[:term]), environment, params[:asset]).to_json |
155 | 155 | end |
156 | 156 | |
157 | - def search_for_users | |
157 | + def search_for_friends_and_members | |
158 | 158 | # If it isn't a ajax call give to the user an access denied response |
159 | 159 | return render_access_denied unless request.xhr? |
160 | 160 | |
... | ... | @@ -166,7 +166,7 @@ class SearchController < PublicController |
166 | 166 | )[:results] |
167 | 167 | |
168 | 168 | if params[:community].present? and (community = Community.find_by_identifier params[:community]) |
169 | - scope = community.members # .select(:id, :name, :identifier) is not working here | |
169 | + scope = community.members.where.not(id: user.id) # .select(:id, :name, :identifier) is not working here | |
170 | 170 | results += find_by_contents( |
171 | 171 | :people, environment, scope, |
172 | 172 | params['q'], {:page => 1} | ... | ... |
public/javascripts/user-mention.js
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 | |
10 | 10 | $('#comment_body, #leave_scrap_content, form.profile-wall-reply-form textarea').mentionsInput({ |
11 | 11 | onDataRequest: function (mode, keyword, onDataRequestCompleteCallback) { |
12 | - var search_url = "/search/search_for_users?q="+keyword; | |
12 | + var search_url = "/search/search_for_friends_and_members?q="+keyword; | |
13 | 13 | |
14 | 14 | $.ajax({ |
15 | 15 | method: "GET", | ... | ... |
test/functional/search_controller_test.rb
... | ... | @@ -660,6 +660,44 @@ class SearchControllerTest < ActionController::TestCase |
660 | 660 | } |
661 | 661 | end |
662 | 662 | |
663 | + should 'search for friends and members render access denied if it is not an ajax call' do | |
664 | + get :search_for_friends_and_members | |
665 | + assert_template 'shared/access_denied' | |
666 | + end | |
667 | + | |
668 | + should 'search for friends and members' do | |
669 | + u1, u2, u3 = fast_create(User), fast_create(User), fast_create(User) | |
670 | + | |
671 | + p1 = fast_create(Person, name: 'fulano', user_id: u1.id) | |
672 | + p2 = fast_create(Person, name: 'ciclano', user_id: u2.id) | |
673 | + p3 = fast_create(Person, name: 'deltrano', user_id: u3.id) | |
674 | + | |
675 | + p1.add_friend(p2) | |
676 | + p1.save! | |
677 | + | |
678 | + c = fast_create(Community, name: 'sample test community') | |
679 | + c.add_member(p1) | |
680 | + c.add_member(p3) | |
681 | + c.save! | |
682 | + | |
683 | + @controller.stubs(:user).returns(p1) | |
684 | + | |
685 | + xhr :get, :search_for_friends_and_members, q: "ano", community: nil | |
686 | + | |
687 | + json_response = ActiveSupport::JSON.decode(@response.body) | |
688 | + | |
689 | + assert_equal p2.name, json_response.first["name"] | |
690 | + | |
691 | + xhr :get, :search_for_friends_and_members, q: "del", community: c.identifier | |
692 | + json_response = ActiveSupport::JSON.decode(@response.body) | |
693 | + assert_equal p3.name, json_response.first["name"] | |
694 | + | |
695 | + xhr :get, :search_for_friends_and_members, q: "ano", community: c.identifier | |
696 | + json_response = ActiveSupport::JSON.decode(@response.body) | |
697 | + assert_equal p2.name, json_response.first["name"] | |
698 | + assert_equal p3.name, json_response.last["name"] | |
699 | + end | |
700 | + | |
663 | 701 | protected |
664 | 702 | |
665 | 703 | def create_event(profile, options) | ... | ... |