orbit-basic/app/models/site.rb

75 lines
2.1 KiB
Ruby

class Site
METAS = ['description', 'keywords']
include Mongoid::Document
include Mongoid::Timestamps
field :in_use_locales, :type => Array
field :valid_locales, :type => Array
field :roaming_id
field :private_key, :type => Binary
field :public_key, :type => Binary
field :frontend_closed, :type => Boolean, :default => false
field :backend_openness_on, :type => Boolean, :default => false
field :desktop_closed, :type => Boolean, :default => false
field :title_always_on, :type => Boolean, :default => false
field :dashbroad_allow_visitor, :type => Boolean, :default => false
field :mail_settings, :type => Hash
field :enabled_for, :type => Array, :default => nil
field :disk_space, :type => String
field :system_package_info, :type => Hash,:default=>{}
field :school
field :department
mount_uploader :default_image, ImageUploader
field :search,:type => Hash
field :resque_namespace,:type => String, :default=>APP_CONFIG['orbit']
field :title, localize: true
field :footer, localize: true
field :sub_menu, localize: true
field :terms_of_user, localize: true
field :google_analytics
field :default_locale
field :mobile_on, :type => Boolean, :default => false
belongs_to :design
has_many :site_metas, :autosave => true, :dependent => :destroy
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
def up_to_date?
res = res.split('rails_3_1').pop.gsub('(', '').gsub(')','').strip rescue nil
res.eql?('local out of date') ? false : true
end
METAS.each do |meta|
define_method meta do |locale|
fetch_meta = self.site_metas.where(key: meta).limit(1)
fetch_meta.blank? ? nil : fetch_meta[0].title_translations[locale]
end
define_method "#{meta}=" do |values|
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
end
end
end