Commit 6e677d68b1a13e42fa0058e476ce97f3ae68c551
1 parent
9b0cf644
Adds polymorphic relationship between circle and person.
Signed-off-by: DylanGuedes <djmgguedes@gmail.com> Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
Showing
9 changed files
with
46 additions
and
26 deletions
Show diff stats
app/models/circle.rb
app/models/external_person.rb
... | ... | @@ -5,7 +5,6 @@ class ExternalPerson < ActiveRecord::Base |
5 | 5 | include ProfileEntity |
6 | 6 | |
7 | 7 | has_many :circles, as: :person |
8 | - has_many :profile_followers, as: :profile | |
9 | 8 | validates_uniqueness_of :identifier, scope: :source |
10 | 9 | |
11 | 10 | validates_presence_of :source, :email, :created_at | ... | ... |
app/models/friendship.rb
... | ... | @@ -10,6 +10,9 @@ class Friendship < ApplicationRecord |
10 | 10 | Friendship.update_cache_counter(:friends_count, friendship.person, 1) |
11 | 11 | Friendship.update_cache_counter(:friends_count, friendship.friend, 1) |
12 | 12 | |
13 | + p "*"*60 | |
14 | + p "BEFORE CIRCLES" | |
15 | + p "*"*60 | |
13 | 16 | circles = friendship.group.blank? ? ['friendships'] : friendship.group.split(',').map(&:strip) |
14 | 17 | circles.each do |circle| |
15 | 18 | friendship.person.follow(friendship.friend, Circle.find_or_create_by(:person => friendship.person, :name => circle, :profile_type => 'Person')) | ... | ... |
app/models/profile.rb
... | ... | @@ -248,8 +248,26 @@ class Profile < ApplicationRecord |
248 | 248 | |
249 | 249 | has_many :email_templates, :foreign_key => :owner_id |
250 | 250 | |
251 | - has_many :profile_followers, as: :profile | |
252 | - has_many :followers, -> { uniq }, :class_name => 'Person', :through => :profile_followers, :source => :person | |
251 | + has_many :profile_followers | |
252 | + scope :memberships_of, -> person { | |
253 | + distinct.select('profiles.*'). | |
254 | + joins(:role_assignments). | |
255 | + where('role_assignments.accessor_type = ? AND role_assignments.accessor_id = ?', person.class.base_class.name, person.id) | |
256 | + } | |
257 | + | |
258 | + def in_circles | |
259 | + Circle.joins(:profile_followers). | |
260 | + where('profiles_circles.profile_id = ?', self.id) | |
261 | + end | |
262 | + | |
263 | + def followers | |
264 | + person_followers = Person.joins(:circles).merge(in_circles) | |
265 | + external_person_followers = ExternalPerson.joins(:circles).merge(in_circles) | |
266 | + | |
267 | + person_followers+external_person_followers | |
268 | + end | |
269 | + | |
270 | + # has_many :followers, -> { uniq }, :through => :profile_followers, :source => :person | |
253 | 271 | |
254 | 272 | # Although this should be a has_one relation, there are no non-silly names for |
255 | 273 | # a foreign key on article to reference the template to which it is | ... | ... |
app/models/profile_follower.rb
... | ... | @@ -4,12 +4,18 @@ class ProfileFollower < ApplicationRecord |
4 | 4 | |
5 | 5 | attr_accessible :profile, :circle |
6 | 6 | |
7 | - belongs_to :profile, polymorphic: :true | |
7 | + #TODO -> user being followed | |
8 | + belongs_to :profile | |
8 | 9 | belongs_to :circle |
9 | 10 | |
10 | - has_one :person, through: :circle, source_type: "ProfileFollower" | |
11 | + #TODO -> circle owner | |
12 | + # has_one :person, through: :circle, source_type: "ProfileFollower" | |
11 | 13 | |
12 | - alias follower person | |
14 | + def circle_owner | |
15 | + self.circle.person | |
16 | + end | |
17 | + | |
18 | + alias follower circle_owner | |
13 | 19 | |
14 | 20 | validates_presence_of :profile_id, :circle_id |
15 | 21 | validates :profile_id, :uniqueness => {:scope => :circle_id, :message => "can't put a profile in the same circle twice"} | ... | ... |
app/views/blocks/profile_info_actions/_common.html.erb
1 | 1 | <li><%= report_abuse(profile, :button) %></li> |
2 | 2 | <% if logged_in? && (user != profile) && profile.allow_followers? %> |
3 | 3 | <li> |
4 | - <% follow = user.follows?(profile) %> | |
4 | + <% follow = profile.followed_by user %> | |
5 | 5 | <%= button(:unfollow, content_tag('span', _('Unfollow')), {:profile => profile.identifier, :controller => 'profile', :action => 'unfollow'}, :method => :post, :id => 'action-unfollow', :title => _("Unfollow"), :style => follow ? "" : "display: none;") %> |
6 | 6 | <%= button(:ok, content_tag('span', _('Follow')), {:profile => profile.identifier, :controller => 'profile', :action => 'find_profile_circles'}, :id => 'action-follow', :title => _("Follow"), :style => follow ? "display: none;" : "") %> |
7 | 7 | <div id="circles-container" style="display: none;"> | ... | ... |
db/migrate/20160810132802_add_profile_type_to_profile_followers.rb
... | ... | @@ -1,11 +0,0 @@ |
1 | -class AddProfileTypeToProfileFollowers < ActiveRecord::Migration | |
2 | - def up | |
3 | - add_column :profiles_circles, :profile_type, :string, default: "Profile" | |
4 | - add_index :profiles_circles, [:profile_id, :profile_type] | |
5 | - end | |
6 | - | |
7 | - def down | |
8 | - remove_column :profiles_circles, :profile_type | |
9 | - remove_index :profiles_circles, [:profile_id, :profile_type] | |
10 | - end | |
11 | -end |
db/schema.rb
... | ... | @@ -11,7 +11,7 @@ |
11 | 11 | # |
12 | 12 | # It's strongly recommended that you check this file into your version control system. |
13 | 13 | |
14 | -ActiveRecord::Schema.define(version: 20160608123748) do | |
14 | +ActiveRecord::Schema.define(version: 20160810132802) do | |
15 | 15 | |
16 | 16 | # These are extensions that must be enabled in order to support this database |
17 | 17 | enable_extension "plpgsql" |
... | ... | @@ -278,10 +278,12 @@ ActiveRecord::Schema.define(version: 20160608123748) do |
278 | 278 | create_table "circles", force: :cascade do |t| |
279 | 279 | t.string "name" |
280 | 280 | t.integer "person_id" |
281 | - t.string "profile_type", null: false | |
281 | + t.string "profile_type", null: false | |
282 | + t.string "person_type", default: "Person" | |
282 | 283 | end |
283 | 284 | |
284 | 285 | add_index "circles", ["person_id", "name"], name: "circles_composite_key_index", unique: true, using: :btree |
286 | + add_index "circles", ["person_id", "person_type"], name: "index_circles_on_person_id_and_person_type", using: :btree | |
285 | 287 | |
286 | 288 | create_table "comments", force: :cascade do |t| |
287 | 289 | t.string "title" |
... | ... | @@ -553,6 +555,11 @@ ActiveRecord::Schema.define(version: 20160608123748) do |
553 | 555 | t.datetime "updated_at" |
554 | 556 | end |
555 | 557 | |
558 | + create_table "private_scraps", force: :cascade do |t| | |
559 | + t.integer "person_id" | |
560 | + t.integer "scrap_id" | |
561 | + end | |
562 | + | |
556 | 563 | create_table "product_qualifiers", force: :cascade do |t| |
557 | 564 | t.integer "product_id" |
558 | 565 | t.integer "qualifier_id" |
... | ... | @@ -681,9 +688,11 @@ ActiveRecord::Schema.define(version: 20160608123748) do |
681 | 688 | t.integer "circle_id" |
682 | 689 | t.datetime "created_at" |
683 | 690 | t.datetime "updated_at" |
691 | + t.string "profile_type", default: "Profile" | |
684 | 692 | end |
685 | 693 | |
686 | 694 | add_index "profiles_circles", ["profile_id", "circle_id"], name: "profiles_circles_composite_key_index", unique: true, using: :btree |
695 | + add_index "profiles_circles", ["profile_id", "profile_type"], name: "index_profiles_circles_on_profile_id_and_profile_type", using: :btree | |
687 | 696 | |
688 | 697 | create_table "qualifier_certifiers", force: :cascade do |t| |
689 | 698 | t.integer "qualifier_id" | ... | ... |
vendor/plugins/action_tracker/lib/action_tracker.rb
... | ... | @@ -100,12 +100,6 @@ module ActionTracker |
100 | 100 | p "&"*40 |
101 | 101 | keep_params.each do |param| |
102 | 102 | result = self |
103 | - p "*"*40 | |
104 | - p "result: #{result}" | |
105 | - p "result.follower:" | |
106 | - p result.circle.person | |
107 | - p "&"*40 | |
108 | - p "*"*40 | |
109 | 103 | param.to_s.split('.').each { |m| result = result.send(m) } |
110 | 104 | stored_params[param.to_s.gsub(/\./, '_')] = result |
111 | 105 | end | ... | ... |