Commit 0380e1c780a7c4a108052dcdaf31cb54f8909e74

Authored by Marcos Pereira
1 parent 4b26bbae
Exists in private-scraps

adds profile_type to circle creation in several places

app/controllers/my_profile/follow_categories_controller.rb
@@ -9,8 +9,9 @@ class FollowCategoriesController < MyProfileController @@ -9,8 +9,9 @@ class FollowCategoriesController < MyProfileController
9 end 9 end
10 10
11 def create 11 def create
  12 + #TODO fix profile_type
12 @follow_category = Circle.new(:name => params[:follow_category][:name], 13 @follow_category = Circle.new(:name => params[:follow_category][:name],
13 - :person => current_person) 14 + :person => current_person, :profile_type => 'Person')
14 if @follow_category.save 15 if @follow_category.save
15 redirect_to :action => 'index' 16 redirect_to :action => 'index'
16 else 17 else
app/controllers/my_profile/followers_controller.rb
@@ -15,8 +15,13 @@ class FollowersController < MyProfileController @@ -15,8 +15,13 @@ class FollowersController < MyProfileController
15 #TODO fix 15 #TODO fix
16 def update_category 16 def update_category
17 params["followed_profile_id"] ||= profile.id 17 params["followed_profile_id"] ||= profile.id
  18 + #TODO FIX profile type. REMOVE THE GAMBIRA
18 if params[:category_name] 19 if params[:category_name]
19 - category = Circle.find_or_create_by(:name => params[:category_name], :person => current_person) 20 + category = Circle.find_or_create_by(:name => params[:category_name], :person => current_person, :profile_type => 'Person')
  21 + if category.id.nil?
  22 + category = Circle.find_or_create_by(:name => params[:category_name], :person => current_person, :profile_type => 'Community')
  23 + end
  24 +
20 follower = ProfileFollower.find_or_create_by(circle: category, profile: Profile.find_by(:id => params[:followed_profile_id])) 25 follower = ProfileFollower.find_or_create_by(circle: category, profile: Profile.find_by(:id => params[:followed_profile_id]))
21 end 26 end
22 27
app/jobs/notify_activity_to_profiles_job.rb
@@ -21,7 +21,7 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) @@ -21,7 +21,7 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id)
21 21
22 #TODO fix spaming notifications when following and unfolling many times 22 #TODO fix spaming notifications when following and unfolling many times
23 # Notify all followers 23 # Notify all followers
24 - 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}))") 24 + 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}))")
25 25
26 if tracked_action.user.is_a? Organization 26 if tracked_action.user.is_a? Organization
27 ActionTrackerNotification.connection.execute "insert into action_tracker_notifications(profile_id, action_tracker_id) " + 27 ActionTrackerNotification.connection.execute "insert into action_tracker_notifications(profile_id, action_tracker_id) " +
app/models/add_member.rb
@@ -22,7 +22,7 @@ class AddMember < Task @@ -22,7 +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, Circle.find_or_create_by(:person => person, :name =>_('memberships'))) 25 + person.follow(organization, Circle.find_or_create_by(:person => person, :name =>_('memberships'), :profile_type => 'Community'))
26 end 26 end
27 27
28 def title 28 def title
app/models/circle.rb
@@ -6,6 +6,7 @@ class Circle < ApplicationRecord @@ -6,6 +6,7 @@ class Circle < ApplicationRecord
6 6
7 validates :name, presence: true 7 validates :name, presence: true
8 validates :person_id, presence: true 8 validates :person_id, presence: true
  9 + validates :profile_type, presence: true
9 10
10 validates :person_id, :uniqueness => {:scope => :name, :message => "can't add two circles with the same name"} 11 validates :person_id, :uniqueness => {:scope => :name, :message => "can't add two circles with the same name"}
11 12
app/models/favorite_enterprise_person.rb
@@ -8,7 +8,7 @@ class FavoriteEnterprisePerson < ApplicationRecord @@ -8,7 +8,7 @@ class FavoriteEnterprisePerson < ApplicationRecord
8 belongs_to :person 8 belongs_to :person
9 9
10 after_create do |favorite| 10 after_create do |favorite|
11 - favorite.person.follow(favotire.enterprise, Circle.find_or_create_by(:person => favorite.person, :name =>_('favorites'))) 11 + favorite.person.follow(favotire.enterprise, Circle.find_or_create_by(:person => favorite.person, :name =>_('favorites'), :profile_type => 'Enterprise'))
12 end 12 end
13 13
14 protected 14 protected
app/models/friendship.rb
@@ -9,14 +9,14 @@ class Friendship < ApplicationRecord @@ -9,14 +9,14 @@ 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, Circle.find_or_create_by(:person => friendship.person, :name => friendship.group)) 12 + friendship.person.follow(friendship.friend, Circle.find_or_create_by(:person => friendship.person, :name => (friendship.group.blank? ? 'friendships': friendship.group), :profile_type => 'Person'))
13 end 13 end
14 14
15 after_destroy do |friendship| 15 after_destroy do |friendship|
16 Friendship.update_cache_counter(:friends_count, friendship.person, -1) 16 Friendship.update_cache_counter(:friends_count, friendship.person, -1)
17 Friendship.update_cache_counter(:friends_count, friendship.friend, -1) 17 Friendship.update_cache_counter(:friends_count, friendship.friend, -1)
18 18
19 - circle=Circle.find_by(:person => friendship.person, :name => friendship.group) 19 + circle=Circle.find_by(:person => friendship.person, :name => (friendship.group.blank? ? 'friendships': friendship.group) )
20 friendship.person.remove_profile_from_circle(friendship.friend, circle) if circle 20 friendship.person.remove_profile_from_circle(friendship.friend, circle) if circle
21 end 21 end
22 22
app/models/profile.rb
@@ -784,7 +784,7 @@ private :generate_url, :url_options @@ -784,7 +784,7 @@ private :generate_url, :url_options
784 else 784 else
785 self.affiliate(person, Profile::Roles.admin(environment.id), attributes) if members.count == 0 785 self.affiliate(person, Profile::Roles.admin(environment.id), attributes) if members.count == 0
786 self.affiliate(person, Profile::Roles.member(environment.id), attributes) 786 self.affiliate(person, Profile::Roles.member(environment.id), attributes)
787 - person.follow(self, Circle.find_or_create_by(:person => person, :name =>_('memberships'))) 787 + person.follow(self, Circle.find_or_create_by(:person => person, :name =>_('memberships'), :profile_type => 'Community'))
788 end 788 end
789 person.tasks.pending.of("InviteMember").select { |t| t.data[:community_id] == self.id }.each { |invite| invite.cancel } 789 person.tasks.pending.of("InviteMember").select { |t| t.data[:community_id] == self.id }.each { |invite| invite.cancel }
790 remove_from_suggestion_list person 790 remove_from_suggestion_list person
app/views/followers/_profile_list.html.erb
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 <%= link_to_profile profile_image(profile) + tag('br') + profile.short_name, 4 <%= link_to_profile profile_image(profile) + tag('br') + profile.short_name,
5 profile.identifier, :class => 'profile-link' %> 5 profile.identifier, :class => 'profile-link' %>
6 <p class="category-name"> 6 <p class="category-name">
7 - <%= profile.category #TODO get categories through scope%> 7 + <%= profile.category %>
8 </p> 8 </p>
9 <div class="controll"> 9 <div class="controll">
10 <%= button_without_text :remove, content_tag('span',_('unfollow')), 10 <%= button_without_text :remove, content_tag('span',_('unfollow')),
db/migrate/20160608123748_create_profile_followers_table.rb
@@ -9,7 +9,7 @@ class CreateProfileFollowersTable &lt; ActiveRecord::Migration @@ -9,7 +9,7 @@ class CreateProfileFollowersTable &lt; ActiveRecord::Migration
9 create_table :circles do |t| 9 create_table :circles do |t|
10 t.column :name, :string 10 t.column :name, :string
11 t.belongs_to :person 11 t.belongs_to :person
12 - t.column :profile_type, :string 12 + t.column :profile_type, :string, :null => false
13 end 13 end
14 14
15 add_foreign_key :profiles_circles, :circles, :on_delete => :nullify 15 add_foreign_key :profiles_circles, :circles, :on_delete => :nullify