app/models/camaleon_cms/site.rb in camaleon_cms-2.3.3 vs app/models/camaleon_cms/site.rb in camaleon_cms-2.3.4
- old
+ new
@@ -1,7 +1,8 @@
class CamaleonCms::Site < CamaleonCms::TermTaxonomy
# attrs: [name, description, slug]
+ include CamaleonCms::SiteDefaultSettings
default_scope { where(taxonomy: :site).reorder(term_group: :desc) }
has_many :metas, -> { where(object_class: 'Site') }, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :delete_all
has_many :post_types, :class_name => "CamaleonCms::PostType", foreign_key: :parent_id, dependent: :destroy
has_many :nav_menus, :class_name => "CamaleonCms::NavMenu", foreign_key: :parent_id, dependent: :destroy, inverse_of: :site
has_many :nav_menu_items, :class_name => "CamaleonCms::NavMenuItem", foreign_key: :term_group
@@ -14,11 +15,10 @@
has_many :posts, through: :post_types, :source => :posts
has_many :plugins, :class_name => "CamaleonCms::Plugin", foreign_key: :parent_id, dependent: :destroy
has_many :themes, :class_name => "CamaleonCms::Theme", foreign_key: :parent_id, dependent: :destroy
after_create :default_settings
- after_create :set_all_users
after_create :set_default_user_roles
after_save :update_routes
before_destroy :destroy_site
after_destroy :reload_routes
validates_uniqueness_of :slug, scope: :taxonomy
@@ -109,95 +109,32 @@
def need_validate_email?
get_option('need_validate_email', false) == true
end
- # auto create default user roles
- def set_default_user_roles(post_type = nil)
- user_role = self.user_roles.where({slug: 'admin', term_group: -1}).first_or_create({name: 'Administrator', description: 'Default roles admin'})
- if user_role.valid?
- d, m = {}, {}
- pts = self.post_types.all.pluck(:id)
- CamaleonCms::UserRole::ROLES[:post_type].each { |value| d[value[:key]] = pts }
- CamaleonCms::UserRole::ROLES[:manager].each { |value| m[value[:key]] = 1 }
- user_role.set_meta("_post_type_#{self.id}", d || {})
- user_role.set_meta("_manager_#{self.id}", m || {})
- end
-
- user_role = self.user_roles.where({slug: 'editor'}).first_or_create({name: 'Editor', description: 'Editor Role'})
- if user_role.valid?
- d = {}
- if post_type.present?
- d = user_role.get_meta("_post_type_#{self.id}", {})
- CamaleonCms::UserRole::ROLES[:post_type].each { |value|
- value_old = d[value[:key].to_sym] || []
- d[value[:key].to_sym] = value_old + [post_type.id]
- }
- else
- pts = self.post_types.all.pluck(:id)
- CamaleonCms::UserRole::ROLES[:post_type].each { |value| d[value[:key]] = pts }
- end
- user_role.set_meta("_post_type_#{self.id}", d || {})
- end
-
- user_role = self.user_roles.where({slug: 'contributor'}).first_or_create({name: 'Contributor', description: 'Contributor Role'})
- if user_role.valid?
- d = {}
- if post_type.present?
- d = user_role.get_meta("_post_type_#{self.id}", {})
- CamaleonCms::UserRole::ROLES[:post_type].each { |value|
- value_old = d[value[:key].to_sym] || []
- d[value[:key].to_sym] = value_old + [post_type.id] if value[:key].to_s == 'edit'
- }
- else
- pts = self.post_types.all.pluck(:id)
- CamaleonCms::UserRole::ROLES[:post_type].each { |value| d[value[:key]] = pts if value[:key].to_s == 'edit' }
- end
- user_role.set_meta("_post_type_#{self.id}", d || {})
- end
-
- unless post_type.present?
- user_role = self.user_roles.where({slug: 'client', term_group: -1}).first_or_create({name: 'Client', description: 'Default roles client'})
- if user_role.valid?
- user_role.set_meta("_post_type_#{self.id}", {})
- user_role.set_meta("_manager_#{self.id}", {})
- end
- end
-
- end
-
# return main site
def self.main_site
@main_site ||= CamaleonCms::Site.reorder(id: :ASC).first
end
# check if this site is the main site
# main site is a site that doesn't have slug
def main_site?
self.class.main_site == self
end
-
alias_method :is_default?, :main_site?
# list all users of current site
def users
if PluginRoutes.system_info["users_share_sites"]
- CamaleonCms::User.where(site_id: -1)
+ CamaleonCms::User.all
else
CamaleonCms::User.where(site_id: self.id)
end
end
+ alias_method :users_include_admins, :users
- # return all users including administrators
- def users_include_admins
- if PluginRoutes.system_info["users_share_sites"]
- CamaleonCms::User.where(site_id: -1)
- else
- CamaleonCms::User.where("site_id = ? or role = ?", self.id, 'admin')
- end
- end
-
# return upload directory for this site (deprecated for cloud support)
def upload_directory(inner_directory = nil)
File.join(Rails.public_path, "/media/#{PluginRoutes.static_system_info["media_slug_folder"] ? self.slug : self.id}", inner_directory.to_s)
end
@@ -263,46 +200,13 @@
end
FileUtils.rm_rf(File.join(Rails.public_path, "/media/#{upload_directory_name}").to_s) # destroy current media directory
users.destroy_all unless PluginRoutes.system_info["users_share_sites"] # destroy all users assigned fot this site
end
- # default structure for each new site
- def default_settings
- default_post_type = [
- {name: 'Post', description: 'Posts', options: {has_category: true, has_tags: true, not_deleted: true, has_summary: true, has_content: true, has_comments: true, has_picture: true, has_template: true, }},
- {name: 'Page', description: 'Pages', options: {has_category: false, has_tags: false, not_deleted: true, has_summary: false, has_content: true, has_comments: false, has_picture: true, has_template: true, has_layout: true}}
- ]
- default_post_type.each do |pt|
- model_pt = self.post_types.create({name: pt[:name], slug: pt[:name].to_s.parameterize, description: pt[:description], data_options: pt[:options]})
- end
-
- # nav menus
- @nav_menu = self.nav_menus.new({name: "Main Menu", slug: "main_menu"})
- if @nav_menu.save
- self.post_types.all.each do |pt|
- if pt.slug == "post"
- title = "Sample Post"
- slug = 'sample-post'
- content = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer pharetra ut augue in posuere. Nulla non malesuada dui. Sed egestas tortor ut purus tempor sodales. Duis non sollicitudin nulla, quis mollis neque. Integer sit amet augue ac neque varius auctor. Vestibulum malesuada leo leo, at semper libero efficitur nec. Etiam semper nisi ac nisi ullamcorper, sed tincidunt purus elementum. Mauris ac congue nibh. Quisque pretium eget leo nec suscipit. </p> <p> Vestibulum ultrices orci ut congue interdum. Morbi dolor nunc, imperdiet vel risus semper, tempor dapibus urna. Phasellus luctus pharetra enim quis volutpat. Integer tristique urna nec malesuada ullamcorper. Curabitur dictum, lectus id ultrices rhoncus, ante neque auctor erat, ut sodales nisi odio sit amet lorem. In hac habitasse platea dictumst. Quisque orci orci, hendrerit at luctus tristique, lobortis in diam. Curabitur ligula enim, rhoncus ut vestibulum a, consequat sit amet nisi. Aliquam bibendum fringilla ultrices. Aliquam erat volutpat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In justo mi, congue in rhoncus lobortis, facilisis in est. Nam et rhoncus purus. </p> <p> Sed sagittis auctor lectus at rutrum. Morbi ultricies felis mi, ut scelerisque augue facilisis eu. In molestie quam ex. Quisque ut sapien sed odio tempus imperdiet. In id accumsan massa. Morbi quis nunc ullamcorper, interdum enim eu, finibus purus. Vestibulum ac fermentum augue, at tempus ante. Aliquam ultrices, purus ut porttitor gravida, dui augue dignissim massa, ac tempor ante dolor at arcu. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Suspendisse placerat risus est, eget varius mi ultricies in. Duis non odio ut felis dapibus eleifend. In fringilla enim lobortis placerat efficitur. </p> <p> Nulla sodales faucibus urna, quis viverra dolor facilisis sollicitudin. Aenean ac egestas nibh. Nam non tortor eget nibh scelerisque fermentum. Etiam ornare, nunc ut luctus mollis, ante dolor consectetur augue, non scelerisque odio est a nulla. Nullam cursus egestas nulla, nec commodo nibh suscipit ut. Mauris ut felis sem. Aenean at mi at nisi dictum blandit sit amet at erat. Etiam eget lobortis tellus. Curabitur in commodo arcu, at vehicula tortor. </p>"
- else
- title = "Welcome"
- slug = 'welcome'
- content = "<p style='text-align: center;'><img width='155' height='155' src='http://camaleon.tuzitio.com/media/132/logo2.png' alt='logo' /></p><p><strong>Camaleon CMS</strong> is a free and open-source tool and a fexible content management system (CMS) based on <a href='http://rubyonrails.org'>Ruby on Rails 4</a> and MySQL. </p> <p>With Camaleon you can do the following:</p> <ul> <li>Create instantly a lot of sites in the same installation</li> <li>Manage your content information in several languages</li> <li>Extend current functionality by plugins (MVC structure and no more echo or prints anywhere)</li> <li>Create or install different themes for each site</li> <li>Create your own structure without coding anything (adapt Camaleon as you want and not you for Camaleon)</li> <li>Create your store and start to sell your products using our plugins</li> <li>Avoid web attacks</li> <li>Compare the speed and enjoy the speed of your new Camaleon site</li> <li>Customize or create your themes for mobile support</li> <li>Support more visitors at the same time</li> <li>Manage your information with a panel like wordpress </li> <li>All urls are oriented for SEO</li> <li>Multiples roles of users</li> </ul>"
- end
- user = self.users.admin_scope.first
- user = self.users.admin_scope.create({email: 'admin@local.com', username: 'admin', password: 'admin', password_confirmation: 'admin', first_name: 'Administrator'}) unless user.present?
- post = pt.add_post({title: title, slug: slug, content: content, user_id: user.id, status: 'published'})
- @nav_menu.append_menu_item({label: title, type: 'post', link: post.id})
- end
- end
- get_anonymous_user
- end
-
# assign all users to this new site
+ # DEPRECATED
def set_all_users
- CamaleonCms::User.all.each do |user|
- self.assign_user(user)
- end
+ return
end
# update all routes of the system
# reload system routes for this site
def update_routes