camaleon_cms 2.3.3 → 2.3.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of camaleon_cms might be problematic. Click here for more details.

Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +7 -12
  3. data/app/assets/javascripts/camaleon_cms/admin/_custom_fields.js +1 -2
  4. data/app/assets/javascripts/camaleon_cms/admin/_data.js +1 -0
  5. data/app/assets/javascripts/camaleon_cms/admin/_post.js +1 -1
  6. data/app/assets/javascripts/camaleon_cms/admin/_posttype.js.coffee +21 -0
  7. data/app/assets/javascripts/camaleon_cms/admin/admin-manifest.js +2 -0
  8. data/app/assets/javascripts/camaleon_cms/admin/jquery_validate/fr.js +49 -0
  9. data/app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb +11 -6
  10. data/app/controllers/camaleon_cms/admin/appearances/themes_controller.rb +6 -0
  11. data/app/controllers/camaleon_cms/admin/media_controller.rb +3 -0
  12. data/app/controllers/camaleon_cms/admin/users_controller.rb +3 -0
  13. data/app/controllers/camaleon_cms/camaleon_controller.rb +5 -0
  14. data/app/controllers/camaleon_cms/frontend_controller.rb +1 -1
  15. data/app/controllers/concerns/camaleon_cms/frontend_concern.rb +1 -1
  16. data/app/decorators/camaleon_cms/site_decorator.rb +1 -1
  17. data/app/decorators/camaleon_cms/user_decorator.rb +4 -0
  18. data/app/helpers/camaleon_cms/admin/custom_fields_helper.rb +4 -4
  19. data/app/helpers/camaleon_cms/camaleon_helper.rb +5 -0
  20. data/app/helpers/camaleon_cms/frontend/nav_menu_helper.rb +16 -16
  21. data/app/helpers/camaleon_cms/hooks_helper.rb +10 -4
  22. data/app/helpers/camaleon_cms/plugins_helper.rb +1 -1
  23. data/app/helpers/camaleon_cms/session_helper.rb +9 -4
  24. data/app/helpers/camaleon_cms/short_code_helper.rb +1 -1
  25. data/app/helpers/camaleon_cms/theme_helper.rb +1 -1
  26. data/app/helpers/camaleon_cms/uploader_helper.rb +10 -7
  27. data/app/mailers/camaleon_cms/html_mailer.rb +33 -17
  28. data/app/models/camaleon_cms/ability.rb +2 -2
  29. data/app/models/camaleon_cms/nav_menu.rb +2 -2
  30. data/app/models/camaleon_cms/nav_menu_item.rb +5 -3
  31. data/app/models/camaleon_cms/site.rb +5 -101
  32. data/app/models/camaleon_cms/user.rb +8 -144
  33. data/app/models/camaleon_cms/user_relationship.rb +1 -1
  34. data/app/models/camaleon_cms/user_role.rb +0 -2
  35. data/app/models/concerns/camaleon_cms/custom_fields_read.rb +14 -7
  36. data/app/models/concerns/camaleon_cms/metas.rb +5 -4
  37. data/app/models/concerns/camaleon_cms/site_default_settings.rb +87 -0
  38. data/app/models/concerns/camaleon_cms/user_methods.rb +142 -0
  39. data/app/uploaders/camaleon_cms_aws_uploader.rb +13 -4
  40. data/app/uploaders/camaleon_cms_uploader.rb +3 -1
  41. data/app/views/camaleon_cms/admin/appearances/nav_menus/_custom_menus.html.erb +11 -5
  42. data/app/views/camaleon_cms/admin/appearances/nav_menus/_external_menu.html.erb +8 -0
  43. data/app/views/camaleon_cms/admin/settings/_media_settings.html.erb +4 -0
  44. data/app/views/camaleon_cms/admin/settings/custom_fields/_get_items.html.erb +155 -154
  45. data/app/views/camaleon_cms/admin/settings/custom_fields/_render.html.erb +1 -1
  46. data/app/views/camaleon_cms/admin/settings/custom_fields/fields/_checkbox.html.erb +1 -1
  47. data/app/views/camaleon_cms/admin/settings/custom_fields/fields/_checkboxes.html.erb +1 -1
  48. data/app/views/camaleon_cms/admin/settings/custom_fields/fields/_posts.html.erb +2 -5
  49. data/app/views/camaleon_cms/admin/settings/custom_fields/form.html.erb +1 -1
  50. data/app/views/camaleon_cms/admin/settings/post_types/_form.html.erb +24 -16
  51. data/app/views/camaleon_cms/admin/users/form.html.erb +2 -2
  52. data/app/views/camaleon_cms/default_theme/single.html.erb +1 -1
  53. data/app/views/layouts/camaleon_cms/admin.html.erb +2 -2
  54. data/config/initializers/model_alias.rb +10 -3
  55. data/config/locales/camaleon_cms/admin/en.yml +10 -0
  56. data/config/locales/camaleon_cms/admin/fr.yml +663 -0
  57. data/config/locales/camaleon_cms/common.yml +66 -0
  58. data/config/routes/frontend.rb +1 -1
  59. data/config/system.json +2 -2
  60. data/db/migrate/20150611161134_post_table_into_utf8.rb +6 -5
  61. data/lib/camaleon_cms/engine.rb +3 -0
  62. data/lib/camaleon_cms/version.rb +1 -1
  63. data/lib/ext/string.rb +1 -54
  64. data/lib/plugin_routes.rb +5 -0
  65. data/spec/decorators/post_type_spec.rb +13 -0
  66. data/spec/dummy/README.rdoc +28 -0
  67. data/spec/dummy/Rakefile +6 -0
  68. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  69. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  70. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  71. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  72. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  73. data/spec/dummy/bin/bundle +3 -0
  74. data/spec/dummy/bin/rails +4 -0
  75. data/spec/dummy/bin/rake +4 -0
  76. data/spec/dummy/bin/setup +29 -0
  77. data/spec/dummy/config.ru +4 -0
  78. data/spec/dummy/config/application.rb +26 -0
  79. data/spec/dummy/config/boot.rb +5 -0
  80. data/spec/dummy/config/database.yml +25 -0
  81. data/spec/dummy/config/environment.rb +5 -0
  82. data/spec/dummy/config/environments/development.rb +41 -0
  83. data/spec/dummy/config/environments/production.rb +79 -0
  84. data/spec/dummy/config/environments/test.rb +42 -0
  85. data/spec/dummy/config/initializers/assets.rb +11 -0
  86. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  87. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  88. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  89. data/spec/dummy/config/initializers/inflections.rb +16 -0
  90. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  91. data/spec/dummy/config/initializers/session_store.rb +3 -0
  92. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  93. data/spec/dummy/config/locales/en.yml +23 -0
  94. data/spec/dummy/config/routes.rb +4 -0
  95. data/spec/dummy/config/secrets.yml +22 -0
  96. data/spec/dummy/db/development.sqlite3 +0 -0
  97. data/spec/dummy/db/schema.rb +186 -0
  98. data/spec/dummy/public/404.html +67 -0
  99. data/spec/dummy/public/422.html +67 -0
  100. data/spec/dummy/public/500.html +66 -0
  101. data/spec/dummy/public/favicon.ico +0 -0
  102. data/spec/features/categories_spec.rb +25 -0
  103. data/spec/features/comments_spec.rb +45 -0
  104. data/spec/features/contact_form_spec.rb +53 -0
  105. data/spec/features/content_groups_spec.rb +45 -0
  106. data/spec/features/custom_fields_spec.rb +47 -0
  107. data/spec/features/frontend/pages_spec.rb +5 -0
  108. data/spec/features/languages_spec.rb +27 -0
  109. data/spec/features/media_spec.rb +50 -0
  110. data/spec/features/menus_spec.rb +46 -0
  111. data/spec/features/pages_spec.rb +30 -0
  112. data/spec/features/plugins_spec.rb +29 -0
  113. data/spec/features/posts_spec.rb +36 -0
  114. data/spec/features/session_spec.rb +52 -0
  115. data/spec/features/settings_spec.rb +17 -0
  116. data/spec/features/shortcodes_spec.rb +11 -0
  117. data/spec/features/sites_spec.rb +45 -0
  118. data/spec/features/tags_spec.rb +25 -0
  119. data/spec/features/themes_spec.rb +18 -0
  120. data/spec/features/user_roles_spec.rb +60 -0
  121. data/spec/features/users_spec.rb +79 -0
  122. data/spec/features/widgets_spec.rb +50 -0
  123. data/spec/helpers/email_helper_spec.rb +16 -0
  124. data/spec/mailers/send_mail_spec.rb +37 -0
  125. data/spec/rails_helper.rb +1 -0
  126. data/spec/routing/post_type_routes_spec.rb +12 -0
  127. data/spec/spec_helper.rb +191 -0
  128. data/spec/support/common.rb +113 -0
  129. data/spec/support/wait_for_ajax.rb +36 -0
  130. metadata +326 -3
@@ -117,7 +117,7 @@ module CamaleonCms::PluginsHelper
117
117
  key = plugin_key || self_plugin_key(1)
118
118
  p = PluginRoutes.plugin_info(key)["gem_mode"] ? "plugins/#{key}/#{asset}" : "plugins/#{key}/assets/#{asset}"
119
119
  begin
120
- asset_url(p)
120
+ ActionController::Base.helpers.asset_url(p)
121
121
  rescue NoMethodError => e
122
122
  p
123
123
  end
@@ -115,12 +115,10 @@ module CamaleonCms::SessionHelper
115
115
  return nil unless c.size == 3
116
116
 
117
117
  if c[1] == request.user_agent && request.ip == c[2]
118
- @cama_current_user = (current_site.users_include_admins.find_by_auth_token(c[0]).decorate rescue nil)
118
+ @cama_current_user = current_site.users_include_admins.find_by_auth_token(c[0]).try(:decorate)
119
119
  end
120
120
  end
121
121
 
122
- alias_method :current_user, :cama_current_user
123
-
124
122
  # check if a visitor was logged in
125
123
  # if the user was not logged in, then redirect to login url
126
124
  def cama_authenticate(redirect_uri = nil)
@@ -141,6 +139,13 @@ module CamaleonCms::SessionHelper
141
139
  private
142
140
  # calculate the current user for API
143
141
  def cama_calc_api_current_user
144
- current_site.users_include_admins.find(doorkeeper_token.resource_owner_id).decorate if doorkeeper_token rescue nil
142
+ begin
143
+ doorkeeper_token
144
+ rescue NameError
145
+ # hack, this method should be called from a context which has
146
+ # doorkeeper_token defined
147
+ return nil
148
+ end
149
+ current_site.users_include_admins.find_by_id(doorkeeper_token.resource_owner_id).try(:decorate) if doorkeeper_token
145
150
  end
146
151
  end
@@ -131,7 +131,7 @@ module CamaleonCms::ShortCodeHelper
131
131
  # if empty, codes will be replaced with all registered shortcodes
132
132
  # Return: (String) reg expression string
133
133
  def cama_reg_shortcode(codes = nil)
134
- "(\\[(#{codes || @_shortcodes.join("|")})(\s|\\]){1}(.*?)\\])"
134
+ "(\\[(#{codes || (@_shortcodes || []).join("|")})(\s|\\]){0}(.*?)\\])"
135
135
  end
136
136
 
137
137
  # determine the content to replace instead the shortcode
@@ -32,7 +32,7 @@ module CamaleonCms::ThemeHelper
32
32
  def theme_asset_url(asset, theme_name = nil)
33
33
  p = theme_asset_path(asset, theme_name)
34
34
  begin
35
- asset_url(p)
35
+ ActionController::Base.helpers.asset_url(p)
36
36
  rescue NoMethodError => e
37
37
  p
38
38
  end
@@ -242,13 +242,16 @@ module CamaleonCms::UploaderHelper
242
242
 
243
243
  # return the current uploader
244
244
  def cama_uploader
245
- @cama_uploader ||=
246
- case current_site.get_option("filesystem_type", "local").downcase
247
- when 's3' || 'aws'
248
- CamaleonCmsAwsUploader.new({current_site: current_site})
249
- else
250
- CamaleonCmsLocalUploader.new({current_site: current_site})
251
- end
245
+ @cama_uploader ||= lambda{
246
+ thumb = current_site.get_option('filesystem_thumb_size', '100x100').split('x')
247
+ args={ server: current_site.get_option("filesystem_type", "local").downcase, thumb: {w: thumb[0], h: thumb[1]}, aws_settings: {region: current_site.get_option("filesystem_region", 'us-west-2'), access_key: current_site.get_option("filesystem_s3_access_key"), secret_key: current_site.get_option("filesystem_s3_secret_key"), bucket: current_site.get_option("filesystem_s3_bucket_name"), cloud_front: current_site.get_option("filesystem_s3_cloudfront")}}; hooks_run("on_uploader", args)
248
+ case args[:server]
249
+ when 's3', 'aws'
250
+ CamaleonCmsAwsUploader.new({current_site: current_site, thumb: args[:thumb], aws_settings: args[:aws_settings]})
251
+ else
252
+ CamaleonCmsLocalUploader.new({current_site: current_site, thumb: args[:thumb]})
253
+ end
254
+ }.call
252
255
  end
253
256
 
254
257
  private
@@ -9,36 +9,52 @@ class CamaleonCms::HtmlMailer < ActionMailer::Base
9
9
  # content='', from=nil, attachs=[], url_base='', current_site, template_name, layout_name, extra_data, format, cc_to
10
10
  def sender(email, subject='Hello', data = {})
11
11
  data = data.to_sym
12
- data[:current_site] = CamaleonCms::Site.main_site.decorate unless data[:current_site].present?
13
- data[:current_site] = CamaleonCms::Site.find(data[:current_site]).decorate if data[:current_site].is_a?(Integer)
14
- current_site = @current_site = data[:current_site]
15
- data = {cc_to: current_site.get_option("email_cc", '').split(','), from: current_site.get_option("email_from") || current_site.get_option("email"), template_name: 'mailer', layout_name: 'camaleon_cms/mailer', format: 'html'}.merge(data)
16
- @subject = subject
17
- @html = data[:content]
18
- @url_base = data[:url_base]
19
- @extra_data = data[:extra_data]
12
+ if data[:current_site].present?
13
+ if data[:current_site].is_a?(Integer)
14
+ data[:current_site] = CamaleonCms::Site.find(data[:current_site]).decorate
15
+ end
16
+ else
17
+ data[:current_site] = CamaleonCms::Site.main_site.decorate
18
+ end
19
+ @current_site = data[:current_site]
20
+ data = {
21
+ cc_to: @current_site.get_option("email_cc", '').split(','),
22
+ from: @current_site.get_option("email_from") || @current_site.get_option("email"),
23
+ template_name: 'mailer',
24
+ layout_name: 'camaleon_cms/mailer',
25
+ format: 'html',
26
+ }.merge(data)
20
27
  data[:cc_to] = [data[:cc_to]] if data[:cc_to].is_a?(String) || !data[:cc_to].present?
21
28
 
22
29
  mail_data = {to: email, subject: subject}
23
- if current_site.get_option("mailer_enabled") == 1
30
+ if @current_site.get_option("mailer_enabled") == 1
24
31
  mail_data[:delivery_method] = :smtp
25
- mail_data[:delivery_method_options] = {user_name: current_site.get_option("email_username"),
26
- password: current_site.get_option("email_pass"),
27
- address: current_site.get_option("email_server"),
28
- port: current_site.get_option("email_port"),
29
- domain: (current_site.the_url.to_s.parse_domain rescue "localhost"),
30
- authentication: "plain",
31
- enable_starttls_auto: true
32
+ mail_data[:delivery_method_options] = {
33
+ user_name: @current_site.get_option("email_username"),
34
+ password: @current_site.get_option("email_pass"),
35
+ address: @current_site.get_option("email_server"),
36
+ port: @current_site.get_option("email_port"),
37
+ domain: (@current_site.the_url.to_s.parse_domain rescue "localhost"),
38
+ authentication: "plain",
39
+ enable_starttls_auto: true,
32
40
  }
33
41
  end
34
42
  mail_data[:cc] = data[:cc_to].clean_empty.join(",") if data[:cc_to].present?
35
43
  mail_data[:from] = data[:from] if data[:from].present?
44
+
45
+ data[:mail_data] = mail_data
46
+ hooks_run('email_late', data)
47
+
48
+ @subject = subject
49
+ @html = data[:content]
50
+ @url_base = data[:url_base]
51
+ @extra_data = data[:extra_data]
36
52
 
37
53
  views_dir = "app/apps/"
38
54
  self.prepend_view_path(File.join($camaleon_engine_dir, views_dir).to_s)
39
55
  self.prepend_view_path(Rails.root.join(views_dir).to_s)
40
56
 
41
- theme = current_site.get_theme
57
+ theme = @current_site.get_theme
42
58
  lookup_context.prefixes.prepend("themes/#{theme.slug}") if theme.settings["gem_mode"]
43
59
  lookup_context.prefixes.prepend("themes/#{theme.slug}/views") unless theme.settings["gem_mode"]
44
60
  lookup_context.use_camaleon_partial_prefixes = true
@@ -11,8 +11,8 @@ class CamaleonCms::Ability
11
11
  can :read, :all
12
12
  else
13
13
  #conditions:
14
- @roles_manager = user.get_role(current_site).get_meta("_manager_#{current_site.id.to_s}", {})
15
- @roles_post_type ||= user.get_role(current_site).get_meta("_post_type_#{current_site.id.to_s}", {})
14
+ @roles_manager ||= (user.get_role(current_site).get_meta("_manager_#{current_site.id.to_s}", {}) || {})
15
+ @roles_post_type ||= (user.get_role(current_site).get_meta("_post_type_#{current_site.id.to_s}", {}) || {})
16
16
 
17
17
  ids_publish = @roles_post_type[:publish] || []
18
18
  ids_edit = @roles_post_type[:edit] || []
@@ -8,12 +8,12 @@ class CamaleonCms::NavMenu < CamaleonCms::TermTaxonomy
8
8
  # add menu item for current menu
9
9
  # value: (Hash) is a hash object that contains label, type, link
10
10
  # options for type: post | category | post_type | post_tag | external
11
- # sample: {label: "my label", type: "external", link: "http://camaleon.tuzitio.com"}
11
+ # sample: {label: "my label", type: "external", link: "http://camaleon.tuzitio.com", target: '_blank'}
12
12
  # sample: {label: "my label", type: "post", link: 10}
13
13
  # sample: {label: "my label", type: "category", link: 12}
14
14
  # return item created
15
15
  def append_menu_item (value)
16
- item = children.create!({name: value[:label], url: value[:link], kind: value[:type]})
16
+ item = children.create!({name: value[:label], url: value[:link], kind: value[:type], target: value[:target]})
17
17
  item
18
18
  end
19
19
 
@@ -3,6 +3,7 @@ class CamaleonCms::NavMenuItem < CamaleonCms::TermTaxonomy
3
3
  alias_attribute :label, :name
4
4
  alias_attribute :url, :description
5
5
  alias_attribute :kind, :slug
6
+ alias_attribute :target, :status
6
7
  # attr_accessible :label, :url, :kind
7
8
  default_scope { where(taxonomy: :nav_menu_item).order(id: :asc) }
8
9
  has_many :metas, ->{ where(object_class: 'NavMenuItem')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
@@ -31,13 +32,13 @@ class CamaleonCms::NavMenuItem < CamaleonCms::TermTaxonomy
31
32
  # same values of NavMenu#append_menu_item
32
33
  # return item created
33
34
  def append_menu_item(value)
34
- children.create({name: value[:label], url: value[:link], kind: value[:type]})
35
+ children.create({name: value[:label], url: value[:link], kind: value[:type], target: value[:target]})
35
36
  end
36
37
 
37
38
  # update current menu
38
- # value: same as append_menu_item (label, link)
39
+ # value: same as append_menu_item (label, link, target)
39
40
  def update_menu_item(value)
40
- self.update({name: value[:label], url: value[:link]})
41
+ self.update({name: value[:label], url: value[:link], target: value[:target]})
41
42
  end
42
43
 
43
44
  # overwrite skip uniq slug validation
@@ -48,6 +49,7 @@ class CamaleonCms::NavMenuItem < CamaleonCms::TermTaxonomy
48
49
  self.parent.update_column('count', self.parent.children.size) if self.parent.present?
49
50
  self.parent_item.update_column('count', self.parent_item.children.size) if self.parent_item.present?
50
51
  self.update_column(:term_group, main_menu.parent_id)
52
+ self.update_column(:term_order, CamaleonCms::NavMenuItem.where(parent_id: self.parent_id).count) # update position
51
53
  end
52
54
 
53
55
  # fast access from site to menu items
@@ -1,5 +1,6 @@
1
1
  class CamaleonCms::Site < CamaleonCms::TermTaxonomy
2
2
  # attrs: [name, description, slug]
3
+ include CamaleonCms::SiteDefaultSettings
3
4
  default_scope { where(taxonomy: :site).reorder(term_group: :desc) }
4
5
  has_many :metas, -> { where(object_class: 'Site') }, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :delete_all
5
6
  has_many :post_types, :class_name => "CamaleonCms::PostType", foreign_key: :parent_id, dependent: :destroy
@@ -16,7 +17,6 @@ class CamaleonCms::Site < CamaleonCms::TermTaxonomy
16
17
  has_many :themes, :class_name => "CamaleonCms::Theme", foreign_key: :parent_id, dependent: :destroy
17
18
 
18
19
  after_create :default_settings
19
- after_create :set_all_users
20
20
  after_create :set_default_user_roles
21
21
  after_save :update_routes
22
22
  before_destroy :destroy_site
@@ -111,60 +111,6 @@ class CamaleonCms::Site < CamaleonCms::TermTaxonomy
111
111
  get_option('need_validate_email', false) == true
112
112
  end
113
113
 
114
- # auto create default user roles
115
- def set_default_user_roles(post_type = nil)
116
- user_role = self.user_roles.where({slug: 'admin', term_group: -1}).first_or_create({name: 'Administrator', description: 'Default roles admin'})
117
- if user_role.valid?
118
- d, m = {}, {}
119
- pts = self.post_types.all.pluck(:id)
120
- CamaleonCms::UserRole::ROLES[:post_type].each { |value| d[value[:key]] = pts }
121
- CamaleonCms::UserRole::ROLES[:manager].each { |value| m[value[:key]] = 1 }
122
- user_role.set_meta("_post_type_#{self.id}", d || {})
123
- user_role.set_meta("_manager_#{self.id}", m || {})
124
- end
125
-
126
- user_role = self.user_roles.where({slug: 'editor'}).first_or_create({name: 'Editor', description: 'Editor Role'})
127
- if user_role.valid?
128
- d = {}
129
- if post_type.present?
130
- d = user_role.get_meta("_post_type_#{self.id}", {})
131
- CamaleonCms::UserRole::ROLES[:post_type].each { |value|
132
- value_old = d[value[:key].to_sym] || []
133
- d[value[:key].to_sym] = value_old + [post_type.id]
134
- }
135
- else
136
- pts = self.post_types.all.pluck(:id)
137
- CamaleonCms::UserRole::ROLES[:post_type].each { |value| d[value[:key]] = pts }
138
- end
139
- user_role.set_meta("_post_type_#{self.id}", d || {})
140
- end
141
-
142
- user_role = self.user_roles.where({slug: 'contributor'}).first_or_create({name: 'Contributor', description: 'Contributor Role'})
143
- if user_role.valid?
144
- d = {}
145
- if post_type.present?
146
- d = user_role.get_meta("_post_type_#{self.id}", {})
147
- CamaleonCms::UserRole::ROLES[:post_type].each { |value|
148
- value_old = d[value[:key].to_sym] || []
149
- d[value[:key].to_sym] = value_old + [post_type.id] if value[:key].to_s == 'edit'
150
- }
151
- else
152
- pts = self.post_types.all.pluck(:id)
153
- CamaleonCms::UserRole::ROLES[:post_type].each { |value| d[value[:key]] = pts if value[:key].to_s == 'edit' }
154
- end
155
- user_role.set_meta("_post_type_#{self.id}", d || {})
156
- end
157
-
158
- unless post_type.present?
159
- user_role = self.user_roles.where({slug: 'client', term_group: -1}).first_or_create({name: 'Client', description: 'Default roles client'})
160
- if user_role.valid?
161
- user_role.set_meta("_post_type_#{self.id}", {})
162
- user_role.set_meta("_manager_#{self.id}", {})
163
- end
164
- end
165
-
166
- end
167
-
168
114
  # return main site
169
115
  def self.main_site
170
116
  @main_site ||= CamaleonCms::Site.reorder(id: :ASC).first
@@ -175,26 +121,17 @@ class CamaleonCms::Site < CamaleonCms::TermTaxonomy
175
121
  def main_site?
176
122
  self.class.main_site == self
177
123
  end
178
-
179
124
  alias_method :is_default?, :main_site?
180
125
 
181
126
  # list all users of current site
182
127
  def users
183
128
  if PluginRoutes.system_info["users_share_sites"]
184
- CamaleonCms::User.where(site_id: -1)
129
+ CamaleonCms::User.all
185
130
  else
186
131
  CamaleonCms::User.where(site_id: self.id)
187
132
  end
188
133
  end
189
-
190
- # return all users including administrators
191
- def users_include_admins
192
- if PluginRoutes.system_info["users_share_sites"]
193
- CamaleonCms::User.where(site_id: -1)
194
- else
195
- CamaleonCms::User.where("site_id = ? or role = ?", self.id, 'admin')
196
- end
197
- end
134
+ alias_method :users_include_admins, :users
198
135
 
199
136
  # return upload directory for this site (deprecated for cloud support)
200
137
  def upload_directory(inner_directory = nil)
@@ -265,43 +202,10 @@ class CamaleonCms::Site < CamaleonCms::TermTaxonomy
265
202
  users.destroy_all unless PluginRoutes.system_info["users_share_sites"] # destroy all users assigned fot this site
266
203
  end
267
204
 
268
- # default structure for each new site
269
- def default_settings
270
- default_post_type = [
271
- {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, }},
272
- {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}}
273
- ]
274
- default_post_type.each do |pt|
275
- model_pt = self.post_types.create({name: pt[:name], slug: pt[:name].to_s.parameterize, description: pt[:description], data_options: pt[:options]})
276
- end
277
-
278
- # nav menus
279
- @nav_menu = self.nav_menus.new({name: "Main Menu", slug: "main_menu"})
280
- if @nav_menu.save
281
- self.post_types.all.each do |pt|
282
- if pt.slug == "post"
283
- title = "Sample Post"
284
- slug = 'sample-post'
285
- 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>"
286
- else
287
- title = "Welcome"
288
- slug = 'welcome'
289
- 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>&nbsp;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>&nbsp;and MySQL.&nbsp;</p> <p>With Camaleon you can do the following:</p> <ul> <li>Create instantly a lot of sites&nbsp;in the same installation</li> <li>Manage your content information in several languages</li> <li>Extend current functionality by&nbsp;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&nbsp;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&nbsp;more visitors at the same time</li> <li>Manage your information with a panel like wordpress&nbsp;</li> <li>All urls are oriented for SEO</li> <li>Multiples roles of users</li> </ul>"
290
- end
291
- user = self.users.admin_scope.first
292
- user = self.users.admin_scope.create({email: 'admin@local.com', username: 'admin', password: 'admin', password_confirmation: 'admin', first_name: 'Administrator'}) unless user.present?
293
- post = pt.add_post({title: title, slug: slug, content: content, user_id: user.id, status: 'published'})
294
- @nav_menu.append_menu_item({label: title, type: 'post', link: post.id})
295
- end
296
- end
297
- get_anonymous_user
298
- end
299
-
300
205
  # assign all users to this new site
206
+ # DEPRECATED
301
207
  def set_all_users
302
- CamaleonCms::User.all.each do |user|
303
- self.assign_user(user)
304
- end
208
+ return
305
209
  end
306
210
 
307
211
  # update all routes of the system
@@ -1,146 +1,10 @@
1
- class CamaleonCms::UniqValidatorUser < ActiveModel::Validator
2
- def validate(record)
3
- record.errors[:base] << "#{I18n.t('camaleon_cms.admin.users.message.requires_different_username')}" if CamaleonCms::User.where(username: record.username).where.not(id: record.id).where("#{CamaleonCms::User.table_name}.site_id" => record.site_id).size > 0
4
- record.errors[:base] << "#{I18n.t('camaleon_cms.admin.users.message.requires_different_email')}" if CamaleonCms::User.where(email: record.email).where.not(id: record.id).where("#{CamaleonCms::User.table_name}.site_id" => record.site_id).size > 0
1
+ unless PluginRoutes.static_system_info['user_model'].present?
2
+ class CamaleonCms::User < ActiveRecord::Base
3
+ include CamaleonCms::UserMethods
4
+ self.table_name = PluginRoutes.static_system_info["cama_users_db_table"] || "#{PluginRoutes.static_system_info["db_prefix"]}users"
5
+ # attr_accessible :username, :role, :email, :parent_id, :last_login_at, :site_id, :password, :password_confirmation, :first_name, :last_name #, :profile_attributes
6
+ # attr_accessible :is_valid_email
5
7
 
8
+ default_scope {order("#{CamaleonCms::User.table_name}.role ASC")}
6
9
  end
7
- end
8
-
9
- class CamaleonCms::User < ActiveRecord::Base
10
- include CamaleonCms::Metas
11
- include CamaleonCms::CustomFieldsRead
12
- self.table_name = PluginRoutes.static_system_info["cama_users_db_table"] || "#{PluginRoutes.static_system_info["db_prefix"]}users"
13
- # attr_accessible :username, :role, :email, :parent_id, :last_login_at, :site_id, :password, :password_confirmation, :first_name, :last_name #, :profile_attributes
14
- # attr_accessible :is_valid_email
15
-
16
- default_scope {order("#{CamaleonCms::User.table_name}.role ASC")}
17
-
18
- validates :username, :presence => true
19
- validates :email, :presence => true, :format => { :with => /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i } #, :unless => Proc.new { |a| a.auth_social.present? }
20
- validates_with CamaleonCms::UniqValidatorUser
21
-
22
- has_secure_password #validations: :auth_social.nil?
23
-
24
- before_create { generate_token(:auth_token) }
25
- before_save :before_saved
26
- before_create :before_saved
27
- after_create :set_all_sites
28
- before_destroy :reassign_posts
29
- # relations
30
-
31
- has_many :metas, ->{ where(object_class: 'User')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
32
- has_many :user_relationships, class_name: "CamaleonCms::UserRelationship", foreign_key: :user_id, dependent: :destroy#, inverse_of: :user
33
- has_many :term_taxonomies, foreign_key: :term_taxonomy_id, class_name: "CamaleonCms::TermTaxonomy", through: :user_relationships, :source => :term_taxonomies
34
- has_many :sites, foreign_key: :term_taxonomy_id, class_name: "CamaleonCms::Site", through: :user_relationships, :source => :term_taxonomies
35
- has_many :all_posts, class_name: "CamaleonCms::Post"
36
-
37
- #scopes
38
- scope :admin_scope, -> { where(:role => 'admin') }
39
- scope :actives, -> { where(:active => 1) }
40
- scope :not_actives, -> { where(:active => 0) }
41
-
42
- #vars
43
- STATUS = {0 => 'Active', 1=>'Not Active'}
44
- ROLE = { 'admin'=>'Administrator', 'client' => 'Client'}
45
-
46
- # return all posts of this user on site
47
- def posts(site)
48
- site.posts.where(user_id: self.id)
49
- end
50
-
51
- def _id
52
- "#{self.role.upcase}-#{self.id}"
53
- end
54
-
55
- def fullname
56
- "#{self.first_name} #{self.last_name}".titleize
57
- end
58
-
59
- def admin?
60
- role == 'admin'
61
- end
62
-
63
- def client?
64
- self.role == 'client'
65
- end
66
-
67
- # return the UserRole Object of this user in Site
68
- def get_role(site)
69
- @_user_role ||= site.user_roles.where(slug: self.role).first
70
- end
71
-
72
- def assign_site(site)
73
- self.user_relationships.where(term_taxonomy_id: site.id).first_or_create
74
- end
75
-
76
- def roleText
77
- User::ROLE[self.role]
78
- end
79
-
80
- def created
81
- self.created_at.strftime('%d/%m/%Y %H:%M')
82
- end
83
-
84
- def updated
85
- self.updated_at.strftime('%d/%m/%Y %H:%M')
86
- end
87
-
88
- # auth
89
- def generate_token(column)
90
- begin
91
- self[column] = SecureRandom.urlsafe_base64
92
- end while CamaleonCms::User.exists?(column => self[column])
93
- end
94
-
95
- def send_password_reset
96
- generate_token(:password_reset_token)
97
- self.password_reset_sent_at = Time.zone.now
98
- save!
99
- end
100
-
101
- def send_confirm_email
102
- generate_token(:confirm_email_token)
103
- self.confirm_email_sent_at = Time.zone.now
104
- save!
105
- end
106
-
107
- private
108
- def create_profile
109
- self.build_profile if self.profile.nil?
110
- end
111
-
112
- def before_saved
113
- self.role = PluginRoutes.system_info["default_user_role"] if self.role.blank?
114
- end
115
-
116
- def set_all_sites
117
- CamaleonCms::Site.all.each do |site|
118
- self.assign_site(site)
119
- end
120
- end
121
-
122
- # reassign all posts of this user to first admin
123
- # reassign all comments of this user to first admin
124
- # if doesn't exist any other administrator, this will cancel the user destroy
125
- def reassign_posts
126
- sites = CamaleonCms::Site.all
127
- sites.each do |site|
128
- u = site.users.admin_scope.where.not(id: self.id).first
129
- unless u.present?
130
- errors.add(:base, "The site \"#{site.name}\" must have at least one administrator")
131
- return false
132
- end
133
- end
134
-
135
- sites.each do |site|
136
- u = site.users.admin_scope.where.not(id: self.id).first
137
- self.posts(site).each do |p|
138
- p.update_column(:user_id, u.id)
139
- p.comments.where(user_id: self.id).each do |c|
140
- c.update_column(:user_id, u.id)
141
- end
142
- end
143
- end
144
- end
145
-
146
- end
10
+ end