diff --git a/app/models/circle.rb b/app/models/circle.rb
index 722db33..1349a2b 100644
--- a/app/models/circle.rb
+++ b/app/models/circle.rb
@@ -1,5 +1,7 @@
class Circle < ApplicationRecord
+ #TODO -> n:m with profile, item in the circle
has_many :profile_followers
+ #TODO -> owner
belongs_to :person, polymorphic: true
attr_accessible :name, :person, :profile_type
diff --git a/app/models/external_person.rb b/app/models/external_person.rb
index bbf1cc3..abab490 100644
--- a/app/models/external_person.rb
+++ b/app/models/external_person.rb
@@ -5,7 +5,6 @@ class ExternalPerson < ActiveRecord::Base
include ProfileEntity
has_many :circles, as: :person
- has_many :profile_followers, as: :profile
validates_uniqueness_of :identifier, scope: :source
validates_presence_of :source, :email, :created_at
diff --git a/app/models/friendship.rb b/app/models/friendship.rb
index 7a6927b..7cf1395 100644
--- a/app/models/friendship.rb
+++ b/app/models/friendship.rb
@@ -10,6 +10,9 @@ class Friendship < ApplicationRecord
Friendship.update_cache_counter(:friends_count, friendship.person, 1)
Friendship.update_cache_counter(:friends_count, friendship.friend, 1)
+ p "*"*60
+ p "BEFORE CIRCLES"
+ p "*"*60
circles = friendship.group.blank? ? ['friendships'] : friendship.group.split(',').map(&:strip)
circles.each do |circle|
friendship.person.follow(friendship.friend, Circle.find_or_create_by(:person => friendship.person, :name => circle, :profile_type => 'Person'))
diff --git a/app/models/profile.rb b/app/models/profile.rb
index 0f18e5c..e7f5837 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -248,8 +248,26 @@ class Profile < ApplicationRecord
has_many :email_templates, :foreign_key => :owner_id
- has_many :profile_followers, as: :profile
- has_many :followers, -> { uniq }, :class_name => 'Person', :through => :profile_followers, :source => :person
+ has_many :profile_followers
+ scope :memberships_of, -> person {
+ distinct.select('profiles.*').
+ joins(:role_assignments).
+ where('role_assignments.accessor_type = ? AND role_assignments.accessor_id = ?', person.class.base_class.name, person.id)
+ }
+
+ def in_circles
+ Circle.joins(:profile_followers).
+ where('profiles_circles.profile_id = ?', self.id)
+ end
+
+ def followers
+ person_followers = Person.joins(:circles).merge(in_circles)
+ external_person_followers = ExternalPerson.joins(:circles).merge(in_circles)
+
+ person_followers+external_person_followers
+ end
+
+ # has_many :followers, -> { uniq }, :through => :profile_followers, :source => :person
# Although this should be a has_one relation, there are no non-silly names for
# a foreign key on article to reference the template to which it is
diff --git a/app/models/profile_follower.rb b/app/models/profile_follower.rb
index 2c539cf..f42129f 100644
--- a/app/models/profile_follower.rb
+++ b/app/models/profile_follower.rb
@@ -4,12 +4,18 @@ class ProfileFollower < ApplicationRecord
attr_accessible :profile, :circle
- belongs_to :profile, polymorphic: :true
+ #TODO -> user being followed
+ belongs_to :profile
belongs_to :circle
- has_one :person, through: :circle, source_type: "ProfileFollower"
+ #TODO -> circle owner
+ # has_one :person, through: :circle, source_type: "ProfileFollower"
- alias follower person
+ def circle_owner
+ self.circle.person
+ end
+
+ alias follower circle_owner
validates_presence_of :profile_id, :circle_id
validates :profile_id, :uniqueness => {:scope => :circle_id, :message => "can't put a profile in the same circle twice"}
diff --git a/app/views/blocks/profile_info_actions/_common.html.erb b/app/views/blocks/profile_info_actions/_common.html.erb
index a59ef79..ed83824 100644
--- a/app/views/blocks/profile_info_actions/_common.html.erb
+++ b/app/views/blocks/profile_info_actions/_common.html.erb
@@ -1,7 +1,7 @@
<%= report_abuse(profile, :button) %>
<% if logged_in? && (user != profile) && profile.allow_followers? %>
- <% follow = user.follows?(profile) %>
+ <% follow = profile.followed_by user %>
<%= button(:unfollow, content_tag('span', _('Unfollow')), {:profile => profile.identifier, :controller => 'profile', :action => 'unfollow'}, :method => :post, :id => 'action-unfollow', :title => _("Unfollow"), :style => follow ? "" : "display: none;") %>
<%= button(:ok, content_tag('span', _('Follow')), {:profile => profile.identifier, :controller => 'profile', :action => 'find_profile_circles'}, :id => 'action-follow', :title => _("Follow"), :style => follow ? "display: none;" : "") %>
diff --git a/db/migrate/20160810132802_add_profile_type_to_profile_followers.rb b/db/migrate/20160810132802_add_profile_type_to_profile_followers.rb
deleted file mode 100644
index e5f4110..0000000
--- a/db/migrate/20160810132802_add_profile_type_to_profile_followers.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-class AddProfileTypeToProfileFollowers < ActiveRecord::Migration
- def up
- add_column :profiles_circles, :profile_type, :string, default: "Profile"
- add_index :profiles_circles, [:profile_id, :profile_type]
- end
-
- def down
- remove_column :profiles_circles, :profile_type
- remove_index :profiles_circles, [:profile_id, :profile_type]
- end
-end
diff --git a/db/schema.rb b/db/schema.rb
index 15f2b0f..8fc48bc 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20160608123748) do
+ActiveRecord::Schema.define(version: 20160810132802) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -278,10 +278,12 @@ ActiveRecord::Schema.define(version: 20160608123748) do
create_table "circles", force: :cascade do |t|
t.string "name"
t.integer "person_id"
- t.string "profile_type", null: false
+ t.string "profile_type", null: false
+ t.string "person_type", default: "Person"
end
add_index "circles", ["person_id", "name"], name: "circles_composite_key_index", unique: true, using: :btree
+ add_index "circles", ["person_id", "person_type"], name: "index_circles_on_person_id_and_person_type", using: :btree
create_table "comments", force: :cascade do |t|
t.string "title"
@@ -553,6 +555,11 @@ ActiveRecord::Schema.define(version: 20160608123748) do
t.datetime "updated_at"
end
+ create_table "private_scraps", force: :cascade do |t|
+ t.integer "person_id"
+ t.integer "scrap_id"
+ end
+
create_table "product_qualifiers", force: :cascade do |t|
t.integer "product_id"
t.integer "qualifier_id"
@@ -681,9 +688,11 @@ ActiveRecord::Schema.define(version: 20160608123748) do
t.integer "circle_id"
t.datetime "created_at"
t.datetime "updated_at"
+ t.string "profile_type", default: "Profile"
end
add_index "profiles_circles", ["profile_id", "circle_id"], name: "profiles_circles_composite_key_index", unique: true, using: :btree
+ add_index "profiles_circles", ["profile_id", "profile_type"], name: "index_profiles_circles_on_profile_id_and_profile_type", using: :btree
create_table "qualifier_certifiers", force: :cascade do |t|
t.integer "qualifier_id"
diff --git a/vendor/plugins/action_tracker/lib/action_tracker.rb b/vendor/plugins/action_tracker/lib/action_tracker.rb
index 4b5ae86..9cd5f94 100644
--- a/vendor/plugins/action_tracker/lib/action_tracker.rb
+++ b/vendor/plugins/action_tracker/lib/action_tracker.rb
@@ -100,12 +100,6 @@ module ActionTracker
p "&"*40
keep_params.each do |param|
result = self
- p "*"*40
- p "result: #{result}"
- p "result.follower:"
- p result.circle.person
- p "&"*40
- p "*"*40
param.to_s.split('.').each { |m| result = result.send(m) }
stored_params[param.to_s.gsub(/\./, '_')] = result
end
--
libgit2 0.21.2