Commit e31770eb839b50a6e914961d09737326fbb3b70b

Authored by Dylan Guedes
1 parent fb7c807f

Adds new ExternalProfile module and refactor ExternalPerson

Signed-off-by: DylanGuedes <djmgguedes@gmail.com>
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
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,18 @@ 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|
7   - next if new_circle.person != self || new_circle.profile_type != profile.class.name
  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
8 17 ProfileFollower.create(profile: profile, circle: new_circle)
9 18 end
10 19 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   - include Follower
7 6  
8   - has_many :circles, as: :person
9 7 validates_uniqueness_of :identifier, scope: :source
10 8  
11 9 validates_presence_of :source, :email, :created_at
... ... @@ -29,13 +27,6 @@ class ExternalPerson &lt; ActiveRecord::Base
29 27 _('Public profile')
30 28 end
31 29  
32   - def avatar
33   - "http://#{self.source}/profile/#{self.identifier}/icon/"
34   - end
35   -
36   - def url
37   - "http://#{self.source}/profile/#{self.identifier}"
38   - end
39 30  
40 31 alias :public_profile_url :url
41 32  
... ... @@ -77,10 +68,6 @@ class ExternalPerson &lt; ActiveRecord::Base
77 68 "#{scheme}://#{self.source}"
78 69 end
79 70  
80   - def profile_custom_icon(gravatar_default=nil)
81   - self.avatar
82   - end
83   -
84 71 def preferred_login_redirection
85 72 environment.redirection_after_login
86 73 end
... ... @@ -124,26 +111,6 @@ class ExternalPerson &lt; ActiveRecord::Base
124 111 "#{jid(options)}/#{self.name}"
125 112 end
126 113  
127   - class ExternalPerson::Image
128   - def initialize(path)
129   - @path = path
130   - end
131   -
132   - def public_filename(size = nil)
133   - URI.join(@path, size.to_s)
134   - end
135   -
136   - def content_type
137   - # This is not really going to be used anywhere that matters
138   - # so we are hardcodding it here.
139   - 'image/png'
140   - end
141   - end
142   -
143   - def image
144   - ExternalPerson::Image.new(avatar)
145   - end
146   -
147 114 def data_hash(gravatar_default = nil)
148 115 friends_list = {}
149 116 {
... ... @@ -162,132 +129,4 @@ class ExternalPerson &lt; ActiveRecord::Base
162 129 }
163 130 end
164 131  
165   - # External Person should respond to all methods in Person and Profile
166   - def person_instance_methods
167   - methods_and_responses = {
168   - enterprises: Enterprise.none, communities: Community.none, friends:
169   - Person.none, memberships: Profile.none, friendships: Person.none,
170   - following_articles: Article.none, article_followers: ArticleFollower.none,
171   - requested_tasks: Task.none, mailings: Mailing.none, scraps_sent:
172   - Scrap.none, favorite_enterprise_people: FavoriteEnterprisePerson.none,
173   - favorite_enterprises: Enterprise.none, acepted_forums: Forum.none,
174   - articles_with_access: Article.none, suggested_profiles:
175   - ProfileSuggestion.none, suggested_people: ProfileSuggestion.none,
176   - suggested_communities: ProfileSuggestion.none, user: nil,
177   - refused_communities: Community.none, has_permission?: false,
178   - has_permission_with_admin?: false, has_permission_without_admin?: false,
179   - has_permission_with_plugins?: false, has_permission_without_plugins?:
180   - false, memberships_by_role: Person.none, can_change_homepage?: false,
181   - can_control_scrap?: false, receives_scrap_notification?: false,
182   - can_control_activity?: false, can_post_content?: false,
183   - suggested_friend_groups: [], friend_groups: [], add_friend: nil,
184   - already_request_friendship?: false, remove_friend: nil,
185   - presence_of_required_fields: nil, active_fields: [], required_fields: [],
186   - signup_fields: [], default_set_of_blocks: [], default_set_of_boxes: [],
187   - default_set_of_articles: [], cell_phone: nil, comercial_phone: nil,
188   - nationality: nil, schooling: nil, contact_information: nil, sex: nil,
189   - birth_date: nil, jabber_id: nil, personal_website: nil, address_reference:
190   - nil, district: nil, schooling_status: nil, formation: nil,
191   - custom_formation: nil, area_of_study: nil, custom_area_of_study: nil,
192   - professional_activity: nil, organization_website: nil, organization: nil,
193   - photo: nil, city: nil, state: nil, country: nil, zip_code: nil,
194   - address_line2: nil, copy_communities_from: nil,
195   - has_organization_pending_tasks?: false, organizations_with_pending_tasks:
196   - Organization.none, pending_tasks_for_organization: Task.none,
197   - build_contact: nil, is_a_friend?: false, ask_to_join?: false, refuse_join:
198   - nil, blocks_to_expire_cache: [], cache_keys: [], communities_cache_key: '',
199   - friends_cache_key: '', manage_friends_cache_key: '',
200   - relationships_cache_key: '', is_member_of?: false,
201   - each_friend: nil, is_last_admin?: false, is_last_admin_leaving?: false,
202   - leave: nil, last_notification: nil, notification_time: 0, notifier: nil,
203   - remove_suggestion: nil, allow_invitation_from?: false, in_social_circle?: false,
204   - allow_followers: false, in_circles: Circle.none, followers: [], in_circle?: false
205   - }
206   -
207   - derivated_methods = generate_derivated_methods(methods_and_responses)
208   - derivated_methods.merge(methods_and_responses)
209   - end
210   -
211   - def profile_instance_methods
212   - methods_and_responses = {
213   - role_assignments: RoleAssignment.none, favorite_enterprises:
214   - Enterprise.none, memberships: Profile.none, friendships: Profile.none,
215   - tasks: Task.none, suggested_profiles: ProfileSuggestion.none,
216   - suggested_people: ProfileSuggestion.none, suggested_communities:
217   - ProfileSuggestion.none, public_profile: true, nickname: nil, custom_footer:
218   - '', custom_header: '', address: '', zip_code: '', contact_phone: '',
219   - image_builder: nil, description: '', closed: false, template_id: nil, lat:
220   - nil, lng: nil, is_template: false, fields_privacy: {}, preferred_domain_id:
221   - nil, category_ids: [], country: '', city: '', state: '',
222   - national_region_code: '', redirect_l10n: false, notification_time: 0,
223   - custom_url_redirection: nil, email_suggestions: false,
224   - allow_members_to_invite: false, invite_friends_only: false, secret: false,
225   - profile_admin_mail_notification: false, redirection_after_login: nil,
226   - profile_activities: ProfileActivity.none, action_tracker_notifications:
227   - ActionTrackerNotification.none, tracked_notifications:
228   - ActionTracker::Record.none, scraps_received: Scrap.none, template:
229   - Profile.none, comments_received: Comment.none, email_templates:
230   - EmailTemplate.none, members: Profile.none, members_like: Profile.none,
231   - members_by: Profile.none, members_by_role: Profile.none, scraps:
232   - Scrap.none, welcome_page_content: nil, settings: {}, find_in_all_tasks:
233   - nil, top_level_categorization: {}, interests: Category.none, geolocation:
234   - '', country_name: '', pending_categorizations: [], add_category: false,
235   - create_pending_categorizations: false, top_level_articles: Article.none,
236   - valid_identifier: true, valid_template: false, create_default_set_of_boxes:
237   - true, copy_blocks_from: nil, default_template: nil,
238   - template_without_default: nil, template_with_default: nil, apply_template:
239   - false, iframe_whitelist: [], recent_documents: Article.none, last_articles:
240   - Article.none, is_validation_entity?: false, hostname: nil, own_hostname:
241   - nil, article_tags: {}, tagged_with: Article.none,
242   - insert_default_article_set: false, copy_articles_from: true,
243   - copy_article_tree: nil, copy_article?: false, add_member: false,
244   - remove_member: false, add_admin: false, remove_admin: false, add_moderator:
245   - false, display_info_to?: true, update_category_from_region: nil,
246   - accept_category?: false, custom_header_expanded: '',
247   - custom_footer_expanded: '', public?: true, themes: [], find_theme: nil,
248   - blogs: Blog.none, blog: nil, has_blog?: false, forums: Forum.none, forum:
249   - nil, has_forum?: false, admins: [], settings_field: {}, setting_changed:
250   - false, public_content: true, enable_contact?: false, folder_types: [],
251   - folders: Article.none, image_galleries: Article.none, image_valid: true,
252   - update_header_and_footer: nil, update_theme: nil, update_layout_template:
253   - nil, recent_actions: ActionTracker::Record.none, recent_notifications:
254   - ActionTracker::Record.none, more_active_label: _('no activity'),
255   - more_popular_label: _('no members'), profile_custom_image: nil,
256   - is_on_homepage?: false, activities: ProfileActivity.none,
257   - may_display_field_to?: true, may_display_location_to?: true, public_fields:
258   - {}, followed_by?: false, display_private_info_to?: true, can_view_field?:
259   - true, remove_from_suggestion_list: nil, layout_template: 'default',
260   - is_admin?: false, add_friend: false, is_a_friend?: false,
261   - already_request_friendship?: false
262   - }
263   -
264   - derivated_methods = generate_derivated_methods(methods_and_responses)
265   - derivated_methods.merge(methods_and_responses)
266   - end
267   -
268   - def method_missing(method, *args, &block)
269   - if person_instance_methods.keys.include?(method)
270   - return person_instance_methods[method]
271   - end
272   - if profile_instance_methods.keys.include? method
273   - return profile_instance_methods[method]
274   - end
275   - end
276   -
277   - def respond_to_missing?(method_name, include_private = false)
278   - person_instance_methods.keys.include?(method_name) ||
279   - profile_instance_methods.keys.include?(method_name) ||
280   - super
281   - end
282   -
283   - private
284   -
285   - def generate_derivated_methods(methods)
286   - derivated_methods = {}
287   - methods.keys.each do |method|
288   - derivated_methods[method.to_s.insert(-1, '?').to_sym] = false
289   - derivated_methods[method.to_s.insert(-1, '=').to_sym] = nil
290   - end
291   - derivated_methods
292   - end
293 132 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
... ...