Commit 08bf9a987d28fa1eeb1007f027081fef45fb8a9f
1 parent
206f864c
Exists in
federation_followers_backend
changes old follow method. fixes some tests. other changes
Showing
9 changed files
with
33 additions
and
17 deletions
Show diff stats
app/models/add_member.rb
@@ -22,6 +22,7 @@ class AddMember < Task | @@ -22,6 +22,7 @@ class AddMember < Task | ||
22 | self.roles = [Profile::Roles.member(organization.environment.id).id] | 22 | self.roles = [Profile::Roles.member(organization.environment.id).id] |
23 | end | 23 | end |
24 | target.affiliate(requestor, self.roles.select{|r| !r.to_i.zero? }.map{|i| Role.find(i)}) | 24 | target.affiliate(requestor, self.roles.select{|r| !r.to_i.zero? }.map{|i| Role.find(i)}) |
25 | + person.follow(organization) | ||
25 | end | 26 | end |
26 | 27 | ||
27 | def title | 28 | def title |
app/models/article.rb
@@ -534,13 +534,13 @@ class Article < ApplicationRecord | @@ -534,13 +534,13 @@ class Article < ApplicationRecord | ||
534 | 534 | ||
535 | scope :display_filter, lambda {|user, profile| | 535 | scope :display_filter, lambda {|user, profile| |
536 | return published if (user.nil? && profile && profile.public?) | 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 | where( | 538 | where( |
539 | [ | 539 | [ |
540 | "published = ? OR last_changed_by_id = ? OR profile_id = ? OR ? | 540 | "published = ? OR last_changed_by_id = ? OR profile_id = ? OR ? |
541 | OR (show_to_followers = ? AND ? AND profile_id IN (?))", true, user.id, user.id, | 541 | OR (show_to_followers = ? AND ? AND profile_id IN (?))", true, user.id, user.id, |
542 | profile.nil? ? false : user.has_permission?(:view_private_content, profile), | 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,7 +88,7 @@ class Block < ApplicationRecord | ||
88 | end | 88 | end |
89 | 89 | ||
90 | def display_to_user?(user) | 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 | end | 92 | end |
93 | 93 | ||
94 | def display_always(context) | 94 | def display_always(context) |
app/models/enterprise.rb
@@ -174,8 +174,8 @@ class Enterprise < Organization | @@ -174,8 +174,8 @@ class Enterprise < Organization | ||
174 | '' | 174 | '' |
175 | end | 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 | end | 181 | end |
app/models/favorite_enterprise_person.rb
@@ -7,6 +7,10 @@ class FavoriteEnterprisePerson < ApplicationRecord | @@ -7,6 +7,10 @@ class FavoriteEnterprisePerson < ApplicationRecord | ||
7 | belongs_to :enterprise | 7 | belongs_to :enterprise |
8 | belongs_to :person | 8 | belongs_to :person |
9 | 9 | ||
10 | + after_create do |favorite| | ||
11 | + favorite.person.follow(favorite.enterprise) | ||
12 | + end | ||
13 | + | ||
10 | protected | 14 | protected |
11 | 15 | ||
12 | def is_trackable? | 16 | def is_trackable? |
app/models/friendship.rb
@@ -9,6 +9,7 @@ class Friendship < ApplicationRecord | @@ -9,6 +9,7 @@ class Friendship < ApplicationRecord | ||
9 | after_create do |friendship| | 9 | after_create do |friendship| |
10 | Friendship.update_cache_counter(:friends_count, friendship.person, 1) | 10 | Friendship.update_cache_counter(:friends_count, friendship.person, 1) |
11 | Friendship.update_cache_counter(:friends_count, friendship.friend, 1) | 11 | Friendship.update_cache_counter(:friends_count, friendship.friend, 1) |
12 | + friendship.person.follow(friendship.friend, friendship.group) | ||
12 | end | 13 | end |
13 | 14 | ||
14 | after_destroy do |friendship| | 15 | after_destroy do |friendship| |
app/models/person.rb
@@ -196,7 +196,7 @@ class Person < Profile | @@ -196,7 +196,7 @@ class Person < Profile | ||
196 | friendship = self.friendships.build | 196 | friendship = self.friendships.build |
197 | friendship.friend = friend | 197 | friendship.friend = friend |
198 | friendship.group = group | 198 | friendship.group = group |
199 | - follow(friend, group) if friendship.save | 199 | + friendship.save |
200 | end | 200 | end |
201 | end | 201 | end |
202 | 202 | ||
@@ -219,7 +219,8 @@ class Person < Profile | @@ -219,7 +219,8 @@ class Person < Profile | ||
219 | end | 219 | end |
220 | 220 | ||
221 | def unfollow(profile) | 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 | end | 224 | end |
224 | 225 | ||
225 | FIELDS = %w[ | 226 | FIELDS = %w[ |
@@ -598,10 +599,14 @@ class Person < Profile | @@ -598,10 +599,14 @@ class Person < Profile | ||
598 | Profile.following_profiles self | 599 | Profile.following_profiles self |
599 | end | 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 | end | 604 | end |
606 | 605 | ||
606 | + #protected | ||
607 | + | ||
608 | + #def followed_by?(profile) | ||
609 | + # self == profile || self.followers.include?(profile) | ||
610 | + #end | ||
611 | + | ||
607 | end | 612 | end |
app/models/profile.rb
@@ -773,6 +773,7 @@ private :generate_url, :url_options | @@ -773,6 +773,7 @@ private :generate_url, :url_options | ||
773 | else | 773 | else |
774 | self.affiliate(person, Profile::Roles.admin(environment.id), attributes) if members.count == 0 | 774 | self.affiliate(person, Profile::Roles.admin(environment.id), attributes) if members.count == 0 |
775 | self.affiliate(person, Profile::Roles.member(environment.id), attributes) | 775 | self.affiliate(person, Profile::Roles.member(environment.id), attributes) |
776 | + person.follow(self) | ||
776 | end | 777 | end |
777 | person.tasks.pending.of("InviteMember").select { |t| t.data[:community_id] == self.id }.each { |invite| invite.cancel } | 778 | person.tasks.pending.of("InviteMember").select { |t| t.data[:community_id] == self.id }.each { |invite| invite.cancel } |
778 | remove_from_suggestion_list person | 779 | remove_from_suggestion_list person |
@@ -1116,7 +1117,11 @@ private :generate_url, :url_options | @@ -1116,7 +1117,11 @@ private :generate_url, :url_options | ||
1116 | end | 1117 | end |
1117 | 1118 | ||
1118 | def followed_by?(person) | 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 | end | 1125 | end |
1121 | 1126 | ||
1122 | def display_private_info_to?(user) | 1127 | def display_private_info_to?(user) |
test/unit/friendship_test.rb
@@ -28,14 +28,14 @@ class FriendshipTest < ActiveSupport::TestCase | @@ -28,14 +28,14 @@ class FriendshipTest < ActiveSupport::TestCase | ||
28 | f.person = a | 28 | f.person = a |
29 | f.friend = b | 29 | f.friend = b |
30 | f.save! | 30 | f.save! |
31 | - ta = ActionTracker::Record.last | 31 | + ta = ActionTracker::Record.where(:target_type => "Friendship").last |
32 | assert_equal a, ta.user | 32 | assert_equal a, ta.user |
33 | assert_equal 'b', ta.get_friend_name[0] | 33 | assert_equal 'b', ta.get_friend_name[0] |
34 | f = Friendship.new | 34 | f = Friendship.new |
35 | f.person = a | 35 | f.person = a |
36 | f.friend = c | 36 | f.friend = c |
37 | f.save! | 37 | f.save! |
38 | - ta = ActionTracker::Record.last | 38 | + ta = ActionTracker::Record.where(:target_type => "Friendship").last |
39 | assert_equal a, ta.user | 39 | assert_equal a, ta.user |
40 | assert_equal 'c', ta.get_friend_name[1] | 40 | assert_equal 'c', ta.get_friend_name[1] |
41 | end | 41 | end |
@@ -46,14 +46,14 @@ class FriendshipTest < ActiveSupport::TestCase | @@ -46,14 +46,14 @@ class FriendshipTest < ActiveSupport::TestCase | ||
46 | f.person = a | 46 | f.person = a |
47 | f.friend = b | 47 | f.friend = b |
48 | f.save! | 48 | f.save! |
49 | - ta = ActionTracker::Record.last | 49 | + ta = ActionTracker::Record.where(:target_type => "Friendship").last |
50 | assert_equal a, ta.user | 50 | assert_equal a, ta.user |
51 | assert_equal ['b'], ta.get_friend_name | 51 | assert_equal ['b'], ta.get_friend_name |
52 | f = Friendship.new | 52 | f = Friendship.new |
53 | f.person = b | 53 | f.person = b |
54 | f.friend = a | 54 | f.friend = a |
55 | f.save! | 55 | f.save! |
56 | - ta = ActionTracker::Record.last | 56 | + ta = ActionTracker::Record.where(:target_type => "Friendship").last |
57 | assert_equal b, ta.user | 57 | assert_equal b, ta.user |
58 | assert_equal ['a'], ta.get_friend_name | 58 | assert_equal ['a'], ta.get_friend_name |
59 | end | 59 | end |