Commit 12c0a4e83bdde03498bf28b3470d77058bceda18
Exists in
master
and in
5 other branches
Merge branch 'fix_community_filter' into 'master'
Fix community filter See merge request !6
Showing
4 changed files
with
20 additions
and
10 deletions
Show diff stats
lib/ext/communities_block.rb
... | ... | @@ -4,10 +4,6 @@ class CommunitiesBlock |
4 | 4 | |
5 | 5 | def profile_list |
6 | 6 | result = get_visible_profiles |
7 | - valid_communities_string = Community.get_valid_communities_string | |
8 | - | |
9 | - result.each{|community| result.delete(community) unless eval(valid_communities_string)} | |
10 | - | |
11 | 7 | result.slice(0..get_limit-1) |
12 | 8 | end |
13 | 9 | |
... | ... | @@ -21,6 +17,13 @@ class CommunitiesBlock |
21 | 17 | visible_profiles = profiles.visible.includes( |
22 | 18 | [:image,:domains,:preferred_domain,:environment] |
23 | 19 | ) |
20 | + | |
21 | + delete_communities = [] | |
22 | + valid_communities_string = Community.get_valid_communities_string | |
23 | + Community.all.each{|community| delete_communities << community.id unless eval(valid_communities_string)} | |
24 | + | |
25 | + visible_profiles = visible_profiles.where(["profiles.id NOT IN (?)", delete_communities]) | |
26 | + | |
24 | 27 | if !prioritize_profiles_with_image |
25 | 28 | return visible_profiles.all( |
26 | 29 | :limit => get_limit, |
... | ... | @@ -32,10 +35,11 @@ class CommunitiesBlock |
32 | 35 | :order => 'profiles.updated_at DESC' |
33 | 36 | ).sort_by {rand} |
34 | 37 | else |
35 | - return visible_profiles.with_image.sort_by {rand} + | |
38 | + visible_profiles = visible_profiles.with_image.sort_by {rand} + | |
36 | 39 | visible_profiles.without_image.all( |
37 | 40 | :limit => get_limit * 5, :order => 'profiles.updated_at DESC' |
38 | 41 | ).sort_by {rand} |
42 | + return visible_profiles | |
39 | 43 | end |
40 | 44 | end |
41 | 45 | end | ... | ... |
lib/ext/community.rb
... | ... | @@ -28,11 +28,14 @@ class Community |
28 | 28 | |
29 | 29 | def self.get_valid_communities_string |
30 | 30 | remove_of_communities_methods = Community.instance_methods.select{|m| m =~ /remove_of_community_search/} |
31 | - valid_communities_string = "" | |
31 | + valid_communities_string = "!(" | |
32 | 32 | remove_of_communities_methods.each do |method| |
33 | - valid_communities_string += "!community.send('#{method}') && " | |
33 | + valid_communities_string += "community.send('#{method}') || " | |
34 | 34 | end |
35 | - valid_communities_string[0..-5] | |
35 | + valid_communities_string = valid_communities_string[0..-5] | |
36 | + valid_communities_string += ")" | |
37 | + | |
38 | + valid_communities_string | |
36 | 39 | end |
37 | 40 | |
38 | 41 | def software? | ... | ... |
lib/ext/search_controller.rb
... | ... | @@ -3,10 +3,12 @@ require_dependency 'search_controller' |
3 | 3 | class SearchController |
4 | 4 | |
5 | 5 | def communities |
6 | + delete_communities = [] | |
6 | 7 | valid_communities_string = Community.get_valid_communities_string |
8 | + Community.all.each{|community| delete_communities << community.id unless eval(valid_communities_string)} | |
7 | 9 | |
8 | 10 | @scope = visible_profiles(Community) |
9 | - @scope.each{|community| @scope.delete(community) unless eval(valid_communities_string)} | |
11 | + @scope = @scope.where(["id NOT IN (?)", delete_communities]) unless delete_communities.empty? | |
10 | 12 | |
11 | 13 | full_text_search |
12 | 14 | end | ... | ... |
test/unit/communities_block_test.rb
... | ... | @@ -24,7 +24,8 @@ class CommunitiesBlockTest < ActiveSupport::TestCase |
24 | 24 | @software_info = nil |
25 | 25 | end |
26 | 26 | should "not have community of software or institution in block" do |
27 | - assert_equal 1, @comminities_block.profile_list.count | |
27 | + assert_includes @comminities_block.profile_list, @community | |
28 | + assert_not_includes @comminities_block.profile_list, @software_info.community | |
28 | 29 | end |
29 | 30 | |
30 | 31 | end | ... | ... |