Commit c05210b2172db71ce158ef4177f8493a81166e07

Authored by Rodrigo Souto
Committed by Antonio Terceiro
1 parent 8a884615

People must have a name now

	* Not allowing people to signup without a name
	* Adding a migrate to set identifier as name for people that are already without a name
	* Changing the field "Full Name" to "Name" and to become red when not filled
	* Adding new db:schema

(ActionItem1352)
app/controllers/public/account_controller.rb
@@ -57,7 +57,6 @@ class AccountController < ApplicationController @@ -57,7 +57,6 @@ class AccountController < ApplicationController
57 @terms_of_use = environment.terms_of_use 57 @terms_of_use = environment.terms_of_use
58 @user.person_data = params[:profile_data] 58 @user.person_data = params[:profile_data]
59 @person = Person.new(params[:profile_data]) 59 @person = Person.new(params[:profile_data])
60 - @person.name = @user.login  
61 @person.environment = @user.environment 60 @person.environment = @user.environment
62 if request.post? && params[self.icaptcha_field].blank? 61 if request.post? && params[self.icaptcha_field].blank?
63 @user.signup! 62 @user.signup!
app/models/person.rb
@@ -184,14 +184,6 @@ class Person < Profile @@ -184,14 +184,6 @@ class Person < Profile
184 ] 184 ]
185 end 185 end
186 186
187 - def name  
188 - if !self[:name].blank?  
189 - self[:name]  
190 - else  
191 - self.user ? self.user.login : nil  
192 - end  
193 - end  
194 -  
195 has_and_belongs_to_many :favorite_enterprises, :class_name => 'Enterprise', :join_table => 'favorite_enteprises_people' 187 has_and_belongs_to_many :favorite_enterprises, :class_name => 'Enterprise', :join_table => 'favorite_enteprises_people'
196 188
197 def email_domain 189 def email_domain
app/views/profile_editor/_person_form.rhtml
1 <% @person ||= @profile %> 1 <% @person ||= @profile %>
2 2
3 -<%= required labelled_form_field(_('Full name'), text_field(:profile_data, :name)) %> 3 +<%= required f.text_field(:name) %>
4 4
5 <% optional_field(@person, 'nickname') do %> 5 <% optional_field(@person, 'nickname') do %>
6 <%= f.text_field(:nickname, :maxlength => 16, :size => 30) %> 6 <%= f.text_field(:nickname, :maxlength => 16, :size => 30) %>
db/migrate/079_fix_people_without_names.rb 0 → 100644
@@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
  1 +class FixPeopleWithoutNames < ActiveRecord::Migration
  2 + def self.up
  3 + select_all("SELECT name, identifier FROM profiles WHERE name = '' or name IS NULL").each do |profile|
  4 + update("UPDATE profiles SET name = '%s' WHERE identifier = '%s'" % [profile['identifier'], profile['identifier']])
  5 + end
  6 + end
  7 +
  8 + def self.down
  9 + say("Nothing to undo (cannot recover the data)")
  10 + end
  11 +end
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 # 9 #
10 # It's strongly recommended to check this file into your version control system. 10 # It's strongly recommended to check this file into your version control system.
11 11
12 -ActiveRecord::Schema.define(:version => 78) do 12 +ActiveRecord::Schema.define(:version => 79) do
13 13
14 create_table "article_versions", :force => true do |t| 14 create_table "article_versions", :force => true do |t|
15 t.integer "article_id" 15 t.integer "article_id"
features/join_community.feature
@@ -53,7 +53,7 @@ Feature: join a community @@ -53,7 +53,7 @@ Feature: join a community
53 | Username | joseoliveira | 53 | Username | joseoliveira |
54 | Password | 123456 | 54 | Password | 123456 |
55 | Password confirmation | 123456 | 55 | Password confirmation | 123456 |
56 - | Full name | Jose Oliveira | 56 + | Name | Jose Oliveira |
57 And I press "Sign up" 57 And I press "Sign up"
58 And I should see "Are you sure you want to join Sample Community?" 58 And I should see "Are you sure you want to join Sample Community?"
59 When I press "Yes, I want to join" 59 When I press "Yes, I want to join"
features/signup.feature
@@ -11,7 +11,7 @@ Feature: signup @@ -11,7 +11,7 @@ Feature: signup
11 And I fill in "Username" with "josesilva" 11 And I fill in "Username" with "josesilva"
12 And I fill in "Password" with "secret" 12 And I fill in "Password" with "secret"
13 And I fill in "Password confirmation" with "secret" 13 And I fill in "Password confirmation" with "secret"
14 - And I fill in "Full name" with "José da Silva" 14 + And I fill in "Name" with "José da Silva"
15 And I press "Sign up" 15 And I press "Sign up"
16 Then I should see "Thanks for signing up!" 16 Then I should see "Thanks for signing up!"
17 17
@@ -22,3 +22,25 @@ Feature: signup @@ -22,3 +22,25 @@ Feature: signup
22 Given I am logged in as "joaosilva" 22 Given I am logged in as "joaosilva"
23 And I go to signup page 23 And I go to signup page
24 Then I should be on Joao Silva's control panel 24 Then I should be on Joao Silva's control panel
  25 +
  26 + Scenario: user cannot register without a name
  27 + Given I am on the homepage
  28 + And I follow "Login"
  29 + And I follow "I want to participate"
  30 + And I fill in "e-Mail" with "josesilva@example.com"
  31 + And I fill in "Username" with "josesilva"
  32 + And I fill in "Password" with "secret"
  33 + And I fill in "Password confirmation" with "secret"
  34 + And I press "Sign up"
  35 + Then I should see "Name can't be blank"
  36 +
  37 + Scenario: user cannot change his name to empty string
  38 + Given the following users
  39 + | login | name |
  40 + | joaosilva | Joao Silva |
  41 + Given I am logged in as "joaosilva"
  42 + And I am on Joao Silva's control panel
  43 + And I follow "Profile Info and settings"
  44 + And I fill in "Name" with ""
  45 + When I press "Save"
  46 + Then I should see "Name can't be blank"
test/factories.rb
@@ -94,7 +94,7 @@ module Noosfero::Factory @@ -94,7 +94,7 @@ module Noosfero::Factory
94 :environment_id => environment_id, 94 :environment_id => environment_id,
95 }.merge(options) 95 }.merge(options)
96 user = fast_insert_with_timestamps(User, data) 96 user = fast_insert_with_timestamps(User, data)
97 - person = fast_insert_with_timestamps(Person, { :type => 'Person', :identifier => name, :user_id => user.id, :environment_id => environment_id }.merge(person_options)) 97 + person = fast_insert_with_timestamps(Person, { :type => 'Person', :identifier => name, :name => name, :user_id => user.id, :environment_id => environment_id }.merge(person_options))
98 homepage = fast_insert_with_timestamps(TextileArticle, { :type => 'TextileArticle', :name => 'homepage', :slug => 'homepage', :path => 'homepage', :profile_id => person.id }) 98 homepage = fast_insert_with_timestamps(TextileArticle, { :type => 'TextileArticle', :name => 'homepage', :slug => 'homepage', :path => 'homepage', :profile_id => person.id })
99 fast_update(person, {:home_page_id => homepage.id}) 99 fast_update(person, {:home_page_id => homepage.id})
100 box = fast_insert(Box, { :owner_type => "Profile", :owner_id => person.id, :position => 1}) 100 box = fast_insert(Box, { :owner_type => "Profile", :owner_id => person.id, :position => 1})
test/unit/person_test.rb
@@ -270,18 +270,6 @@ class PersonTest &lt; Test::Unit::TestCase @@ -270,18 +270,6 @@ class PersonTest &lt; Test::Unit::TestCase
270 assert_equal 'José', p.name 270 assert_equal 'José', p.name
271 end 271 end
272 272
273 - should 'fallback to login when person_info is not present' do  
274 - p = create_user('randomhacker').person  
275 - p.name = nil  
276 - assert_equal 'randomhacker', p.name  
277 - end  
278 -  
279 - should 'fallback to login when name is blank' do  
280 - p = create_user('randomhacker').person  
281 - p.name = ''  
282 - assert_equal 'randomhacker', p.name  
283 - end  
284 -  
285 should 'have favorite enterprises' do 273 should 'have favorite enterprises' do
286 p = create_user('test_person').person 274 p = create_user('test_person').person
287 e = Enterprise.create!(:name => 'test_ent', :identifier => 'test_ent') 275 e = Enterprise.create!(:name => 'test_ent', :identifier => 'test_ent')