Commit 08bf9a987d28fa1eeb1007f027081fef45fb8a9f

Authored by Marcos Pereira
1 parent 206f864c

changes old follow method. fixes some tests. other changes

app/models/add_member.rb
... ... @@ -22,6 +22,7 @@ class AddMember < Task
22 22 self.roles = [Profile::Roles.member(organization.environment.id).id]
23 23 end
24 24 target.affiliate(requestor, self.roles.select{|r| !r.to_i.zero? }.map{|i| Role.find(i)})
  25 + person.follow(organization)
25 26 end
26 27  
27 28 def title
... ...
app/models/article.rb
... ... @@ -534,13 +534,13 @@ class Article < ApplicationRecord
534 534  
535 535 scope :display_filter, lambda {|user, profile|
536 536 return published if (user.nil? && profile && profile.public?)
537   - return [] if user.nil? || (profile && !profile.public? && !user.follows?(profile))
  537 + return [] if user.nil? || (profile && !profile.public? && !profile.in_social_circle?(user))
538 538 where(
539 539 [
540 540 "published = ? OR last_changed_by_id = ? OR profile_id = ? OR ?
541 541 OR (show_to_followers = ? AND ? AND profile_id IN (?))", true, user.id, user.id,
542 542 profile.nil? ? false : user.has_permission?(:view_private_content, profile),
543   - true, (profile.nil? ? true : user.follows?(profile)), ( profile.nil? ? (user.friends.select('profiles.id')) : [profile.id])
  543 + true, (profile.nil? ? true : profile.in_social_circle?(user)), ( profile.nil? ? (user.friends.select('profiles.id')) : [profile.id])
544 544 ]
545 545 )
546 546 }
... ...
app/models/block.rb
... ... @@ -88,7 +88,7 @@ class Block < ApplicationRecord
88 88 end
89 89  
90 90 def display_to_user?(user)
91   - display_user == 'all' || (user.nil? && display_user == 'not_logged') || (user && display_user == 'logged') || (user && display_user == 'followers' && user.follows?(owner))
  91 + display_user == 'all' || (user.nil? && display_user == 'not_logged') || (user && display_user == 'logged') || (user && display_user == 'followers' && owner.in_social_circle?(user))
92 92 end
93 93  
94 94 def display_always(context)
... ...
app/models/enterprise.rb
... ... @@ -174,8 +174,8 @@ class Enterprise < Organization
174 174 ''
175 175 end
176 176  
177   - def followed_by? person
178   - super or self.fans.where(id: person.id).count > 0
179   - end
  177 + #def followed_by? person
  178 + # super or self.fans.where(id: person.id).count > 0
  179 + #end
180 180  
181 181 end
... ...
app/models/favorite_enterprise_person.rb
... ... @@ -7,6 +7,10 @@ class FavoriteEnterprisePerson < ApplicationRecord
7 7 belongs_to :enterprise
8 8 belongs_to :person
9 9  
  10 + after_create do |favorite|
  11 + favorite.person.follow(favorite.enterprise)
  12 + end
  13 +
10 14 protected
11 15  
12 16 def is_trackable?
... ...
app/models/friendship.rb
... ... @@ -9,6 +9,7 @@ class Friendship < ApplicationRecord
9 9 after_create do |friendship|
10 10 Friendship.update_cache_counter(:friends_count, friendship.person, 1)
11 11 Friendship.update_cache_counter(:friends_count, friendship.friend, 1)
  12 + friendship.person.follow(friendship.friend, friendship.group)
12 13 end
13 14  
14 15 after_destroy do |friendship|
... ...
app/models/person.rb
... ... @@ -196,7 +196,7 @@ class Person < Profile
196 196 friendship = self.friendships.build
197 197 friendship.friend = friend
198 198 friendship.group = group
199   - follow(friend, group) if friendship.save
  199 + friendship.save
200 200 end
201 201 end
202 202  
... ... @@ -219,7 +219,8 @@ class Person < Profile
219 219 end
220 220  
221 221 def unfollow(profile)
222   - ProfileFollower.where(follower_id: id, profile_id: profile.id).first.destroy
  222 + follower = ProfileFollower.where(follower_id: id, profile_id: profile.id) if profile
  223 + follower.first.destroy if follower.present?
223 224 end
224 225  
225 226 FIELDS = %w[
... ... @@ -598,10 +599,14 @@ class Person < Profile
598 599 Profile.following_profiles self
599 600 end
600 601  
601   - protected
602   -
603   - def followed_by?(profile)
604   - self == profile || self.followers.include?(profile)
  602 + def in_social_circle?(person)
  603 + self.is_a_friend?(person) || super
605 604 end
606 605  
  606 + #protected
  607 +
  608 + #def followed_by?(profile)
  609 + # self == profile || self.followers.include?(profile)
  610 + #end
  611 +
607 612 end
... ...
app/models/profile.rb
... ... @@ -773,6 +773,7 @@ private :generate_url, :url_options
773 773 else
774 774 self.affiliate(person, Profile::Roles.admin(environment.id), attributes) if members.count == 0
775 775 self.affiliate(person, Profile::Roles.member(environment.id), attributes)
  776 + person.follow(self)
776 777 end
777 778 person.tasks.pending.of("InviteMember").select { |t| t.data[:community_id] == self.id }.each { |invite| invite.cancel }
778 779 remove_from_suggestion_list person
... ... @@ -1116,7 +1117,11 @@ private :generate_url, :url_options
1116 1117 end
1117 1118  
1118 1119 def followed_by?(person)
1119   - person.is_member_of?(self)
  1120 + (person == self) || (person.in? self.followers)
  1121 + end
  1122 +
  1123 + def in_social_circle?(person)
  1124 + (person == self) || (person.is_member_of?(self))
1120 1125 end
1121 1126  
1122 1127 def display_private_info_to?(user)
... ...
test/unit/friendship_test.rb
... ... @@ -28,14 +28,14 @@ class FriendshipTest < ActiveSupport::TestCase
28 28 f.person = a
29 29 f.friend = b
30 30 f.save!
31   - ta = ActionTracker::Record.last
  31 + ta = ActionTracker::Record.where(:target_type => "Friendship").last
32 32 assert_equal a, ta.user
33 33 assert_equal 'b', ta.get_friend_name[0]
34 34 f = Friendship.new
35 35 f.person = a
36 36 f.friend = c
37 37 f.save!
38   - ta = ActionTracker::Record.last
  38 + ta = ActionTracker::Record.where(:target_type => "Friendship").last
39 39 assert_equal a, ta.user
40 40 assert_equal 'c', ta.get_friend_name[1]
41 41 end
... ... @@ -46,14 +46,14 @@ class FriendshipTest < ActiveSupport::TestCase
46 46 f.person = a
47 47 f.friend = b
48 48 f.save!
49   - ta = ActionTracker::Record.last
  49 + ta = ActionTracker::Record.where(:target_type => "Friendship").last
50 50 assert_equal a, ta.user
51 51 assert_equal ['b'], ta.get_friend_name
52 52 f = Friendship.new
53 53 f.person = b
54 54 f.friend = a
55 55 f.save!
56   - ta = ActionTracker::Record.last
  56 + ta = ActionTracker::Record.where(:target_type => "Friendship").last
57 57 assert_equal b, ta.user
58 58 assert_equal ['a'], ta.get_friend_name
59 59 end
... ...