Commit 56346bc95beae1dd28123118a3f2315482e57c29
1 parent
59897e5e
Exists in
master
and in
28 other branches
Set fields default to private
Showing
2 changed files
with
17 additions
and
18 deletions
Show diff stats
app/models/person.rb
... | ... | @@ -471,8 +471,9 @@ class Person < Profile |
471 | 471 | Scrap.find_by_sql("SELECT id, updated_at, '#{Scrap.to_s}' AS klass FROM #{Scrap.table_name} WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} WHERE action_tracker.user_id = #{self.id} and action_tracker.verb != 'leave_scrap_to_self' and action_tracker.verb != 'add_member_in_community' ORDER BY updated_at DESC") |
472 | 472 | end |
473 | 473 | |
474 | + # by default, all fields are private | |
474 | 475 | def public_fields |
475 | - self.fields_privacy.nil? ? self.active_fields : self.fields_privacy.reject{ |k, v| v != 'public' }.keys.map(&:to_s) | |
476 | + self.fields_privacy.nil? ? [] : self.fields_privacy.reject{ |k, v| v != 'public' }.keys.map(&:to_s) | |
476 | 477 | end |
477 | 478 | |
478 | 479 | protected | ... | ... |
test/unit/person_test.rb
... | ... | @@ -55,7 +55,7 @@ class PersonTest < ActiveSupport::TestCase |
55 | 55 | |
56 | 56 | p1 = u.person |
57 | 57 | assert_equal u, p1.user |
58 | - | |
58 | + | |
59 | 59 | p2 = Person.new(:environment => Environment.default) |
60 | 60 | p2.user = u |
61 | 61 | assert !p2.valid? |
... | ... | @@ -202,7 +202,7 @@ class PersonTest < ActiveSupport::TestCase |
202 | 202 | should 'have friends' do |
203 | 203 | p1 = create_user('testuser1').person |
204 | 204 | p2 = create_user('testuser2').person |
205 | - | |
205 | + | |
206 | 206 | p1.add_friend(p2) |
207 | 207 | |
208 | 208 | p1.friends.reload |
... | ... | @@ -237,7 +237,7 @@ class PersonTest < ActiveSupport::TestCase |
237 | 237 | p2 = create_user('testuser2').person |
238 | 238 | p3 = create_user('testuser3').person |
239 | 239 | p4 = create_user('testuser4').person |
240 | - | |
240 | + | |
241 | 241 | p1.add_friend(p2, 'group1') |
242 | 242 | p1.add_friend(p3, 'group2') |
243 | 243 | p1.add_friend(p4, 'group1') |
... | ... | @@ -248,7 +248,7 @@ class PersonTest < ActiveSupport::TestCase |
248 | 248 | should 'not suggest duplicated friend groups' do |
249 | 249 | p1 = create_user('testuser1').person |
250 | 250 | p2 = create_user('testuser2').person |
251 | - | |
251 | + | |
252 | 252 | p1.add_friend(p2, 'friends') |
253 | 253 | |
254 | 254 | assert_equal p1.suggested_friend_groups, p1.suggested_friend_groups.uniq |
... | ... | @@ -307,7 +307,7 @@ class PersonTest < ActiveSupport::TestCase |
307 | 307 | assert_equal 'my contact', person.contact_information |
308 | 308 | end |
309 | 309 | |
310 | - should 'provide desired info fields' do | |
310 | + should 'provide desired info fields' do | |
311 | 311 | p = Person.new(:environment => Environment.default) |
312 | 312 | assert p.respond_to?(:photo) |
313 | 313 | assert p.respond_to?(:address) |
... | ... | @@ -472,7 +472,7 @@ class PersonTest < ActiveSupport::TestCase |
472 | 472 | should 'require custom_area_of_study if area_of_study is others' do |
473 | 473 | e = Environment.default |
474 | 474 | e.expects(:required_person_fields).returns(['area_of_study', 'custom_area_of_study']).at_least_once |
475 | - | |
475 | + | |
476 | 476 | person = Person.new(:environment => e, :area_of_study => 'Others') |
477 | 477 | assert !person.valid? |
478 | 478 | assert person.errors.invalid?(:custom_area_of_study) |
... | ... | @@ -507,7 +507,7 @@ class PersonTest < ActiveSupport::TestCase |
507 | 507 | should 'not require custom_formation if formation is not others' do |
508 | 508 | e = Environment.default |
509 | 509 | e.expects(:required_person_fields).returns(['formation']).at_least_once |
510 | - | |
510 | + | |
511 | 511 | person = Person.new(:environment => e, :formation => 'Agrometeorology') |
512 | 512 | assert !person.valid? |
513 | 513 | assert ! person.errors.invalid?(:custom_formation) |
... | ... | @@ -829,13 +829,13 @@ class PersonTest < ActiveSupport::TestCase |
829 | 829 | assert !p1.is_a_friend?(p3) |
830 | 830 | p1.add_friend(p4) |
831 | 831 | assert p1.is_a_friend?(p4) |
832 | - | |
832 | + | |
833 | 833 | action_tracker = fast_create(ActionTracker::Record) |
834 | 834 | ActionTrackerNotification.delete_all |
835 | 835 | count = ActionTrackerNotification.count |
836 | 836 | Delayed::Job.destroy_all |
837 | 837 | Person.notify_activity(action_tracker) |
838 | - process_delayed_job_queue | |
838 | + process_delayed_job_queue | |
839 | 839 | assert_equal count + 3, ActionTrackerNotification.count |
840 | 840 | ActionTrackerNotification.all.map{|a|a.profile}.map do |profile| |
841 | 841 | [p1,p2,p4].include?(profile) |
... | ... | @@ -853,7 +853,7 @@ class PersonTest < ActiveSupport::TestCase |
853 | 853 | assert !p1.is_a_friend?(p3) |
854 | 854 | p1.add_friend(p4) |
855 | 855 | assert p1.is_a_friend?(p4) |
856 | - | |
856 | + | |
857 | 857 | action_tracker = fast_create(ActionTracker::Record) |
858 | 858 | |
859 | 859 | assert_difference(Delayed::Job, :count, 1) do |
... | ... | @@ -872,7 +872,7 @@ class PersonTest < ActiveSupport::TestCase |
872 | 872 | assert !p1.is_a_friend?(p3) |
873 | 873 | p1.add_friend(p4) |
874 | 874 | assert p1.is_a_friend?(p4) |
875 | - | |
875 | + | |
876 | 876 | action_tracker = fast_create(ActionTracker::Record) |
877 | 877 | |
878 | 878 | Delayed::Job.delete_all |
... | ... | @@ -896,7 +896,7 @@ class PersonTest < ActiveSupport::TestCase |
896 | 896 | assert p3.is_member_of?(community) |
897 | 897 | assert !p2.is_member_of?(community) |
898 | 898 | process_delayed_job_queue |
899 | - | |
899 | + | |
900 | 900 | action_tracker = fast_create(ActionTracker::Record, :verb => 'create_article') |
901 | 901 | action_tracker.target = community |
902 | 902 | action_tracker.save! |
... | ... | @@ -924,7 +924,7 @@ class PersonTest < ActiveSupport::TestCase |
924 | 924 | community.add_member(p4) |
925 | 925 | assert p4.is_member_of?(community) |
926 | 926 | assert !p2.is_member_of?(community) |
927 | - | |
927 | + | |
928 | 928 | action_tracker = fast_create(ActionTracker::Record) |
929 | 929 | article = mock() |
930 | 930 | action_tracker.stubs(:target).returns(article) |
... | ... | @@ -1271,12 +1271,10 @@ class PersonTest < ActiveSupport::TestCase |
1271 | 1271 | assert person.has_permission?('bli', Profile.new) |
1272 | 1272 | end |
1273 | 1273 | |
1274 | - should 'active fields are public if fields privacy is nil' do | |
1274 | + should 'active fields are private if fields privacy is nil' do | |
1275 | 1275 | p = fast_create(Person) |
1276 | 1276 | p.expects(:fields_privacy).returns(nil) |
1277 | - f = %w(sex birth_date) | |
1278 | - p.expects(:active_fields).returns(f) | |
1279 | - assert_equal f, p.public_fields | |
1277 | + assert_equal [], p.public_fields | |
1280 | 1278 | end |
1281 | 1279 | |
1282 | 1280 | should 'return public fields' do | ... | ... |