Commit 15d2984bdb486659418ebad237007e4201bba72e

Authored by Arthur Esposte
1 parent 2847cdb2
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

Remove user validations for governemental users

lib/ext/person.rb
... ... @@ -13,6 +13,7 @@ class Person
13 13 def institution?
14 14 false
15 15 end
  16 +
16 17 def secondary_email
17 18 self.user.secondary_email unless self.user.nil?
18 19 end
... ...
lib/ext/user.rb
... ... @@ -7,7 +7,7 @@ class User
7 7 has_and_belongs_to_many :institutions
8 8  
9 9 validate :email_different_secondary?, :email_has_already_been_used?,
10   - :secondary_email_format, :email_suffix_is_gov?
  10 + :secondary_email_format
11 11  
12 12 scope :primary_or_secondary_email_already_used?, lambda { |email|
13 13 where("email=? OR secondary_email=?", email, email)
... ... @@ -52,39 +52,9 @@ class User
52 52 end
53 53 end
54 54  
55   - def email_suffix_is_gov?
56   - check_gov_suffix_in_secondary_email
57   - check_gov_email_have_institution
58   - end
59   -
60 55 private
61 56  
62 57 def valid_format?(value, string_format)
63 58 !value.nil? && value.length > 0 && !string_format.match(value).nil?
64 59 end
65   -
66   - def check_gov_suffix_in_secondary_email
67   - unless primary_email_has_gov_suffix?
68   - self.errors.add(
69   - :base,
70   - _("The governamental email must be the primary one.")
71   - ) if secondary_email_has_gov_suffix?
72   - end
73   - end
74   -
75   - def check_gov_email_have_institution
76   - self.errors.add(
77   - :base,
78   - _("Institution is obligatory if user has a government email.")
79   - ) if primary_email_has_gov_suffix? && self.institutions.blank?
80   - end
81   -
82   - def primary_email_has_gov_suffix?
83   - valid_format?(self.email, GOV_SUFFIX)
84   - end
85   -
86   - def secondary_email_has_gov_suffix?
87   - valid_format?(self.secondary_email, GOV_SUFFIX)
88   - end
89   -
90 60 end
... ...
test/unit/user_test.rb
... ... @@ -84,45 +84,6 @@ class UserTest < ActiveSupport::TestCase
84 84 assert user2.save
85 85 end
86 86  
87   - should 'return an error if secondary email is governmental and primary is not' do
88   - invalid_msg = "The governamental email must be the primary one."
89   - user = fast_create(User)
90   -
91   - user.email = "test@email.com"
92   - user.secondary_email = "test@gov.br"
93   -
94   - assert !user.save
95   - assert user.errors.full_messages.include?(invalid_msg)
96   - end
97   -
98   - # should 'have institution if email is governmental' do
99   - # user = fast_create(User)
100   - #
101   - # user.email = "testtest@gov.br"
102   - #
103   - # user.institutions = []
104   - # assert !user.save, "this should not save"
105   - #
106   - # gov_power = GovernmentalPower.create(:name=>"Some Gov Power")
107   - # gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
108   - # juridical_nature = JuridicalNature.create(:name => "Autarquia")
109   - # institution = create_public_institution(
110   - # "Ministerio Publico da Uniao",
111   - # "MPU",
112   - # "BR",
113   - # "DF",
114   - # "Gama",
115   - # juridical_nature,
116   - # gov_power,
117   - # gov_sphere,
118   - # "44.555.666/7777-88"
119   - # )
120   - # institution.save!
121   - #
122   - # user.institutions << institution
123   - # assert user.save, "this should save"
124   - # end
125   -
126 87 private
127 88  
128 89 def create_default_user
... ...