| Class | Environment |
| In: |
app/models/environment.rb
|
| Parent: | ActiveRecord::Base |
A Environment is like a website to be hosted in the platform. It may contain multiple Profile‘s and can be identified by several different domains.
returns the available features for a Environment, in the form of a hash, with pairs in the form ‘feature_name’ => ‘Feature name‘.
# File app/models/environment.rb, line 23
23: def self.available_features
24: {
25: 'disable_asset_articles' => _('Disable search for articles '),
26: 'disable_asset_enterprises' => __('Disable search for enterprises'),
27: 'disable_asset_people' => _('Disable search for people'),
28: 'disable_asset_communities' => __('Disable search for communities'),
29: 'disable_asset_products' => _('Disable search for products'),
30: 'disable_asset_events' => _('Disable search for events'),
31: 'disable_products_for_enterprises' => _('Disable products for enterprises'),
32: 'disable_categories' => _('Disable categories'),
33: }
34: end
the default Environment.
# File app/models/environment.rb, line 264
264: def self.default
265: self.find(:first, :conditions => [ 'is_default = ?', true ] )
266: end
# File app/models/environment.rb, line 158
158: def activation_blocked_text
159: self.settings['activation_blocked_text']
160: end
# File app/models/environment.rb, line 162
162: def activation_blocked_text= value
163: self.settings['activation_blocked_text'] = value
164: end
# File app/models/environment.rb, line 330
330: def community_template
331: Community.find_by_id settings[:community_template_id]
332: end
# File app/models/environment.rb, line 340
340: def create_templates
341: pre = self.name.to_slug + '_'
342: ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => self, :public_profile => false).id
343: com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => self, :public_profile => false).id
344: pass = Digest::MD5.hexdigest rand.to_s
345: user = User.create!(:login => (pre + 'person_template'), :email => (pre + 'template@template.noo'), :password => pass, :password_confirmation => pass, :environment => self).person
346: user.public_profile = false
347: user.save!
348: usr_id = user.id
349: self.settings[:enterprise_template_id] = ent_id
350: self.settings[:community_template_id] = com_id
351: self.settings[:person_template_id] = usr_id
352: self.save!
353: end
Returns the hostname of the first domain associated to this environment.
If force_www is true, adds ‘www.’ at the beginning of the hostname. If the environment has not associated domains, returns ‘localhost’.
# File app/models/environment.rb, line 277
277: def default_hostname(email_hostname = false)
278: if self.domains(true).empty?
279: 'localhost'
280: else
281: domain = self.domains.find(:first, :order => 'id').name
282: email_hostname ? domain : (force_www ? ('www.' + domain) : domain)
283: end
284: end
the description of the environment. Normally used in the homepage.
# File app/models/environment.rb, line 207
207: def description
208: self.settings[:description]
209: end
sets the description of the environment
# File app/models/environment.rb, line 212
212: def description=(value)
213: self.settings[:description] = value
214: end
Disables a feature identified by its name
# File app/models/environment.rb, line 101
101: def disable(feature)
102: self.settings["#{feature}_enabled"] = false
103: end
# File app/models/environment.rb, line 295
295: def disable_ssl
296: settings[:disable_ssl]
297: end
# File app/models/environment.rb, line 299
299: def disable_ssl=(value)
300: settings[:disable_ssl] = value
301: end
Enables a feature identified by its name
# File app/models/environment.rb, line 96
96: def enable(feature)
97: self.settings["#{feature}_enabled"] = true
98: end
Tells if a feature, identified by its name, is enabled
# File app/models/environment.rb, line 106
106: def enabled?(feature)
107: self.settings["#{feature}_enabled"] == true
108: end
enables the features identified by features, which is expected to be an Enumarable object containing the identifiers of the desired features. Passing nil is the same as passing an empty Array.
# File app/models/environment.rb, line 113
113: def enabled_features=(features)
114: features ||= []
115: self.class.available_features.keys.each do |feature|
116: if features.include? feature
117: self.enable(feature)
118: else
119: self.disable(feature)
120: end
121: end
122: end
# File app/models/environment.rb, line 326
326: def enterprise_template
327: Enterprise.find_by_id settings[:enterprise_template_id]
328: end
Whether this environment should force having ‘www.’ in its domain name or not. Defauls to false.
See also default_hostname
# File app/models/environment.rb, line 236
236: def force_www
237: settings[:force_www] || false
238: end
returns true if this Environment has terms of enterprise use to be accepted by users before registration or activation of enterprises.
# File app/models/environment.rb, line 154
154: def has_terms_of_enterprise_use?
155: ! self.settings['terms_of_enterprise_use'].blank?
156: end
returns true if this Environment has terms of use to be accepted by users before registration.
# File app/models/environment.rb, line 137
137: def has_terms_of_use?
138: ! self.settings['terms_of_use'].nil?
139: end
# File app/models/environment.rb, line 318
318: def layout_template
319: settings[:layout_template] || 'default'
320: end
# File app/models/environment.rb, line 322
322: def layout_template=(value)
323: settings[:layout_template] = value
324: end
# File app/models/environment.rb, line 166
166: def message_for_disabled_enterprise
167: self.settings['message_for_disabled_enterprise']
168: end
# File app/models/environment.rb, line 170
170: def message_for_disabled_enterprise=(value)
171: self.settings['message_for_disabled_enterprise'] = value
172: end
returns the approval method used for this environment. Possible values are:
Defaults to :admim.
# File app/models/environment.rb, line 177
177: def organization_approval_method
178: self.settings['organization_approval_method'] || :admin
179: end
Sets the organization_approval_method. Only accepts the following values:
Trying to set organization_approval_method to any other value will raise an ArgumentError.
The value passed as argument is converted to a Symbol before being actually set to this setting.
# File app/models/environment.rb, line 194
194: def organization_approval_method=(value)
195: actual_value = value.to_sym
196:
197: accepted_values = %w[
198: admin
199: region
200: ].map(&:to_sym)
201: raise ArgumentError unless accepted_values.include?(actual_value)
202:
203: self.settings['organization_approval_method'] = actual_value
204: end
# File app/models/environment.rb, line 334
334: def person_template
335: Person.find_by_id settings[:person_template_id]
336: end
# File app/models/environment.rb, line 308
308: def recent_documents(limit = 10)
309: self.articles.recent(limit)
310: end
returns a Hash containing the Environment configuration
# File app/models/environment.rb, line 91
91: def settings
92: self[:settings] ||= {}
93: end
# File app/models/environment.rb, line 216
216: def terminology
217: if self.settings[:terminology]
218: self.settings[:terminology].constantize.instance
219: else
220: Noosfero.terminology
221: end
222: end
# File app/models/environment.rb, line 224
224: def terminology=(value)
225: if value
226: self.settings[:terminology] = value.class.name
227: else
228: self.settings[:terminology] = nil
229: end
230: end
the environment‘s terms of enterprise use: every enterprise member must accept them before registering or activating enterprises.
# File app/models/environment.rb, line 143
143: def terms_of_enterprise_use
144: self.settings['terms_of_enterprise_use']
145: end
sets the environment‘s terms of enterprise use.
# File app/models/environment.rb, line 148
148: def terms_of_enterprise_use=(value)
149: self.settings['terms_of_enterprise_use'] = value
150: end
the environment‘s terms of use: every user must accept them before registering.
# File app/models/environment.rb, line 126
126: def terms_of_use
127: self.settings['terms_of_use']
128: end
sets the environment‘s terms of use.
# File app/models/environment.rb, line 131
131: def terms_of_use=(value)
132: self.settings['terms_of_use'] = value
133: end
returns an array with the top level categories for this environment.
# File app/models/environment.rb, line 269
269: def top_level_categories
270: Category.top_level_for(self)
271: end