diff --git a/db/migrate/20150408130613_remove_secondary_email_from_user.rb b/db/migrate/20150408130613_remove_secondary_email_from_user.rb new file mode 100644 index 0000000..2546592 --- /dev/null +++ b/db/migrate/20150408130613_remove_secondary_email_from_user.rb @@ -0,0 +1,10 @@ +class RemoveSecondaryEmailFromUser < ActiveRecord::Migration + def up + remove_column :users, :secondary_email + end + + def down + add_column :users, :secondary_email + end + +end diff --git a/features/user_profile_edition.feature b/features/user_profile_edition.feature index 8513add..759e583 100644 --- a/features/user_profile_edition.feature +++ b/features/user_profile_edition.feature @@ -23,11 +23,6 @@ Feature: Institution Field | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | Ministerio do Planejamento | And I am logged in as mpog_admin - Scenario: Go to control panel when clicked on 'Complete your profile' link - When I follow "Complete your profile" - Then I should see "Profile settings for " - And I should see "Personal information" - @selenium Scenario: Add more then one instituion on profile editor Given I follow "Edit Profile" @@ -40,11 +35,6 @@ Feature: Institution Field And I should see "Governo do DF" within ".institutions_added" @selenium - Scenario: Verify text information to use governmental e-mail - Given I follow "Edit Profile" - Then I should see "If you work in a public agency use your government e-Mail" - - @selenium Scenario: Verify if field 'city' is shown when Brazil is selected Given I follow "Edit Profile" Then I should see "City" @@ -61,4 +51,3 @@ Feature: Institution Field And I fill in "input_institution" with "Some Nonexistent Institution" And I sleep for 1 seconds Then I should see "No institution found" - diff --git a/lib/ext/person.rb b/lib/ext/person.rb index 5a7f078..1e98f71 100644 --- a/lib/ext/person.rb +++ b/lib/ext/person.rb @@ -4,10 +4,6 @@ require_dependency 'person' class Person - settings_items :percentage_incomplete, :type => :string, :default => "" - - attr_accessible :percentage_incomplete - delegate :login, :to => :user, :prefix => true def institutions @@ -20,14 +16,6 @@ class Person institutions end - def secondary_email - self.user.secondary_email unless self.user.nil? - end - - def secondary_email= value - self.user.secondary_email = value unless self.user.nil? - end - def software? false end diff --git a/lib/ext/user.rb b/lib/ext/user.rb index 173937c..ec3d6b8 100644 --- a/lib/ext/user.rb +++ b/lib/ext/user.rb @@ -2,89 +2,6 @@ require_dependency 'user' class User - GOV_SUFFIX = /^.*@[gov.br|jus.br|leg.br|mp.br]+$/ - has_and_belongs_to_many :institutions - validate :email_different_secondary?, :email_has_already_been_used?, - :secondary_email_format, :email_suffix_is_gov? - - scope :primary_or_secondary_email_already_used?, lambda { |email| - where("email=? OR secondary_email=?", email, email) - } - - def email_different_secondary? - self.errors.add( - :base, - _("Email must be different from secondary email.") - ) if self.email == self.secondary_email - end - - def email_has_already_been_used? - user_already_saved = User.find(:first, - :conditions => ["email = ?", self.email]) - - if user_already_saved.nil? - primary_email_hasnt_been_used = - User.primary_or_secondary_email_already_used?(self.email).empty? - - if !self.secondary_email.nil? and self.secondary_email.empty? - self.secondary_email = nil - end - - secondary_email_hasnt_been_used = - User.primary_or_secondary_email_already_used?(self.secondary_email). - empty? - - if !primary_email_hasnt_been_used or !secondary_email_hasnt_been_used - self.errors.add(:base, _("E-mail or secondary e-mail already taken.")) - end - end - end - - def secondary_email_format - if !self.secondary_email.nil? and self.secondary_email.length > 0 - test = /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/ - - unless test.match(self.secondary_email) - self.errors.add(:base, _("Invalid secondary email format.")) - end - end - end - - def email_suffix_is_gov? - check_gov_suffix_in_secondary_email - check_gov_email_have_institution - end - - private - - def valid_format?(value, string_format) - !value.nil? && value.length > 0 && !string_format.match(value).nil? - end - - def check_gov_suffix_in_secondary_email - unless primary_email_has_gov_suffix? - self.errors.add( - :base, - _("The governamental email must be the primary one.") - ) if secondary_email_has_gov_suffix? - end - end - - def check_gov_email_have_institution - self.errors.add( - :base, - _("Institution is obligatory if user has a government email.") - ) if primary_email_has_gov_suffix? && self.institutions.blank? - end - - def primary_email_has_gov_suffix? - valid_format?(self.email, GOV_SUFFIX) - end - - def secondary_email_has_gov_suffix? - valid_format?(self.secondary_email, GOV_SUFFIX) - end - -end \ No newline at end of file +end diff --git a/lib/software_communities_plugin.rb b/lib/software_communities_plugin.rb index 557e210..945e76c 100644 --- a/lib/software_communities_plugin.rb +++ b/lib/software_communities_plugin.rb @@ -17,22 +17,6 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin _('Add Public Software and MPOG features.') end - # Hotspot to insert html without an especific hotspot on view. - def body_beginning - return if context.session[:user].nil? or context.session[:hide_incomplete_percentage] == true - - person = context.environment.people.where(:user_id=>context.session[:user]).first - - if context.profile && context.profile.person? and !person.nil? - @person = person - @percentege = calc_percentage_registration(person) - - if @percentege >= 0 and @percentege < 100 - expanded_template('incomplete_registration.html.erb') - end - end - end - def profile_editor_extras profile = context.profile @@ -125,7 +109,6 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin views/new-software.js views/user-edit-profile.js views/create-institution.js - views/complete-registration.js views/search-software-catalog.js views/profile-tabs-software.js views/new-community.js @@ -152,17 +135,6 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin end end - def calc_percentage_registration(person) - required_list = profile_required_list - empty_fields = profile_required_empty_list person - count = required_list[:person_fields].count + - required_list[:user_fields].count - percentege = 100 - ((empty_fields.count * 100) / count) - person.percentage_incomplete = percentege - person.save(validate: false) - percentege - end - def admin_panel_links [ { @@ -177,37 +149,6 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin protected - def profile_required_list - fields = {} - fields[:person_fields] = %w(cell_phone - contact_phone - comercial_phone - country - city - state - organization_website - image - identifier - name) - - fields[:user_fields] = %w(secondary_email email) - fields - end - - - def profile_required_empty_list(person) - empty_fields = [] - required_list = profile_required_list - - required_list[:person_fields].each do |field| - empty_fields << field.sub('_',' ') if person.send(field).blank? - end - required_list[:user_fields].each do |field| - empty_fields << field.sub('_',' ') if person.user.send(field).blank? - end - empty_fields - end - def user_transaction user_editor_institution_actions diff --git a/public/initializer.js b/public/initializer.js index d2a753d..f4f8916 100644 --- a/public/initializer.js +++ b/public/initializer.js @@ -7,7 +7,6 @@ 'NewSoftware', 'UserEditProfile', 'CreateInstitution', - 'CompleteRegistration', 'SearchSoftwareCatalog', 'SoftwareDownload', 'ProfileTabsSoftware', diff --git a/public/style.css b/public/style.css index 4a492f7..0163087 100644 --- a/public/style.css +++ b/public/style.css @@ -38,27 +38,6 @@ width: 180px; } -#complete_registration { - padding: 5px; - width: 100%; - background-color: #fff; -} - -#complete_registration a { - text-decoration: none; -} - -#complete_registration a:hover { - font-weight: bold; -} - -#complete_registration_percentage { - width: 100%; - height: 20px; - background: #fff; - border: solid 1px #000; -} - #profile-data .invalid { border-color: rgb(127, 0, 0); box-shadow: 0px 0px 7px red; diff --git a/public/views/complete-registration.js b/public/views/complete-registration.js deleted file mode 100644 index 6fe903e..0000000 --- a/public/views/complete-registration.js +++ /dev/null @@ -1,60 +0,0 @@ -modulejs.define('CompleteRegistration', ['jquery', 'NoosferoRoot'], function($, NoosferoRoot) { - 'use strict'; - - - var AJAX_URL = { - hide_registration_incomplete_percentage: - NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/hide_registration_incomplete_percentage") - }; - - - function hide_incomplete_percentage(evt) { - evt.preventDefault(); - - jQuery.get(AJAX_URL.hide_registration_incomplete_percentage, {hide:true}, function(response){ - if( response === true ) { - jQuery("#complete_registration").fadeOut(); - } - }); - } - - - function show_complete_progressbar() { - var percentage = jQuery("#complete_registration_message span").html(); - var canvas_tag = document.getElementById("complete_registration_percentage"); - - if( canvas_tag !== null ) { - var context = canvas_tag.getContext("2d"); - - percentage = canvas_tag.width*(percentage/100.0); - - context.beginPath(); - context.rect(0, 0, percentage, canvas_tag.height); - context.fillStyle = '#00FF00'; - context.fill(); - } - } - - - function repositioning_bar_percentage() { - var complete_message = $("#complete_registration").remove(); - - $(".profile-info-options").before(complete_message); - } - - - return { - isCurrentPage: function() { - return $("#complete_registration").length === 1; - }, - - - init: function() { - repositioning_bar_percentage(); - - jQuery(".hide-incomplete-percentage").click(hide_incomplete_percentage); - - show_complete_progressbar(); - } - } -}); \ No newline at end of file diff --git a/test/helpers/plugin_test_helper.rb b/test/helpers/plugin_test_helper.rb index 415eb49..14d409a 100644 --- a/test/helpers/plugin_test_helper.rb +++ b/test/helpers/plugin_test_helper.rb @@ -46,13 +46,12 @@ module PluginTestHelper community end - def create_person name, email, password, password_confirmation, secondary_email, state, city + def create_person name, email, password, password_confirmation, state, city user = create_user( name.to_slug, email, password, password_confirmation, - secondary_email ) person = Person::new @@ -70,14 +69,13 @@ module PluginTestHelper person end - def create_user login, email, password, password_confirmation, secondary_email + def create_user login, email, password, password_confirmation user = User.new user.login = login user.email = email user.password = password user.password_confirmation = password_confirmation - user.secondary_email = secondary_email user end diff --git a/test/unit/communities_block_test.rb b/test/unit/communities_block_test.rb index a92eeb2..5c542d4 100644 --- a/test/unit/communities_block_test.rb +++ b/test/unit/communities_block_test.rb @@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' class CommunitiesBlockTest < ActiveSupport::TestCase include PluginTestHelper def setup - @person = create_person("My Name", "user@email.com", "123456", "123456", "user@secondary_email.com", "Any State", "Some City") + @person = create_person("My Name", "user@email.com", "123456", "123456", "Any State", "Some City") @gov_power = GovernmentalPower.create(:name=>"Some Gov Power") @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") diff --git a/test/unit/institutions_block_test.rb b/test/unit/institutions_block_test.rb index 37ceb71..e0af039 100644 --- a/test/unit/institutions_block_test.rb +++ b/test/unit/institutions_block_test.rb @@ -27,7 +27,6 @@ class InstitutionsBlockTest < ActiveSupport::TestCase "jose_augusto@email.com", "aaaaaaa", "aaaaaaa", - "jose_silva@email.com", "DF", "Gama" ) diff --git a/test/unit/software_communities_person_test.rb b/test/unit/software_communities_person_test.rb index b29b189..e945dda 100644 --- a/test/unit/software_communities_person_test.rb +++ b/test/unit/software_communities_person_test.rb @@ -15,7 +15,6 @@ class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase "user@email.com", "123456", "123456", - "user@secondary_email.com", "Any State", "Some City" ) @@ -29,13 +28,6 @@ class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase assert_kind_of Noosfero::Plugin, @plugin end - - should 'return true when the email has not gov.br,jus.br,leg.br or mp.br' do - @user.secondary_email = "test_email@com.br" - @user.email = "test_email@net.br" - assert @user.save - end - should 'save person with a valid full name' do p = Person::new :name=>"S1mpl3 0f N4m3", :identifier=>"simple-name" p.user = fast_create(:user) @@ -63,23 +55,6 @@ class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase assert !p.save , _("Name Should begin with a capital letter and no special characters") end - should 'calculate the percentege of person incomplete fields' do - @person.cell_phone = "76888919" - @person.contact_phone = "987654321" - - assert_equal(67, @plugin.calc_percentage_registration(@person)) - - @person.comercial_phone = "11223344" - @person.country = "I dont know" - @person.state = "I dont know" - @person.city = "I dont know" - @person.organization_website = "www.whatever.com" - @person.image = Image::new :uploaded_data=>fixture_file_upload('/files/rails.png', 'image/png') - @person.save - - assert_equal(100, @plugin.calc_percentage_registration(@person)) - end - should 'get a list of softwares of a person' do software1 = create_software_info "noosfero" software2 = create_software_info "colab" diff --git a/test/unit/software_communities_plugin_user_test.rb b/test/unit/software_communities_plugin_user_test.rb deleted file mode 100644 index 7f9655a..0000000 --- a/test/unit/software_communities_plugin_user_test.rb +++ /dev/null @@ -1,138 +0,0 @@ -require File.dirname(__FILE__) + '/../../../../test/test_helper' -require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' - -class SoftwareCommunitiesPluginUserTest < ActiveSupport::TestCase - include PluginTestHelper - - should 'not save user whose both email and secondary email are the same' do - - user = fast_create(User) - user.email = "test@email.com" - user.secondary_email = "test@email.com" - - assert !user.save - end - - should 'not save user whose email and secondary email have been taken' do - user1 = create_default_user - user2 = fast_create(User) - - user2.email = "primary@email.com" - user2.secondary_email = "secondary@email.com" - assert !user2.save - end - - should 'not save user whose email has already been used' do - user1 = create_default_user - user2 = fast_create(User) - - user2.email = "primary@email.com" - user2.secondary_email = "noosfero@email.com" - assert !user2.save - end - - should 'not save user whose email has been taken another in users secondary email' do - user1 = create_default_user - user2 = fast_create(User) - - user2.login = "another-login" - user2.email = "secondary@email.com" - user2.secondary_email = "noosfero@email.com" - assert !user2.save - end - - should 'not save user whose secondary email has been taken used in another users email' do - user1 = create_default_user - user2 = fast_create(User) - - user2.login = "another-login" - user2.email = "noosfero@email.com" - user2.secondary_email = "primary@email.com" - assert !user2.save - end - - should 'not save user whose secondary email has already been used in another users secondary email' do - user1 = create_default_user - user2 = fast_create(User) - - user2.login = "another-login" - user2.email = "noosfero@email.com" - user2.secondary_email = "secondary@email.com" - assert !user2.save - end - - should 'not save user whose secondary email is in the wrong format' do - user = fast_create(User) - user.email = "test@email.com" - user.secondary_email = "notarightformat.com" - - assert !user.save - - user.secondary_email = "not@arightformatcom" - - assert !user.save - end - - should 'save more than one user without secondary email' do - user = fast_create(User) - user.email = "test@email.com" - user.secondary_email = "" - user.save - - user2 = fast_create(User) - user2.email = "test2@email.com" - user2.secondary_email = "" - assert user2.save - end - should 'return an error if secondary email is governmental and primary is not' do - invalid_msg = "The governamental email must be the primary one." - user = fast_create(User) - - user.email = "test@email.com" - user.secondary_email = "test@gov.br" - - assert !user.save - assert user.errors.full_messages.include?(invalid_msg) - end - - should 'have institution if email is governmental' do - user = fast_create(User) - - user.email = "testtest@gov.br" - - user.institutions = [] - assert !user.save, "this should not save" - - gov_power = GovernmentalPower.create(:name=>"Some Gov Power") - gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") - juridical_nature = JuridicalNature.create(:name => "Autarquia") - institution = create_public_institution( - "Ministerio Publico da Uniao", - "MPU", - "BR", - "DF", - "Gama", - juridical_nature, - gov_power, - gov_sphere, - "44.555.666/7777-88" - ) - institution.save! - - user.institutions << institution - assert user.save, "this should save" - end - - private - - def create_default_user - user = fast_create(User) - user.login = "a-login" - user.email = "primary@email.com" - user.secondary_email = "secondary@email.com" - user.save - - return user - end - -end diff --git a/test/unit/softwares_block_test.rb b/test/unit/softwares_block_test.rb index d14e080..44b5064 100644 --- a/test/unit/softwares_block_test.rb +++ b/test/unit/softwares_block_test.rb @@ -27,7 +27,6 @@ class SoftwaresBlockTest < ActiveSupport::TestCase "jose_augusto@email.com", "aaaaaaa", "aaaaaaa", - "jose_silva@email.com", "DF", "Gama" ) diff --git a/views/incomplete_registration.html.erb b/views/incomplete_registration.html.erb deleted file mode 100644 index 8eb6af2..0000000 --- a/views/incomplete_registration.html.erb +++ /dev/null @@ -1,11 +0,0 @@ -
-
-
<%= _("Complete Profile")+": #{@percentege}%" %>
- -
- <%= link_to _("Complete your profile"), "#{Noosfero.root}/myprofile/#{@person.identifier}/profile_editor/edit" %> | - <%= link_to _("Hide"), "#", :class=>"hide-incomplete-percentage" %> -
-
-
- diff --git a/views/person_editor_extras.html.erb b/views/person_editor_extras.html.erb index 341fd50..8b7f7ec 100644 --- a/views/person_editor_extras.html.erb +++ b/views/person_editor_extras.html.erb @@ -1,11 +1,3 @@ -
- <%= label_tag "user[secondary_email]", _('Secondary e-mail')+":", :class=>"formlabel" %> - -
- <%= text_field_tag "user[secondary_email]", context.profile.user.secondary_email %> -
-
-
<%= label_tag "user[institution_ids]", _('Institutions'), :class=>"formlabel" %> -- libgit2 0.21.2