diff --git a/app/helpers/profile_editor_helper.rb b/app/helpers/profile_editor_helper.rb
index bd164f7..7cb999e 100644
--- a/app/helpers/profile_editor_helper.rb
+++ b/app/helpers/profile_editor_helper.rb
@@ -147,7 +147,7 @@ module ProfileEditorHelper
def unchangeable_privacy_field(profile)
if profile.public?
- labelled_check_box(_('Public'), '', '', true, :disabled => true)
+ labelled_check_box(_('Public'), '', '', true, :disabled => true, :title => _('This field must be public'), :class => 'disabled')
else
''
end
diff --git a/app/helpers/profile_helper.rb b/app/helpers/profile_helper.rb
index 4c83cd4..3fe2c48 100644
--- a/app/helpers/profile_helper.rb
+++ b/app/helpers/profile_helper.rb
@@ -1,8 +1,8 @@
module ProfileHelper
def display_field(title, profile, field, force = false)
- if (!force && field.to_s != 'email' && !profile.active_fields.include?(field.to_s)) ||
- ((profile.active_fields.include?(field.to_s) || field.to_s == 'email') && !profile.public_fields.include?(field.to_s) && (!user || (user != profile && !user.is_a_friend?(profile))))
+ if (!force && !profile.active_fields.include?(field.to_s)) ||
+ (profile.active_fields.include?(field.to_s) && !profile.public_fields.include?(field.to_s) && (!user || (user != profile && !user.is_a_friend?(profile))))
return ''
end
value = profile.send(field)
@@ -28,4 +28,14 @@ module ProfileHelper
end
end
+ def display_work_info(profile)
+ organization = display_field(_('Organization:'), profile, :organization)
+ organization_site = display_field(_('Organization website:'), profile, :organization_website) { |url| link_to(url, url) }
+ if organization.blank? && organization_site.blank?
+ ''
+ else
+ content_tag('tr', content_tag('th', _('Work'), { :colspan => 2 })) + organization + organization_site
+ end
+ end
+
end
diff --git a/app/models/person.rb b/app/models/person.rb
index 9a76ecc..648b98a 100644
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -178,7 +178,8 @@ class Person < Profile
include MaybeAddHttp
def active_fields
- environment ? environment.active_person_fields : []
+ fields = environment ? environment.active_person_fields : []
+ fields << 'email'
end
def required_fields
diff --git a/app/views/profile/_person_profile.rhtml b/app/views/profile/_person_profile.rhtml
index 1a64928..9fac130 100644
--- a/app/views/profile/_person_profile.rhtml
+++ b/app/views/profile/_person_profile.rhtml
@@ -16,14 +16,7 @@
<%= display_contact profile %>
<% cache_timeout(profile.relationships_cache_key, 4.hours) do %>
- <% if !(profile.organization.blank? && profile.organization_website.blank?) && (profile.active_fields.include?('organization') || profile.active_fields.include?('organization_website')) %>
-
- <%= _('Work')%> |
-
- <% end %>
- <%= display_field(_('Organization:'), profile, :organization) %>
- <%= display_field(_('Organization website:'), profile, :organization_website) { |url| link_to(url, url) }%>
-
+ <%= display_work_info profile %>
<% if !environment.enabled?('disable_asset_enterprises') && !profile.enterprises.empty? %>
@@ -51,6 +44,6 @@
<%= render :partial => 'common' %>
-
-<% end %>
+ <% end %>
+
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index 153be0f..8e927f0 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -6107,14 +6107,17 @@ li.profile-activity-item.upload_image .activity-gallery-images-count-1 img {
display: table-row;
}
+.field-with-privacy-selector:hover {
+ background-color: #F0F0F0;
+}
+
.controller-profile_editor #profile-data .field-with-privacy-selector .formfieldline {
- display: table-cell;
width: auto;
}
.field-privacy-selector {
display: table-cell;
- vertical-align: bottom;
+ vertical-align: middle;
text-align: center;
width: 100px;
}
diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb
index 135bf17..0efbddf 100644
--- a/test/unit/application_helper_test.rb
+++ b/test/unit/application_helper_test.rb
@@ -379,8 +379,10 @@ class ApplicationHelperTest < ActiveSupport::TestCase
controller.stubs(:action_name).returns('edit')
profile = Person.new
- profile.expects(:active_fields).returns(['field'])
- assert_equal 'SIGNUP_FIELD', optional_field(profile, 'field', 'SIGNUP_FIELD')
+ profile.stubs(:active_fields).returns(['field'])
+
+ expects(:profile_field_privacy_selector).with(profile, 'field').returns('')
+ assert_tag_in_string optional_field(profile, 'field', 'EDIT_FIELD'), :tag => 'div', :content => 'EDIT_FIELD', :attributes => {:class => 'field-with-privacy-selector'}
end
should 'not display active fields' do
@@ -394,7 +396,7 @@ class ApplicationHelperTest < ActiveSupport::TestCase
profile = Person.new
profile.expects(:active_fields).returns([])
- assert_equal '', optional_field(profile, 'field', 'SIGNUP_FIELD')
+ assert_equal '', optional_field(profile, 'field', 'EDIT_FIELD')
end
should 'display required fields' do
@@ -406,11 +408,13 @@ class ApplicationHelperTest < ActiveSupport::TestCase
controller.stubs(:controller_name).returns('')
controller.stubs(:action_name).returns('edit')
- stubs(:required).with('SIGNUP_FIELD').returns('SIGNUP_FIELD')
profile = Person.new
- profile.expects(:active_fields).returns(['field'])
+ profile.stubs(:active_fields).returns(['field'])
profile.expects(:required_fields).returns(['field'])
- assert_equal 'SIGNUP_FIELD', optional_field(profile, 'field', 'SIGNUP_FIELD')
+
+ stubs(:required).with(anything).returns('EDIT_FIELD')
+ expects(:profile_field_privacy_selector).with(profile, 'field').returns('')
+ assert_equal 'EDIT_FIELD', optional_field(profile, 'field', 'EDIT_FIELD')
end
should 'base theme uses default icon theme' do
diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb
index e3f9e25..04d4ef6 100644
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -441,6 +441,14 @@ class PersonTest < ActiveSupport::TestCase
assert_equal e.active_person_fields, person.active_fields
end
+ should 'return email as active_person_fields' do
+ e = Environment.default
+ e.expects(:active_person_fields).returns(['nickname']).at_least_once
+ person = Person.new(:environment => e)
+
+ assert_equal ['nickname', 'email'], person.active_fields
+ end
+
should 'return required_person_fields' do
e = Environment.default
e.expects(:required_person_fields).returns(['cell_phone', 'comercial_phone']).at_least_once
diff --git a/test/unit/profile_helper_test.rb b/test/unit/profile_helper_test.rb
index 65af3ac..c280c46 100644
--- a/test/unit/profile_helper_test.rb
+++ b/test/unit/profile_helper_test.rb
@@ -2,6 +2,10 @@ require File.dirname(__FILE__) + '/../test_helper'
class ProfileHelperTest < ActiveSupport::TestCase
+ include ProfileHelper
+ include ApplicationHelper
+ include ActionView::Helpers::TagHelper
+
def setup
@profile = mock
@helper = mock
@@ -9,8 +13,85 @@ class ProfileHelperTest < ActiveSupport::TestCase
end
attr_reader :profile, :helper
- def test_true
- assert true
+ should 'not display field if field is not active and not forced' do
+ profile.expects(:active_fields).returns([])
+ assert_equal '', display_field('Title', profile, 'field')
+ end
+
+ should 'display field if field is not active but is forced' do
+ profile.expects(:active_fields).returns([])
+ profile.expects(:field).returns('value')
+ assert_match /Title.*value/, display_field('Title', profile, 'field', true)
+ end
+
+ should 'not display field if field is active but not public and not logged in' do
+ profile.stubs(:active_fields).returns(['field'])
+ profile.expects(:public_fields).returns([])
+ @controller = mock
+ @controller.stubs(:user).returns(nil)
+ assert_equal '', display_field('Title', profile, 'field')
+ end
+
+ should 'not display field if field is active but not public and user is not friend' do
+ profile.stubs(:active_fields).returns(['field'])
+ profile.expects(:public_fields).returns([])
+ user = mock
+ user.expects(:is_a_friend?).with(profile).returns(false)
+ @controller = mock
+ @controller.stubs(:user).returns(user)
+ assert_equal '', display_field('Title', profile, 'field')
+ end
+
+ should 'display field if field is active and not public but user is profile owner' do
+ profile.stubs(:active_fields).returns(['field'])
+ profile.expects(:public_fields).returns([])
+ profile.expects(:field).returns('value')
+ @controller = mock
+ @controller.stubs(:user).returns(profile)
+ assert_match /Title.*value/, display_field('Title', profile, 'field', true)
+ end
+
+ should 'display field if field is active and not public but user is a friend' do
+ profile.stubs(:active_fields).returns(['field'])
+ profile.expects(:public_fields).returns([])
+ profile.expects(:field).returns('value')
+ user = mock
+ user.expects(:is_a_friend?).with(profile).returns(true)
+ @controller = mock
+ @controller.stubs(:user).returns(user)
+ assert_match /Title.*value/, display_field('Title', profile, 'field', true)
+ end
+
+ should 'not display work info if field is active but not public and user is not friend' do
+ profile.stubs(:active_fields).returns(['organization', 'organization_website'])
+ profile.expects(:public_fields).returns([]).times(2)
+ user = mock
+ user.expects(:is_a_friend?).with(profile).returns(false).times(2)
+ @controller = mock
+ @controller.stubs(:user).returns(user)
+ assert_equal '', display_work_info(profile)
+ end
+
+ should 'display work info if field is active and not public but user is profile owner' do
+ profile.stubs(:active_fields).returns(['organization', 'organization_website'])
+ profile.expects(:public_fields).returns([]).times(2)
+ profile.expects(:organization).returns('Organization Name')
+ profile.expects(:organization_website).returns('')
+ @controller = mock
+ @controller.stubs(:user).returns(profile)
+ assert_match /Work.*Organization Name/, display_work_info(profile)
+ end
+
+ should 'display work info if field is active and not public but user is a friend' do
+ profile.stubs(:active_fields).returns(['organization', 'organization_website'])
+ profile.expects(:public_fields).returns([]).times(2)
+ profile.expects(:organization).returns('Organization Name')
+ profile.expects(:organization_website).returns('')
+ user = mock
+ user.expects(:is_a_friend?).with(profile).returns(true).times(2)
+ @controller = mock
+ @controller.stubs(:user).returns(user)
+ assert_match /Work.*Organization Name/, display_work_info(profile)
end
end
--
libgit2 0.21.2