diff --git a/app/models/concerns/profile_entity.rb b/app/models/concerns/profile_entity.rb
index 16541c0..47bc029 100644
--- a/app/models/concerns/profile_entity.rb
+++ b/app/models/concerns/profile_entity.rb
@@ -12,6 +12,8 @@ module ProfileEntity
before_create :set_default_environment
+ scope :recent, -> limit=nil { order('id DESC').limit(limit) }
+
end
def disable
@@ -65,4 +67,77 @@ module ProfileEntity
end
end
+ def to_liquid
+ HashWithIndifferentAccess.new :name => name, :identifier => identifier
+ end
+
+ # Tells whether a specified profile has members or nor.
+ #
+ # On this class, returns false by default.
+ def has_members?
+ false
+ end
+
+ def apply_type_specific_template(template)
+ end
+
+ # Override this method in subclasses of Profile to create a default article
+ # set upon creation. Note that this method will be called *only* if there is
+ # no template for the type of profile (i.e. if the template was removed or in
+ # the creation of the template itself).
+ #
+ # This method must return an array of pre-populated articles, which will be
+ # associated to the profile before being saved. Example:
+ #
+ # def default_set_of_articles
+ # [Blog.new(:name => 'Blog'), Gallery.new(:name => 'Gallery')]
+ # end
+ #
+ # By default, this method returns an empty array.
+ def default_set_of_articles
+ []
+ end
+
+ def blocks_to_expire_cache
+ []
+ end
+
+ def cache_keys(params = {})
+ []
+ end
+
+ def members_cache_key(params = {})
+ page = params[:npage] || '1'
+ sort = (params[:sort] == 'desc') ? params[:sort] : 'asc'
+ cache_key + '-members-page-' + page + '-' + sort
+ end
+
+ def more_recent_label
+ _("Since: ")
+ end
+
+ def control_panel_settings_button
+ {:title => _('Edit Profile'), :icon => 'edit-profile'}
+ end
+
+ def control_panel_settings_button
+ {:title => _('Profile Info and settings'), :icon => 'edit-profile'}
+ end
+
+ def exclude_verbs_on_activities
+ %w[]
+ end
+
+ def allow_invitation_from(person)
+ false
+ end
+
+ module ClassMethods
+
+ def identification
+ name
+ end
+
+ end
+
end
diff --git a/app/models/external_person.rb b/app/models/external_person.rb
index 0e972b6..d15d33a 100644
--- a/app/models/external_person.rb
+++ b/app/models/external_person.rb
@@ -23,87 +23,92 @@ class ExternalPerson < ActiveRecord::Base
user
end
- def url
- "http://#{self.source}/#{self.identifier}"
+ def privacy_setting
+ _('Public profile')
end
- alias :public_profile_url :url
-
def avatar
"http://#{self.source}/profile/#{self.identifier}/icon/"
end
+ def url
+ "http://#{self.source}/#{self.identifier}"
+ end
+
+ alias :public_profile_url :url
+
def admin_url
"http://#{self.source}/myprofile/#{self.identifier}"
end
- def profile_custom_icon(gravatar_default=nil)
- self.avatar
+ def tasks_url
+ self.url
end
-
- def preferred_login_redirection
- environment.redirection_after_login
+ def leave_url(reload = false)
+ self.url
end
-
- def person?
- true
+ def join_url
+ self.url
end
-
- def is_admin?(environment = nil)
- false
+ def join_not_logged_url
+ self.url
end
-
- def lat
- nil
+ def check_membership_url
+ self.url
end
- def lng
- nil
+ def add_url
+ self.url
end
-
- def role_assignments
- RoleAssignment.none
+ def check_friendship_url
+ self.url
end
-
- def favorite_enterprises
- Enterprise.none
+ def people_suggestions_url
+ self.url
end
-
- def memberships
- Profile.none
+ def communities_suggestions_url
+ self.url
+ end
+ def top_url(scheme = 'http')
+ "#{scheme}://#{self.source}"
end
- def friendships
- Profile.none
+ def profile_custom_icon(gravatar_default=nil)
+ self.avatar
end
- def tasks
- Task.none
+ def preferred_login_redirection
+ environment.redirection_after_login
end
- def suggested_profiles
- ProfileSuggestion.none
+ def location
+ self.source
end
- def suggested_people
- ProfileSuggestion.none
+
+ def default_hostname
+ environment.default_hostname
end
- def suggested_communities
- ProfileSuggestion.none
+
+ def possible_domains
+ environment.domains
end
- def add_friend(friend, group = nil)
- false
+ def person?
+ true
end
- def follows?(profile)
- false
+ def contact_email(*args)
+ self.email
end
- def is_a_friend?(person)
- false
+ def notification_emails
+ [self.contact_email]
end
- def already_request_friendship?(person)
- false
+ def jid(options = {})
+ "#{self.identifier}@#{self.source}"
+ end
+ def full_jid(options = {})
+ "#{jid(options)}/#{self.name}"
end
class ExternalPerson::Image
@@ -126,18 +131,6 @@ class ExternalPerson < ActiveRecord::Base
ExternalPerson::Image.new(avatar)
end
- def is_template?
- false
- end
-
- def enterprises
- []
- end
-
- def friends
- []
- end
-
def data_hash(gravatar_default = nil)
friends_list = {}
{
@@ -155,4 +148,86 @@ class ExternalPerson < ActiveRecord::Base
'chat_enabled' => false
}
end
+
+ # External Person should respond to all methods in Person and Profile
+ def person_instance_methods
+ {}
+ 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:
+ ActionTrackerNotification.none, tracked_notifications:
+ ActionTracker::Record.none, scraps_received: Scrap.none, template:
+ Profile.none, comments_received: Comment.none, email_templates:
+ EmailTemplate.none, members: Profile.none, members_like: Profile.none,
+ members_by: Profile.none, members_by_role: Profile.none, scraps:
+ Scrap.none, welcome_page_content: nil, settings: {}, find_in_all_tasks:
+ nil, top_level_categorization: {}, interests: Category.none, geolocation:
+ '', country_name: '', pending_categorizations: [], add_category: false,
+ create_pending_categorizations: false, top_level_articles: Article.none,
+ valid_identifier: true, valid_template: false, create_default_set_of_boxes:
+ true, copy_blocks_from: nil, default_template: nil,
+ template_without_default: nil, template_with_default: nil, apply_template:
+ false, iframe_whitelist: [], recent_documents: Article.none, last_articles:
+ Article.none, is_validation_entity?: false, hostname: nil, own_hostname:
+ nil, article_tags: {}, tagged_with: Article.none,
+ insert_default_article_set: false, copy_articles_from: true,
+ copy_article_tree: nil, copy_article?: false, add_member: false,
+ remove_member: false, add_admin: false, remove_admin: false, add_moderator:
+ false, display_info_to?: true, update_category_from_region: nil,
+ accept_category?: false, custom_header_expanded: '',
+ custom_footer_expanded: '', public?: true, themes: [], find_theme: nil,
+ blogs: Blog.none, blog: nil, has_blog?: false, forums: Forum.none, forum:
+ nil, has_forum?: false, admins: [], settings_field: {}, setting_changed:
+ false, public_content: true, enable_contact?: false, folder_types: [],
+ folders: Article.none, image_galleries: Article.none, image_valid: true,
+ update_header_and_footer: nil, update_theme: nil, update_layout_template:
+ nil, recent_actions: ActionTracker::Record.none, recent_notifications:
+ ActionTracker::Record.none, more_active_label: _('no activity'),
+ more_popular_label: _('no members'), profile_custom_image: nil,
+ is_on_homepage?: false, activities: ProfileActivity.none,
+ may_display_field_to?: true, may_display_location_to?: true, public_fields:
+ {}, followed_by?: false, display_private_info_to?: true, can_view_field?:
+ true, remove_from_suggestion_list: nil, layout_template: 'default',
+ is_admin?: false, add_friend: false, follows?: false, is_a_friend?: false,
+ 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.merge(methods_and_responses)
+ end
+
+ def method_missing(method, *args, &block)
+ if person_instance_methods.keys.include?(method)
+ return person_instance_methods[method]
+ end
+ if profile_instance_methods.keys.include? method
+ return profile_instance_methods[method]
+ end
+ end
+
+ def respond_to_missing?(method_name, include_private = false)
+ person_instance_methods.keys.include?(method_name) ||
+ profile_instance_methods.keys.include?(method_name) ||
+ super
+ end
end
diff --git a/app/models/profile.rb b/app/models/profile.rb
index d44d8aa..7686f89 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -116,8 +116,6 @@ class Profile < ApplicationRecord
}
scope :no_templates, -> { where is_template: false }
- scope :recent, -> limit=nil { order('id DESC').limit(limit) }
-
# Returns a scoped object to select profiles in a given location or in a radius
# distance from the given location center.
@@ -483,9 +481,6 @@ class Profile < ApplicationRecord
self.save(:validate => false)
end
- def apply_type_specific_template(template)
- end
-
xss_terminate :only => [ :name, :nickname, :address, :contact_phone, :description ], :on => 'validation'
xss_terminate :only => [ :custom_footer, :custom_header ], :with => 'white_list'
@@ -526,10 +521,6 @@ class Profile < ApplicationRecord
).order('articles.published_at desc, articles.id desc')
end
- def to_liquid
- HashWithIndifferentAccess.new :name => name, :identifier => identifier
- end
-
class << self
# finds a profile by its identifier. This method is a shortcut to
@@ -653,13 +644,6 @@ private :generate_url, :url_options
self.articles.tagged_with(tag)
end
- # Tells whether a specified profile has members or nor.
- #
- # On this class, returns false by default.
- def has_members?
- false
- end
-
after_create :insert_default_article_set
def insert_default_article_set
if template
@@ -674,23 +658,6 @@ private :generate_url, :url_options
end
end
- # Override this method in subclasses of Profile to create a default article
- # set upon creation. Note that this method will be called *only* if there is
- # no template for the type of profile (i.e. if the template was removed or in
- # the creation of the template itself).
- #
- # This method must return an array of pre-populated articles, which will be
- # associated to the profile before being saved. Example:
- #
- # def default_set_of_articles
- # [Blog.new(:name => 'Blog'), Gallery.new(:name => 'Gallery')]
- # end
- #
- # By default, this method returns an empty array.
- def default_set_of_articles
- []
- end
-
def copy_articles_from other
return false if other.top_level_articles.empty?
other.top_level_articles.each do |a|
@@ -891,14 +858,6 @@ private :generate_url, :url_options
articles.galleries
end
- def blocks_to_expire_cache
- []
- end
-
- def cache_keys(params = {})
- []
- end
-
validate :image_valid
def image_valid
@@ -935,16 +894,6 @@ private :generate_url, :url_options
self.update_attribute(:layout_template, template)
end
- def members_cache_key(params = {})
- page = params[:npage] || '1'
- sort = (params[:sort] == 'desc') ? params[:sort] : 'asc'
- cache_key + '-members-page-' + page + '-' + sort
- end
-
- def more_recent_label
- _("Since: ")
- end
-
def recent_actions
tracked_actions.recent
end
@@ -999,18 +948,6 @@ private :generate_url, :url_options
end
end
- def control_panel_settings_button
- {:title => _('Edit Profile'), :icon => 'edit-profile'}
- end
-
- def self.identification
- name
- end
-
- def exclude_verbs_on_activities
- %w[]
- end
-
# Customize in subclasses
def activities
self.profile_activities.includes(:activity).order('updated_at DESC')
@@ -1045,10 +982,6 @@ private :generate_url, :url_options
self.active_fields
end
- def control_panel_settings_button
- {:title => _('Profile Info and settings'), :icon => 'edit-profile'}
- end
-
def followed_by?(person)
person.is_member_of?(self)
end
@@ -1076,8 +1009,4 @@ private :generate_url, :url_options
suggestion.disable if suggestion
end
- def allow_invitation_from(person)
- false
- end
-
end
diff --git a/test/unit/external_person_test.rb b/test/unit/external_person_test.rb
index fe6c127..fe62e3b 100644
--- a/test/unit/external_person_test.rb
+++ b/test/unit/external_person_test.rb
@@ -1,7 +1,7 @@
# encoding: UTF-8
require_relative "../test_helper"
-class PersonTest < ActiveSupport::TestCase
+class ExternalPersonTest < ActiveSupport::TestCase
fixtures :environments
def setup
@@ -101,4 +101,15 @@ class PersonTest < ActiveSupport::TestCase
should 'profile image has public filename and mimetype' do
end
+
+ should 'respond to all instance methods in Profile' do
+ methods = Profile.public_instance_methods(false)
+ methods.each do |method|
+ # We test if ExternalPerson responds to same methods as Profile, 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 =~ /type_name|^autosave_.*|^after_.*|^before_.*|validate_.*|^attribute_.*|.*_?tags?_?.*|^custom_value.*|^custom_context.*|^xss.*|bar/
+ end
+ end
+
end
--
libgit2 0.21.2