diff --git a/app/controllers/my_profile/follow_categories_controller.rb b/app/controllers/my_profile/follow_categories_controller.rb index 468859a..c65a7d0 100644 --- a/app/controllers/my_profile/follow_categories_controller.rb +++ b/app/controllers/my_profile/follow_categories_controller.rb @@ -9,8 +9,9 @@ class FollowCategoriesController < MyProfileController end def create + #TODO fix profile_type @follow_category = Circle.new(:name => params[:follow_category][:name], - :person => current_person) + :person => current_person, :profile_type => 'Person') if @follow_category.save redirect_to :action => 'index' else diff --git a/app/controllers/my_profile/followers_controller.rb b/app/controllers/my_profile/followers_controller.rb index 4c695a9..eda3740 100644 --- a/app/controllers/my_profile/followers_controller.rb +++ b/app/controllers/my_profile/followers_controller.rb @@ -15,8 +15,13 @@ class FollowersController < MyProfileController #TODO fix def update_category params["followed_profile_id"] ||= profile.id + #TODO FIX profile type. REMOVE THE GAMBIRA if params[:category_name] - category = Circle.find_or_create_by(:name => params[:category_name], :person => current_person) + category = Circle.find_or_create_by(:name => params[:category_name], :person => current_person, :profile_type => 'Person') + if category.id.nil? + category = Circle.find_or_create_by(:name => params[:category_name], :person => current_person, :profile_type => 'Community') + end + follower = ProfileFollower.find_or_create_by(circle: category, profile: Profile.find_by(:id => params[:followed_profile_id])) end diff --git a/app/jobs/notify_activity_to_profiles_job.rb b/app/jobs/notify_activity_to_profiles_job.rb index 4510315..294ab18 100644 --- a/app/jobs/notify_activity_to_profiles_job.rb +++ b/app/jobs/notify_activity_to_profiles_job.rb @@ -21,7 +21,7 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) #TODO fix spaming notifications when following and unfolling many times # Notify all followers - ActionTrackerNotification.connection.execute("INSERT INTO action_tracker_notifications(profile_id, action_tracker_id) SELECT f.follower_id, #{tracked_action.id} FROM profile_followers AS f WHERE profile_id=#{tracked_action.user.id} AND (f.follower_id NOT IN (SELECT atn.profile_id FROM action_tracker_notifications AS atn WHERE atn.action_tracker_id = #{tracked_action.id}))") + ActionTrackerNotification.connection.execute("INSERT INTO action_tracker_notifications(profile_id, action_tracker_id) SELECT DISTINCT c.person_id, #{tracked_action.id} FROM profiles_circles AS p JOIN circles as c ON c.id = p.circle_id WHERE p.profile_id = #{tracked_action.user.id} AND (c.person_id NOT IN (SELECT atn.profile_id FROM action_tracker_notifications AS atn WHERE atn.action_tracker_id = #{tracked_action.id}))") if tracked_action.user.is_a? Organization ActionTrackerNotification.connection.execute "insert into action_tracker_notifications(profile_id, action_tracker_id) " + diff --git a/app/models/add_member.rb b/app/models/add_member.rb index cbb5f35..535a9ae 100644 --- a/app/models/add_member.rb +++ b/app/models/add_member.rb @@ -22,7 +22,7 @@ class AddMember < Task self.roles = [Profile::Roles.member(organization.environment.id).id] end target.affiliate(requestor, self.roles.select{|r| !r.to_i.zero? }.map{|i| Role.find(i)}) - person.follow(organization, Circle.find_or_create_by(:person => person, :name =>_('memberships'))) + person.follow(organization, Circle.find_or_create_by(:person => person, :name =>_('memberships'), :profile_type => 'Community')) end def title diff --git a/app/models/circle.rb b/app/models/circle.rb index 73106d7..781045e 100644 --- a/app/models/circle.rb +++ b/app/models/circle.rb @@ -6,6 +6,7 @@ class Circle < ApplicationRecord validates :name, presence: true validates :person_id, presence: true + validates :profile_type, presence: true validates :person_id, :uniqueness => {:scope => :name, :message => "can't add two circles with the same name"} diff --git a/app/models/favorite_enterprise_person.rb b/app/models/favorite_enterprise_person.rb index b432d87..d03b999 100644 --- a/app/models/favorite_enterprise_person.rb +++ b/app/models/favorite_enterprise_person.rb @@ -8,7 +8,7 @@ class FavoriteEnterprisePerson < ApplicationRecord belongs_to :person after_create do |favorite| - favorite.person.follow(favotire.enterprise, Circle.find_or_create_by(:person => favorite.person, :name =>_('favorites'))) + favorite.person.follow(favotire.enterprise, Circle.find_or_create_by(:person => favorite.person, :name =>_('favorites'), :profile_type => 'Enterprise')) end protected diff --git a/app/models/friendship.rb b/app/models/friendship.rb index 76ded0a..ab1efba 100644 --- a/app/models/friendship.rb +++ b/app/models/friendship.rb @@ -9,14 +9,14 @@ class Friendship < ApplicationRecord after_create do |friendship| Friendship.update_cache_counter(:friends_count, friendship.person, 1) Friendship.update_cache_counter(:friends_count, friendship.friend, 1) - friendship.person.follow(friendship.friend, Circle.find_or_create_by(:person => friendship.person, :name => friendship.group)) + friendship.person.follow(friendship.friend, Circle.find_or_create_by(:person => friendship.person, :name => (friendship.group.blank? ? 'friendships': friendship.group), :profile_type => 'Person')) end after_destroy do |friendship| Friendship.update_cache_counter(:friends_count, friendship.person, -1) Friendship.update_cache_counter(:friends_count, friendship.friend, -1) - circle=Circle.find_by(:person => friendship.person, :name => friendship.group) + circle=Circle.find_by(:person => friendship.person, :name => (friendship.group.blank? ? 'friendships': friendship.group) ) friendship.person.remove_profile_from_circle(friendship.friend, circle) if circle end diff --git a/app/models/profile.rb b/app/models/profile.rb index 33e13cf..af44c16 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -784,7 +784,7 @@ private :generate_url, :url_options else self.affiliate(person, Profile::Roles.admin(environment.id), attributes) if members.count == 0 self.affiliate(person, Profile::Roles.member(environment.id), attributes) - person.follow(self, Circle.find_or_create_by(:person => person, :name =>_('memberships'))) + person.follow(self, Circle.find_or_create_by(:person => person, :name =>_('memberships'), :profile_type => 'Community')) end person.tasks.pending.of("InviteMember").select { |t| t.data[:community_id] == self.id }.each { |invite| invite.cancel } remove_from_suggestion_list person diff --git a/app/views/followers/_profile_list.html.erb b/app/views/followers/_profile_list.html.erb index 846d12b..fe1d7a3 100644 --- a/app/views/followers/_profile_list.html.erb +++ b/app/views/followers/_profile_list.html.erb @@ -4,7 +4,7 @@ <%= link_to_profile profile_image(profile) + tag('br') + profile.short_name, profile.identifier, :class => 'profile-link' %>
- <%= profile.category #TODO get categories through scope%> + <%= profile.category %>