Compare View
Commits (2)
-
This reverts commit bfbd548c9f5088ca91299c8b5529dd6964ed5233.
Showing
6 changed files
Show diff stats
app/models/concerns/external_user.rb
@@ -20,7 +20,7 @@ module ExternalUser | @@ -20,7 +20,7 @@ module ExternalUser | ||
20 | if login && domain && environment.has_federated_network?(domain) | 20 | if login && domain && environment.has_federated_network?(domain) |
21 | external_environment = environment.external_environments.find_by_domain(domain) | 21 | external_environment = environment.external_environments.find_by_domain(domain) |
22 | scheme = "http#{external_environment.uses_ssl? ? 's' : ''}" | 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 | login+'@'+domain) | 24 | login+'@'+domain) |
25 | http = build_request(url) | 25 | http = build_request(url) |
26 | req = Net::HTTP::Get.new(url.to_s) | 26 | req = Net::HTTP::Get.new(url.to_s) |
app/models/concerns/follower.rb
@@ -2,9 +2,22 @@ module Follower | @@ -2,9 +2,22 @@ module Follower | ||
2 | extend ActiveSupport::Concern | 2 | extend ActiveSupport::Concern |
3 | 3 | ||
4 | def follow(profile, circles) | 4 | def follow(profile, circles) |
5 | + puts "follow..." | ||
5 | circles = [circles] unless circles.is_a?(Array) | 6 | circles = [circles] unless circles.is_a?(Array) |
6 | circles.each do |new_circle| | 7 | circles.each do |new_circle| |
8 | +<<<<<<< HEAD | ||
7 | next if new_circle.owner != self || !profile.kind_of?(new_circle.profile_type.constantize) | 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 | ProfileFollower.create(profile: profile, circle: new_circle) | 21 | ProfileFollower.create(profile: profile, circle: new_circle) |
9 | end | 22 | end |
10 | end | 23 | end |
app/models/external_person.rb
1 | # A pseudo profile is a person from a remote network | 1 | # A pseudo profile is a person from a remote network |
2 | -class ExternalPerson < ActiveRecord::Base | 2 | +class ExternalPerson < ExternalProfile |
3 | 3 | ||
4 | include Human | 4 | include Human |
5 | include ProfileEntity | 5 | include ProfileEntity |
6 | include Follower | 6 | include Follower |
7 | - include Followable | ||
8 | 7 | ||
9 | has_many :profile_followers, :as => :profile | 8 | has_many :profile_followers, :as => :profile |
10 | has_many :circles, :through => :profile_followers | 9 | has_many :circles, :through => :profile_followers |
@@ -33,13 +32,6 @@ class ExternalPerson < ActiveRecord::Base | @@ -33,13 +32,6 @@ class ExternalPerson < ActiveRecord::Base | ||
33 | _('Public profile') | 32 | _('Public profile') |
34 | end | 33 | end |
35 | 34 | ||
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 | 35 | ||
44 | alias :public_profile_url :url | 36 | alias :public_profile_url :url |
45 | 37 | ||
@@ -81,10 +73,6 @@ class ExternalPerson < ActiveRecord::Base | @@ -81,10 +73,6 @@ class ExternalPerson < ActiveRecord::Base | ||
81 | "#{scheme}://#{self.source}" | 73 | "#{scheme}://#{self.source}" |
82 | end | 74 | end |
83 | 75 | ||
84 | - def profile_custom_icon(gravatar_default=nil) | ||
85 | - self.avatar | ||
86 | - end | ||
87 | - | ||
88 | def preferred_login_redirection | 76 | def preferred_login_redirection |
89 | environment.redirection_after_login | 77 | environment.redirection_after_login |
90 | end | 78 | end |
@@ -128,26 +116,6 @@ class ExternalPerson < ActiveRecord::Base | @@ -128,26 +116,6 @@ class ExternalPerson < ActiveRecord::Base | ||
128 | "#{jid(options)}/#{self.name}" | 116 | "#{jid(options)}/#{self.name}" |
129 | end | 117 | end |
130 | 118 | ||
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 | def data_hash(gravatar_default = nil) | 119 | def data_hash(gravatar_default = nil) |
152 | friends_list = {} | 120 | friends_list = {} |
153 | { | 121 | { |
@@ -0,0 +1,171 @@ | @@ -0,0 +1,171 @@ | ||
1 | +class ExternalProfile < ActiveRecord::Base | ||
2 | + | ||
3 | + include Followable | ||
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/20160829170524_rename_external_people_to_external_profiles.rb
0 → 100644
db/migrate/20160829185118_add_type_to_external_profile.rb
0 → 100644