Commit 4d6c78ba82bc2a01d49d46448f3fe6b61b856a8a

Authored by Fabio Teixeira
1 parent c559daa0
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

Set the defaults institution's community admin

(add_user_to_institution_community)

Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
config/siorg.yml
... ... @@ -7,3 +7,5 @@ web_service:
7 7 legislative: 2
8 8 judiciary: 3
9 9 additional_params: retornarOrgaoEntidadeVinculados=NAO
  10 + environment_name: Noosfero
  11 + default_community_admin: adminuser
10 12 \ No newline at end of file
... ...
controllers/mpog_software_plugin_controller.rb
... ... @@ -76,6 +76,8 @@ class MpogSoftwarePluginController &lt; ApplicationController
76 76  
77 77 response_message = if verify_recaptcha(:model=> institution, :message => _('Please type the word correctly'))
78 78 if institution.errors.full_messages.empty? and institution.valid? and institution.save
  79 + institution.community.add_admin(environment.admins.first) unless environment.admins.empty?
  80 +
79 81 {:success => true, :message => _("Institution successful created!"), :institution_data=>{:name=>institution.name, :id=>institution.id}}
80 82 else
81 83 {:success => false, :message => _("Institution could not be created!"), :errors => institution.errors.full_messages}
... ...
lib/institution_helper.rb
... ... @@ -9,6 +9,20 @@ module InstitutionHelper
9 9 def self.mass_update
10 10 @web_service_info = self.web_service_info
11 11  
  12 + environment = Environment.find_by_name(@web_service_info["environment_name"])
  13 +
  14 + if environment.nil?
  15 + puts "\n", "="*80, "Could not find the informed environment: #{@web_service_info["environment_name"]}", "="*80, "\n"
  16 + return
  17 + end
  18 +
  19 + admin = environment.people.find_by_name(@web_service_info["default_community_admin"])
  20 +
  21 + if admin.nil?
  22 + puts "\n", "="*80, "Could not find the informed admin: #{@web_service_info["default_community_admin"]}", "="*80, "\n"
  23 + return
  24 + end
  25 +
12 26 POWERS.each do |power|
13 27 SPHERES.each do |sphere|
14 28 json = self.get_json power, sphere
... ... @@ -26,6 +40,8 @@ module InstitutionHelper
26 40  
27 41 institution = self.set_institution_data institution, unit
28 42 institution.save
  43 +
  44 + institution.community.add_admin(admin)
29 45 end
30 46 end
31 47 end
... ...
test/functional/mpog_software_plugin_controller_test.rb
... ... @@ -7,9 +7,18 @@ class MpogSoftwarePluginController; def rescue_action(e) raise e end; end
7 7 class MpogSoftwarePluginControllerTest < ActionController::TestCase
8 8  
9 9 def setup
  10 + admin = create_user("adminuser").person
  11 + admin.stubs(:has_permission?).returns("true")
  12 +
  13 + @environment = Environment.default
  14 + @environment.enabled_plugins = ['MpogSoftwarePlugin']
  15 + @environment.add_admin(admin)
  16 + @environment.save
  17 +
10 18 @govPower = GovernmentalPower.create(:name=>"Some Gov Power")
11 19 @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
12 20 @response = ActionController::TestResponse.new
  21 +
13 22 @institution_list = []
14 23 @institution_list << create_public_institution("Ministerio Publico da Uniao", "MPU", @govPower, @govSphere)
15 24 @institution_list << create_public_institution("Tribunal Regional da Uniao", "TRU", @govPower, @govSphere)
... ... @@ -75,6 +84,24 @@ class MpogSoftwarePluginControllerTest &lt; ActionController::TestCase
75 84 assert !json_response["success"]
76 85 end
77 86  
  87 + should "set the environment admin as institution community admin" do
  88 + @controller.stubs(:verify_recaptcha).returns(true)
  89 +
  90 + xhr :get, :new_institution,
  91 + :authenticity_token=>"dsa45a6das52sd",
  92 + :community=>{:name=>"Another instituon community"},
  93 + :institution => {:cnpj=>"10.254.577/8910-12", :acronym=>"aic", :type=>"PublicInstitution"},
  94 + :governmental=>{:power=>@govPower.id, :sphere=>@govSphere.id},
  95 + :recaptcha_response_field=>''
  96 +
  97 + json_response = ActiveSupport::JSON.decode(@response.body)
  98 +
  99 + assert json_response["success"]
  100 +
  101 + assert Community.last.admins.include?(@environment.admins.first)
  102 + assert_equal Community.last.name, "Another instituon community"
  103 + end
  104 +
78 105 should "verify if institution name already exists" do
79 106 xhr :get, :institution_already_exists, :name=>"Ministerio Publico da Uniao"
80 107 assert_equal "true", @response.body
... ...
test/integration/institution_helper_test.rb 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +
  3 +class InstitutionHelperTest < ActionController::IntegrationTest
  4 +
  5 + def setup
  6 + admin = create_user("test_admin").person
  7 + admin.stubs(:has_permission?).returns("true")
  8 +
  9 + @environment = Environment.default
  10 + @environment.enabled_plugins = ['MpogSoftwarePlugin']
  11 + @environment.add_admin(admin)
  12 + @environment.name = "test_environment"
  13 + @environment.save
  14 + end
  15 +
  16 + should "not proceed with SIORG script if environment name isn't the informed" do
  17 + assert !InstitutionHelper.mass_update
  18 + end
  19 +
  20 + should "not proceed with SIORG script if admin name isn't the informed" do
  21 + @environment.name = "Noosfero"
  22 + @environment.save
  23 +
  24 + assert !InstitutionHelper.mass_update
  25 + end
  26 +end
... ...
test/unit/institution_helper_test.rb
... ... @@ -1,18 +0,0 @@
1   -require File.dirname(__FILE__) + '/../../../../test/test_helper'
2   -
3   -class InstitutionHelperTest < ActiveSupport::TestCase
4   -
5   - should "populate public institutions with data from SIORG" do
6   - Institution.destroy_all
7   -
8   - InstitutionHelper.mass_update
9   -
10   - assert Institution.count != 0
11   - end
12   -
13   - should "receive json data from SIORG" do
14   - data = InstitutionHelper.get_json(2, 1)
15   -
16   - assert data["unidades"].count != 0
17   - end
18   -end