diff --git a/app/models/concerns/human.rb b/app/models/concerns/human.rb index e9e7f90..d67c266 100644 --- a/app/models/concerns/human.rb +++ b/app/models/concerns/human.rb @@ -30,4 +30,13 @@ module Human AbuseComplaint.finished.where(:requestor_id => self).count > 0 end + # Sets the identifier for this person. Raises an exception when called on a + # existing person (since peoples' identifiers cannot be changed) + def identifier=(value) + unless self.new_record? + raise ArgumentError.new(_('An existing person cannot be renamed.')) + end + self[:identifier] = value + end + end diff --git a/app/models/external_person.rb b/app/models/external_person.rb index d15d33a..7e9a11e 100644 --- a/app/models/external_person.rb +++ b/app/models/external_person.rb @@ -32,7 +32,7 @@ class ExternalPerson < ActiveRecord::Base end def url - "http://#{self.source}/#{self.identifier}" + "http://#{self.source}/profile/#{self.identifier}" end alias :public_profile_url :url @@ -41,6 +41,9 @@ class ExternalPerson < ActiveRecord::Base "http://#{self.source}/myprofile/#{self.identifier}" end + def wall_url + self.url + end def tasks_url self.url end @@ -104,6 +107,14 @@ class ExternalPerson < ActiveRecord::Base [self.contact_email] end + def email_domain + self.source + end + + def email_addresses + ['%s@%s' % [self.identifier, self.source] ] + end + def jid(options = {}) "#{self.identifier}@#{self.source}" end @@ -151,26 +162,65 @@ class ExternalPerson < ActiveRecord::Base # External Person should respond to all methods in Person and Profile def person_instance_methods - {} + methods_and_responses = { + enterprises: Enterprise.none, communities: Community.none, friends: + Person.none, memberships: Profile.none, friendships: Person.none, + following_articles: Article.none, article_followers: ArticleFollower.none, + requested_tasks: Task.none, mailings: Mailing.none, scraps_sent: + Scrap.none, favorite_enterprise_people: FavoriteEnterprisePerson.none, + favorite_enterprises: Enterprise.none, acepted_forums: Forum.none, + articles_with_access: Article.none, suggested_profiles: + ProfileSuggestion.none, suggested_people: ProfileSuggestion.none, + suggested_communities: ProfileSuggestion.none, user: nil, + refused_communities: Community.none, has_permission?: false, + has_permission_with_admin?: false, has_permission_without_admin?: false, + has_permission_with_plugins?: false, has_permission_without_plugins?: + false, memberships_by_role: Person.none, can_change_homepage?: false, + can_control_scrap?: false, receives_scrap_notification?: false, + can_control_activity?: false, can_post_content?: false, + suggested_friend_groups: [], friend_groups: [], add_friend: nil, + already_request_friendship?: false, remove_friend: nil, + presence_of_required_fields: nil, active_fields: [], required_fields: [], + signup_fields: [], default_set_of_blocks: [], default_set_of_boxes: [], + default_set_of_articles: [], cell_phone: nil, comercial_phone: nil, + nationality: nil, schooling: nil, contact_information: nil, sex: nil, + birth_date: nil, jabber_id: nil, personal_website: nil, address_reference: + nil, district: nil, schooling_status: nil, formation: nil, + custom_formation: nil, area_of_study: nil, custom_area_of_study: nil, + professional_activity: nil, organization_website: nil, organization: nil, + photo: nil, city: nil, state: nil, country: nil, zip_code: nil, + address_line2: nil, copy_communities_from: nil, + has_organization_pending_tasks?: false, organizations_with_pending_tasks: + Organization.none, pending_tasks_for_organization: Task.none, + build_contact: nil, is_a_friend?: false, ask_to_join?: false, refuse_join: + nil, blocks_to_expire_cache: [], cache_keys: [], communities_cache_key: '', + friends_cache_key: '', manage_friends_cache_key: '', + relationships_cache_key: '', is_member_of?: false, follows?: false, + each_friend: nil, is_last_admin?: false, is_last_admin_leaving?: false, + leave: nil, last_notification: nil, notification_time: 0, notifier: nil, + remove_suggestion: nil, allow_invitation_from?: false + } + + derivated_methods = generate_derivated_methods(methods_and_responses) + derivated_methods.merge(methods_and_responses) end def profile_instance_methods methods_and_responses = { role_assignments: RoleAssignment.none, favorite_enterprises: - Enterprise.none, enterprises: Enterprise.none, memberships: Profile.none, - friendships: Profile.none, friends: Profile.none, tasks: Task.none, - suggested_profiles: ProfileSuggestion.none, suggested_people: - ProfileSuggestion.none, suggested_communities: ProfileSuggestion.none, - public_profile: true, nickname: nil, custom_footer: '', custom_header: '', - address: '', zip_code: '', contact_phone: '', image_builder: nil, - description: '', closed: false, template_id: nil, lat: nil, lng: nil, - is_template: false, fields_privacy: {}, preferred_domain_id: nil, - category_ids: [], country: '', city: '', state: '', national_region_code: - '', redirect_l10n: false, notification_time: 0, custom_url_redirection: - nil, email_suggestions: false, allow_members_to_invite: false, - invite_friends_only: false, secret: false, profile_admin_mail_notification: - false, redirection_after_login: nil, profile_activities: - ProfileActivity.none, action_tracker_notifications: + Enterprise.none, memberships: Profile.none, friendships: Profile.none, + tasks: Task.none, suggested_profiles: ProfileSuggestion.none, + suggested_people: ProfileSuggestion.none, suggested_communities: + ProfileSuggestion.none, public_profile: true, nickname: nil, custom_footer: + '', custom_header: '', address: '', zip_code: '', contact_phone: '', + image_builder: nil, description: '', closed: false, template_id: nil, lat: + nil, lng: nil, is_template: false, fields_privacy: {}, preferred_domain_id: + nil, category_ids: [], country: '', city: '', state: '', + national_region_code: '', redirect_l10n: false, notification_time: 0, + custom_url_redirection: nil, email_suggestions: false, + allow_members_to_invite: false, invite_friends_only: false, secret: false, + profile_admin_mail_notification: false, redirection_after_login: nil, + profile_activities: ProfileActivity.none, action_tracker_notifications: ActionTrackerNotification.none, tracked_notifications: ActionTracker::Record.none, scraps_received: Scrap.none, template: Profile.none, comments_received: Comment.none, email_templates: @@ -208,11 +258,7 @@ class ExternalPerson < ActiveRecord::Base already_request_friendship?: false } - derivated_methods = {} - methods_and_responses.keys.each do |method| - derivated_methods[method.to_s.insert(-1, '?').to_sym] = false - derivated_methods[method.to_s.insert(-1, '=').to_sym] = nil - end + derivated_methods = generate_derivated_methods(methods_and_responses) derivated_methods.merge(methods_and_responses) end @@ -230,4 +276,15 @@ class ExternalPerson < ActiveRecord::Base profile_instance_methods.keys.include?(method_name) || super end + + private + + def generate_derivated_methods(methods) + derivated_methods = {} + methods.keys.each do |method| + derivated_methods[method.to_s.insert(-1, '?').to_sym] = false + derivated_methods[method.to_s.insert(-1, '=').to_sym] = nil + end + derivated_methods + end end diff --git a/app/models/person.rb b/app/models/person.rb index 3c06f1f..dcf9059 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -164,15 +164,6 @@ class Person < Profile (self.has_permission?('post_content', profile) || self.has_permission?('publish_content', profile)) end - # Sets the identifier for this person. Raises an exception when called on a - # existing person (since peoples' identifiers cannot be changed) - def identifier=(value) - unless self.new_record? - raise ArgumentError.new(_('An existing person cannot be renamed.')) - end - self[:identifier] = value - end - def suggested_friend_groups (friend_groups.compact + [ _('friends'), _('work'), _('school'), _('family') ]).map {|i| i if !i.empty?}.compact.uniq end diff --git a/test/unit/external_person_test.rb b/test/unit/external_person_test.rb index fe62e3b..a88a578 100644 --- a/test/unit/external_person_test.rb +++ b/test/unit/external_person_test.rb @@ -65,41 +65,43 @@ class ExternalPersonTest < ActiveSupport::TestCase end should 'have an avatar from its original environment' do - assert_match /http:\/\/#{@external_person.source}\/.*/, @external_person.avatar + assert_match(/http:\/\/#{@external_person.source}\/.*/, @external_person.avatar) end should 'generate a custom profile icon based on its avatar' do + skip end should 'have an url to its profile on its original environment' do + skip end should 'have a public profile url' do + skip end should 'have an admin url to its profile on its original environment' do - end - - should 'respond to lat and lng' do - assert_respond_to ExternalPerson.new, :lat - assert_respond_to ExternalPerson.new, :lng - assert_nil @external_person.lat - assert_nil @external_person.lng + skip end should 'never be a friend of another person' do + skip end should 'never send a friend request to another person' do + skip end should 'not follow another profile' do + skip end should 'have an image' do + skip end should 'profile image has public filename and mimetype' do + skip end should 'respond to all instance methods in Profile' do @@ -112,4 +114,13 @@ class ExternalPersonTest < ActiveSupport::TestCase end end + should 'respond to all instance methods in Person' do + methods = Person.public_instance_methods(false) + methods.each do |method| + # We test if ExternalPerson responds to same methods as Person, but we + # skip methods generated by plugins, libs and validations, which are + # usually only used internally + assert_respond_to ExternalPerson.new, method.to_sym unless method =~ /^autosave_.*|validate_.*|^before_.*|^after_.*|^assignment_.*|^(city|state)_.*/ + end + end end -- libgit2 0.21.2