Class: Account

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/account.rb

Overview


Defined Under Namespace

Classes: DomainNotFound, LoginRequired

Constant Summary collapse

CURRENCY_TYPES =
{ 'British Pound (£)'.html_safe => 'GBP',
'Czech Koruna (Kč)'.html_safe => 'CZK',
'Euro (€)'.html_safe => 'EUR',
'Indian Rupee (Rs)' => 'INR',
'Japanese Yen (¥)'.html_safe => 'JPY',
'Swiss Franc (Fr)' => 'CHF',
'US Dollar ($)' => 'USD' }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#analytics_validationObject

Returns the value of attribute analytics_validation.



19
20
21
# File 'app/models/account.rb', line 19

def analytics_validation
  @analytics_validation
end

#email_validationObject

Returns the value of attribute email_validation.



19
20
21
# File 'app/models/account.rb', line 19

def email_validation
  @email_validation
end

#general_validationObject

Returns the value of attribute general_validation.



19
20
21
# File 'app/models/account.rb', line 19

def general_validation
  @general_validation
end

#media_validationObject

Returns the value of attribute media_validation.



19
20
21
# File 'app/models/account.rb', line 19

def media_validation
  @media_validation
end

#metadata_validationObject

Returns the value of attribute metadata_validation.



19
20
21
# File 'app/models/account.rb', line 19

def 
  @metadata_validation
end

#url_baseObject




152
153
154
# File 'app/models/account.rb', line 152

def url_base
  @url_base
end

#url_hostObject

Returns the value of attribute url_host.



20
21
22
# File 'app/models/account.rb', line 20

def url_host
  @url_host
end

#url_protocolObject

Returns the value of attribute url_protocol.



20
21
22
# File 'app/models/account.rb', line 20

def url_protocol
  @url_protocol
end

Class Method Details

.currentObject



126
127
128
# File 'app/models/account.rb', line 126

def self.current
  Thread.current[:account]
end

.current=(account) ⇒ Object

Since we need the current account for the default scope in models, we need this information easily available at the model level. This is thread safe, as opposed to using a simple cattr_accessor. But we must ensure the that thread info is nulled out after every request using an around_filter




122
123
124
# File 'app/models/account.rb', line 122

def self.current=()
  Thread.current[:account] = 
end

.current_by_prefix(account_prefix) ⇒ Object

Set the current account by looking up the account prefix. To be used when operating outside a request, such as from the console




133
134
135
# File 'app/models/account.rb', line 133

def self.current_by_prefix()
  Account.current = Account.()
end

.find_account(host) ⇒ Object

Find the account using the specified host (usually from the request url). Check for certain special subdomains before lookup:

dev, www, backoffice, staging, stg-

Supports xip.io format for testing on local network

dev.testapp.net.192.168.1.5.xip.io

is a valid address. See xip.io for more info




108
109
110
111
112
113
114
# File 'app/models/account.rb', line 108

def self.(host)
  host      ||= ""
  separated   = host.downcase.split('.')
  separated   = separated[0..-7] if host.end_with?('xip.io') # strip off xip.io and ip address
  separated   = separated.delete_if { |x| x == 'dev' || x == 'www' || x == 'backoffice' || x =~ /stg-/ || x == 'staging' }
  self.find_by_domain(separated.join('.')) or raise Account::DomainNotFound.new("Invalid domain: #{host}")
end

Instance Method Details

#create_default_rolesObject




157
158
159
160
# File 'app/models/account.rb', line 157

def create_default_roles
  Role.unscoped.create!(name: 'admin',   account_id: self.id)
  Role.unscoped.create!(name: 'beta',    account_id: self.id)
end

#current_themeObject

Get the name of the current theme - which is simply the account prefix




232
233
234
# File 'app/models/account.rb', line 232

def current_theme
  
end

#index_pathObject

take the root path and use the default locale




191
192
193
# File 'app/models/account.rb', line 191

def index_path
  "/#{preferred_default_locale}/index"
end

#parent_themeObject

Get the name of the parent theme




238
239
240
# File 'app/models/account.rb', line 238

def parent_theme
  ThemesForRails.config.parent_theme(current_theme)
end

#set_default_valuesObject

Once an account is found, setup the default url_ values.




139
140
141
# File 'app/models/account.rb', line 139

def set_default_values
  set_url_parts(self.ssl_enabled? ? 'https://' : 'http://', self.domain)
end

#set_url_parts(protocol, host) ⇒ Object

set the protocol and host for the account’s url. During request processing, this is usually called with the request.protocol and request.host_with_port




146
147
148
149
# File 'app/models/account.rb', line 146

def set_url_parts(protocol, host)
  self.url_protocol  = protocol
  self.url_host      = host
end

#site_enabled?Boolean


Returns:

  • (Boolean)


163
164
165
# File 'app/models/account.rb', line 163

def site_enabled?
  preferred_site_enabled?
end

#site_localesObject

Reutrn an array of locales used for the site. Split on commas and whitespace




185
186
187
# File 'app/models/account.rb', line 185

def site_locales
  preferred_locales.split(/,\s*/)
end

#site_maintenance?Boolean


Returns:

  • (Boolean)


168
169
170
# File 'app/models/account.rb', line 168

def site_maintenance?
  preferred_site_maintenance?
end

#smtp_settingsObject




196
197
198
199
200
201
202
203
204
# File 'app/models/account.rb', line 196

def smtp_settings
  {
    :address              => preferred_smtp_address,
    :port                 => preferred_smtp_port,
    :domain               => preferred_smtp_domain,
    :user_name            => preferred_smtp_user_name,
    :password             => preferred_smtp_password
  }
end

#ssl_enabled?Boolean


Returns:

  • (Boolean)


173
174
175
# File 'app/models/account.rb', line 173

def ssl_enabled?
  preferred_ssl_enabled?
end

#theme_data(options = {}) ⇒ Object

Return the current theme’s data structure. parent: true will give the parent theme’s data if no data exists, return an empty hash




210
211
212
213
214
215
216
# File 'app/models/account.rb', line 210

def theme_data(options = {})
  if options[:parent]
    ThemesForRails.config.themes_data(parent_theme) || {}
  else
    ThemesForRails.config.themes_data(current_theme) || {}
  end
end

#theme_option(option_name) ⇒ Object

Get the value of the specific theme option.




220
221
222
# File 'app/models/account.rb', line 220

def theme_option(option_name)
  theme_data(parent: true).merge(theme_data)[option_name.to_s]
end

#theme_pathObject

get the account’s theme filesystem path




226
227
228
# File 'app/models/account.rb', line 226

def theme_path
  "#{ThemesForRails.config.themes_path}/#{current_theme}"
end

#verify_locale(locale) ⇒ Object

check the local is a supported locale. If not, return site default




179
180
181
# File 'app/models/account.rb', line 179

def verify_locale(locale)
  (site_locales.include? locale.to_s) ? locale : preferred_default_locale
end