Commit e75f707844069766235891fa523ac1e9a97b44b0
1 parent
02b98139
Exists in
master
and in
29 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 | 62 | self.user.nil? ? nil : self.user.email |
63 | 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 | 73 | def is_admin? |
66 | 74 | role_assignments.map{|ra|ra.role.permissions}.any? do |ps| |
67 | 75 | ps.any? do |p| | ... | ... |
app/views/profile/index.rhtml
... | ... | @@ -8,16 +8,22 @@ |
8 | 8 | |
9 | 9 | <ul> |
10 | 10 | <li> |
11 | - <strong><%= _('Name:') %></strong> | |
12 | - <%= profile.name %> | |
11 | + <strong><%= _('Name:') %></strong> | |
12 | + <%= profile.name %> | |
13 | 13 | </li> |
14 | 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 | 17 | </li> |
18 | 18 | |
19 | 19 | <%# FIXME %> |
20 | 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 | 27 | <li><%= link_to _('Friends'), :action => 'friends' %></li> |
22 | 28 | <li><%= link_to __('Communities'), :action => 'communities' %></li> |
23 | 29 | <li><%= link_to __('Enterprises'), :action => 'enterprises' %></li> | ... | ... |
app/views/profile_editor/_person.rhtml
test/functional/profile_controller_test.rb
... | ... | @@ -283,4 +283,23 @@ class ProfileControllerTest < Test::Unit::TestCase |
283 | 283 | assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => '/profile/testuser/tag/two'} } |
284 | 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 | 305 | end | ... | ... |
test/functional/profile_editor_controller_test.rb
... | ... | @@ -507,6 +507,14 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
507 | 507 | person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person |
508 | 508 | get :edit, :profile => person.identifier |
509 | 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 | 518 | end |
511 | 519 | |
512 | 520 | end | ... | ... |
test/unit/person_test.rb
... | ... | @@ -113,6 +113,17 @@ class PersonTest < Test::Unit::TestCase |
113 | 113 | assert_nil p.email |
114 | 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 | 127 | should 'be an admin if have permission of environment administration' do |
117 | 128 | role = Role.create!(:name => 'just_another_admin_role') |
118 | 129 | env = Environment.create!(:name => 'blah') | ... | ... |