Commit ce3b9daa65e92213f91da43524959f7648f74361

Authored by Luciano Prestes
1 parent 211d2087
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Fix bug on filter communities

lib/ext/communities_block.rb
@@ -4,10 +4,6 @@ class CommunitiesBlock @@ -4,10 +4,6 @@ class CommunitiesBlock
4 4
5 def profile_list 5 def profile_list
6 result = get_visible_profiles 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 result.slice(0..get_limit-1) 7 result.slice(0..get_limit-1)
12 end 8 end
13 9
@@ -21,6 +17,13 @@ class CommunitiesBlock @@ -21,6 +17,13 @@ class CommunitiesBlock
21 visible_profiles = profiles.visible.includes( 17 visible_profiles = profiles.visible.includes(
22 [:image,:domains,:preferred_domain,:environment] 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 if !prioritize_profiles_with_image 27 if !prioritize_profiles_with_image
25 return visible_profiles.all( 28 return visible_profiles.all(
26 :limit => get_limit, 29 :limit => get_limit,
@@ -32,10 +35,11 @@ class CommunitiesBlock @@ -32,10 +35,11 @@ class CommunitiesBlock
32 :order => 'profiles.updated_at DESC' 35 :order => 'profiles.updated_at DESC'
33 ).sort_by {rand} 36 ).sort_by {rand}
34 else 37 else
35 - return visible_profiles.with_image.sort_by {rand} + 38 + visible_profiles = visible_profiles.with_image.sort_by {rand} +
36 visible_profiles.without_image.all( 39 visible_profiles.without_image.all(
37 :limit => get_limit * 5, :order => 'profiles.updated_at DESC' 40 :limit => get_limit * 5, :order => 'profiles.updated_at DESC'
38 ).sort_by {rand} 41 ).sort_by {rand}
  42 + return visible_profiles
39 end 43 end
40 end 44 end
41 end 45 end
lib/ext/community.rb
@@ -28,11 +28,14 @@ class Community @@ -28,11 +28,14 @@ class Community
28 28
29 def self.get_valid_communities_string 29 def self.get_valid_communities_string
30 remove_of_communities_methods = Community.instance_methods.select{|m| m =~ /remove_of_community_search/} 30 remove_of_communities_methods = Community.instance_methods.select{|m| m =~ /remove_of_community_search/}
31 - valid_communities_string = "" 31 + valid_communities_string = "!("
32 remove_of_communities_methods.each do |method| 32 remove_of_communities_methods.each do |method|
33 - valid_communities_string += "!community.send('#{method}') && " 33 + valid_communities_string += "community.send('#{method}') || "
34 end 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 end 39 end
37 40
38 def software? 41 def software?
lib/ext/search_controller.rb
@@ -3,10 +3,12 @@ require_dependency &#39;search_controller&#39; @@ -3,10 +3,12 @@ require_dependency &#39;search_controller&#39;
3 class SearchController 3 class SearchController
4 4
5 def communities 5 def communities
  6 + delete_communities = []
6 valid_communities_string = Community.get_valid_communities_string 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 @scope = visible_profiles(Community) 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 full_text_search 13 full_text_search
12 end 14 end
test/unit/communities_block_test.rb
@@ -24,7 +24,8 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase @@ -24,7 +24,8 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase
24 @software_info = nil 24 @software_info = nil
25 end 25 end
26 should "not have community of software or institution in block" do 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 end 29 end
29 30
30 end 31 end