Commit aa37360cdc7a415255bb534c9637eadee009836e

Authored by Dylan Guedes
1 parent 2f038eed

Revert "Revert "Adds new ExternalProfile module and refactor ExternalPerson""

This reverts commit bfbd548c9f5088ca91299c8b5529dd6964ed5233.
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   - url = URI.parse(scheme+"://"+ domain +'/.well-known/webfinger?resource=acct:'+
  23 +p 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,9 +2,22 @@ module Follower
2 2 extend ActiveSupport::Concern
3 3  
4 4 def follow(profile, circles)
  5 + puts "follow..."
5 6 circles = [circles] unless circles.is_a?(Array)
6 7 circles.each do |new_circle|
  8 +<<<<<<< HEAD
7 9 next if new_circle.owner != self || !profile.kind_of?(new_circle.profile_type.constantize)
  10 +=======
  11 + puts "seguindo alguen..."
  12 + puts "profile_type: #{new_circle.profile_type}, class_name: #{profile.class.name}"
  13 + puts "new_circle.person: #{new_circle.person}, self: #{self}"
  14 + if (new_circle.person != self && !(self.kind_of?(new_circle.person.class)) || new_circle.profile_type != profile.class.name)
  15 + next
  16 + end
  17 + puts '*20'*20
  18 + puts "CHEGOU NO PROFILE FOLLOWER"
  19 + puts '*20'*20
  20 +>>>>>>> parent of bfbd548... Revert "Adds new ExternalProfile module and refactor ExternalPerson"
8 21 ProfileFollower.create(profile: profile, circle: new_circle)
9 22 end
10 23 end
... ...
app/models/external_person.rb
1 1 # A pseudo profile is a person from a remote network
2   -class ExternalPerson < ActiveRecord::Base
  2 +class ExternalPerson < ExternalProfile
3 3  
4 4 include Human
5 5 include ProfileEntity
  6 +<<<<<<< HEAD
6 7 include Follower
7 8 include Followable
8 9  
9 10 has_many :profile_followers, :as => :profile
10 11 has_many :circles, :through => :profile_followers
11 12 has_many :owned_circles, as: :owner, :class_name => "Circle"
  13 +=======
  14 +>>>>>>> parent of bfbd548... Revert "Adds new ExternalProfile module and refactor ExternalPerson"
12 15  
13 16 validates_uniqueness_of :identifier, scope: :source
14 17  
... ... @@ -33,13 +36,6 @@ class ExternalPerson &lt; ActiveRecord::Base
33 36 _('Public profile')
34 37 end
35 38  
36   - def avatar
37   - "http://#{self.source}/profile/#{self.identifier}/icon/"
38   - end
39   -
40   - def url
41   - "http://#{self.source}/profile/#{self.identifier}"
42   - end
43 39  
44 40 alias :public_profile_url :url
45 41  
... ... @@ -81,10 +77,6 @@ class ExternalPerson &lt; ActiveRecord::Base
81 77 "#{scheme}://#{self.source}"
82 78 end
83 79  
84   - def profile_custom_icon(gravatar_default=nil)
85   - self.avatar
86   - end
87   -
88 80 def preferred_login_redirection
89 81 environment.redirection_after_login
90 82 end
... ... @@ -128,26 +120,6 @@ class ExternalPerson &lt; ActiveRecord::Base
128 120 "#{jid(options)}/#{self.name}"
129 121 end
130 122  
131   - class ExternalPerson::Image
132   - def initialize(path)
133   - @path = path
134   - end
135   -
136   - def public_filename(size = nil)
137   - URI.join(@path, size.to_s)
138   - end
139   -
140   - def content_type
141   - # This is not really going to be used anywhere that matters
142   - # so we are hardcodding it here.
143   - 'image/png'
144   - end
145   - end
146   -
147   - def image
148   - ExternalPerson::Image.new(avatar)
149   - end
150   -
151 123 def data_hash(gravatar_default = nil)
152 124 friends_list = {}
153 125 {
... ... @@ -166,6 +138,7 @@ class ExternalPerson &lt; ActiveRecord::Base
166 138 }
167 139 end
168 140  
  141 +<<<<<<< HEAD
169 142 # External Person should respond to all methods in Person and Profile
170 143 def person_instance_methods
171 144 methods_and_responses = {
... ... @@ -299,4 +272,6 @@ class ExternalPerson &lt; ActiveRecord::Base
299 272 end
300 273 derivated_methods
301 274 end
  275 +=======
  276 +>>>>>>> parent of bfbd548... Revert "Adds new ExternalProfile module and refactor ExternalPerson"
302 277 end
... ...
app/models/external_profile.rb 0 → 100644
... ... @@ -0,0 +1,171 @@
  1 +class ExternalProfile < ActiveRecord::Base
  2 +
  3 + include Follower
  4 +
  5 + has_many :circles, as: :person
  6 +
  7 + def name
  8 + "#{self[:name]}@#{self.source}"
  9 + end
  10 +
  11 + class ExternalProfile::Image
  12 + def initialize(path)
  13 + @path = path
  14 + end
  15 +
  16 + def public_filename(size = nil)
  17 + URI.join(@path, size.to_s)
  18 + end
  19 +
  20 + def content_type
  21 + # This is not really going to be used anywhere that matters
  22 + # so we are hardcodding it here.
  23 + 'image/png'
  24 + end
  25 + end
  26 +
  27 + def url
  28 + "http://#{self.source}/profile/#{self.identifier}"
  29 + end
  30 +
  31 + def image
  32 + ExternalProfile::Image.new(avatar)
  33 + end
  34 +
  35 + def profile_custom_icon(gravatar_default=nil)
  36 + self.avatar
  37 + end
  38 +
  39 + def avatar
  40 + "http://#{self.source}/profile/#{self.identifier}/icon/"
  41 + end
  42 +
  43 + # External Person should respond to all methods in Person and Profile
  44 + def person_instance_methods
  45 + methods_and_responses = {
  46 + enterprises: Enterprise.none, communities: Community.none, friends:
  47 + Person.none, memberships: Profile.none, friendships: Person.none,
  48 + following_articles: Article.none, article_followers: ArticleFollower.none,
  49 + requested_tasks: Task.none, mailings: Mailing.none, scraps_sent:
  50 + Scrap.none, favorite_enterprise_people: FavoriteEnterprisePerson.none,
  51 + favorite_enterprises: Enterprise.none, acepted_forums: Forum.none,
  52 + articles_with_access: Article.none, suggested_profiles:
  53 + ProfileSuggestion.none, suggested_people: ProfileSuggestion.none,
  54 + suggested_communities: ProfileSuggestion.none, user: nil,
  55 + refused_communities: Community.none, has_permission?: false,
  56 + has_permission_with_admin?: false, has_permission_without_admin?: false,
  57 + has_permission_with_plugins?: false, has_permission_without_plugins?:
  58 + false, memberships_by_role: Person.none, can_change_homepage?: false,
  59 + can_control_scrap?: false, receives_scrap_notification?: false,
  60 + can_control_activity?: false, can_post_content?: false,
  61 + suggested_friend_groups: [], friend_groups: [], add_friend: nil,
  62 + already_request_friendship?: false, remove_friend: nil,
  63 + presence_of_required_fields: nil, active_fields: [], required_fields: [],
  64 + signup_fields: [], default_set_of_blocks: [], default_set_of_boxes: [],
  65 + default_set_of_articles: [], cell_phone: nil, comercial_phone: nil,
  66 + nationality: nil, schooling: nil, contact_information: nil, sex: nil,
  67 + birth_date: nil, jabber_id: nil, personal_website: nil, address_reference:
  68 + nil, district: nil, schooling_status: nil, formation: nil,
  69 + custom_formation: nil, area_of_study: nil, custom_area_of_study: nil,
  70 + professional_activity: nil, organization_website: nil, organization: nil,
  71 + photo: nil, city: nil, state: nil, country: nil, zip_code: nil,
  72 + address_line2: nil, copy_communities_from: nil,
  73 + has_organization_pending_tasks?: false, organizations_with_pending_tasks:
  74 + Organization.none, pending_tasks_for_organization: Task.none,
  75 + build_contact: nil, is_a_friend?: false, ask_to_join?: false, refuse_join:
  76 + nil, blocks_to_expire_cache: [], cache_keys: [], communities_cache_key: '',
  77 + friends_cache_key: '', manage_friends_cache_key: '',
  78 + relationships_cache_key: '', is_member_of?: false,
  79 + each_friend: nil, is_last_admin?: false, is_last_admin_leaving?: false,
  80 + leave: nil, last_notification: nil, notification_time: 0, notifier: nil,
  81 + remove_suggestion: nil, allow_invitation_from?: false, in_social_circle?: false,
  82 + allow_followers: false, in_circles: Circle.none, followers: [], in_circle?: false
  83 + }
  84 +
  85 + derivated_methods = generate_derivated_methods(methods_and_responses)
  86 + derivated_methods.merge(methods_and_responses)
  87 + end
  88 +
  89 + def profile_instance_methods
  90 + methods_and_responses = {
  91 + role_assignments: RoleAssignment.none, favorite_enterprises:
  92 + Enterprise.none, memberships: Profile.none, friendships: Profile.none,
  93 + tasks: Task.none, suggested_profiles: ProfileSuggestion.none,
  94 + suggested_people: ProfileSuggestion.none, suggested_communities:
  95 + ProfileSuggestion.none, public_profile: true, nickname: nil, custom_footer:
  96 + '', custom_header: '', address: '', zip_code: '', contact_phone: '',
  97 + image_builder: nil, description: '', closed: false, template_id: nil, lat:
  98 + nil, lng: nil, is_template: false, fields_privacy: {}, preferred_domain_id:
  99 + nil, category_ids: [], country: '', city: '', state: '',
  100 + national_region_code: '', redirect_l10n: false, notification_time: 0,
  101 + custom_url_redirection: nil, email_suggestions: false,
  102 + allow_members_to_invite: false, invite_friends_only: false, secret: false,
  103 + profile_admin_mail_notification: false, redirection_after_login: nil,
  104 + profile_activities: ProfileActivity.none, action_tracker_notifications:
  105 + ActionTrackerNotification.none, tracked_notifications:
  106 + ActionTracker::Record.none, scraps_received: Scrap.none, template:
  107 + Profile.none, comments_received: Comment.none, email_templates:
  108 + EmailTemplate.none, members: Profile.none, members_like: Profile.none,
  109 + members_by: Profile.none, members_by_role: Profile.none, scraps:
  110 + Scrap.none, welcome_page_content: nil, settings: {}, find_in_all_tasks:
  111 + nil, top_level_categorization: {}, interests: Category.none, geolocation:
  112 + '', country_name: '', pending_categorizations: [], add_category: false,
  113 + create_pending_categorizations: false, top_level_articles: Article.none,
  114 + valid_identifier: true, valid_template: false, create_default_set_of_boxes:
  115 + true, copy_blocks_from: nil, default_template: nil,
  116 + template_without_default: nil, template_with_default: nil, apply_template:
  117 + false, iframe_whitelist: [], recent_documents: Article.none, last_articles:
  118 + Article.none, is_validation_entity?: false, hostname: nil, own_hostname:
  119 + nil, article_tags: {}, tagged_with: Article.none,
  120 + insert_default_article_set: false, copy_articles_from: true,
  121 + copy_article_tree: nil, copy_article?: false, add_member: false,
  122 + remove_member: false, add_admin: false, remove_admin: false, add_moderator:
  123 + false, display_info_to?: true, update_category_from_region: nil,
  124 + accept_category?: false, custom_header_expanded: '',
  125 + custom_footer_expanded: '', public?: true, themes: [], find_theme: nil,
  126 + blogs: Blog.none, blog: nil, has_blog?: false, forums: Forum.none, forum:
  127 + nil, has_forum?: false, admins: [], settings_field: {}, setting_changed:
  128 + false, public_content: true, enable_contact?: false, folder_types: [],
  129 + folders: Article.none, image_galleries: Article.none, image_valid: true,
  130 + update_header_and_footer: nil, update_theme: nil, update_layout_template:
  131 + nil, recent_actions: ActionTracker::Record.none, recent_notifications:
  132 + ActionTracker::Record.none, more_active_label: _('no activity'),
  133 + more_popular_label: _('no members'), profile_custom_image: nil,
  134 + is_on_homepage?: false, activities: ProfileActivity.none,
  135 + may_display_field_to?: true, may_display_location_to?: true, public_fields:
  136 + {}, followed_by?: false, display_private_info_to?: true, can_view_field?:
  137 + true, remove_from_suggestion_list: nil, layout_template: 'default',
  138 + is_admin?: false, add_friend: false, is_a_friend?: false,
  139 + already_request_friendship?: false
  140 + }
  141 +
  142 + derivated_methods = generate_derivated_methods(methods_and_responses)
  143 + derivated_methods.merge(methods_and_responses)
  144 + end
  145 +
  146 + def method_missing(method, *args, &block)
  147 + if person_instance_methods.keys.include?(method)
  148 + return person_instance_methods[method]
  149 + end
  150 + if profile_instance_methods.keys.include? method
  151 + return profile_instance_methods[method]
  152 + end
  153 + end
  154 +
  155 + def respond_to_missing?(method_name, include_private = false)
  156 + person_instance_methods.keys.include?(method_name) ||
  157 + profile_instance_methods.keys.include?(method_name) ||
  158 + super
  159 + end
  160 +
  161 + private
  162 +
  163 + def generate_derivated_methods(methods)
  164 + derivated_methods = {}
  165 + methods.keys.each do |method|
  166 + derivated_methods[method.to_s.insert(-1, '?').to_sym] = false
  167 + derivated_methods[method.to_s.insert(-1, '=').to_sym] = nil
  168 + end
  169 + derivated_methods
  170 + end
  171 +end
... ...
db/migrate/20160822110424_rename_external_people_to_external_profiles.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class RenameExternalPeopleToExternalProfiles < ActiveRecord::Migration
  2 + def up
  3 + rename_table :external_people, :external_profiles
  4 + end
  5 +
  6 + def down
  7 + rename_table :external_profiles, :external_people
  8 + end
  9 +end
... ...