Commit 4232b460751377c2d467c773d035dd3da37a6364
1 parent
435165db
Exists in
master
and in
20 other branches
Fix edit institution page
- Autocomplete bugs - Permission filter Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com> Signed-off-by: Omar Junior <omarroinuj@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Showing
7 changed files
with
69 additions
and
54 deletions
Show diff stats
src/noosfero-spb/gov_user/controllers/gov_user_plugin_myprofile_controller.rb
1 | 1 | class GovUserPluginMyprofileController < MyProfileController |
2 | 2 | append_view_path File.join(File.dirname(__FILE__) + '/../views') |
3 | 3 | |
4 | + protect "edit_institution", :profile | |
5 | + | |
4 | 6 | def index |
5 | 7 | end |
6 | 8 | |
... | ... | @@ -19,7 +21,7 @@ class GovUserPluginMyprofileController < MyProfileController |
19 | 21 | |
20 | 22 | def update_institution |
21 | 23 | @institution.community.update_attributes(params[:community]) |
22 | - @institution.update_attributes(params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature)) | |
24 | + @institution.update_attributes(params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature).merge({:name => params[:community][:name]})) | |
23 | 25 | if @institution.type == "PublicInstitution" |
24 | 26 | begin |
25 | 27 | governmental_updates | ... | ... |
src/noosfero-spb/gov_user/db/migrate/20160113194207_fix_institutions_with_wrong_country.rb
0 → 100644
... | ... | @@ -0,0 +1,16 @@ |
1 | +class FixInstitutionsWithWrongCountry < ActiveRecord::Migration | |
2 | + def up | |
3 | + select_all("SELECT id, data FROM profiles WHERE type = 'Community'").each do |community| | |
4 | + settings = YAML.load(community['data'] || {}.to_yaml) | |
5 | + if !settings[:country].nil? && settings[:country].downcase == "brasil" | |
6 | + settings[:country] = 'BR' | |
7 | + assignments = ActiveRecord::Base.send(:sanitize_sql_for_assignment, {:data => settings.to_yaml}) | |
8 | + update("UPDATE profiles SET %s WHERE id = %d" % [assignments, community['id']]) | |
9 | + end | |
10 | + end | |
11 | + end | |
12 | + | |
13 | + def down | |
14 | + say "This migration can't be reverted." | |
15 | + end | |
16 | +end | ... | ... |
src/noosfero-spb/gov_user/public/views/create-institution.js
... | ... | @@ -29,6 +29,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
29 | 29 | $(".public-institutions-fields").hide(); |
30 | 30 | $("#institutions_governmental_power option").selected(0); |
31 | 31 | $("#institutions_governmental_sphere option").selected(0); |
32 | + $("#institutions_juridical_nature option").selected(0); | |
32 | 33 | $("#cnpj_required_field_mark").html("(*)"); |
33 | 34 | } |
34 | 35 | |
... | ... | @@ -270,8 +271,9 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
270 | 271 | |
271 | 272 | |
272 | 273 | function show_hide_cnpj_city(country) { |
273 | - var cnpj = $("#institutions_cnpj").parent(); | |
274 | + var cnpj = $("#institutions_cnpj").parent().parent(); | |
274 | 275 | var city = $("#community_city").parent(); |
276 | + var city_label = $('label[for="community_city"]'); | |
275 | 277 | var state = $("#community_state").parent(); |
276 | 278 | var inst_type = $("input[name='institutions[type]']:checked").val(); |
277 | 279 | |
... | ... | @@ -284,11 +286,13 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
284 | 286 | |
285 | 287 | if ( country !== "BR" ) { |
286 | 288 | cnpj.hide(); |
287 | - city.hide(); | |
289 | + city.find('input').val(''); city.hide(); | |
290 | + city_label.hide(); | |
288 | 291 | state.hide(); |
289 | 292 | } else { |
290 | 293 | cnpj.show(); |
291 | 294 | city.show(); |
295 | + city_label.show(); | |
292 | 296 | state.show(); |
293 | 297 | } |
294 | 298 | } |
... | ... | @@ -368,7 +372,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
368 | 372 | function set_events() { |
369 | 373 | $("input[name='institutions[type]']").click(function(){ |
370 | 374 | institution_type_actions(this.value); |
371 | - }).trigger("click"); | |
375 | + }); | |
372 | 376 | |
373 | 377 | $('#save_institution_button').click(save_institution); |
374 | 378 | $('#cancel_institution_button').click(cancel_institution); | ... | ... |
src/noosfero-spb/gov_user/public/views/new-community.js
... | ... | @@ -2,11 +2,6 @@ |
2 | 2 | |
3 | 3 | modulejs.define("NewCommunity", ['jquery'], function($) { |
4 | 4 | |
5 | - function replace_mandatory_message() { | |
6 | - $(".required-field").first() | |
7 | - .replaceWith("<span class='required-field'> Os campos em destaque<label class='pseudoformlabel'> (*)</label> são obrigatórios. </span>"); | |
8 | - } | |
9 | - | |
10 | 5 | function remove_image_builder_text() { |
11 | 6 | $("label:contains('Image builder')").hide(); |
12 | 7 | } |
... | ... | @@ -22,7 +17,6 @@ modulejs.define("NewCommunity", ['jquery'], function($) { |
22 | 17 | }, |
23 | 18 | |
24 | 19 | init: function() { |
25 | - replace_mandatory_message(); | |
26 | 20 | remove_image_builder_text(); |
27 | 21 | hide_organization_template_fields(); |
28 | 22 | } | ... | ... |
src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb
... | ... | @@ -18,29 +18,30 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase |
18 | 18 | @offer_1 = create_user('Ana de Souza') |
19 | 19 | @offer_2 = create_user('Angelo Roberto') |
20 | 20 | |
21 | - login_as(@person.user_login) | |
22 | - @environment = Environment.default | |
23 | - @environment.enable_plugin('GovUserPlugin') | |
24 | - @environment.save! | |
25 | - end | |
26 | - should "user edit its community institution" do | |
27 | - govPower = GovernmentalPower.create(:name=>"Some Gov Power") | |
28 | - govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
21 | + gov_power = GovernmentalPower.create(:name=>"Some Gov Power") | |
22 | + gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
29 | 23 | juridical_nature = JuridicalNature.create(:name => "Autarquia") |
30 | - | |
31 | - institution = InstitutionTestHelper.create_public_institution( | |
24 | + @institution = InstitutionTestHelper.create_public_institution( | |
32 | 25 | "Ministerio Publico da Uniao", |
33 | 26 | "MPU", |
34 | 27 | "BR", |
35 | 28 | "DF", |
36 | 29 | "Gama", |
37 | 30 | juridical_nature, |
38 | - govPower, | |
39 | - govSphere, | |
31 | + gov_power, | |
32 | + gov_sphere, | |
40 | 33 | "12.345.678/9012-45" |
41 | 34 | ) |
42 | 35 | |
43 | - identifier = institution.community.identifier | |
36 | + login_as(@person.user_login) | |
37 | + @environment = Environment.default | |
38 | + @environment.enable_plugin('GovUserPlugin') | |
39 | + @environment.save! | |
40 | + end | |
41 | + | |
42 | + should "admin user edit an institution" do | |
43 | + @institution.community.add_admin @person | |
44 | + identifier = @institution.community.identifier | |
44 | 45 | |
45 | 46 | fields = InstitutionTestHelper.generate_form_fields( |
46 | 47 | "institution new name", |
... | ... | @@ -53,7 +54,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase |
53 | 54 | |
54 | 55 | post( |
55 | 56 | :edit_institution, |
56 | - :profile=>institution.community.identifier, | |
57 | + :profile=>@institution.community.identifier, | |
57 | 58 | :community=>fields[:community], |
58 | 59 | :institutions=>fields[:institutions] |
59 | 60 | ) |
... | ... | @@ -62,25 +63,31 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase |
62 | 63 | assert_not_equal "Ministerio Publico da Uniao", institution.community.name |
63 | 64 | end |
64 | 65 | |
65 | - should "not user edit its community institution with wrong values" do | |
66 | - govPower = GovernmentalPower.create(:name=>"Some Gov Power") | |
67 | - govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
68 | - juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
69 | - | |
70 | - institution = InstitutionTestHelper.create_public_institution( | |
71 | - "Ministerio Publico da Uniao", | |
72 | - "MPU", | |
66 | + should "regular user should not edit an institution" do | |
67 | + identifier = @institution.community.identifier | |
68 | + fields = InstitutionTestHelper.generate_form_fields( | |
69 | + "institution new name", | |
73 | 70 | "BR", |
74 | 71 | "DF", |
75 | 72 | "Gama", |
76 | - juridical_nature, | |
77 | - govPower, | |
78 | - govSphere, | |
79 | - "12.345.678/9012-45" | |
73 | + "12.345.678/9012-45", | |
74 | + "PrivateInstitution" | |
75 | + ) | |
76 | + | |
77 | + post( | |
78 | + :edit_institution, | |
79 | + :profile=>@institution.community.identifier, | |
80 | + :community=>fields[:community], | |
81 | + :institutions=>fields[:institutions] | |
80 | 82 | ) |
81 | 83 | |
82 | - identifier = institution.community.identifier | |
84 | + institution = Community[identifier].institution | |
85 | + assert_equal "Ministerio Publico da Uniao", institution.community.name | |
86 | + assert_response 403 | |
87 | + end | |
83 | 88 | |
89 | + should "not user edit its community institution with wrong values" do | |
90 | + identifier = @institution.community.identifier | |
84 | 91 | fields = InstitutionTestHelper.generate_form_fields( |
85 | 92 | "", |
86 | 93 | "BR", |
... | ... | @@ -92,7 +99,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase |
92 | 99 | |
93 | 100 | post( |
94 | 101 | :edit_institution, |
95 | - :profile=>institution.community.identifier, | |
102 | + :profile=>@institution.community.identifier, | |
96 | 103 | :community=>fields[:community], |
97 | 104 | :institutions=>fields[:institutions] |
98 | 105 | ) | ... | ... |
src/noosfero-spb/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb
... | ... | @@ -19,6 +19,10 @@ |
19 | 19 | |
20 | 20 | <div id = 'create_institution_errors' class='errorExplanation hide-field'></div> |
21 | 21 | |
22 | +<div class="spb-row spb-col spb-col-12 required-field"> | |
23 | + <%= _("The highlighted fields are mandatory") %> | |
24 | +</div> | |
25 | + | |
22 | 26 | <div> |
23 | 27 | <%= labelled_form_for :community,:html => { :multipart => true, :id=>"institution_form" } do |f| %> |
24 | 28 | <%= hidden_field_tag "edit_institution_page", true %> |
... | ... | @@ -26,25 +30,19 @@ |
26 | 30 | <span class=''> |
27 | 31 | <div class='formfield type-radio'> |
28 | 32 | <label> <%= _("Public Institution") %> |
29 | - <%= radio_button_tag("institutions[type]", "PublicInstitution", (@institution.type == "PublicInstitution" ? true : false)) %> | |
33 | + <%= radio_button_tag("institutions[type]", "PublicInstitution", (@institution.type == "PublicInstitution")) %> | |
30 | 34 | </label> |
31 | 35 | |
32 | 36 | <label> |
33 | 37 | <%= _("Private Institution") %> |
34 | - <%= radio_button_tag("institutions[type]" ,"PrivateInstitution", (@institution.type == "PrivateInstitution" ? true : false))%> | |
38 | + <%= radio_button_tag("institutions[type]" ,"PrivateInstitution", (@institution.type == "PrivateInstitution"))%> | |
35 | 39 | </label> |
36 | 40 | </div> |
37 | 41 | </span> |
38 | 42 | |
39 | - <%= required f.text_field(:name, :value => @institution.community.name) %> | |
40 | - <%= content_tag :span, _("Institution name already exists"), :id=>"already_exists_text", :class=>"errorExplanation hide-field" %> | |
43 | + <%= required labelled_form_field(_('Corporate Name'), text_field_tag('community[name]', @institution.community.name)) %> | |
41 | 44 | |
42 | - <span class='required-field'> | |
43 | - <div class="formfield type-text"> | |
44 | - <%= inst.label "corporate_name", _("Corporate Name"), :class=>"formlabel" %> | |
45 | - <%= required inst.text_field(:corporate_name, :value => @institution.corporate_name) %> | |
46 | - </div> | |
47 | - </span> | |
45 | + <%= labelled_form_field(_('Fantasy name'), inst.text_field(:corporate_name, :value => @institution.corporate_name)) %> | |
48 | 46 | |
49 | 47 | <%= required select_country(_('Country'), 'community', 'country', {:class => 'type-select', :id => "community_country"}, :selected => @institution.community.country) %> |
50 | 48 | ... | ... |
src/noosfero-spb/software_communities/public/views/new-community.js
1 | 1 | modulejs.define("NewCommunity", ['jquery'], function($) { |
2 | 2 | |
3 | - function replace_mandatory_message() { | |
4 | - $(".required-field").first() | |
5 | - .replaceWith("<span class='required-field'> Os campos em destaque<label class='pseudoformlabel'> (*)</label> são obrigatórios. </span>"); | |
6 | - } | |
7 | - | |
8 | 3 | function remove_image_builder_text() { |
9 | 4 | $("label:contains('Image builder')").hide(); |
10 | 5 | } |
... | ... | @@ -20,7 +15,6 @@ modulejs.define("NewCommunity", ['jquery'], function($) { |
20 | 15 | }, |
21 | 16 | |
22 | 17 | init: function() { |
23 | - replace_mandatory_message(); | |
24 | 18 | remove_image_builder_text(); |
25 | 19 | hide_organization_template_fields(); |
26 | 20 | } | ... | ... |