Compare View

switch
from
...
to
 
Commits (3)
app/controllers/my_profile/circles_controller.rb
... ... @@ -3,7 +3,7 @@ class CirclesController < MyProfileController
3 3 before_action :accept_only_post, :only => [:create, :update, :destroy]
4 4  
5 5 def index
6   - @circles = profile.circles
  6 + @circles = profile.owned_circles
7 7 end
8 8  
9 9 def new
... ... @@ -11,7 +11,7 @@ class CirclesController < MyProfileController
11 11 end
12 12  
13 13 def create
14   - @circle = Circle.new(params[:circle].merge({ :person => profile }))
  14 + @circle = Circle.new(params[:circle].merge({ :owner => profile }))
15 15 if @circle.save
16 16 redirect_to :action => 'index'
17 17 else
... ... @@ -21,7 +21,7 @@ class CirclesController < MyProfileController
21 21  
22 22 def xhr_create
23 23 if request.xhr?
24   - circle = Circle.new(params[:circle].merge({:person => profile }))
  24 + circle = Circle.new(params[:circle].merge({:owner => profile }))
25 25 if circle.save
26 26 render :partial => "circle_checkbox", :locals => { :circle => circle },
27 27 :status => 201
... ...
app/controllers/my_profile/followers_controller.rb
... ... @@ -17,7 +17,7 @@ class FollowersController < MyProfileController
17 17  
18 18 def set_category_modal
19 19 followed_profile = Profile.find(params[:followed_profile_id])
20   - circles = Circle.where(:person => profile, :profile_type => followed_profile.class.name)
  20 + circles = Circle.where(:owner => profile, :profile_type => followed_profile.class.name)
21 21 render :partial => 'followers/edit_circles_modal', :locals => { :circles => circles, :followed_profile => followed_profile }
22 22 end
23 23  
... ...
app/controllers/public/profile_controller.rb
... ... @@ -176,7 +176,7 @@ class ProfileController < PublicController
176 176 end
177 177  
178 178 def find_profile_circles
179   - circles = Circle.where(:person => current_person, :profile_type => profile.class.name)
  179 + circles = Circle.where(:owner => current_person, :profile_type => profile.class.name)
180 180 render :partial => 'blocks/profile_info_actions/circles', :locals => { :circles => circles, :profile_types => Circle.profile_types.to_a }
181 181 end
182 182  
... ...
app/models/circle.rb
1 1 class Circle < ApplicationRecord
2 2 #TODO -> n:m with profile, item in the circle
3   - has_many :profile_followers
  3 + has_many :profile, :through => :profile_follower
4 4 #TODO -> owner
5   - belongs_to :person, polymorphic: true
  5 + belongs_to :owner, polymorphic: true
6 6  
7   - attr_accessible :name, :person, :profile_type
  7 + attr_accessible :name, :owner, :profile_type
8 8  
9 9 validates :name, presence: true
10   - validates :person_id, presence: true
  10 + validates :owner_id, presence: true
11 11 validates :profile_type, presence: true
12   - validates :person_id, :uniqueness => {:scope => :name, :message => "can't add two circles with the same name"}
  12 + validates :owner_id, :uniqueness => {:scope => :name, :message => "can't add two circles with the same name"}
13 13  
14 14 validate :profile_type_must_be_in_list
15 15  
... ...
app/models/concerns/external_user.rb
... ... @@ -20,7 +20,7 @@ module ExternalUser
20 20 if login && domain && environment.has_federated_network?(domain)
21 21 external_environment = environment.external_environments.find_by_domain(domain)
22 22 scheme = "http#{external_environment.uses_ssl? ? 's' : ''}"
23   -p url = URI.parse(scheme+"://"+ domain +'/.well-known/webfinger?resource=acct:'+
  23 + url = URI.parse(scheme+"://"+ domain +'/.well-known/webfinger?resource=acct:'+
24 24 login+'@'+domain)
25 25 http = build_request(url)
26 26 req = Net::HTTP::Get.new(url.to_s)
... ...
app/models/concerns/follower.rb
... ... @@ -2,18 +2,9 @@ module Follower
2 2 extend ActiveSupport::Concern
3 3  
4 4 def follow(profile, circles)
5   - puts "follow..."
6 5 circles = [circles] unless circles.is_a?(Array)
7 6 circles.each do |new_circle|
8   - puts "seguindo alguen..."
9   - puts "profile_type: #{new_circle.profile_type}, class_name: #{profile.class.name}"
10   - puts "new_circle.person: #{new_circle.person}, self: #{self}"
11   - if (new_circle.person != self && !(self.kind_of?(new_circle.person.class)) || new_circle.profile_type != profile.class.name)
12   - next
13   - end
14   - puts '*20'*20
15   - puts "CHEGOU NO PROFILE FOLLOWER"
16   - puts '*20'*20
  7 + next if new_circle.owner != self || new_circle.profile_type != profile.class.name
17 8 ProfileFollower.create(profile: profile, circle: new_circle)
18 9 end
19 10 end
... ... @@ -42,7 +33,7 @@ module Follower
42 33 end
43 34  
44 35 def remove_profile_from_circle(profile, circle)
45   - return if circle.person != self
  36 + return if circle.owner != self
46 37 ProfileFollower.with_profile(profile).with_circle(circle).destroy_all
47 38 end
48 39  
... ...
app/models/external_person.rb
1 1 # A pseudo profile is a person from a remote network
2   -class ExternalPerson < ExternalProfile
  2 +class ExternalPerson < ActiveRecord::Base
3 3  
4 4 include Human
5 5 include ProfileEntity
  6 + include Follower
  7 +
  8 + has_many :profile_followers
  9 + has_many :circles, :through => :profile_followers, :as => :profile
  10 + has_many :owned_circles, as: :owner, :class_name => "Circle"
6 11  
7 12 validates_uniqueness_of :identifier, scope: :source
8 13  
... ... @@ -27,6 +32,13 @@ class ExternalPerson &lt; ExternalProfile
27 32 _('Public profile')
28 33 end
29 34  
  35 + def avatar
  36 + "http://#{self.source}/profile/#{self.identifier}/icon/"
  37 + end
  38 +
  39 + def url
  40 + "http://#{self.source}/profile/#{self.identifier}"
  41 + end
30 42  
31 43 alias :public_profile_url :url
32 44  
... ... @@ -68,6 +80,10 @@ class ExternalPerson &lt; ExternalProfile
68 80 "#{scheme}://#{self.source}"
69 81 end
70 82  
  83 + def profile_custom_icon(gravatar_default=nil)
  84 + self.avatar
  85 + end
  86 +
71 87 def preferred_login_redirection
72 88 environment.redirection_after_login
73 89 end
... ... @@ -111,6 +127,26 @@ class ExternalPerson &lt; ExternalProfile
111 127 "#{jid(options)}/#{self.name}"
112 128 end
113 129  
  130 + class ExternalPerson::Image
  131 + def initialize(path)
  132 + @path = path
  133 + end
  134 +
  135 + def public_filename(size = nil)
  136 + URI.join(@path, size.to_s)
  137 + end
  138 +
  139 + def content_type
  140 + # This is not really going to be used anywhere that matters
  141 + # so we are hardcodding it here.
  142 + 'image/png'
  143 + end
  144 + end
  145 +
  146 + def image
  147 + ExternalPerson::Image.new(avatar)
  148 + end
  149 +
114 150 def data_hash(gravatar_default = nil)
115 151 friends_list = {}
116 152 {
... ... @@ -129,4 +165,132 @@ class ExternalPerson &lt; ExternalProfile
129 165 }
130 166 end
131 167  
  168 + # External Person should respond to all methods in Person and Profile
  169 + def person_instance_methods
  170 + methods_and_responses = {
  171 + enterprises: Enterprise.none, communities: Community.none, friends:
  172 + Person.none, memberships: Profile.none, friendships: Person.none,
  173 + following_articles: Article.none, article_followers: ArticleFollower.none,
  174 + requested_tasks: Task.none, mailings: Mailing.none, scraps_sent:
  175 + Scrap.none, favorite_enterprise_people: FavoriteEnterprisePerson.none,
  176 + favorite_enterprises: Enterprise.none, acepted_forums: Forum.none,
  177 + articles_with_access: Article.none, suggested_profiles:
  178 + ProfileSuggestion.none, suggested_people: ProfileSuggestion.none,
  179 + suggested_communities: ProfileSuggestion.none, user: nil,
  180 + refused_communities: Community.none, has_permission?: false,
  181 + has_permission_with_admin?: false, has_permission_without_admin?: false,
  182 + has_permission_with_plugins?: false, has_permission_without_plugins?:
  183 + false, memberships_by_role: Person.none, can_change_homepage?: false,
  184 + can_control_scrap?: false, receives_scrap_notification?: false,
  185 + can_control_activity?: false, can_post_content?: false,
  186 + suggested_friend_groups: [], friend_groups: [], add_friend: nil,
  187 + already_request_friendship?: false, remove_friend: nil,
  188 + presence_of_required_fields: nil, active_fields: [], required_fields: [],
  189 + signup_fields: [], default_set_of_blocks: [], default_set_of_boxes: [],
  190 + default_set_of_articles: [], cell_phone: nil, comercial_phone: nil,
  191 + nationality: nil, schooling: nil, contact_information: nil, sex: nil,
  192 + birth_date: nil, jabber_id: nil, personal_website: nil, address_reference:
  193 + nil, district: nil, schooling_status: nil, formation: nil,
  194 + custom_formation: nil, area_of_study: nil, custom_area_of_study: nil,
  195 + professional_activity: nil, organization_website: nil, organization: nil,
  196 + photo: nil, city: nil, state: nil, country: nil, zip_code: nil,
  197 + address_line2: nil, copy_communities_from: nil,
  198 + has_organization_pending_tasks?: false, organizations_with_pending_tasks:
  199 + Organization.none, pending_tasks_for_organization: Task.none,
  200 + build_contact: nil, is_a_friend?: false, ask_to_join?: false, refuse_join:
  201 + nil, blocks_to_expire_cache: [], cache_keys: [], communities_cache_key: '',
  202 + friends_cache_key: '', manage_friends_cache_key: '',
  203 + relationships_cache_key: '', is_member_of?: false,
  204 + each_friend: nil, is_last_admin?: false, is_last_admin_leaving?: false,
  205 + leave: nil, last_notification: nil, notification_time: 0, notifier: nil,
  206 + remove_suggestion: nil, allow_invitation_from?: false, in_social_circle?: false,
  207 + allow_followers: false, in_circles: Circle.none, followers: [], in_circle?: false
  208 + }
  209 +
  210 + derivated_methods = generate_derivated_methods(methods_and_responses)
  211 + derivated_methods.merge(methods_and_responses)
  212 + end
  213 +
  214 + def profile_instance_methods
  215 + methods_and_responses = {
  216 + role_assignments: RoleAssignment.none, favorite_enterprises:
  217 + Enterprise.none, memberships: Profile.none, friendships: Profile.none,
  218 + tasks: Task.none, suggested_profiles: ProfileSuggestion.none,
  219 + suggested_people: ProfileSuggestion.none, suggested_communities:
  220 + ProfileSuggestion.none, public_profile: true, nickname: nil, custom_footer:
  221 + '', custom_header: '', address: '', zip_code: '', contact_phone: '',
  222 + image_builder: nil, description: '', closed: false, template_id: nil, lat:
  223 + nil, lng: nil, is_template: false, fields_privacy: {}, preferred_domain_id:
  224 + nil, category_ids: [], country: '', city: '', state: '',
  225 + national_region_code: '', redirect_l10n: false, notification_time: 0,
  226 + custom_url_redirection: nil, email_suggestions: false,
  227 + allow_members_to_invite: false, invite_friends_only: false, secret: false,
  228 + profile_admin_mail_notification: false, redirection_after_login: nil,
  229 + profile_activities: ProfileActivity.none, action_tracker_notifications:
  230 + ActionTrackerNotification.none, tracked_notifications:
  231 + ActionTracker::Record.none, scraps_received: Scrap.none, template:
  232 + Profile.none, comments_received: Comment.none, email_templates:
  233 + EmailTemplate.none, members: Profile.none, members_like: Profile.none,
  234 + members_by: Profile.none, members_by_role: Profile.none, scraps:
  235 + Scrap.none, welcome_page_content: nil, settings: {}, find_in_all_tasks:
  236 + nil, top_level_categorization: {}, interests: Category.none, geolocation:
  237 + '', country_name: '', pending_categorizations: [], add_category: false,
  238 + create_pending_categorizations: false, top_level_articles: Article.none,
  239 + valid_identifier: true, valid_template: false, create_default_set_of_boxes:
  240 + true, copy_blocks_from: nil, default_template: nil,
  241 + template_without_default: nil, template_with_default: nil, apply_template:
  242 + false, iframe_whitelist: [], recent_documents: Article.none, last_articles:
  243 + Article.none, is_validation_entity?: false, hostname: nil, own_hostname:
  244 + nil, article_tags: {}, tagged_with: Article.none,
  245 + insert_default_article_set: false, copy_articles_from: true,
  246 + copy_article_tree: nil, copy_article?: false, add_member: false,
  247 + remove_member: false, add_admin: false, remove_admin: false, add_moderator:
  248 + false, display_info_to?: true, update_category_from_region: nil,
  249 + accept_category?: false, custom_header_expanded: '',
  250 + custom_footer_expanded: '', public?: true, themes: [], find_theme: nil,
  251 + blogs: Blog.none, blog: nil, has_blog?: false, forums: Forum.none, forum:
  252 + nil, has_forum?: false, admins: [], settings_field: {}, setting_changed:
  253 + false, public_content: true, enable_contact?: false, folder_types: [],
  254 + folders: Article.none, image_galleries: Article.none, image_valid: true,
  255 + update_header_and_footer: nil, update_theme: nil, update_layout_template:
  256 + nil, recent_actions: ActionTracker::Record.none, recent_notifications:
  257 + ActionTracker::Record.none, more_active_label: _('no activity'),
  258 + more_popular_label: _('no members'), profile_custom_image: nil,
  259 + is_on_homepage?: false, activities: ProfileActivity.none,
  260 + may_display_field_to?: true, may_display_location_to?: true, public_fields:
  261 + {}, followed_by?: false, display_private_info_to?: true, can_view_field?:
  262 + true, remove_from_suggestion_list: nil, layout_template: 'default',
  263 + is_admin?: false, add_friend: false, is_a_friend?: false,
  264 + already_request_friendship?: false
  265 + }
  266 +
  267 + derivated_methods = generate_derivated_methods(methods_and_responses)
  268 + derivated_methods.merge(methods_and_responses)
  269 + end
  270 +
  271 + def method_missing(method, *args, &block)
  272 + if person_instance_methods.keys.include?(method)
  273 + return person_instance_methods[method]
  274 + end
  275 + if profile_instance_methods.keys.include? method
  276 + return profile_instance_methods[method]
  277 + end
  278 + end
  279 +
  280 + def respond_to_missing?(method_name, include_private = false)
  281 + person_instance_methods.keys.include?(method_name) ||
  282 + profile_instance_methods.keys.include?(method_name) ||
  283 + super
  284 + end
  285 +
  286 + private
  287 +
  288 + def generate_derivated_methods(methods)
  289 + derivated_methods = {}
  290 + methods.keys.each do |method|
  291 + derivated_methods[method.to_s.insert(-1, '?').to_sym] = false
  292 + derivated_methods[method.to_s.insert(-1, '=').to_sym] = nil
  293 + end
  294 + derivated_methods
  295 + end
132 296 end
... ...
app/models/person.rb
... ... @@ -94,7 +94,7 @@ class Person &lt; Profile
94 94 has_many :following_articles, :class_name => 'Article', :through => :article_followers, :source => :article
95 95 has_many :friendships, :dependent => :destroy
96 96 has_many :friends, :class_name => 'Person', :through => :friendships
97   - has_many :circles, as: :person
  97 + has_many :owned_circles, as: :owner, :class_name => 'Circle'
98 98  
99 99 scope :online, -> {
100 100 joins(:user).where("users.chat_status != '' AND users.chat_status_at >= ?", DateTime.now - User.expires_chat_status_every.minutes)
... ...
app/models/profile.rb
... ... @@ -223,14 +223,7 @@ class Profile &lt; ApplicationRecord
223 223 distinct.select('profiles.*').
224 224 joins('left join profiles_circles ON profiles_circles.profile_id = profiles.id').
225 225 joins('left join circles ON circles.id = profiles_circles.circle_id').
226   - where('circles.person_id = ?', person.id)
227   - }
228   -
229   - scope :in_circle, -> circle{
230   - distinct.select('profiles.*').
231   - joins('left join profiles_circles ON profiles_circles.profile_id = profiles.id').
232   - joins('left join circles ON circles.id = profiles_circles.circle_id').
233   - where('circles.id = ?', circle.id)
  226 + where('circles.owner_id = ?', person.id)
234 227 }
235 228  
236 229 settings_items :allow_followers, :type => :boolean, :default => true
... ... @@ -249,15 +242,11 @@ class Profile &lt; ApplicationRecord
249 242 has_many :email_templates, :foreign_key => :owner_id
250 243  
251 244 has_many :profile_followers
252   -
253   - def in_circles
254   - Circle.joins(:profile_followers).
255   - where('profiles_circles.profile_id = ?', self.id)
256   - end
  245 + has_many :circles, :through => :profile_followers, :as => :profile
257 246  
258 247 def followers
259   - person_followers = Person.joins(:circles).merge(in_circles).uniq
260   - external_person_followers = ExternalPerson.joins(:circles).merge(in_circles).uniq
  248 + person_followers = Person.joins(:owned_circles).merge(circles).uniq
  249 + external_person_followers = ExternalPerson.joins(:owned_circles).merge(circles).uniq
261 250  
262 251 person_followers + external_person_followers
263 252 end
... ... @@ -1068,7 +1057,7 @@ private :generate_url, :url_options
1068 1057 person.kind_of?(Profile) && person.has_permission?('destroy_profile', self)
1069 1058 end
1070 1059  
1071   - def in_circle?(circle, follower)
1072   - ProfileFollower.with_follower(follower).with_circle(circle).with_profile(self).present?
  1060 + def in_circle?(circle)
  1061 + circle.in? self.circles
1073 1062 end
1074 1063 end
... ...
app/models/profile_follower.rb
... ... @@ -5,14 +5,14 @@ class ProfileFollower &lt; ApplicationRecord
5 5 attr_accessible :profile, :circle
6 6  
7 7 #TODO -> user being followed
8   - belongs_to :profile
  8 + belongs_to :profile, :polymorphic => true
9 9 belongs_to :circle
10 10  
11 11 #TODO -> circle owner
12 12 # has_one :person, through: :circle, source_type: "ProfileFollower"
13 13  
14 14 def circle_owner
15   - self.circle.person
  15 + self.circle.owner
16 16 end
17 17  
18 18 alias follower circle_owner
... ... @@ -21,7 +21,7 @@ class ProfileFollower &lt; ApplicationRecord
21 21 validates :profile_id, :uniqueness => {:scope => :circle_id, :message => "can't put a profile in the same circle twice"}
22 22  
23 23 scope :with_follower, -> person{
24   - joins(:circle).where('circles.person_id = ?', person.id)
  24 + joins(:circle).where('circles.owner_id = ?', person.id)
25 25 }
26 26  
27 27 scope :with_profile, -> profile{
... ...
app/views/blocks/profile_info_actions/_select_circles.html.erb
... ... @@ -3,7 +3,7 @@
3 3 <div id="circles-checkboxes">
4 4 <% circles.each do |circle| %>
5 5 <div class="circle">
6   - <%= labelled_check_box circle.name, "circles[#{circle.name}]", circle.id, followed_profile.in_circle?(circle, follower) %>
  6 + <%= labelled_check_box circle.name, "circles[#{circle.name}]", circle.id, followed_profile.in_circle?(circle) %>
7 7 </div>
8 8 <% end %>
9 9 </div>
... ...
db/migrate/20160822174619_adds_profile_type_to_profile_followers.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class AddsProfileTypeToProfileFollowers < ActiveRecord::Migration
  2 + def up
  3 + add_column :profiles_circles, :profile_type, :string, default: "Person"
  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/migrate/20160822184703_rename_person_id_from_circles.rb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +class RenamePersonIdFromCircles < ActiveRecord::Migration
  2 + def up
  3 + rename_column :circles, :person_id, :owner_id
  4 + rename_column :circles, :person_type, :owner_type
  5 + end
  6 +
  7 + def down
  8 + rename_column :circles, :owner_id, :person_id
  9 + rename_column :circles, :owner_type, :person_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: 20160810132802) do
  14 +ActiveRecord::Schema.define(version: 20160608123748) do
15 15  
16 16 # These are extensions that must be enabled in order to support this database
17 17 enable_extension "plpgsql"
... ... @@ -278,12 +278,10 @@ ActiveRecord::Schema.define(version: 20160810132802) 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
282   - t.string "person_type", default: "Person"
  281 + t.string "profile_type", null: false
283 282 end
284 283  
285 284 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
287 285  
288 286 create_table "comments", force: :cascade do |t|
289 287 t.string "title"
... ... @@ -555,11 +553,6 @@ ActiveRecord::Schema.define(version: 20160810132802) do
555 553 t.datetime "updated_at"
556 554 end
557 555  
558   - create_table "private_scraps", force: :cascade do |t|
559   - t.integer "person_id"
560   - t.integer "scrap_id"
561   - end
562   -
563 556 create_table "product_qualifiers", force: :cascade do |t|
564 557 t.integer "product_id"
565 558 t.integer "qualifier_id"
... ... @@ -688,11 +681,9 @@ ActiveRecord::Schema.define(version: 20160810132802) do
688 681 t.integer "circle_id"
689 682 t.datetime "created_at"
690 683 t.datetime "updated_at"
691   - t.string "profile_type", default: "Profile"
692 684 end
693 685  
694 686 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
696 687  
697 688 create_table "qualifier_certifiers", force: :cascade do |t|
698 689 t.integer "qualifier_id"
... ...