Commit ea63d985701f93a8d4cc8bc5454a998642af8ce7
1 parent
4bcc8485
Exists in
federation-webfinger
Makes ExternalProfile respond to all Person methods to avoid breakage
Showing
4 changed files
with
106 additions
and
38 deletions
Show diff stats
app/models/concerns/human.rb
@@ -30,4 +30,13 @@ module Human | @@ -30,4 +30,13 @@ module Human | ||
30 | AbuseComplaint.finished.where(:requestor_id => self).count > 0 | 30 | AbuseComplaint.finished.where(:requestor_id => self).count > 0 |
31 | end | 31 | end |
32 | 32 | ||
33 | + # Sets the identifier for this person. Raises an exception when called on a | ||
34 | + # existing person (since peoples' identifiers cannot be changed) | ||
35 | + def identifier=(value) | ||
36 | + unless self.new_record? | ||
37 | + raise ArgumentError.new(_('An existing person cannot be renamed.')) | ||
38 | + end | ||
39 | + self[:identifier] = value | ||
40 | + end | ||
41 | + | ||
33 | end | 42 | end |
app/models/external_person.rb
@@ -32,7 +32,7 @@ class ExternalPerson < ActiveRecord::Base | @@ -32,7 +32,7 @@ class ExternalPerson < ActiveRecord::Base | ||
32 | end | 32 | end |
33 | 33 | ||
34 | def url | 34 | def url |
35 | - "http://#{self.source}/#{self.identifier}" | 35 | + "http://#{self.source}/profile/#{self.identifier}" |
36 | end | 36 | end |
37 | 37 | ||
38 | alias :public_profile_url :url | 38 | alias :public_profile_url :url |
@@ -41,6 +41,9 @@ class ExternalPerson < ActiveRecord::Base | @@ -41,6 +41,9 @@ class ExternalPerson < ActiveRecord::Base | ||
41 | "http://#{self.source}/myprofile/#{self.identifier}" | 41 | "http://#{self.source}/myprofile/#{self.identifier}" |
42 | end | 42 | end |
43 | 43 | ||
44 | + def wall_url | ||
45 | + self.url | ||
46 | + end | ||
44 | def tasks_url | 47 | def tasks_url |
45 | self.url | 48 | self.url |
46 | end | 49 | end |
@@ -104,6 +107,14 @@ class ExternalPerson < ActiveRecord::Base | @@ -104,6 +107,14 @@ class ExternalPerson < ActiveRecord::Base | ||
104 | [self.contact_email] | 107 | [self.contact_email] |
105 | end | 108 | end |
106 | 109 | ||
110 | + def email_domain | ||
111 | + self.source | ||
112 | + end | ||
113 | + | ||
114 | + def email_addresses | ||
115 | + ['%s@%s' % [self.identifier, self.source] ] | ||
116 | + end | ||
117 | + | ||
107 | def jid(options = {}) | 118 | def jid(options = {}) |
108 | "#{self.identifier}@#{self.source}" | 119 | "#{self.identifier}@#{self.source}" |
109 | end | 120 | end |
@@ -151,26 +162,65 @@ class ExternalPerson < ActiveRecord::Base | @@ -151,26 +162,65 @@ class ExternalPerson < ActiveRecord::Base | ||
151 | 162 | ||
152 | # External Person should respond to all methods in Person and Profile | 163 | # External Person should respond to all methods in Person and Profile |
153 | def person_instance_methods | 164 | def person_instance_methods |
154 | - {} | 165 | + methods_and_responses = { |
166 | + enterprises: Enterprise.none, communities: Community.none, friends: | ||
167 | + Person.none, memberships: Profile.none, friendships: Person.none, | ||
168 | + following_articles: Article.none, article_followers: ArticleFollower.none, | ||
169 | + requested_tasks: Task.none, mailings: Mailing.none, scraps_sent: | ||
170 | + Scrap.none, favorite_enterprise_people: FavoriteEnterprisePerson.none, | ||
171 | + favorite_enterprises: Enterprise.none, acepted_forums: Forum.none, | ||
172 | + articles_with_access: Article.none, suggested_profiles: | ||
173 | + ProfileSuggestion.none, suggested_people: ProfileSuggestion.none, | ||
174 | + suggested_communities: ProfileSuggestion.none, user: nil, | ||
175 | + refused_communities: Community.none, has_permission?: false, | ||
176 | + has_permission_with_admin?: false, has_permission_without_admin?: false, | ||
177 | + has_permission_with_plugins?: false, has_permission_without_plugins?: | ||
178 | + false, memberships_by_role: Person.none, can_change_homepage?: false, | ||
179 | + can_control_scrap?: false, receives_scrap_notification?: false, | ||
180 | + can_control_activity?: false, can_post_content?: false, | ||
181 | + suggested_friend_groups: [], friend_groups: [], add_friend: nil, | ||
182 | + already_request_friendship?: false, remove_friend: nil, | ||
183 | + presence_of_required_fields: nil, active_fields: [], required_fields: [], | ||
184 | + signup_fields: [], default_set_of_blocks: [], default_set_of_boxes: [], | ||
185 | + default_set_of_articles: [], cell_phone: nil, comercial_phone: nil, | ||
186 | + nationality: nil, schooling: nil, contact_information: nil, sex: nil, | ||
187 | + birth_date: nil, jabber_id: nil, personal_website: nil, address_reference: | ||
188 | + nil, district: nil, schooling_status: nil, formation: nil, | ||
189 | + custom_formation: nil, area_of_study: nil, custom_area_of_study: nil, | ||
190 | + professional_activity: nil, organization_website: nil, organization: nil, | ||
191 | + photo: nil, city: nil, state: nil, country: nil, zip_code: nil, | ||
192 | + address_line2: nil, copy_communities_from: nil, | ||
193 | + has_organization_pending_tasks?: false, organizations_with_pending_tasks: | ||
194 | + Organization.none, pending_tasks_for_organization: Task.none, | ||
195 | + build_contact: nil, is_a_friend?: false, ask_to_join?: false, refuse_join: | ||
196 | + nil, blocks_to_expire_cache: [], cache_keys: [], communities_cache_key: '', | ||
197 | + friends_cache_key: '', manage_friends_cache_key: '', | ||
198 | + relationships_cache_key: '', is_member_of?: false, follows?: false, | ||
199 | + each_friend: nil, is_last_admin?: false, is_last_admin_leaving?: false, | ||
200 | + leave: nil, last_notification: nil, notification_time: 0, notifier: nil, | ||
201 | + remove_suggestion: nil, allow_invitation_from?: false | ||
202 | + } | ||
203 | + | ||
204 | + derivated_methods = generate_derivated_methods(methods_and_responses) | ||
205 | + derivated_methods.merge(methods_and_responses) | ||
155 | end | 206 | end |
156 | 207 | ||
157 | def profile_instance_methods | 208 | def profile_instance_methods |
158 | methods_and_responses = { | 209 | methods_and_responses = { |
159 | role_assignments: RoleAssignment.none, favorite_enterprises: | 210 | role_assignments: RoleAssignment.none, favorite_enterprises: |
160 | - Enterprise.none, enterprises: Enterprise.none, memberships: Profile.none, | ||
161 | - friendships: Profile.none, friends: Profile.none, tasks: Task.none, | ||
162 | - suggested_profiles: ProfileSuggestion.none, suggested_people: | ||
163 | - ProfileSuggestion.none, suggested_communities: ProfileSuggestion.none, | ||
164 | - public_profile: true, nickname: nil, custom_footer: '', custom_header: '', | ||
165 | - address: '', zip_code: '', contact_phone: '', image_builder: nil, | ||
166 | - description: '', closed: false, template_id: nil, lat: nil, lng: nil, | ||
167 | - is_template: false, fields_privacy: {}, preferred_domain_id: nil, | ||
168 | - category_ids: [], country: '', city: '', state: '', national_region_code: | ||
169 | - '', redirect_l10n: false, notification_time: 0, custom_url_redirection: | ||
170 | - nil, email_suggestions: false, allow_members_to_invite: false, | ||
171 | - invite_friends_only: false, secret: false, profile_admin_mail_notification: | ||
172 | - false, redirection_after_login: nil, profile_activities: | ||
173 | - ProfileActivity.none, action_tracker_notifications: | 211 | + Enterprise.none, memberships: Profile.none, friendships: Profile.none, |
212 | + tasks: Task.none, suggested_profiles: ProfileSuggestion.none, | ||
213 | + suggested_people: ProfileSuggestion.none, suggested_communities: | ||
214 | + ProfileSuggestion.none, public_profile: true, nickname: nil, custom_footer: | ||
215 | + '', custom_header: '', address: '', zip_code: '', contact_phone: '', | ||
216 | + image_builder: nil, description: '', closed: false, template_id: nil, lat: | ||
217 | + nil, lng: nil, is_template: false, fields_privacy: {}, preferred_domain_id: | ||
218 | + nil, category_ids: [], country: '', city: '', state: '', | ||
219 | + national_region_code: '', redirect_l10n: false, notification_time: 0, | ||
220 | + custom_url_redirection: nil, email_suggestions: false, | ||
221 | + allow_members_to_invite: false, invite_friends_only: false, secret: false, | ||
222 | + profile_admin_mail_notification: false, redirection_after_login: nil, | ||
223 | + profile_activities: ProfileActivity.none, action_tracker_notifications: | ||
174 | ActionTrackerNotification.none, tracked_notifications: | 224 | ActionTrackerNotification.none, tracked_notifications: |
175 | ActionTracker::Record.none, scraps_received: Scrap.none, template: | 225 | ActionTracker::Record.none, scraps_received: Scrap.none, template: |
176 | Profile.none, comments_received: Comment.none, email_templates: | 226 | Profile.none, comments_received: Comment.none, email_templates: |
@@ -208,11 +258,7 @@ class ExternalPerson < ActiveRecord::Base | @@ -208,11 +258,7 @@ class ExternalPerson < ActiveRecord::Base | ||
208 | already_request_friendship?: false | 258 | already_request_friendship?: false |
209 | } | 259 | } |
210 | 260 | ||
211 | - derivated_methods = {} | ||
212 | - methods_and_responses.keys.each do |method| | ||
213 | - derivated_methods[method.to_s.insert(-1, '?').to_sym] = false | ||
214 | - derivated_methods[method.to_s.insert(-1, '=').to_sym] = nil | ||
215 | - end | 261 | + derivated_methods = generate_derivated_methods(methods_and_responses) |
216 | derivated_methods.merge(methods_and_responses) | 262 | derivated_methods.merge(methods_and_responses) |
217 | end | 263 | end |
218 | 264 | ||
@@ -230,4 +276,15 @@ class ExternalPerson < ActiveRecord::Base | @@ -230,4 +276,15 @@ class ExternalPerson < ActiveRecord::Base | ||
230 | profile_instance_methods.keys.include?(method_name) || | 276 | profile_instance_methods.keys.include?(method_name) || |
231 | super | 277 | super |
232 | end | 278 | end |
279 | + | ||
280 | + private | ||
281 | + | ||
282 | + def generate_derivated_methods(methods) | ||
283 | + derivated_methods = {} | ||
284 | + methods.keys.each do |method| | ||
285 | + derivated_methods[method.to_s.insert(-1, '?').to_sym] = false | ||
286 | + derivated_methods[method.to_s.insert(-1, '=').to_sym] = nil | ||
287 | + end | ||
288 | + derivated_methods | ||
289 | + end | ||
233 | end | 290 | end |
app/models/person.rb
@@ -164,15 +164,6 @@ class Person < Profile | @@ -164,15 +164,6 @@ class Person < Profile | ||
164 | (self.has_permission?('post_content', profile) || self.has_permission?('publish_content', profile)) | 164 | (self.has_permission?('post_content', profile) || self.has_permission?('publish_content', profile)) |
165 | end | 165 | end |
166 | 166 | ||
167 | - # Sets the identifier for this person. Raises an exception when called on a | ||
168 | - # existing person (since peoples' identifiers cannot be changed) | ||
169 | - def identifier=(value) | ||
170 | - unless self.new_record? | ||
171 | - raise ArgumentError.new(_('An existing person cannot be renamed.')) | ||
172 | - end | ||
173 | - self[:identifier] = value | ||
174 | - end | ||
175 | - | ||
176 | def suggested_friend_groups | 167 | def suggested_friend_groups |
177 | (friend_groups.compact + [ _('friends'), _('work'), _('school'), _('family') ]).map {|i| i if !i.empty?}.compact.uniq | 168 | (friend_groups.compact + [ _('friends'), _('work'), _('school'), _('family') ]).map {|i| i if !i.empty?}.compact.uniq |
178 | end | 169 | end |
test/unit/external_person_test.rb
@@ -65,41 +65,43 @@ class ExternalPersonTest < ActiveSupport::TestCase | @@ -65,41 +65,43 @@ class ExternalPersonTest < ActiveSupport::TestCase | ||
65 | end | 65 | end |
66 | 66 | ||
67 | should 'have an avatar from its original environment' do | 67 | should 'have an avatar from its original environment' do |
68 | - assert_match /http:\/\/#{@external_person.source}\/.*/, @external_person.avatar | 68 | + assert_match(/http:\/\/#{@external_person.source}\/.*/, @external_person.avatar) |
69 | end | 69 | end |
70 | 70 | ||
71 | should 'generate a custom profile icon based on its avatar' do | 71 | should 'generate a custom profile icon based on its avatar' do |
72 | + skip | ||
72 | end | 73 | end |
73 | 74 | ||
74 | should 'have an url to its profile on its original environment' do | 75 | should 'have an url to its profile on its original environment' do |
76 | + skip | ||
75 | end | 77 | end |
76 | 78 | ||
77 | should 'have a public profile url' do | 79 | should 'have a public profile url' do |
80 | + skip | ||
78 | end | 81 | end |
79 | 82 | ||
80 | should 'have an admin url to its profile on its original environment' do | 83 | should 'have an admin url to its profile on its original environment' do |
81 | - end | ||
82 | - | ||
83 | - should 'respond to lat and lng' do | ||
84 | - assert_respond_to ExternalPerson.new, :lat | ||
85 | - assert_respond_to ExternalPerson.new, :lng | ||
86 | - assert_nil @external_person.lat | ||
87 | - assert_nil @external_person.lng | 84 | + skip |
88 | end | 85 | end |
89 | 86 | ||
90 | should 'never be a friend of another person' do | 87 | should 'never be a friend of another person' do |
88 | + skip | ||
91 | end | 89 | end |
92 | 90 | ||
93 | should 'never send a friend request to another person' do | 91 | should 'never send a friend request to another person' do |
92 | + skip | ||
94 | end | 93 | end |
95 | 94 | ||
96 | should 'not follow another profile' do | 95 | should 'not follow another profile' do |
96 | + skip | ||
97 | end | 97 | end |
98 | 98 | ||
99 | should 'have an image' do | 99 | should 'have an image' do |
100 | + skip | ||
100 | end | 101 | end |
101 | 102 | ||
102 | should 'profile image has public filename and mimetype' do | 103 | should 'profile image has public filename and mimetype' do |
104 | + skip | ||
103 | end | 105 | end |
104 | 106 | ||
105 | should 'respond to all instance methods in Profile' do | 107 | should 'respond to all instance methods in Profile' do |
@@ -112,4 +114,13 @@ class ExternalPersonTest < ActiveSupport::TestCase | @@ -112,4 +114,13 @@ class ExternalPersonTest < ActiveSupport::TestCase | ||
112 | end | 114 | end |
113 | end | 115 | end |
114 | 116 | ||
117 | + should 'respond to all instance methods in Person' do | ||
118 | + methods = Person.public_instance_methods(false) | ||
119 | + methods.each do |method| | ||
120 | + # We test if ExternalPerson responds to same methods as Person, but we | ||
121 | + # skip methods generated by plugins, libs and validations, which are | ||
122 | + # usually only used internally | ||
123 | + assert_respond_to ExternalPerson.new, method.to_sym unless method =~ /^autosave_.*|validate_.*|^before_.*|^after_.*|^assignment_.*|^(city|state)_.*/ | ||
124 | + end | ||
125 | + end | ||
115 | end | 126 | end |