Commit b899b03b8b05fee8fb32688263b60e604dac3d5c

Authored by David Silva
1 parent e999d703
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

Decrease mpog_software_plugin block complexity.

Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com>
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing 1 changed file with 34 additions and 23 deletions   Show diff stats
lib/mpog_software_plugin.rb
@@ -71,17 +71,9 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin @@ -71,17 +71,9 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
71 end 71 end
72 72
73 def profile_tabs 73 def profile_tabs
74 - if context.profile.community? && context.profile.software?  
75 - { :title => _("Software"),  
76 - :id => 'mpog-fields',  
77 - :content => Proc::new do render :partial => 'software_tab' end,  
78 - :start => true }  
79 - elsif context.profile.community? && context.profile.institution?  
80 - { :title => _("Institution"),  
81 - :id => 'mpog-fields',  
82 - :content => Proc::new do render :partial => 'institution_tab' end,  
83 - :start => true  
84 - } 74 + if context.profile.community?
  75 + return profile_tabs_software if context.profile.software?
  76 + profile_tabs_institution
85 end 77 end
86 end 78 end
87 79
@@ -396,18 +388,7 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin @@ -396,18 +388,7 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
396 end 388 end
397 end 389 end
398 390
399 - leave_communities = (old_communities - new_communities)  
400 - enter_communities = (new_communities - old_communities)  
401 -  
402 - leave_communities.each do |community|  
403 - community.remove_member(user.person)  
404 - user.institutions.delete(community.institution)  
405 - end  
406 -  
407 - enter_communities.each do |community|  
408 - community.add_member(user.person)  
409 - user.institutions << community.institution  
410 - end 391 + manage_user_institutions(user, leave_communities, enter_communities)
411 end 392 end
412 393
413 def show_sisp_field 394 def show_sisp_field
@@ -457,4 +438,34 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin @@ -457,4 +438,34 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
457 } 438 }
458 } 439 }
459 end 440 end
  441 +
  442 + def manage_user_institutions(leave_communities,enter_communities)
  443 + leave_communities = (old_communities - new_communities)
  444 + enter_communities = (new_communities - old_communities)
  445 +
  446 + leave_communities.each do |community|
  447 + community.remove_member(user.person)
  448 + user.institutions.delete(community.institution)
  449 + end
  450 +
  451 + enter_communities.each do |community|
  452 + community.add_member(user.person)
  453 + user.institutions << community.institution
  454 + end
  455 + end
  456 +
  457 + def profile_tabs_software
  458 + { :title => _("Software"),
  459 + :id => 'mpog-fields',
  460 + :content => Proc::new do render :partial => 'software_tab' end,
  461 + :start => true }
  462 + end
  463 +
  464 + def profile_tabs_institution
  465 + { :title => _("Institution"),
  466 + :id => 'mpog-fields',
  467 + :content => Proc::new do render :partial => 'institution_tab' end,
  468 + :start => true
  469 + }
  470 + end
460 end 471 end