Commit f579218e0b4ae2873d97f3f4e26af85102b238b2

Authored by Luciano Prestes
1 parent c2ecb2c2
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

Removes institutions and software in Communities Block

Fixed bug in Profile Helper

Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
lib/ext/communities_block.rb 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +require_dependency 'communities_block'
  2 +
  3 +class CommunitiesBlock
  4 +
  5 + def profile_list
  6 + result = nil
  7 + visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment])
  8 + if !prioritize_profiles_with_image
  9 + result = visible_profiles.all(:limit => get_limit, :order => 'profiles.updated_at DESC').sort_by{ rand }
  10 + elsif profiles.visible.with_image.count >= get_limit
  11 + result = visible_profiles.with_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand }
  12 + else
  13 + result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand }
  14 + end
  15 +
  16 + list_without_software_and_institution = []
  17 +
  18 + visible_profiles.each do |p|
  19 + if p.class == Community and !p.software? and !p.institution?
  20 + list_without_software_and_institution << p
  21 + end
  22 + end
  23 +
  24 + result = list_without_software_and_institution
  25 +
  26 + result.slice(0..get_limit-1)
  27 + end
  28 +
  29 +end
0 30 \ No newline at end of file
... ...
lib/ext/profile_helper.rb
1   -module ProfileHelper extend ProfileHelper
  1 +require_dependency 'profile_helper'
  2 +
  3 +module ProfileHelper
2 4 PERSON_CATEGORIES[:mpog_profile_information] = [:secondary_email, :institutions]
3 5  
4 6 def display_mpog_field(title, profile, field, force = false)
... ...
test/unit/communities_block_test.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/plugin_test_helper'
  3 +
  4 +class CommunitiesBlockTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 + def setup
  7 + @person = create_person("My Name", "user@email.com", "123456", "123456", "user@secondary_email.com", "Any State", "Some City")
  8 +
  9 + @gov_power = GovernmentalPower.create(:name=>"Some Gov Power")
  10 + @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
  11 + @juridical_nature = JuridicalNature.create(:name => "Autarquia")
  12 +
  13 + @institution = create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @gov_power, @gov_sphere)
  14 + @institution.community.add_member(@person)
  15 +
  16 + @software_info = create_software_info("Novo Software")
  17 + @software_info.community.add_member(@person)
  18 +
  19 + @community = create_community("Nova Comunidade")
  20 + @community.add_member(@person)
  21 +
  22 +
  23 + @comminities_block = CommunitiesBlock.new
  24 + @comminities_block.expects(:owner).at_least_once.returns(@person)
  25 + end
  26 +
  27 + should "not have community of software or institution in block" do
  28 + assert_equal 1, @comminities_block.profile_list.count
  29 + end
  30 +
  31 +end
... ...
test/unit/plugin_test_helper.rb
1 1 module PluginTestHelper
2 2  
  3 + def create_community name
  4 + community = fast_create(Community)
  5 + community.name = name
  6 + community.save
  7 + community
  8 + end
  9 +
  10 + def create_software_info name
  11 + community = create_community(name)
  12 + software_info = SoftwareInfo.new
  13 + software_info.community = community
  14 + software_info.save
  15 + software_info
  16 + end
  17 +
3 18 def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s
4 19 institution = PublicInstitution.new
5 20 institution.community = create_community_institution(name, country, state, city)
... ...