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.
- checksums.yaml +4 -4
- data/Rakefile +7 -12
- data/app/assets/javascripts/camaleon_cms/admin/_custom_fields.js +1 -2
- data/app/assets/javascripts/camaleon_cms/admin/_data.js +1 -0
- data/app/assets/javascripts/camaleon_cms/admin/_post.js +1 -1
- data/app/assets/javascripts/camaleon_cms/admin/_posttype.js.coffee +21 -0
- data/app/assets/javascripts/camaleon_cms/admin/admin-manifest.js +2 -0
- data/app/assets/javascripts/camaleon_cms/admin/jquery_validate/fr.js +49 -0
- data/app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb +11 -6
- data/app/controllers/camaleon_cms/admin/appearances/themes_controller.rb +6 -0
- data/app/controllers/camaleon_cms/admin/media_controller.rb +3 -0
- data/app/controllers/camaleon_cms/admin/users_controller.rb +3 -0
- data/app/controllers/camaleon_cms/camaleon_controller.rb +5 -0
- data/app/controllers/camaleon_cms/frontend_controller.rb +1 -1
- data/app/controllers/concerns/camaleon_cms/frontend_concern.rb +1 -1
- data/app/decorators/camaleon_cms/site_decorator.rb +1 -1
- data/app/decorators/camaleon_cms/user_decorator.rb +4 -0
- data/app/helpers/camaleon_cms/admin/custom_fields_helper.rb +4 -4
- data/app/helpers/camaleon_cms/camaleon_helper.rb +5 -0
- data/app/helpers/camaleon_cms/frontend/nav_menu_helper.rb +16 -16
- data/app/helpers/camaleon_cms/hooks_helper.rb +10 -4
- data/app/helpers/camaleon_cms/plugins_helper.rb +1 -1
- data/app/helpers/camaleon_cms/session_helper.rb +9 -4
- data/app/helpers/camaleon_cms/short_code_helper.rb +1 -1
- data/app/helpers/camaleon_cms/theme_helper.rb +1 -1
- data/app/helpers/camaleon_cms/uploader_helper.rb +10 -7
- data/app/mailers/camaleon_cms/html_mailer.rb +33 -17
- data/app/models/camaleon_cms/ability.rb +2 -2
- data/app/models/camaleon_cms/nav_menu.rb +2 -2
- data/app/models/camaleon_cms/nav_menu_item.rb +5 -3
- data/app/models/camaleon_cms/site.rb +5 -101
- data/app/models/camaleon_cms/user.rb +8 -144
- data/app/models/camaleon_cms/user_relationship.rb +1 -1
- data/app/models/camaleon_cms/user_role.rb +0 -2
- data/app/models/concerns/camaleon_cms/custom_fields_read.rb +14 -7
- data/app/models/concerns/camaleon_cms/metas.rb +5 -4
- data/app/models/concerns/camaleon_cms/site_default_settings.rb +87 -0
- data/app/models/concerns/camaleon_cms/user_methods.rb +142 -0
- data/app/uploaders/camaleon_cms_aws_uploader.rb +13 -4
- data/app/uploaders/camaleon_cms_uploader.rb +3 -1
- data/app/views/camaleon_cms/admin/appearances/nav_menus/_custom_menus.html.erb +11 -5
- data/app/views/camaleon_cms/admin/appearances/nav_menus/_external_menu.html.erb +8 -0
- data/app/views/camaleon_cms/admin/settings/_media_settings.html.erb +4 -0
- data/app/views/camaleon_cms/admin/settings/custom_fields/_get_items.html.erb +155 -154
- data/app/views/camaleon_cms/admin/settings/custom_fields/_render.html.erb +1 -1
- data/app/views/camaleon_cms/admin/settings/custom_fields/fields/_checkbox.html.erb +1 -1
- data/app/views/camaleon_cms/admin/settings/custom_fields/fields/_checkboxes.html.erb +1 -1
- data/app/views/camaleon_cms/admin/settings/custom_fields/fields/_posts.html.erb +2 -5
- data/app/views/camaleon_cms/admin/settings/custom_fields/form.html.erb +1 -1
- data/app/views/camaleon_cms/admin/settings/post_types/_form.html.erb +24 -16
- data/app/views/camaleon_cms/admin/users/form.html.erb +2 -2
- data/app/views/camaleon_cms/default_theme/single.html.erb +1 -1
- data/app/views/layouts/camaleon_cms/admin.html.erb +2 -2
- data/config/initializers/model_alias.rb +10 -3
- data/config/locales/camaleon_cms/admin/en.yml +10 -0
- data/config/locales/camaleon_cms/admin/fr.yml +663 -0
- data/config/locales/camaleon_cms/common.yml +66 -0
- data/config/routes/frontend.rb +1 -1
- data/config/system.json +2 -2
- data/db/migrate/20150611161134_post_table_into_utf8.rb +6 -5
- data/lib/camaleon_cms/engine.rb +3 -0
- data/lib/camaleon_cms/version.rb +1 -1
- data/lib/ext/string.rb +1 -54
- data/lib/plugin_routes.rb +5 -0
- data/spec/decorators/post_type_spec.rb +13 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +26 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +186 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/features/categories_spec.rb +25 -0
- data/spec/features/comments_spec.rb +45 -0
- data/spec/features/contact_form_spec.rb +53 -0
- data/spec/features/content_groups_spec.rb +45 -0
- data/spec/features/custom_fields_spec.rb +47 -0
- data/spec/features/frontend/pages_spec.rb +5 -0
- data/spec/features/languages_spec.rb +27 -0
- data/spec/features/media_spec.rb +50 -0
- data/spec/features/menus_spec.rb +46 -0
- data/spec/features/pages_spec.rb +30 -0
- data/spec/features/plugins_spec.rb +29 -0
- data/spec/features/posts_spec.rb +36 -0
- data/spec/features/session_spec.rb +52 -0
- data/spec/features/settings_spec.rb +17 -0
- data/spec/features/shortcodes_spec.rb +11 -0
- data/spec/features/sites_spec.rb +45 -0
- data/spec/features/tags_spec.rb +25 -0
- data/spec/features/themes_spec.rb +18 -0
- data/spec/features/user_roles_spec.rb +60 -0
- data/spec/features/users_spec.rb +79 -0
- data/spec/features/widgets_spec.rb +50 -0
- data/spec/helpers/email_helper_spec.rb +16 -0
- data/spec/mailers/send_mail_spec.rb +37 -0
- data/spec/rails_helper.rb +1 -0
- data/spec/routing/post_type_routes_spec.rb +12 -0
- data/spec/spec_helper.rb +191 -0
- data/spec/support/common.rb +113 -0
- data/spec/support/wait_for_ajax.rb +36 -0
- metadata +326 -3
@@ -3,5 +3,5 @@ class CamaleonCms::UserRelationship < ActiveRecord::Base
|
|
3
3
|
# attr_accessible :user_id, :term_taxonomy_id, :term_order, :active
|
4
4
|
|
5
5
|
belongs_to :term_taxonomies, :class_name => "CamaleonCms::TermTaxonomy", foreign_key: :term_taxonomy_id, inverse_of: :user_relationships
|
6
|
-
belongs_to :user, :class_name => "CamaleonCms::User", foreign_key: :user_id
|
6
|
+
belongs_to :user, :class_name => "CamaleonCms::User", foreign_key: :user_id
|
7
7
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
class CamaleonCms::UserRole < CamaleonCms::TermTaxonomy
|
2
2
|
default_scope { where(taxonomy: :user_roles) }
|
3
3
|
has_many :metas, ->{ where(object_class: 'UserRole')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
|
4
|
-
has_many :user_relationships, :class_name => "CamaleonCms::UserRelationship", :foreign_key => :term_taxonomy_id, dependent: :destroy
|
5
|
-
has_many :users, through: :user_relationships, :source => :user
|
6
4
|
belongs_to :site, :class_name => "CamaleonCms::Site", foreign_key: :parent_id
|
7
5
|
|
8
6
|
def roles_post_type
|
@@ -53,8 +53,7 @@ module CamaleonCms::CustomFieldsRead extend ActiveSupport::Concern
|
|
53
53
|
# return collections CustomFieldGroup
|
54
54
|
# site: site object
|
55
55
|
def get_user_field_groups(site)
|
56
|
-
|
57
|
-
site.custom_field_groups.where(object_class: class_name)
|
56
|
+
site.custom_field_groups.where(object_class: self.class.to_s.parseCamaClass)
|
58
57
|
end
|
59
58
|
|
60
59
|
|
@@ -112,8 +111,8 @@ module CamaleonCms::CustomFieldsRead extend ActiveSupport::Concern
|
|
112
111
|
self.field_values.to_a.uniq.each do |field_value|
|
113
112
|
custom_field = field_value.custom_fields
|
114
113
|
values = custom_field.values.where(objectid: self.id).pluck(:value)
|
115
|
-
fields[field_value.custom_field_slug] = custom_field.
|
116
|
-
fields[field_value.custom_field_slug] = {values: custom_field.
|
114
|
+
fields[field_value.custom_field_slug] = custom_field.cama_options[:multiple].to_s.to_bool ? values : values.first unless include_options
|
115
|
+
fields[field_value.custom_field_slug] = {values: custom_field.cama_options[:multiple].to_s.to_bool ? values : values.first, options: custom_field.cama_options, id: custom_field.id} if include_options
|
117
116
|
end
|
118
117
|
fields.to_sym
|
119
118
|
end
|
@@ -127,7 +126,7 @@ module CamaleonCms::CustomFieldsRead extend ActiveSupport::Concern
|
|
127
126
|
custom_field = field_value.custom_fields
|
128
127
|
# if custom_field.options[:show_frontend].to_s.to_bool
|
129
128
|
values = custom_field.values.where(objectid: self.id).pluck(:value)
|
130
|
-
fields[field_value.custom_field_slug] = custom_field.attributes.merge(options: custom_field.
|
129
|
+
fields[field_value.custom_field_slug] = custom_field.attributes.merge(options: custom_field.cama_options, values: custom_field.cama_options[:multiple].to_s.to_bool ? values : values.first)
|
131
130
|
# end
|
132
131
|
end
|
133
132
|
fields.to_sym
|
@@ -176,7 +175,13 @@ module CamaleonCms::CustomFieldsRead extend ActiveSupport::Concern
|
|
176
175
|
|
177
176
|
# return field object for current model
|
178
177
|
def get_field_object(slug)
|
179
|
-
CamaleonCms::CustomField.where(
|
178
|
+
CamaleonCms::CustomField.where(
|
179
|
+
slug: slug,
|
180
|
+
parent_id: get_field_groups.pluck(:id),
|
181
|
+
).first || CamaleonCms::CustomField.where(
|
182
|
+
slug: slug,
|
183
|
+
parent_id: get_field_groups({include_parent: true})
|
184
|
+
).first
|
180
185
|
end
|
181
186
|
|
182
187
|
# save all fields sent from browser (reservated for browser request)
|
@@ -231,7 +236,9 @@ module CamaleonCms::CustomFieldsRead extend ActiveSupport::Concern
|
|
231
236
|
def set_field_value(key, value, args = {})
|
232
237
|
args = {order: 0, group_number: 0, field_id: nil, clear: true}.merge(args)
|
233
238
|
args[:field_id] = get_field_object(key).id rescue nil unless args[:field_id].present?
|
234
|
-
|
239
|
+
unless args[:field_id].present?
|
240
|
+
raise ArgumentError, "There is no custom field configured for #{key}"
|
241
|
+
end
|
235
242
|
self.field_values.where({custom_field_slug: key, group_number: args[:group_number]}).delete_all if args[:clear]
|
236
243
|
v = {custom_field_id: args[:field_id], custom_field_slug: key, value: fix_meta_value(value), term_order: args[:order], group_number: args[:group_number]}
|
237
244
|
if value.is_a?(Array)
|
@@ -42,6 +42,7 @@ module CamaleonCms::Metas extend ActiveSupport::Concern
|
|
42
42
|
def options(meta_key = "_default")
|
43
43
|
get_meta(meta_key, {})
|
44
44
|
end
|
45
|
+
alias_method :cama_options, :options
|
45
46
|
|
46
47
|
# add configuration for current object
|
47
48
|
# key: attribute name
|
@@ -50,7 +51,7 @@ module CamaleonCms::Metas extend ActiveSupport::Concern
|
|
50
51
|
# sample: mymodel.set_custom_option("my_settings", "color", "red")
|
51
52
|
def set_option(key, value = nil, meta_key = "_default")
|
52
53
|
return if key.nil?
|
53
|
-
data =
|
54
|
+
data = cama_options(meta_key)
|
54
55
|
data[key] = fix_meta_var(value)
|
55
56
|
set_meta(meta_key, data)
|
56
57
|
value
|
@@ -62,14 +63,14 @@ module CamaleonCms::Metas extend ActiveSupport::Concern
|
|
62
63
|
# return default if option value == ""
|
63
64
|
# return value for attribute
|
64
65
|
def get_option(key = nil, default = nil, meta_key = "_default")
|
65
|
-
values =
|
66
|
+
values = cama_options(meta_key)
|
66
67
|
key = key.to_sym
|
67
68
|
values.has_key?(key) && values[key] != "" ? values[key] : default
|
68
69
|
end
|
69
70
|
|
70
71
|
# delete attribute from configuration
|
71
72
|
def delete_option(key, meta_key = "_default")
|
72
|
-
values =
|
73
|
+
values = cama_options(meta_key)
|
73
74
|
key = key.to_sym
|
74
75
|
values.delete(key) if values.has_key?(key)
|
75
76
|
set_meta(meta_key, values)
|
@@ -79,7 +80,7 @@ module CamaleonCms::Metas extend ActiveSupport::Concern
|
|
79
80
|
# h: {ket1: "sdsds", ff: "fdfdfdfd"}
|
80
81
|
def set_options(h = {}, meta_key = "_default")
|
81
82
|
if h.present?
|
82
|
-
data =
|
83
|
+
data = cama_options(meta_key)
|
83
84
|
PluginRoutes.fixActionParameter(h).to_sym.each do |key, value|
|
84
85
|
data[key] = fix_meta_var(value)
|
85
86
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module CamaleonCms::SiteDefaultSettings extend ActiveSupport::Concern
|
2
|
+
# default structure for each new site
|
3
|
+
def default_settings
|
4
|
+
default_post_type = [
|
5
|
+
{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, }},
|
6
|
+
{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}}
|
7
|
+
]
|
8
|
+
default_post_type.each do |pt|
|
9
|
+
model_pt = self.post_types.create({name: pt[:name], slug: pt[:name].to_s.parameterize, description: pt[:description], data_options: pt[:options]})
|
10
|
+
end
|
11
|
+
|
12
|
+
# nav menus
|
13
|
+
@nav_menu = self.nav_menus.new({name: "Main Menu", slug: "main_menu"})
|
14
|
+
if @nav_menu.save
|
15
|
+
self.post_types.all.each do |pt|
|
16
|
+
if pt.slug == "post"
|
17
|
+
title = "Sample Post"
|
18
|
+
slug = 'sample-post'
|
19
|
+
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>"
|
20
|
+
else
|
21
|
+
title = "Welcome"
|
22
|
+
slug = 'welcome'
|
23
|
+
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>"
|
24
|
+
end
|
25
|
+
user = self.users.admin_scope.first
|
26
|
+
user = self.users.admin_scope.create({email: 'admin@local.com', username: 'admin', password: 'admin', password_confirmation: 'admin', first_name: 'Administrator'}) unless user.present?
|
27
|
+
post = pt.add_post({title: title, slug: slug, content: content, user_id: user.id, status: 'published'})
|
28
|
+
@nav_menu.append_menu_item({label: title, type: 'post', link: post.id})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
get_anonymous_user
|
32
|
+
end
|
33
|
+
|
34
|
+
# auto create default user roles
|
35
|
+
def set_default_user_roles(post_type = nil)
|
36
|
+
user_role = self.user_roles.where({slug: 'admin', term_group: -1}).first_or_create({name: 'Administrator', description: 'Default roles admin'})
|
37
|
+
if user_role.valid?
|
38
|
+
d, m = {}, {}
|
39
|
+
pts = self.post_types.all.pluck(:id)
|
40
|
+
CamaleonCms::UserRole::ROLES[:post_type].each { |value| d[value[:key]] = pts }
|
41
|
+
CamaleonCms::UserRole::ROLES[:manager].each { |value| m[value[:key]] = 1 }
|
42
|
+
user_role.set_meta("_post_type_#{self.id}", d || {})
|
43
|
+
user_role.set_meta("_manager_#{self.id}", m || {})
|
44
|
+
end
|
45
|
+
|
46
|
+
user_role = self.user_roles.where({slug: 'editor'}).first_or_create({name: 'Editor', description: 'Editor Role'})
|
47
|
+
if user_role.valid?
|
48
|
+
d = {}
|
49
|
+
if post_type.present?
|
50
|
+
d = user_role.get_meta("_post_type_#{self.id}", {})
|
51
|
+
CamaleonCms::UserRole::ROLES[:post_type].each { |value|
|
52
|
+
value_old = d[value[:key].to_sym] || []
|
53
|
+
d[value[:key].to_sym] = value_old + [post_type.id]
|
54
|
+
}
|
55
|
+
else
|
56
|
+
pts = self.post_types.all.pluck(:id)
|
57
|
+
CamaleonCms::UserRole::ROLES[:post_type].each { |value| d[value[:key]] = pts }
|
58
|
+
end
|
59
|
+
user_role.set_meta("_post_type_#{self.id}", d || {})
|
60
|
+
end
|
61
|
+
|
62
|
+
user_role = self.user_roles.where({slug: 'contributor'}).first_or_create({name: 'Contributor', description: 'Contributor Role'})
|
63
|
+
if user_role.valid?
|
64
|
+
d = {}
|
65
|
+
if post_type.present?
|
66
|
+
d = user_role.get_meta("_post_type_#{self.id}", {})
|
67
|
+
CamaleonCms::UserRole::ROLES[:post_type].each { |value|
|
68
|
+
value_old = d[value[:key].to_sym] || []
|
69
|
+
d[value[:key].to_sym] = value_old + [post_type.id] if value[:key].to_s == 'edit'
|
70
|
+
}
|
71
|
+
else
|
72
|
+
pts = self.post_types.all.pluck(:id)
|
73
|
+
CamaleonCms::UserRole::ROLES[:post_type].each { |value| d[value[:key]] = pts if value[:key].to_s == 'edit' }
|
74
|
+
end
|
75
|
+
user_role.set_meta("_post_type_#{self.id}", d || {})
|
76
|
+
end
|
77
|
+
|
78
|
+
unless post_type.present?
|
79
|
+
user_role = self.user_roles.where({slug: 'client', term_group: -1}).first_or_create({name: 'Client', description: 'Default roles client'})
|
80
|
+
if user_role.valid?
|
81
|
+
user_role.set_meta("_post_type_#{self.id}", {})
|
82
|
+
user_role.set_meta("_manager_#{self.id}", {})
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
class CamaleonCms::UniqValidatorUser < ActiveModel::Validator
|
2
|
+
def validate(record)
|
3
|
+
users = CamaleonCms::User.all
|
4
|
+
users = CamaleonCms::User.where(site_id: record.site_id) unless PluginRoutes.system_info["users_share_sites"]
|
5
|
+
record.errors[:base] << "#{I18n.t('camaleon_cms.admin.users.message.requires_different_username')}" if users.where(username: record.username).where.not(id: record.id).size > 0
|
6
|
+
record.errors[:base] << "#{I18n.t('camaleon_cms.admin.users.message.requires_different_email')}" if users.where(email: record.email).where.not(id: record.id).size > 0
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module CamaleonCms::UserMethods extend ActiveSupport::Concern
|
11
|
+
included do
|
12
|
+
include CamaleonCms::Metas
|
13
|
+
include CamaleonCms::CustomFieldsRead
|
14
|
+
|
15
|
+
validates :username, :presence => true
|
16
|
+
validates :email, :presence => true, :format => { :with => /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i } #, :unless => Proc.new { |a| a.auth_social.present? }
|
17
|
+
validates_with CamaleonCms::UniqValidatorUser
|
18
|
+
|
19
|
+
has_secure_password #validations: :auth_social.nil?
|
20
|
+
|
21
|
+
before_create { generate_token(:auth_token) }
|
22
|
+
before_save :before_saved
|
23
|
+
before_create :before_saved
|
24
|
+
before_destroy :reassign_posts
|
25
|
+
# relations
|
26
|
+
|
27
|
+
has_many :metas, ->{ where(object_class: 'User')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :destroy
|
28
|
+
has_many :user_relationships, class_name: "CamaleonCms::UserRelationship", foreign_key: :user_id, dependent: :destroy#, inverse_of: :user
|
29
|
+
has_many :term_taxonomies, foreign_key: :term_taxonomy_id, class_name: "CamaleonCms::TermTaxonomy", through: :user_relationships, :source => :term_taxonomies
|
30
|
+
has_many :all_posts, class_name: "CamaleonCms::Post"
|
31
|
+
|
32
|
+
#scopes
|
33
|
+
scope :admin_scope, -> { where(:role => 'admin') }
|
34
|
+
scope :actives, -> { where(:active => 1) }
|
35
|
+
scope :not_actives, -> { where(:active => 0) }
|
36
|
+
|
37
|
+
#vars
|
38
|
+
STATUS = {0 => 'Active', 1=>'Not Active'}
|
39
|
+
ROLE = { 'admin'=>'Administrator', 'client' => 'Client'}
|
40
|
+
end
|
41
|
+
|
42
|
+
# return all posts of this user on site
|
43
|
+
def posts(site)
|
44
|
+
site.posts.where(user_id: self.id)
|
45
|
+
end
|
46
|
+
|
47
|
+
def _id
|
48
|
+
"#{self.role.upcase}-#{self.id}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def fullname
|
52
|
+
"#{self.first_name} #{self.last_name}".titleize
|
53
|
+
end
|
54
|
+
|
55
|
+
def admin?
|
56
|
+
role == 'admin'
|
57
|
+
end
|
58
|
+
|
59
|
+
def client?
|
60
|
+
self.role == 'client'
|
61
|
+
end
|
62
|
+
|
63
|
+
# return the UserRole Object of this user in Site
|
64
|
+
def get_role(site)
|
65
|
+
@_user_role ||= site.user_roles.where(slug: self.role).first
|
66
|
+
end
|
67
|
+
|
68
|
+
# assign a new site for current user
|
69
|
+
def assign_site(site)
|
70
|
+
self.update_column(:site_id, site.id)
|
71
|
+
end
|
72
|
+
|
73
|
+
def sites
|
74
|
+
if PluginRoutes.system_info["users_share_sites"]
|
75
|
+
CamaleonCms::Site.all
|
76
|
+
else
|
77
|
+
CamaleonCms::Site.where(id: self.site_id)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# DEPRECATED, please use user.the_role
|
82
|
+
def roleText
|
83
|
+
User::ROLE[self.role]
|
84
|
+
end
|
85
|
+
|
86
|
+
def created
|
87
|
+
self.created_at.strftime('%d/%m/%Y %H:%M')
|
88
|
+
end
|
89
|
+
|
90
|
+
def updated
|
91
|
+
self.updated_at.strftime('%d/%m/%Y %H:%M')
|
92
|
+
end
|
93
|
+
|
94
|
+
# auth
|
95
|
+
def generate_token(column)
|
96
|
+
begin
|
97
|
+
self[column] = SecureRandom.urlsafe_base64
|
98
|
+
end while CamaleonCms::User.exists?(column => self[column])
|
99
|
+
end
|
100
|
+
|
101
|
+
def send_password_reset
|
102
|
+
generate_token(:password_reset_token)
|
103
|
+
self.password_reset_sent_at = Time.zone.now
|
104
|
+
save!
|
105
|
+
end
|
106
|
+
|
107
|
+
def send_confirm_email
|
108
|
+
generate_token(:confirm_email_token)
|
109
|
+
self.confirm_email_sent_at = Time.zone.now
|
110
|
+
save!
|
111
|
+
end
|
112
|
+
|
113
|
+
def decorator_class
|
114
|
+
'CamaleonCms::UserDecorator'.constantize
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
def before_saved
|
119
|
+
self.role = PluginRoutes.system_info["default_user_role"] if self.role.blank?
|
120
|
+
end
|
121
|
+
|
122
|
+
# deprecated
|
123
|
+
def set_all_sites
|
124
|
+
return
|
125
|
+
end
|
126
|
+
|
127
|
+
# reassign all posts of this user to first admin
|
128
|
+
# reassign all comments of this user to first admin
|
129
|
+
# if doesn't exist any other administrator, this will cancel the user destroy
|
130
|
+
def reassign_posts
|
131
|
+
all_posts.each do |p|
|
132
|
+
s = p.post_type.site
|
133
|
+
u = s.users.admin_scope.where.not(id: self.id).first
|
134
|
+
if u.present?
|
135
|
+
p.update_column(:user_id, u.id)
|
136
|
+
p.comments.where(user_id: self.id).each do |c|
|
137
|
+
c.update_column(:user_id, u.id)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -1,4 +1,13 @@
|
|
1
1
|
class CamaleonCmsAwsUploader < CamaleonCmsUploader
|
2
|
+
|
3
|
+
def after_initialize
|
4
|
+
@cloudfront = @aws_settings[:cloud_front] || @current_site.get_option("filesystem_s3_cloudfront")
|
5
|
+
@aws_region = @aws_settings[:region] || @current_site.get_option("filesystem_region", 'us-west-2')
|
6
|
+
@aws_akey = @aws_settings[:access_key] || @current_site.get_option("filesystem_s3_access_key")
|
7
|
+
@aws_asecret = @aws_settings[:secret_key] || @current_site.get_option("filesystem_s3_secret_key")
|
8
|
+
@aws_bucket = @aws_settings[:bucket] || @current_site.get_option("filesystem_s3_bucket_name")
|
9
|
+
end
|
10
|
+
|
2
11
|
# recover all files from AWS and parse it to save into DB as cache
|
3
12
|
def browser_files
|
4
13
|
objects = {}
|
@@ -14,11 +23,11 @@ class CamaleonCmsAwsUploader < CamaleonCmsUploader
|
|
14
23
|
def file_parse(s3_file)
|
15
24
|
key = s3_file.is_a?(String) ? s3_file : s3_file.key
|
16
25
|
key = "/#{key}" unless key.starts_with?('/')
|
17
|
-
is_dir = File.extname(key) == ''
|
26
|
+
is_dir = s3_file.is_a?(String) || File.extname(key) == ''
|
18
27
|
res = {
|
19
28
|
"name" => File.basename(key),
|
20
29
|
"key" => key,
|
21
|
-
"url" => is_dir ? '' : (@
|
30
|
+
"url" => is_dir ? '' : (@cloudfront.present? ? File.join(@cloudfront, key) : s3_file.public_url),
|
22
31
|
"is_folder" => is_dir,
|
23
32
|
"size" => is_dir ? 0 : s3_file.size.round(2),
|
24
33
|
"format" => is_dir ? 'folder' : self.class.get_file_format(key),
|
@@ -73,9 +82,9 @@ class CamaleonCmsAwsUploader < CamaleonCmsUploader
|
|
73
82
|
# return: (AWS Bucket object)
|
74
83
|
def bucket
|
75
84
|
@bucket ||= lambda{
|
76
|
-
config = Aws.config.update({ region: @
|
85
|
+
config = Aws.config.update({ region: @aws_region, credentials: Aws::Credentials.new(@aws_akey, @aws_asecret) })
|
77
86
|
s3 = Aws::S3::Resource.new
|
78
|
-
bucket = s3.bucket(@
|
87
|
+
bucket = s3.bucket(@aws_bucket)
|
79
88
|
}.call
|
80
89
|
end
|
81
90
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
class CamaleonCmsUploader
|
2
2
|
attr_accessor :thumb
|
3
|
-
# root_folder, current_site,
|
3
|
+
# root_folder= '/var/www/my_public_foler/', current_site= CamaSite.first.decorate, thumb = {w: 100, h: 75},
|
4
|
+
# aws_settings: {region, access_key, secret_key, bucket}
|
4
5
|
def initialize(args = {})
|
5
6
|
@current_site = args[:current_site]
|
6
7
|
t_w, t_h = @current_site.get_option('filesystem_thumb_size', '100x100').split('x')
|
7
8
|
@thumb = args[:thumb] || {w: t_w, h: t_h}
|
9
|
+
@aws_settings = args[:aws_settings] || {}
|
8
10
|
@args = args
|
9
11
|
after_initialize
|
10
12
|
end
|
@@ -20,11 +20,17 @@ r = {custom_menus: {}, menu: @nav_menu}; hooks_run("nav_menu_custom", r) %>
|
|
20
20
|
<div class="tab-pane active class_type">
|
21
21
|
<ul class="">
|
22
22
|
<% r[:custom_menus].each do |k, item| %>
|
23
|
-
|
24
|
-
<
|
25
|
-
<
|
26
|
-
|
27
|
-
|
23
|
+
<% if item[:link].present? %>
|
24
|
+
<li>
|
25
|
+
<label class="class_slug">
|
26
|
+
<input type="checkbox" value="<%= item[:link] %>" data-label="<%= item[:title] %>"> <%= item[:title] %>
|
27
|
+
</label>
|
28
|
+
</li>
|
29
|
+
<% else %>
|
30
|
+
<li>
|
31
|
+
<h4><%= item[:title] %></h4>
|
32
|
+
</li>
|
33
|
+
<% end %>
|
28
34
|
<% end %>
|
29
35
|
</ul>
|
30
36
|
</div>
|
@@ -8,7 +8,15 @@
|
|
8
8
|
<label><%= t('camaleon_cms.admin.menus.link_url')%></label>
|
9
9
|
<input id="external_url" class="form-control translatable" name="external_url" value="<%= menu_item.url %>" />
|
10
10
|
</div>
|
11
|
+
<div class="form-group">
|
12
|
+
<label><%= t('camaleon_cms.admin.menus.target', default: 'Target')%></label>
|
13
|
+
<%= select_tag 'target', options_for_select({'_blank' => t('camaleon_cms.admin.menus.targets.blank', default: 'Blank'), '_parent' => t('camaleon_cms.admin.menus.targets.parent', default: 'Parent')}.invert, menu_item.target), include_blank: true, class: 'form-control' %>
|
14
|
+
</div>
|
15
|
+
|
11
16
|
<%= r = {html: "", menu_item: menu_item, nav_menu: nav_menu}; hooks_run("menu_external_form", r); raw(r[:html]); %>
|
17
|
+
<!--Sample custom values for external menus using above hook -->
|
18
|
+
<!--<input class="form-control translatable" name="options[external_urlll]" value="<%#= menu_item.get_option('external_urlll') %>" />-->
|
19
|
+
|
12
20
|
<div class="text-right">
|
13
21
|
<button type="submit" id="add_external_link" class="btn btn-primary"><%= menu_item.new_record? ? t('camaleon_cms.admin.button.add_menu', default: 'Add to Menu') : t('camaleon_cms.admin.button.update_menu', default: 'Update Menu') %> <i class="fa fa-arrow-right"></i></button>
|
14
22
|
</div>
|
@@ -7,4 +7,8 @@
|
|
7
7
|
<label for=""><%= t('camaleon_cms.admin.settings.filesystem_thumb_size', default: 'Thumbnail dimension [100x100]') %></label><br>
|
8
8
|
<%= text_field :options, :filesystem_thumb_size, :class => "form-control", :value => @site.get_option('filesystem_thumb_size', '100x100'), placeholder: '100x100' %>
|
9
9
|
</div>
|
10
|
+
<div class="form-group">
|
11
|
+
<label for=""><%= t('camaleon_cms.admin.settings.file_actions_in_modals', default: 'Show File Actions in Modals') %></label><br>
|
12
|
+
<%= check_box :options, :file_actions_in_modals, {checked: @site.get_option('file_actions_in_modals') == 'yes'}, 'yes', 'no' %>
|
13
|
+
</div>
|
10
14
|
</div>
|