diff --git a/app/models/person.rb b/app/models/person.rb
index 1a9a740..ce28780 100644
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -62,6 +62,14 @@ class Person < Profile
self.user.nil? ? nil : self.user.email
end
+ def email= (email)
+ self.user.email = email if ! self.user.nil?
+ end
+
+ after_update do |person|
+ person.user.save!
+ end
+
def is_admin?
role_assignments.map{|ra|ra.role.permissions}.any? do |ps|
ps.any? do |p|
diff --git a/app/views/profile/index.rhtml b/app/views/profile/index.rhtml
index 83501d6..0c1cbe3 100644
--- a/app/views/profile/index.rhtml
+++ b/app/views/profile/index.rhtml
@@ -8,16 +8,22 @@
-
- <%= _('Name:') %>
- <%= profile.name %>
+ <%= _('Name:') %>
+ <%= profile.name %>
-
- <%= _('Homepage: ') %>
- <%= link_to url_for(profile.url), profile.url %>
+ <%= _('Homepage:') %>
+ <%= link_to url_for(profile.url), profile.url %>
<%# FIXME %>
<% if profile.kind_of? Person %>
+ <% if profile.friends.include?(user) %>
+ -
+ <%= _('e-Mail:') %>
+ <%= content_tag 'a', profile.email, :href => 'mailto:'+profile.email %>
+
+ <% end %>
- <%= link_to _('Friends'), :action => 'friends' %>
- <%= link_to __('Communities'), :action => 'communities' %>
- <%= link_to __('Enterprises'), :action => 'enterprises' %>
diff --git a/app/views/profile_editor/_person.rhtml b/app/views/profile_editor/_person.rhtml
index 31ce177..f0060fa 100644
--- a/app/views/profile_editor/_person.rhtml
+++ b/app/views/profile_editor/_person.rhtml
@@ -8,6 +8,7 @@
<%= f.text_field(:name) %>
+ <%= labelled_form_field(_('e-Mail'), text_field(:profile_data, :email)) %>
<%= f.text_field(:contact_information) %>
<%= f.text_field(:contact_phone) %>
<%# use :size => 3 if you want 3 radios by line %>
diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb
index 6e38d65..482d48f 100644
--- a/test/functional/profile_controller_test.rb
+++ b/test/functional/profile_controller_test.rb
@@ -283,4 +283,23 @@ class ProfileControllerTest < Test::Unit::TestCase
assert_tag :tag => 'div', :attributes => { :class => /main-block/ }, :descendant => { :tag => 'a', :attributes => { :href => '/profile/testuser/tag/two'} }
end
+ should 'show e-mail for friends on profile page' do
+ p1 = create_user('tusr1').person
+ p2 = create_user('tusr2', :email => 't2@t2.com').person
+ p2.add_friend p1
+ login_as 'tusr1'
+
+ get :index, :profile => 'tusr2'
+ assert_tag :content => /t2@t2.com/
+ end
+
+ should 'not show e-mail for non friends on profile page' do
+ p1 = create_user('tusr1').person
+ p2 = create_user('tusr2', :email => 't2@t2.com').person
+ login_as 'tusr1'
+
+ get :index, :profile => 'tusr2'
+ assert_no_tag :content => /t2@t2.com/
+ end
+
end
diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb
index 9498d2e..7c026d2 100644
--- a/test/functional/profile_editor_controller_test.rb
+++ b/test/functional/profile_editor_controller_test.rb
@@ -507,6 +507,14 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person
get :edit, :profile => person.identifier
assert_no_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' }
+
+ should 'show a e-mail field in profile editor' do
+ create_user('test_user', :email=>'teste_user@teste.com')
+ login_as('test_user')
+ get :profile_editor, :action => 'edit', :profile => 'test_user'
+
+ assert_tag :tag => 'input',
+ :attributes => { :name=>'profile_data[email]', :value=>'teste_user@teste.com' }
end
end
diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb
index e0d0f4e..1b1a7cb 100644
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -113,6 +113,17 @@ class PersonTest < Test::Unit::TestCase
assert_nil p.email
end
+ should 'set email through person instance' do
+ u = create_user('testuser')
+ p = u.person
+
+ p.email = 'damnit@example.com'
+ p.save!
+
+ u.reload
+ assert_equal 'damnit@example.com', u.email
+ end
+
should 'be an admin if have permission of environment administration' do
role = Role.create!(:name => 'just_another_admin_role')
env = Environment.create!(:name => 'blah')
--
libgit2 0.21.2