Commit e75f707844069766235891fa523ac1e9a97b44b0
1 parent
02b98139
Exists in
master
and in
22 other branches
ActionItem709: the user e-mail is now editable and visible for friends at the profile page
Showing
6 changed files
with
57 additions
and
4 deletions
Show diff stats
app/models/person.rb
| @@ -62,6 +62,14 @@ class Person < Profile | @@ -62,6 +62,14 @@ class Person < Profile | ||
| 62 | self.user.nil? ? nil : self.user.email | 62 | self.user.nil? ? nil : self.user.email |
| 63 | end | 63 | end |
| 64 | 64 | ||
| 65 | + def email= (email) | ||
| 66 | + self.user.email = email if ! self.user.nil? | ||
| 67 | + end | ||
| 68 | + | ||
| 69 | + after_update do |person| | ||
| 70 | + person.user.save! | ||
| 71 | + end | ||
| 72 | + | ||
| 65 | def is_admin? | 73 | def is_admin? |
| 66 | role_assignments.map{|ra|ra.role.permissions}.any? do |ps| | 74 | role_assignments.map{|ra|ra.role.permissions}.any? do |ps| |
| 67 | ps.any? do |p| | 75 | ps.any? do |p| |
app/views/profile/index.rhtml
| @@ -8,16 +8,22 @@ | @@ -8,16 +8,22 @@ | ||
| 8 | 8 | ||
| 9 | <ul> | 9 | <ul> |
| 10 | <li> | 10 | <li> |
| 11 | - <strong><%= _('Name:') %></strong> | ||
| 12 | - <%= profile.name %> | 11 | + <strong><%= _('Name:') %></strong> |
| 12 | + <%= profile.name %> | ||
| 13 | </li> | 13 | </li> |
| 14 | <li> | 14 | <li> |
| 15 | - <strong><%= _('Homepage: ') %></strong> | ||
| 16 | - <%= link_to url_for(profile.url), profile.url %> | 15 | + <strong><%= _('Homepage:') %></strong> |
| 16 | + <%= link_to url_for(profile.url), profile.url %> | ||
| 17 | </li> | 17 | </li> |
| 18 | 18 | ||
| 19 | <%# FIXME %> | 19 | <%# FIXME %> |
| 20 | <% if profile.kind_of? Person %> | 20 | <% if profile.kind_of? Person %> |
| 21 | + <% if profile.friends.include?(user) %> | ||
| 22 | + <li> | ||
| 23 | + <strong><%= _('e-Mail:') %></strong> | ||
| 24 | + <%= content_tag 'a', profile.email, :href => 'mailto:'+profile.email %> | ||
| 25 | + </li> | ||
| 26 | + <% end %> | ||
| 21 | <li><%= link_to _('Friends'), :action => 'friends' %></li> | 27 | <li><%= link_to _('Friends'), :action => 'friends' %></li> |
| 22 | <li><%= link_to __('Communities'), :action => 'communities' %></li> | 28 | <li><%= link_to __('Communities'), :action => 'communities' %></li> |
| 23 | <li><%= link_to __('Enterprises'), :action => 'enterprises' %></li> | 29 | <li><%= link_to __('Enterprises'), :action => 'enterprises' %></li> |
app/views/profile_editor/_person.rhtml
| @@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | <%= f.text_field(:name) %> | 10 | <%= f.text_field(:name) %> |
| 11 | + <%= labelled_form_field(_('e-Mail'), text_field(:profile_data, :email)) %> | ||
| 11 | <%= f.text_field(:contact_information) %> | 12 | <%= f.text_field(:contact_information) %> |
| 12 | <%= f.text_field(:contact_phone) %> | 13 | <%= f.text_field(:contact_phone) %> |
| 13 | <%# use :size => 3 if you want 3 radios by line %> | 14 | <%# use :size => 3 if you want 3 radios by line %> |
test/functional/profile_controller_test.rb
| @@ -283,4 +283,23 @@ class ProfileControllerTest < Test::Unit::TestCase | @@ -283,4 +283,23 @@ class ProfileControllerTest < Test::Unit::TestCase | ||
| 283 | assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => '/profile/testuser/tag/two'} } | 283 | assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => '/profile/testuser/tag/two'} } |
| 284 | end | 284 | end |
| 285 | 285 | ||
| 286 | + should 'show e-mail for friends on profile page' do | ||
| 287 | + p1 = create_user('tusr1').person | ||
| 288 | + p2 = create_user('tusr2', :email => 't2@t2.com').person | ||
| 289 | + p2.add_friend p1 | ||
| 290 | + login_as 'tusr1' | ||
| 291 | + | ||
| 292 | + get :index, :profile => 'tusr2' | ||
| 293 | + assert_tag :content => /t2@t2.com/ | ||
| 294 | + end | ||
| 295 | + | ||
| 296 | + should 'not show e-mail for non friends on profile page' do | ||
| 297 | + p1 = create_user('tusr1').person | ||
| 298 | + p2 = create_user('tusr2', :email => 't2@t2.com').person | ||
| 299 | + login_as 'tusr1' | ||
| 300 | + | ||
| 301 | + get :index, :profile => 'tusr2' | ||
| 302 | + assert_no_tag :content => /t2@t2.com/ | ||
| 303 | + end | ||
| 304 | + | ||
| 286 | end | 305 | end |
test/functional/profile_editor_controller_test.rb
| @@ -507,6 +507,14 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -507,6 +507,14 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
| 507 | person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person | 507 | person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person |
| 508 | get :edit, :profile => person.identifier | 508 | get :edit, :profile => person.identifier |
| 509 | assert_no_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' } | 509 | assert_no_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' } |
| 510 | + | ||
| 511 | + should 'show a e-mail field in profile editor' do | ||
| 512 | + create_user('test_user', :email=>'teste_user@teste.com') | ||
| 513 | + login_as('test_user') | ||
| 514 | + get :profile_editor, :action => 'edit', :profile => 'test_user' | ||
| 515 | + | ||
| 516 | + assert_tag :tag => 'input', | ||
| 517 | + :attributes => { :name=>'profile_data[email]', :value=>'teste_user@teste.com' } | ||
| 510 | end | 518 | end |
| 511 | 519 | ||
| 512 | end | 520 | end |
test/unit/person_test.rb
| @@ -113,6 +113,17 @@ class PersonTest < Test::Unit::TestCase | @@ -113,6 +113,17 @@ class PersonTest < Test::Unit::TestCase | ||
| 113 | assert_nil p.email | 113 | assert_nil p.email |
| 114 | end | 114 | end |
| 115 | 115 | ||
| 116 | + should 'set email through person instance' do | ||
| 117 | + u = create_user('testuser') | ||
| 118 | + p = u.person | ||
| 119 | + | ||
| 120 | + p.email = 'damnit@example.com' | ||
| 121 | + p.save! | ||
| 122 | + | ||
| 123 | + u.reload | ||
| 124 | + assert_equal 'damnit@example.com', u.email | ||
| 125 | + end | ||
| 126 | + | ||
| 116 | should 'be an admin if have permission of environment administration' do | 127 | should 'be an admin if have permission of environment administration' do |
| 117 | role = Role.create!(:name => 'just_another_admin_role') | 128 | role = Role.create!(:name => 'just_another_admin_role') |
| 118 | env = Environment.create!(:name => 'blah') | 129 | env = Environment.create!(:name => 'blah') |