Class: Caboose::Site
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Caboose::Site
- Defined in:
- app/models/caboose/site.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build_new_site ⇒ Object
- #custom_css ⇒ Object
- #custom_css=(str) ⇒ Object
- #custom_css_url ⇒ Object
- #custom_js ⇒ Object
- #custom_js=(str) ⇒ Object
- #custom_js_url ⇒ Object
- #default_layout ⇒ Object
- #init_users_and_roles ⇒ Object
- #primary_domain ⇒ Object
- #product_default ⇒ Object
- #retargeting_config ⇒ Object
- #smtp_config ⇒ Object
- #social_config ⇒ Object
- #theme ⇒ Object
- #update_cloudinary_favicon ⇒ Object
- #update_cloudinary_logo ⇒ Object
- #valid_domains ⇒ Object
- #validate_presence_of_store_config ⇒ Object
- #variant_default ⇒ Object
Class Method Details
.id_for_domain(domain) ⇒ Object
141 142 143 144 145 |
# File 'app/models/caboose/site.rb', line 141 def self.id_for_domain(domain) d = Caboose::Domain.where(:domain => domain).first return nil if d.nil? return d.site_id end |
.sanitize_name(name) ⇒ Object
151 152 153 |
# File 'app/models/caboose/site.rb', line 151 def self.sanitize_name(name) self.name = self.name.downcase.gsub(' ', '_') end |
Instance Method Details
#build_new_site ⇒ Object
92 93 94 95 96 97 98 |
# File 'app/models/caboose/site.rb', line 92 def build_new_site # if defined?(SuiteBuilder) == 'constant' && SuiteBuilder.class == Class helper = Caboose::SiteBuilder.new(self.name) helper.create_site_blocks(self.id) # end # self.init_users_and_roles end |
#custom_css ⇒ Object
180 181 182 183 184 185 186 187 |
# File 'app/models/caboose/site.rb', line 180 def custom_css resp = HTTParty.get('https:' + self.custom_css_url) if resp.nil? || resp.code.to_i == 403 self.custom_css = "" return "" end return resp.body end |
#custom_css=(str) ⇒ Object
198 199 200 201 202 203 204 205 |
# File 'app/models/caboose/site.rb', line 198 def custom_css=(str) config = YAML.load(File.read(Rails.root.join('config', 'aws.yml')))[Rails.env] AWS.config(:access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key']) bucket = AWS::S3.new.buckets[config['bucket']] bucket.objects["assets/#{self.name}/css/custom.css"].write(str, :acl => 'public-read', :content_type => 'text/css') self.date_css_updated = DateTime.now.utc self.save end |
#custom_css_url ⇒ Object
165 166 167 168 169 |
# File 'app/models/caboose/site.rb', line 165 def custom_css_url url = "//#{Caboose::cdn_domain}/assets/#{self.name}/css/custom.css" url << "?#{self.date_css_updated.strftime('%Y%m%d%H%M%S')}" if self.date_css_updated return url end |
#custom_js ⇒ Object
171 172 173 174 175 176 177 178 |
# File 'app/models/caboose/site.rb', line 171 def custom_js resp = HTTParty.get('https:' + self.custom_js_url) if resp.nil? || resp.code.to_i == 403 self.custom_js = "" return "" end return resp.body end |
#custom_js=(str) ⇒ Object
189 190 191 192 193 194 195 196 |
# File 'app/models/caboose/site.rb', line 189 def custom_js=(str) config = YAML.load(File.read(Rails.root.join('config', 'aws.yml')))[Rails.env] AWS.config(:access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key']) bucket = AWS::S3.new.buckets[config['bucket']] bucket.objects["assets/#{self.name}/js/custom.js"].write(str, :acl => 'public-read', :content_type => 'application/javascript') self.date_js_updated = DateTime.now.utc self.save end |
#custom_js_url ⇒ Object
159 160 161 162 163 |
# File 'app/models/caboose/site.rb', line 159 def custom_js_url url = "//#{Caboose::cdn_domain}/assets/#{self.name}/js/custom.js" url << "?#{self.date_js_updated.strftime('%Y%m%d%H%M%S')}" if self.date_js_updated return url end |
#default_layout ⇒ Object
106 107 108 109 |
# File 'app/models/caboose/site.rb', line 106 def default_layout return Caboose::BlockType.where(:id => self.default_layout_id).first if self.default_layout_id return Caboose::BlockType.where(:name => 'layout_basic').first end |
#init_users_and_roles ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'app/models/caboose/site.rb', line 207 def init_users_and_roles admin_user = Caboose::User.where( :site_id => self.id, :username => 'admin').first admin_user = Caboose::User.create(:site_id => self.id, :username => 'admin', :email => '[email protected]', :password => Digest::SHA1.hexdigest(Caboose::salt + 'caboose')) if admin_user.nil? admin_role = Caboose::Role.where( :site_id => self.id, :name => 'Admin').first admin_role = Caboose::Role.create(:site_id => self.id, :parent_id => -1, :name => 'Admin') if admin_role.nil? elo_user = Caboose::User.where( :site_id => self.id, :username => 'elo').first elo_user = Caboose::User.create(:site_id => self.id, :username => 'elo', :email => '[email protected]') if elo_user.nil? elo_role = Caboose::Role.where( :site_id => self.id, :name => 'Everyone Logged Out').first elo_role = Caboose::Role.create(:site_id => self.id, :name => 'Everyone Logged Out', :parent_id => -1) if elo_role.nil? eli_user = Caboose::User.where( :site_id => self.id, :username => 'eli').first eli_user = Caboose::User.create(:site_id => self.id, :username => 'eli', :email => '[email protected]') if eli_user.nil? eli_role = Caboose::Role.where( :site_id => self.id, :name => 'Everyone Logged In').first eli_role = Caboose::Role.create(:site_id => self.id, :name => 'Everyone Logged In', :parent_id => elo_role.id) if eli_role.nil? # Make sure the admin role has the admin "all" permission admin_perm = Caboose::Permission.where(:resource => 'all', :action => 'all').first rp = Caboose::RolePermission.where(:role_id => admin_role.id, :permission_id => admin_perm.id).first rp = Caboose::RolePermission.create(:role_id => admin_role.id, :permission_id => admin_perm.id) if rp.nil? # Make sure the admin user is a member of the admin role rm = Caboose::RoleMembership.where(:role_id => admin_role.id, :user_id => admin_user.id).first rm = Caboose::RoleMembership.create(:role_id => admin_role.id, :user_id => admin_user.id) if rm.nil? # Make sure the elo user is a member of the elo role rm = Caboose::RoleMembership.where( :role_id => elo_role.id, :user_id => elo_user.id).first rm = Caboose::RoleMembership.create(:role_id => elo_role.id, :user_id => elo_user.id) if rm.nil? # Make sure the eli user is a member of the eli role rm = Caboose::RoleMembership.where( :role_id => eli_role.id, :user_id => eli_user.id).first rm = Caboose::RoleMembership.create(:role_id => eli_role.id, :user_id => eli_user.id) if rm.nil? end |
#primary_domain ⇒ Object
155 156 157 |
# File 'app/models/caboose/site.rb', line 155 def primary_domain Caboose::Domain.where(:site_id => self.id, :primary => true).first end |
#product_default ⇒ Object
129 130 131 132 133 |
# File 'app/models/caboose/site.rb', line 129 def product_default pd = Caboose::ProductDefault.where(:site_id => self.id).first pd = Caboose::ProductDefault.create(:site_id => self.id) if pd.nil? return pd end |
#retargeting_config ⇒ Object
123 124 125 126 127 |
# File 'app/models/caboose/site.rb', line 123 def retargeting_config c = Caboose::RetargetingConfig.where(:site_id => self.id).first c = Caboose::RetargetingConfig.create(:site_id => self.id) if c.nil? return c end |
#smtp_config ⇒ Object
111 112 113 114 115 |
# File 'app/models/caboose/site.rb', line 111 def smtp_config c = Caboose::SmtpConfig.where(:site_id => self.id).first c = Caboose::SmtpConfig.create(:site_id => self.id) if c.nil? return c end |
#social_config ⇒ Object
117 118 119 120 121 |
# File 'app/models/caboose/site.rb', line 117 def s = Caboose::SocialConfig.where(:site_id => self.id).first s = Caboose::SocialConfig.create(:site_id => self.id) if s.nil? return s end |
#theme ⇒ Object
72 73 74 |
# File 'app/models/caboose/site.rb', line 72 def theme Caboose::Theme.where(:id => self.theme_id).first end |
#update_cloudinary_favicon ⇒ Object
84 85 86 87 88 89 90 |
# File 'app/models/caboose/site.rb', line 84 def update_cloudinary_favicon if Caboose::use_cloudinary result = Cloudinary::Uploader.upload("https:#{self.favicon.url(:thumb)}" , :public_id => "caboose/favicons/#{self.id}_thumb", :overwrite => true) self.cl_favicon_version = result['version'] if result && result['version'] self.save end end |
#update_cloudinary_logo ⇒ Object
76 77 78 79 80 81 82 |
# File 'app/models/caboose/site.rb', line 76 def update_cloudinary_logo if Caboose::use_cloudinary result = Cloudinary::Uploader.upload("https:#{self.logo.url(:large)}" , :public_id => "caboose/site_logos/#{self.id}_large", :overwrite => true) self.cl_logo_version = result['version'] if result && result['version'] self.save end end |
#valid_domains ⇒ Object
147 148 149 |
# File 'app/models/caboose/site.rb', line 147 def valid_domains self.domains.map{ |d| d.domain.blank? ? "" : d.domain.gsub(":3000","") } end |
#validate_presence_of_store_config ⇒ Object
100 101 102 103 104 |
# File 'app/models/caboose/site.rb', line 100 def validate_presence_of_store_config if self.use_store && !Caboose::StoreConfig.where(:site_id => self.id).exists? Caboose::StoreConfig.create(:site_id => self.id) end end |
#variant_default ⇒ Object
135 136 137 138 139 |
# File 'app/models/caboose/site.rb', line 135 def variant_default vd = Caboose::VariantDefault.where(:site_id => self.id).first vd = Caboose::VariantDefault.create(:site_id => self.id) if vd.nil? return vd end |