Commit 9e654d48133c2fcaf1dc41a7b3c17b8693850a65

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

correcoes_aderencia: Make Full Name validation ignore "áàâãéèêíïóôõöú"

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Rodrigo Medeiros <rodrigo.mss01@gmail.com>
lib/ext/person.rb
  1 +# encoding: utf-8
  2 +
1 3 require_dependency 'person'
2 4  
3 5 class Person
... ... @@ -58,17 +60,19 @@ class Person
58 60 end
59 61  
60 62 def validate_full_name
61   - reg_firsts_char = /(^|\s)([a-z]|[0-9])/
62   - reg_special_char = /[^\w\*\s]/
  63 + full_validation = /([^\w\*\s*])|(^|\s)([a-z]|[0-9])/
  64 + partial_validation = /[^\w\*\s]/
63 65 invalid = false
64 66  
65 67 return false if self.name.blank?
66 68  
67   - self.name.split(" ").each do |value|
  69 + validation_name = replace_some_special_chars(self.name)
  70 +
  71 + validation_name.split(" ").each do |value|
68 72 invalid = if value.length > 3
69   - reg_firsts_char.match(value) || reg_special_char.match(value)
  73 + full_validation.match(value)
70 74 else
71   - reg_special_char.match(value)
  75 + partial_validation.match(value)
72 76 end
73 77 end
74 78  
... ... @@ -82,4 +86,24 @@ class Person
82 86 def software?
83 87 false
84 88 end
  89 +
  90 + private
  91 +
  92 + def replace_some_special_chars text
  93 + text.gsub(/([áàâãéèêíïóôõöú])/) do |value|
  94 + if( ["á","à","â","ã"].include?(value) )
  95 + "a"
  96 + elsif( ["é","è","ê"].include?(value) )
  97 + "e"
  98 + elsif( ["í","ï"].include?(value) )
  99 + "i"
  100 + elsif ( ["ó","ô","õ","ö"].include?(value) )
  101 + "o"
  102 + elsif( ["ú"].indexOf(value) )
  103 + "u"
  104 + else
  105 + value
  106 + end
  107 + end
  108 + end
85 109 end
... ...
public/mpog-user-validations.js
... ... @@ -148,17 +148,37 @@
148 148 }
149 149  
150 150 function set_full_name_validation() {
  151 + // Sorry, I know its ugly. But I cant get ([^\w\*\s*])|(^|\s)([a-z]|[0-9])
  152 + // to ignore Brazilian not so much special chars in names
  153 + function replace_some_special_chars(text) {
  154 + return text.replace(/([áàâãéèêíïóôõöú])/g, function(value){
  155 + if( ["á","à","â","ã"].indexOf(value) != -1 )
  156 + return "a";
  157 + else if( ["é","è","ê"].indexOf(value) != -1 )
  158 + return "e";
  159 + else if( ["í","ï"].indexOf(value) != -1 )
  160 + return "i";
  161 + else if ( ["ó","ô","õ","ö"].indexOf(value) != -1 )
  162 + return "o";
  163 + else if( ["ú"].indexOf(value) != -1 )
  164 + return "u";
  165 + else
  166 + return value;
  167 + });
  168 + }
  169 +
151 170 function is_invalid_formated(text) {
152   - var reg_firsts_char = /(^|\s)([a-z]|[0-9])/g;
153   - var reg_special_char = /[^\w\*\s*]/g;
154   - var invalid = false;
  171 + var full_validation = /([^\w\*\s*])|(^|\s)([a-z]|[0-9])/; // no special chars and do not initialize with no capital latter
  172 + var partial_validation = /[^\w\*\s*]/; // no special chars
  173 + text = replace_some_special_chars(text);
155 174 var slices = text.split(" ");
  175 + var invalid = false;
156 176  
157 177 for(var i = 0; i < slices.length; i++) {
158 178 if( slices[i].length > 3 ) {
159   - invalid = reg_firsts_char.test(slices[i]) || reg_special_char.test(slices[i]);
  179 + invalid = full_validation.test(slices[i]);
160 180 } else {
161   - invalid = reg_special_char.test(slices[i]);
  181 + invalid = partial_validation.test(slices[i]);
162 182 }
163 183  
164 184 if(invalid) break;
... ...
test/unit/mpog_person_test.rb
  1 +# encoding: utf-8
  2 +
1 3 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2 4  
3 5 class MpogSoftwarePluginPersonTest < ActiveSupport::TestCase
... ... @@ -8,6 +10,13 @@ class MpogSoftwarePluginPersonTest &lt; ActiveSupport::TestCase
8 10 assert_equal true, p.save
9 11 end
10 12  
  13 + should 'save person with a valid full name with accents' do
  14 + p = Person::new :name=>'Jônatàs dâ Sîlvã Jösé', :identifier=>"jonatas-jose-da-silva"
  15 + p.user = fast_create(:user)
  16 +
  17 + assert_equal true, p.save
  18 + end
  19 +
11 20 should 'not save person whose name has not capital letter' do
12 21 p = Person::new :name=>"simple name"
13 22 assert !p.save, _("Name Should begin with a capital letter and no special characters")
... ...