Commit a7a813a68df35fd1dd60eabe711b3d7b15253e29

Authored by Gabriela Navarro
Committed by Luciano Prestes
1 parent 1657cdb0
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

Add Softwares Block and tests

Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
lib/mpog_software_plugin.rb
... ... @@ -204,6 +204,12 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
204 204 end
205 205 end
206 206  
  207 + def self.extra_blocks
  208 + {
  209 + SoftwaresBlock => {:type => [Environment, Person] }
  210 + }
  211 + end
  212 +
207 213 def stylesheet?
208 214 true
209 215 end
... ...
lib/softwares_block.rb 0 → 100644
... ... @@ -0,0 +1,64 @@
  1 +class SoftwaresBlock < CommunitiesBlock
  2 +
  3 + attr_accessible :accessor_id, :accessor_type, :role_id, :resource_id, :resource_type
  4 +
  5 + def self.description
  6 + _('Softwares')
  7 + end
  8 +
  9 + def default_title
  10 + n_('{#} software', '{#} softwares', profile_count)
  11 + end
  12 +
  13 + def help
  14 + _('This block displays the softwares in which the user is a member.')
  15 + end
  16 +
  17 + def footer
  18 + owner = self.owner
  19 + case owner
  20 + when Profile
  21 + lambda do |context|
  22 + link_to s_('softwares|View all'), :profile => owner.identifier, :controller => 'profile', :action => 'communities'
  23 + end
  24 + when Environment
  25 + lambda do |context|
  26 + link_to s_('softwares|View all'), :controller => 'search', :action => 'communities'
  27 + end
  28 + else
  29 + ''
  30 + end
  31 + end
  32 +
  33 + def profile_count
  34 + profile_list.count
  35 + end
  36 +
  37 + def profiles
  38 + owner.communities
  39 + end
  40 +
  41 + def profile_list
  42 + result = nil
  43 + visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment])
  44 + if !prioritize_profiles_with_image
  45 + result = visible_profiles.all(:limit => get_limit, :order => 'profiles.updated_at DESC').sort_by{ rand }
  46 + elsif profiles.visible.with_image.count >= get_limit
  47 + result = visible_profiles.with_image.all(:limit => get_limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand }
  48 + else
  49 + 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 }
  50 + end
  51 +
  52 + list_with_software = []
  53 +
  54 + visible_profiles.each do |p|
  55 + if p.class == Community and p.software? and !p.institution?
  56 + list_with_software << p
  57 + end
  58 + end
  59 +
  60 + result = list_with_software
  61 +
  62 + result.slice(0..get_limit-1)
  63 + end
  64 +end
... ...
test/unit/softwares_block_test.rb 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/plugin_test_helper'
  3 +
  4 +class SoftwaresBlockTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 + should 'inherit from ProfileListBlock' do
  7 + assert_kind_of ProfileListBlock, SoftwaresBlock.new
  8 + end
  9 +
  10 + should 'declare its default title' do
  11 + SoftwaresBlock.any_instance.stubs(:profile_count).returns(0)
  12 + assert_not_equal ProfileListBlock.new.default_title, SoftwaresBlock.new.default_title
  13 + end
  14 +
  15 + should 'describe itself' do
  16 + assert_not_equal ProfileListBlock.description, SoftwaresBlock.description
  17 + end
  18 +
  19 + should 'give empty footer on unsupported owner type' do
  20 + block = SoftwaresBlock.new
  21 + block.expects(:owner).returns(1)
  22 + assert_equal '', block.footer
  23 + end
  24 +
  25 + should 'list softwares' do
  26 + user = create_person("Jose_Augusto", "jose_augusto@email.com", "aaaaaaa", "aaaaaaa", "jose_silva@email.com", "DF", "Gama")
  27 +
  28 + software_info = create_software_info("new software")
  29 + software_info.community.add_member(user)
  30 +
  31 + block = SoftwaresBlock.new
  32 + block.expects(:owner).at_least_once.returns(user)
  33 +
  34 + assert_equivalent [software_info.community], block.profiles
  35 + end
  36 +
  37 +end
... ...