Commit 0380e1c780a7c4a108052dcdaf31cb54f8909e74
1 parent
4b26bbae
Exists in
private-scraps
adds profile_type to circle creation in several places
Showing
10 changed files
with
17 additions
and
10 deletions
Show diff stats
app/controllers/my_profile/follow_categories_controller.rb
... | ... | @@ -9,8 +9,9 @@ class FollowCategoriesController < MyProfileController |
9 | 9 | end |
10 | 10 | |
11 | 11 | def create |
12 | + #TODO fix profile_type | |
12 | 13 | @follow_category = Circle.new(:name => params[:follow_category][:name], |
13 | - :person => current_person) | |
14 | + :person => current_person, :profile_type => 'Person') | |
14 | 15 | if @follow_category.save |
15 | 16 | redirect_to :action => 'index' |
16 | 17 | else | ... | ... |
app/controllers/my_profile/followers_controller.rb
... | ... | @@ -15,8 +15,13 @@ class FollowersController < MyProfileController |
15 | 15 | #TODO fix |
16 | 16 | def update_category |
17 | 17 | params["followed_profile_id"] ||= profile.id |
18 | + #TODO FIX profile type. REMOVE THE GAMBIRA | |
18 | 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 | 25 | follower = ProfileFollower.find_or_create_by(circle: category, profile: Profile.find_by(:id => params[:followed_profile_id])) |
21 | 26 | end |
22 | 27 | ... | ... |
app/jobs/notify_activity_to_profiles_job.rb
... | ... | @@ -21,7 +21,7 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) |
21 | 21 | |
22 | 22 | #TODO fix spaming notifications when following and unfolling many times |
23 | 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 | 26 | if tracked_action.user.is_a? Organization |
27 | 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 | 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, 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 | 26 | end |
27 | 27 | |
28 | 28 | def title | ... | ... |
app/models/circle.rb
... | ... | @@ -6,6 +6,7 @@ class Circle < ApplicationRecord |
6 | 6 | |
7 | 7 | validates :name, presence: true |
8 | 8 | validates :person_id, presence: true |
9 | + validates :profile_type, presence: true | |
9 | 10 | |
10 | 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 | 8 | belongs_to :person |
9 | 9 | |
10 | 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 | 12 | end |
13 | 13 | |
14 | 14 | protected | ... | ... |
app/models/friendship.rb
... | ... | @@ -9,14 +9,14 @@ 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, 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 | 13 | end |
14 | 14 | |
15 | 15 | after_destroy do |friendship| |
16 | 16 | Friendship.update_cache_counter(:friends_count, friendship.person, -1) |
17 | 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 | 20 | friendship.person.remove_profile_from_circle(friendship.friend, circle) if circle |
21 | 21 | end |
22 | 22 | ... | ... |
app/models/profile.rb
... | ... | @@ -784,7 +784,7 @@ private :generate_url, :url_options |
784 | 784 | else |
785 | 785 | self.affiliate(person, Profile::Roles.admin(environment.id), attributes) if members.count == 0 |
786 | 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 | 788 | end |
789 | 789 | person.tasks.pending.of("InviteMember").select { |t| t.data[:community_id] == self.id }.each { |invite| invite.cancel } |
790 | 790 | remove_from_suggestion_list person | ... | ... |
app/views/followers/_profile_list.html.erb
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 | <%= link_to_profile profile_image(profile) + tag('br') + profile.short_name, |
5 | 5 | profile.identifier, :class => 'profile-link' %> |
6 | 6 | <p class="category-name"> |
7 | - <%= profile.category #TODO get categories through scope%> | |
7 | + <%= profile.category %> | |
8 | 8 | </p> |
9 | 9 | <div class="controll"> |
10 | 10 | <%= button_without_text :remove, content_tag('span',_('unfollow')), | ... | ... |
db/migrate/20160608123748_create_profile_followers_table.rb
... | ... | @@ -9,7 +9,7 @@ class CreateProfileFollowersTable < ActiveRecord::Migration |
9 | 9 | create_table :circles do |t| |
10 | 10 | t.column :name, :string |
11 | 11 | t.belongs_to :person |
12 | - t.column :profile_type, :string | |
12 | + t.column :profile_type, :string, :null => false | |
13 | 13 | end |
14 | 14 | |
15 | 15 | add_foreign_key :profiles_circles, :circles, :on_delete => :nullify | ... | ... |