Commit 4d6c78ba82bc2a01d49d46448f3fe6b61b856a8a
1 parent
c559daa0
Exists in
master
and in
79 other branches
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>
Showing
6 changed files
with
73 additions
and
18 deletions
Show diff stats
config/siorg.yml
@@ -7,3 +7,5 @@ web_service: | @@ -7,3 +7,5 @@ web_service: | ||
7 | legislative: 2 | 7 | legislative: 2 |
8 | judiciary: 3 | 8 | judiciary: 3 |
9 | additional_params: retornarOrgaoEntidadeVinculados=NAO | 9 | additional_params: retornarOrgaoEntidadeVinculados=NAO |
10 | + environment_name: Noosfero | ||
11 | + default_community_admin: adminuser | ||
10 | \ No newline at end of file | 12 | \ No newline at end of file |
controllers/mpog_software_plugin_controller.rb
@@ -76,6 +76,8 @@ class MpogSoftwarePluginController < ApplicationController | @@ -76,6 +76,8 @@ class MpogSoftwarePluginController < ApplicationController | ||
76 | 76 | ||
77 | response_message = if verify_recaptcha(:model=> institution, :message => _('Please type the word correctly')) | 77 | response_message = if verify_recaptcha(:model=> institution, :message => _('Please type the word correctly')) |
78 | if institution.errors.full_messages.empty? and institution.valid? and institution.save | 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 | {:success => true, :message => _("Institution successful created!"), :institution_data=>{:name=>institution.name, :id=>institution.id}} | 81 | {:success => true, :message => _("Institution successful created!"), :institution_data=>{:name=>institution.name, :id=>institution.id}} |
80 | else | 82 | else |
81 | {:success => false, :message => _("Institution could not be created!"), :errors => institution.errors.full_messages} | 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,6 +9,20 @@ module InstitutionHelper | ||
9 | def self.mass_update | 9 | def self.mass_update |
10 | @web_service_info = self.web_service_info | 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 | POWERS.each do |power| | 26 | POWERS.each do |power| |
13 | SPHERES.each do |sphere| | 27 | SPHERES.each do |sphere| |
14 | json = self.get_json power, sphere | 28 | json = self.get_json power, sphere |
@@ -26,6 +40,8 @@ module InstitutionHelper | @@ -26,6 +40,8 @@ module InstitutionHelper | ||
26 | 40 | ||
27 | institution = self.set_institution_data institution, unit | 41 | institution = self.set_institution_data institution, unit |
28 | institution.save | 42 | institution.save |
43 | + | ||
44 | + institution.community.add_admin(admin) | ||
29 | end | 45 | end |
30 | end | 46 | end |
31 | end | 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,9 +7,18 @@ class MpogSoftwarePluginController; def rescue_action(e) raise e end; end | ||
7 | class MpogSoftwarePluginControllerTest < ActionController::TestCase | 7 | class MpogSoftwarePluginControllerTest < ActionController::TestCase |
8 | 8 | ||
9 | def setup | 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 | @govPower = GovernmentalPower.create(:name=>"Some Gov Power") | 18 | @govPower = GovernmentalPower.create(:name=>"Some Gov Power") |
11 | @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | 19 | @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") |
12 | @response = ActionController::TestResponse.new | 20 | @response = ActionController::TestResponse.new |
21 | + | ||
13 | @institution_list = [] | 22 | @institution_list = [] |
14 | @institution_list << create_public_institution("Ministerio Publico da Uniao", "MPU", @govPower, @govSphere) | 23 | @institution_list << create_public_institution("Ministerio Publico da Uniao", "MPU", @govPower, @govSphere) |
15 | @institution_list << create_public_institution("Tribunal Regional da Uniao", "TRU", @govPower, @govSphere) | 24 | @institution_list << create_public_institution("Tribunal Regional da Uniao", "TRU", @govPower, @govSphere) |
@@ -75,6 +84,24 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase | @@ -75,6 +84,24 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase | ||
75 | assert !json_response["success"] | 84 | assert !json_response["success"] |
76 | end | 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 | should "verify if institution name already exists" do | 105 | should "verify if institution name already exists" do |
79 | xhr :get, :institution_already_exists, :name=>"Ministerio Publico da Uniao" | 106 | xhr :get, :institution_already_exists, :name=>"Ministerio Publico da Uniao" |
80 | assert_equal "true", @response.body | 107 | assert_equal "true", @response.body |
@@ -0,0 +1,26 @@ | @@ -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,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 |