2011-04-13 10:19:51 +00:00
|
|
|
class Site
|
|
|
|
|
2012-05-06 16:54:18 +00:00
|
|
|
METAS = ['description', 'keywords']
|
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
include Mongoid::Document
|
2011-03-08 09:25:46 +00:00
|
|
|
include Mongoid::Timestamps
|
2011-04-13 10:19:51 +00:00
|
|
|
|
|
|
|
field :in_use_locales, :type => Array
|
|
|
|
field :valid_locales, :type => Array
|
2013-10-18 07:24:28 +00:00
|
|
|
field :enable_locales, :type => Array
|
2011-04-13 10:19:51 +00:00
|
|
|
|
2011-08-18 05:43:33 +00:00
|
|
|
field :roaming_id
|
|
|
|
field :private_key, :type => Binary
|
|
|
|
field :public_key, :type => Binary
|
2013-04-23 10:48:18 +00:00
|
|
|
|
2013-10-14 08:47:34 +00:00
|
|
|
field :frontend_open, :type => Boolean, :default => true
|
2013-04-23 10:48:18 +00:00
|
|
|
field :backend_openness_on, :type => Boolean, :default => false
|
2013-09-06 08:41:02 +00:00
|
|
|
field :desktop_closed, :type => Boolean, :default => false
|
2013-10-11 13:08:22 +00:00
|
|
|
field :sitemap_menu_in_header, :type => Boolean, :default => false
|
2013-10-15 02:37:03 +00:00
|
|
|
field :enable_terms_of_use, :type => Boolean, :default => false
|
2013-10-18 07:24:28 +00:00
|
|
|
field :enable_language_detection, :type => Boolean, :default => false
|
2013-04-23 10:48:18 +00:00
|
|
|
|
2012-05-07 07:11:43 +00:00
|
|
|
field :title_always_on, :type => Boolean, :default => false
|
2012-08-23 08:05:14 +00:00
|
|
|
field :dashbroad_allow_visitor, :type => Boolean, :default => false
|
2012-05-09 03:38:29 +00:00
|
|
|
field :mail_settings, :type => Hash
|
2013-04-24 11:21:11 +00:00
|
|
|
|
|
|
|
field :disk_space, :type => String
|
|
|
|
field :system_package_info, :type => Hash,:default=>{}
|
|
|
|
|
2011-08-18 05:43:33 +00:00
|
|
|
field :school
|
|
|
|
field :department
|
2013-10-21 08:47:36 +00:00
|
|
|
field :default_locale
|
2012-07-26 08:39:29 +00:00
|
|
|
|
|
|
|
mount_uploader :default_image, ImageUploader
|
2013-10-16 10:33:57 +00:00
|
|
|
mount_uploader :favicon, ImageUploader
|
2012-03-21 10:30:12 +00:00
|
|
|
|
2012-07-25 09:20:25 +00:00
|
|
|
field :search,:type => Hash
|
2013-06-19 07:45:53 +00:00
|
|
|
field :resque_namespace,:type => String, :default=>APP_CONFIG['orbit']
|
2012-07-25 21:07:32 +00:00
|
|
|
field :title, localize: true
|
|
|
|
field :footer, localize: true
|
|
|
|
field :sub_menu, localize: true
|
2013-10-11 13:08:22 +00:00
|
|
|
field :terms_of_use, localize: true
|
2013-09-02 09:31:34 +00:00
|
|
|
field :google_analytics
|
2013-01-06 19:57:36 +00:00
|
|
|
|
|
|
|
field :mobile_on, :type => Boolean, :default => false
|
2013-08-30 10:17:27 +00:00
|
|
|
|
2012-12-07 04:14:31 +00:00
|
|
|
belongs_to :design
|
2012-07-25 21:07:32 +00:00
|
|
|
has_many :site_metas, :autosave => true, :dependent => :destroy
|
2013-10-18 07:24:28 +00:00
|
|
|
validate :in_use_locales, :minimum_enabled_locales
|
|
|
|
|
|
|
|
def minimum_enabled_locales
|
|
|
|
size = self.in_use_locales.length
|
|
|
|
if size < 1
|
|
|
|
errors.add(:size, "Needs at least one language in use")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def maximum_enabled_locales
|
|
|
|
size = self.in_use_locales.length
|
|
|
|
if size >= 2
|
2013-10-21 08:47:36 +00:00
|
|
|
errors.add(:size, "Max 2 values allowed")
|
2013-10-18 07:24:28 +00:00
|
|
|
end
|
|
|
|
end
|
2012-05-06 16:54:18 +00:00
|
|
|
|
2011-08-18 05:43:33 +00:00
|
|
|
def generate_keys
|
|
|
|
private_key = OpenSSL::PKey::RSA.generate(2048)
|
|
|
|
self.public_key = private_key.public_key.to_s
|
|
|
|
self.private_key = private_key.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def registered?
|
|
|
|
!self.roaming_id.blank?
|
|
|
|
end
|
|
|
|
|
2011-08-23 11:40:49 +00:00
|
|
|
def up_to_date?
|
2011-08-25 00:30:09 +00:00
|
|
|
res = res.split('rails_3_1').pop.gsub('(', '').gsub(')','').strip rescue nil
|
2011-08-23 11:40:49 +00:00
|
|
|
res.eql?('local out of date') ? false : true
|
|
|
|
end
|
2012-05-06 16:54:18 +00:00
|
|
|
|
|
|
|
METAS.each do |meta|
|
2012-07-26 05:27:27 +00:00
|
|
|
define_method meta do |locale|
|
2012-05-06 16:54:18 +00:00
|
|
|
fetch_meta = self.site_metas.where(key: meta).limit(1)
|
2012-07-26 05:27:27 +00:00
|
|
|
fetch_meta.blank? ? nil : fetch_meta[0].title_translations[locale]
|
2012-05-06 16:54:18 +00:00
|
|
|
end
|
|
|
|
define_method "#{meta}=" do |values|
|
2012-07-26 05:27:27 +00:00
|
|
|
fetch_meta = self.site_metas.where(key: meta).limit(1)[0] rescue nil
|
|
|
|
fetch_meta = self.site_metas.build(key: meta) if fetch_meta.blank?
|
|
|
|
fetch_meta.title_translations = values
|
|
|
|
fetch_meta.save
|
2012-05-06 16:54:18 +00:00
|
|
|
end
|
|
|
|
end
|
2011-08-23 11:40:49 +00:00
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
end
|