diff --git a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb index 1571c77..84bd92b 100644 --- a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb +++ b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb @@ -1,6 +1,8 @@ class GovUserPluginMyprofileController < MyProfileController append_view_path File.join(File.dirname(__FILE__) + '/../views') + protect "edit_institution", :profile + def index end @@ -19,7 +21,7 @@ class GovUserPluginMyprofileController < MyProfileController def update_institution @institution.community.update_attributes(params[:community]) - @institution.update_attributes(params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature)) + @institution.update_attributes(params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature).merge({:name => params[:community][:name]})) if @institution.type == "PublicInstitution" begin governmental_updates diff --git a/src/noosfero-spb/gov_user/db/migrate/20160113194207_fix_institutions_with_wrong_country.rb b/src/noosfero-spb/gov_user/db/migrate/20160113194207_fix_institutions_with_wrong_country.rb new file mode 100644 index 0000000..2bc7f45 --- /dev/null +++ b/src/noosfero-spb/gov_user/db/migrate/20160113194207_fix_institutions_with_wrong_country.rb @@ -0,0 +1,16 @@ +class FixInstitutionsWithWrongCountry < ActiveRecord::Migration + def up + select_all("SELECT id, data FROM profiles WHERE type = 'Community'").each do |community| + settings = YAML.load(community['data'] || {}.to_yaml) + if !settings[:country].nil? && settings[:country].downcase == "brasil" + settings[:country] = 'BR' + assignments = ActiveRecord::Base.send(:sanitize_sql_for_assignment, {:data => settings.to_yaml}) + update("UPDATE profiles SET %s WHERE id = %d" % [assignments, community['id']]) + end + end + end + + def down + say "This migration can't be reverted." + end +end diff --git a/src/noosfero-spb/gov_user/public/views/create-institution.js b/src/noosfero-spb/gov_user/public/views/create-institution.js index 61578c1..2e92e92 100644 --- a/src/noosfero-spb/gov_user/public/views/create-institution.js +++ b/src/noosfero-spb/gov_user/public/views/create-institution.js @@ -29,6 +29,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] $(".public-institutions-fields").hide(); $("#institutions_governmental_power option").selected(0); $("#institutions_governmental_sphere option").selected(0); + $("#institutions_juridical_nature option").selected(0); $("#cnpj_required_field_mark").html("(*)"); } @@ -270,8 +271,9 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] function show_hide_cnpj_city(country) { - var cnpj = $("#institutions_cnpj").parent(); + var cnpj = $("#institutions_cnpj").parent().parent(); var city = $("#community_city").parent(); + var city_label = $('label[for="community_city"]'); var state = $("#community_state").parent(); var inst_type = $("input[name='institutions[type]']:checked").val(); @@ -284,11 +286,13 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] if ( country !== "BR" ) { cnpj.hide(); - city.hide(); + city.find('input').val(''); city.hide(); + city_label.hide(); state.hide(); } else { cnpj.show(); city.show(); + city_label.show(); state.show(); } } @@ -368,7 +372,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] function set_events() { $("input[name='institutions[type]']").click(function(){ institution_type_actions(this.value); - }).trigger("click"); + }); $('#save_institution_button').click(save_institution); $('#cancel_institution_button').click(cancel_institution); diff --git a/src/noosfero-spb/gov_user/public/views/new-community.js b/src/noosfero-spb/gov_user/public/views/new-community.js index 0de70c7..f9834d2 100644 --- a/src/noosfero-spb/gov_user/public/views/new-community.js +++ b/src/noosfero-spb/gov_user/public/views/new-community.js @@ -2,11 +2,6 @@ modulejs.define("NewCommunity", ['jquery'], function($) { - function replace_mandatory_message() { - $(".required-field").first() - .replaceWith(" Os campos em destaque são obrigatórios. "); - } - function remove_image_builder_text() { $("label:contains('Image builder')").hide(); } @@ -22,7 +17,6 @@ modulejs.define("NewCommunity", ['jquery'], function($) { }, init: function() { - replace_mandatory_message(); remove_image_builder_text(); hide_organization_template_fields(); } diff --git a/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb b/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb index 61c48b1..f21b325 100644 --- a/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb +++ b/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb @@ -18,29 +18,30 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase @offer_1 = create_user('Ana de Souza') @offer_2 = create_user('Angelo Roberto') - login_as(@person.user_login) - @environment = Environment.default - @environment.enable_plugin('GovUserPlugin') - @environment.save! - end - should "user edit its community institution" do - govPower = GovernmentalPower.create(:name=>"Some Gov Power") - govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") + gov_power = GovernmentalPower.create(:name=>"Some Gov Power") + gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") juridical_nature = JuridicalNature.create(:name => "Autarquia") - - institution = InstitutionTestHelper.create_public_institution( + @institution = InstitutionTestHelper.create_public_institution( "Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", juridical_nature, - govPower, - govSphere, + gov_power, + gov_sphere, "12.345.678/9012-45" ) - identifier = institution.community.identifier + login_as(@person.user_login) + @environment = Environment.default + @environment.enable_plugin('GovUserPlugin') + @environment.save! + end + + should "admin user edit an institution" do + @institution.community.add_admin @person + identifier = @institution.community.identifier fields = InstitutionTestHelper.generate_form_fields( "institution new name", @@ -53,7 +54,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase post( :edit_institution, - :profile=>institution.community.identifier, + :profile=>@institution.community.identifier, :community=>fields[:community], :institutions=>fields[:institutions] ) @@ -62,25 +63,31 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase assert_not_equal "Ministerio Publico da Uniao", institution.community.name end - should "not user edit its community institution with wrong values" do - govPower = GovernmentalPower.create(:name=>"Some Gov Power") - govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") - juridical_nature = JuridicalNature.create(:name => "Autarquia") - - institution = InstitutionTestHelper.create_public_institution( - "Ministerio Publico da Uniao", - "MPU", + should "regular user should not edit an institution" do + identifier = @institution.community.identifier + fields = InstitutionTestHelper.generate_form_fields( + "institution new name", "BR", "DF", "Gama", - juridical_nature, - govPower, - govSphere, - "12.345.678/9012-45" + "12.345.678/9012-45", + "PrivateInstitution" + ) + + post( + :edit_institution, + :profile=>@institution.community.identifier, + :community=>fields[:community], + :institutions=>fields[:institutions] ) - identifier = institution.community.identifier + institution = Community[identifier].institution + assert_equal "Ministerio Publico da Uniao", institution.community.name + assert_response 403 + end + should "not user edit its community institution with wrong values" do + identifier = @institution.community.identifier fields = InstitutionTestHelper.generate_form_fields( "", "BR", @@ -92,7 +99,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase post( :edit_institution, - :profile=>institution.community.identifier, + :profile=>@institution.community.identifier, :community=>fields[:community], :institutions=>fields[:institutions] ) diff --git a/src/noosfero-spb/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb b/src/noosfero-spb/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb index 7b0f936..1f07a54 100644 --- a/src/noosfero-spb/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb +++ b/src/noosfero-spb/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb @@ -19,6 +19,10 @@
+