profile_entity.rb
2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
module ProfileEntity
extend ActiveSupport::Concern
included do
attr_accessible :name, :identifier, :environment
validates_presence_of :identifier, :name
belongs_to :environment
has_many :search_terms, :as => :context
has_many :abuse_complaints, :as => :reported, :foreign_key => 'requestor_id', :dependent => :destroy
before_create :set_default_environment
scope :recent, -> limit=nil { order('id DESC').limit(limit) }
end
def disable
self.visible = false
self.save
end
def enable
self.visible = true
self.save
end
def opened_abuse_complaint
abuse_complaints.opened.first
end
def set_default_environment
if self.environment.nil?
self.environment = Environment.default
end
true
end
# returns +false+
def person?
self.kind_of?(Person)
end
def enterprise?
self.kind_of?(Enterprise)
end
def organization?
self.kind_of?(Organization)
end
def community?
self.kind_of?(Community)
end
include ActionView::Helpers::TextHelper
def short_name(chars = 40)
if self[:nickname].blank?
if chars
truncate self.name, length: chars, omission: '...'
else
self.name
end
else
self[:nickname]
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 <tt>false</tt> 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