camaleon_cms 2.5.3.1 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/app/apps/plugins/front_cache/front_cache_helper.rb +1 -1
  3. data/app/assets/images/camaleon_cms/language/md.png +0 -0
  4. data/app/models/camaleon_cms/ability.rb +94 -92
  5. data/app/models/camaleon_cms/category.rb +45 -44
  6. data/app/models/camaleon_cms/custom_field.rb +26 -25
  7. data/app/models/camaleon_cms/custom_field_group.rb +115 -114
  8. data/app/models/camaleon_cms/custom_fields_relationship.rb +21 -19
  9. data/app/models/camaleon_cms/media.rb +48 -44
  10. data/app/models/camaleon_cms/meta.rb +5 -3
  11. data/app/models/camaleon_cms/nav_menu.rb +27 -24
  12. data/app/models/camaleon_cms/nav_menu_item.rb +58 -54
  13. data/app/models/camaleon_cms/plugin.rb +62 -60
  14. data/app/models/camaleon_cms/post.rb +205 -227
  15. data/app/models/camaleon_cms/post_comment.rb +44 -42
  16. data/app/models/camaleon_cms/post_default.rb +65 -62
  17. data/app/models/camaleon_cms/post_relationship.rb +1 -2
  18. data/app/models/camaleon_cms/post_tag.rb +9 -6
  19. data/app/models/camaleon_cms/post_type.rb +170 -163
  20. data/app/models/camaleon_cms/site.rb +211 -203
  21. data/app/models/camaleon_cms/term_relationship.rb +16 -14
  22. data/app/models/camaleon_cms/term_taxonomy.rb +49 -54
  23. data/app/models/camaleon_cms/theme.rb +24 -23
  24. data/app/models/camaleon_cms/user.rb +18 -13
  25. data/app/models/camaleon_cms/user_role.rb +130 -128
  26. data/app/models/camaleon_cms/widget/assigned.rb +25 -21
  27. data/app/models/camaleon_cms/widget/main.rb +40 -36
  28. data/app/models/camaleon_cms/widget/sidebar.rb +20 -16
  29. data/app/validators/camaleon_cms/post_uniq_validator.rb +28 -0
  30. data/app/validators/camaleon_cms/uniq_validator.rb +9 -0
  31. data/config/locales/camaleon_cms/admin/ar.yml +1 -0
  32. data/config/locales/camaleon_cms/admin/de.yml +1 -0
  33. data/config/locales/camaleon_cms/admin/en.yml +82 -21
  34. data/config/locales/camaleon_cms/admin/fr.yml +1 -0
  35. data/config/locales/camaleon_cms/admin/it.yml +1 -0
  36. data/config/locales/camaleon_cms/admin/js/de.yml +51 -0
  37. data/config/locales/camaleon_cms/admin/js/en.yml +51 -0
  38. data/config/locales/camaleon_cms/admin/js/es.yml +53 -0
  39. data/config/locales/camaleon_cms/admin/js/it.yml +44 -0
  40. data/config/locales/camaleon_cms/admin/js/nl.yml +42 -0
  41. data/config/locales/camaleon_cms/admin/js/pt-BR.yml +44 -0
  42. data/config/locales/camaleon_cms/admin/js/ru.yml +51 -0
  43. data/config/locales/camaleon_cms/admin/js/uk.yml +51 -0
  44. data/config/locales/camaleon_cms/admin/js/zh-CN.yml +51 -0
  45. data/config/locales/camaleon_cms/admin/nl.yml +1 -0
  46. data/config/locales/camaleon_cms/admin/ru.yml +1 -0
  47. data/config/locales/camaleon_cms/admin/uk.yml +2 -1
  48. data/config/locales/camaleon_cms/admin/zh-CH.yml +1 -0
  49. data/config/locales/camaleon_cms/common.md +3 -0
  50. data/config/locales/camaleon_cms/common/ar.yml +66 -0
  51. data/config/locales/camaleon_cms/common/de.yml +66 -0
  52. data/config/locales/camaleon_cms/common/en.yml +63 -0
  53. data/config/locales/camaleon_cms/common/es.yml +66 -0
  54. data/config/locales/camaleon_cms/common/fr.yml +66 -0
  55. data/config/locales/camaleon_cms/common/it.yml +63 -0
  56. data/config/locales/camaleon_cms/common/md.yml +60 -0
  57. data/config/locales/camaleon_cms/common/nl.yml +64 -0
  58. data/config/locales/camaleon_cms/common/pt-BR.yml +65 -0
  59. data/config/locales/camaleon_cms/common/pt.yml +65 -0
  60. data/config/locales/camaleon_cms/common/ru.yml +66 -0
  61. data/config/locales/camaleon_cms/common/uk.yml +64 -0
  62. data/config/locales/camaleon_cms/common/zh-CN.yml +66 -0
  63. data/config/locales/camaleon_cms/languages/ar.yml +16 -0
  64. data/config/locales/camaleon_cms/languages/de.yml +16 -0
  65. data/config/locales/camaleon_cms/languages/en.yml +16 -0
  66. data/config/locales/camaleon_cms/languages/es.yml +16 -0
  67. data/config/locales/camaleon_cms/languages/it.yml +16 -0
  68. data/config/locales/camaleon_cms/languages/md.yml +15 -0
  69. data/config/locales/camaleon_cms/languages/nl.yml +16 -0
  70. data/config/locales/camaleon_cms/languages/pt-BR.yml +16 -0
  71. data/config/locales/camaleon_cms/languages/pt.yml +16 -0
  72. data/config/locales/camaleon_cms/languages/ru.yml +16 -0
  73. data/config/locales/camaleon_cms/languages/uk.yml +16 -0
  74. data/config/locales/camaleon_cms/languages/zh-CN.yml +16 -0
  75. data/config/locales/camaleon_cms/routes/de.yml +8 -0
  76. data/config/locales/camaleon_cms/routes/es.yml +8 -0
  77. data/config/locales/camaleon_cms/routes/fr.yml +8 -0
  78. data/config/locales/camaleon_cms/routes/it.yml +8 -0
  79. data/config/locales/camaleon_cms/routes/md.yml +8 -0
  80. data/config/locales/camaleon_cms/routes/pt-BR.yml +8 -0
  81. data/config/locales/camaleon_cms/routes/pt.yml +8 -0
  82. data/config/locales/camaleon_cms/routes/ru.yml +8 -0
  83. data/config/locales/camaleon_cms/routes/uk.yml +8 -0
  84. data/config/locales/camaleon_cms/routes/zh-CN.yml +8 -0
  85. data/config/locales/md.yml +207 -0
  86. data/lib/camaleon_cms/version.rb +1 -1
  87. data/spec/dummy/config/application.rb +14 -2
  88. metadata +102 -109
  89. data/config/locales/camaleon_cms/admin/js.yml +0 -435
  90. data/config/locales/camaleon_cms/common.yml +0 -786
  91. data/config/locales/camaleon_cms/languages.yml +0 -167
  92. data/config/locales/camaleon_cms/routes.yml +0 -71
  93. data/spec/dummy/db/development.sqlite3 +0 -0
  94. data/spec/dummy/db/test.sqlite3 +0 -0
  95. data/spec/dummy/log/development.log +0 -254
  96. data/spec/dummy/log/test.log +0 -46384
  97. data/spec/dummy/public/media/1/rails_tmp.png +0 -0
  98. data/spec/dummy/public/media/1/rails_tmp_1.png +0 -0
  99. data/spec/dummy/public/media/1/rails_tmp_2.png +0 -0
  100. data/spec/dummy/public/media/1/rails_tmp_3.png +0 -0
  101. data/spec/dummy/public/media/1/sample/rails_tmp.png +0 -0
  102. data/spec/dummy/public/media/1/sample/thumb/rails_tmp-png.png +0 -0
  103. data/spec/dummy/public/media/1/slide33.jpg +0 -0
  104. data/spec/dummy/public/media/1/thumb/rails_tmp-png.png +0 -0
  105. data/spec/dummy/public/media/1/thumb/rails_tmp-png_20x.png +0 -0
  106. data/spec/dummy/public/media/1/thumb/rails_tmp-png_300x300.png +0 -0
  107. data/spec/dummy/public/media/1/thumb/rails_tmp-png_505x350.png +0 -0
  108. data/spec/dummy/public/media/1/thumb/rails_tmp_1-png.png +0 -0
  109. data/spec/dummy/public/media/1/thumb/rails_tmp_2-png.png +0 -0
  110. data/spec/dummy/public/media/1/thumb/rails_tmp_3-png.png +0 -0
  111. data/spec/dummy/public/media/1/thumb/slide33-jpg.jpg +0 -0
  112. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-13.472.html +0 -457
  113. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-13.472.png +0 -0
  114. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-28.693.html +0 -428
  115. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-19-28.693.png +0 -0
  116. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-22-45.502.html +0 -337
  117. data/spec/dummy/tmp/capybara/screenshot_2019-09-04-09-22-45.502.png +0 -0
  118. data/spec/support/fixtures/rails_tmp.png +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30adea4169e0803e53034bc3b43fab98c94d1283b7a61bce52381d0bcbc18d3e
4
- data.tar.gz: b8e7c5cf3f14f1d72fd9725ec1e6c4c15babe9a5ccd8d89e35ba79bac49fd5a0
3
+ metadata.gz: 397cc4329729b870190f21057d1d58a8cd9877479851c865953d41280fa88be1
4
+ data.tar.gz: c694f405c6161e611c6c21432e73f2d3e371efe55156196b0323674ac35832f0
5
5
  SHA512:
6
- metadata.gz: 676d4efcc885eb8eb35b2ed29f3adeef52aba1438924ce4f90e6eb1151a6b801008722dcec0a1f85b6f8f080ca99dde33c6f9210326e69edfffd854717b5b846
7
- data.tar.gz: '0529c9a722fb77fcae4d00391749a5fe1804a39dd33fa422ff6c8783baa2d6113f1d1547c9eb7408243511f011cd36c65f7d49d00f336a81920c008210e8a8aa'
6
+ metadata.gz: 7eafee5524c10e26013ebaf8639759fda224c9611bc9143d455009d7b56568f80f108d5c678e740429d9e96aeff18fb65cde892d13d93affd901d1b4522eddef
7
+ data.tar.gz: c17d29772c58a438fb8374fdd1c0cc9ddadd83925bd5940839d1a8c96a00f89f63798973fd4088fa3ce828c997a3be673c4dd71fbe226c2292794c7d6c3646f8
@@ -95,7 +95,7 @@ module Plugins::FrontCache::FrontCacheHelper
95
95
  @caches[:cache_counter] += 1
96
96
  current_site.set_meta("front_cache_elements", @caches)
97
97
  else
98
- Rails.cache.clear rescue nil
98
+ Rails.cache.clear
99
99
  @caches[:cache_counter] = 0
100
100
  current_site.set_meta("front_cache_elements", @caches)
101
101
  end
@@ -1,109 +1,111 @@
1
- class CamaleonCms::Ability
2
- include CanCan::Ability
1
+ module CamaleonCms
2
+ class Ability
3
+ include CanCan::Ability
3
4
 
4
- def initialize(user, current_site = nil)
5
- # Define abilities for the passed in user here. For example:
6
- #
7
- user ||= CamaleonCms::User.new # guest user (not logged in)
8
- if user.admin?
9
- can :manage, :all
10
- elsif user.client?
11
- can :read, :all
12
- else
13
- # conditions:
14
- current_user_role = user.get_role(current_site) || current_site.user_roles.new
15
- @roles_manager ||= current_user_role.get_meta("_manager_#{current_site.id}", {}) || {}
16
- @roles_post_type ||= current_user_role.get_meta("_post_type_#{current_site.id}", {}) || {}
5
+ def initialize(user, current_site = nil)
6
+ # Define abilities for the passed in user here. For example:
7
+ #
8
+ user ||= CamaleonCms::User.new # guest user (not logged in)
9
+ if user.admin?
10
+ can :manage, :all
11
+ elsif user.client?
12
+ can :read, :all
13
+ else
14
+ # conditions:
15
+ current_user_role = user.get_role(current_site) || current_site.user_roles.new
16
+ @roles_manager ||= current_user_role.get_meta("_manager_#{current_site.id}", {}) || {}
17
+ @roles_post_type ||= current_user_role.get_meta("_post_type_#{current_site.id}", {}) || {}
17
18
 
18
- ids_publish = @roles_post_type[:publish] || []
19
- ids_edit = @roles_post_type[:edit] || []
20
- ids_edit_other = @roles_post_type[:edit_other] || []
21
- ids_edit_publish = @roles_post_type[:edit_publish] || []
22
- ids_delete = @roles_post_type[:delete] || []
23
- ids_delete_other = @roles_post_type[:delete_other] || []
24
- ids_delete_publish = @roles_post_type[:delete_publish] || []
19
+ ids_publish = @roles_post_type[:publish] || []
20
+ ids_edit = @roles_post_type[:edit] || []
21
+ ids_edit_other = @roles_post_type[:edit_other] || []
22
+ ids_edit_publish = @roles_post_type[:edit_publish] || []
23
+ ids_delete = @roles_post_type[:delete] || []
24
+ ids_delete_other = @roles_post_type[:delete_other] || []
25
+ ids_delete_publish = @roles_post_type[:delete_publish] || []
25
26
 
26
- can :posts, CamaleonCms::PostType do |pt|
27
- (ids_edit + ids_edit_other + ids_edit_publish).to_i.include?(pt.id) rescue false
28
- end
27
+ can :posts, CamaleonCms::PostType do |pt|
28
+ (ids_edit + ids_edit_other + ids_edit_publish).to_i.include?(pt.id) rescue false
29
+ end
29
30
 
30
- can :create_post, CamaleonCms::PostType do |pt|
31
- ids_edit.to_i.include?(pt.id) rescue false
32
- end
33
- can :publish_post, CamaleonCms::PostType do |pt|
34
- ids_publish.to_i.include?(pt.id) rescue false
35
- end
36
- can :edit_other, CamaleonCms::PostType do |pt|
37
- ids_edit_other.to_i.include?(pt.id) rescue false
38
- end
39
- can :edit_publish, CamaleonCms::PostType do |pt|
40
- ids_edit_publish.to_i.include?(pt.id) rescue false
41
- end
31
+ can :create_post, CamaleonCms::PostType do |pt|
32
+ ids_edit.to_i.include?(pt.id) rescue false
33
+ end
34
+ can :publish_post, CamaleonCms::PostType do |pt|
35
+ ids_publish.to_i.include?(pt.id) rescue false
36
+ end
37
+ can :edit_other, CamaleonCms::PostType do |pt|
38
+ ids_edit_other.to_i.include?(pt.id) rescue false
39
+ end
40
+ can :edit_publish, CamaleonCms::PostType do |pt|
41
+ ids_edit_publish.to_i.include?(pt.id) rescue false
42
+ end
42
43
 
43
- can :categories, CamaleonCms::PostType do |pt|
44
- @roles_post_type[:manage_categories].to_i.include?(pt.id) rescue false
45
- end
46
- can :post_tags, CamaleonCms::PostType do |pt|
47
- @roles_post_type[:manage_tags].to_i.include?(pt.id) rescue false
48
- end
44
+ can :categories, CamaleonCms::PostType do |pt|
45
+ @roles_post_type[:manage_categories].to_i.include?(pt.id) rescue false
46
+ end
47
+ can :post_tags, CamaleonCms::PostType do |pt|
48
+ @roles_post_type[:manage_tags].to_i.include?(pt.id) rescue false
49
+ end
49
50
 
50
- can :update, CamaleonCms::Post do |post|
51
- pt_id = post.post_type.id
52
- r = false
53
- r ||= ids_edit.to_i.include?(pt_id) && post.user_id == user.id rescue false
54
- r ||= ids_edit_publish.to_i.include?(pt_id) && post.published? rescue false
55
- r ||= ids_edit_other.to_i.include?(pt_id) && post.user_id != user.id rescue false
56
- r
57
- end
51
+ can :update, CamaleonCms::Post do |post|
52
+ pt_id = post.post_type.id
53
+ r = false
54
+ r ||= ids_edit.to_i.include?(pt_id) && post.user_id == user.id rescue false
55
+ r ||= ids_edit_publish.to_i.include?(pt_id) && post.published? rescue false
56
+ r ||= ids_edit_other.to_i.include?(pt_id) && post.user_id != user.id rescue false
57
+ r
58
+ end
58
59
 
59
- can :destroy, CamaleonCms::Post do |post|
60
- pt_id = post.post_type.id
61
- r = false
62
- r ||= ids_delete.to_i.include?(pt_id) && post.user_id == user.id rescue false
63
- r ||= ids_delete_publish.to_i.include?(pt_id) && post.published? rescue false
64
- r ||= ids_delete_other.to_i.include?(pt_id) && post.user_id != user.id rescue false
65
- r
66
- end
60
+ can :destroy, CamaleonCms::Post do |post|
61
+ pt_id = post.post_type.id
62
+ r = false
63
+ r ||= ids_delete.to_i.include?(pt_id) && post.user_id == user.id rescue false
64
+ r ||= ids_delete_publish.to_i.include?(pt_id) && post.published? rescue false
65
+ r ||= ids_delete_other.to_i.include?(pt_id) && post.user_id != user.id rescue false
66
+ r
67
+ end
67
68
 
68
- # support for custom abilities for each posttype
69
- # sample: http://camaleon.tuzitio.com/documentation/category/40756-uncategorized/custom-models.html
70
- @roles_post_type.each do |k , v|
71
- next if ['edit', 'edit_other', 'edit_publish', 'publish', 'manage_categories'].include?(k.to_s)
72
- can k.to_sym, CamaleonCms::PostType do |pt|
73
- v.include?(pt.id.to_s) rescue false
69
+ # support for custom abilities for each posttype
70
+ # sample: http://camaleon.tuzitio.com/documentation/category/40756-uncategorized/custom-models.html
71
+ @roles_post_type.each do |k , v|
72
+ next if ['edit', 'edit_other', 'edit_publish', 'publish', 'manage_categories'].include?(k.to_s)
73
+ can k.to_sym, CamaleonCms::PostType do |pt|
74
+ v.include?(pt.id.to_s) rescue false
75
+ end
74
76
  end
75
- end
76
77
 
77
- # others
78
- can :manage, :media if @roles_manager[:media] rescue false
79
- can :manage, :comments if @roles_manager[:comments] rescue false
80
- # can :manage, :forms if @roles_manager[:forms] rescue false
81
- can :manage, :themes if @roles_manager[:themes] rescue false
82
- can :manage, :widgets if @roles_manager[:widgets] rescue false
83
- can :manage, :nav_menu if @roles_manager[:nav_menu] rescue false
84
- can :manage, :plugins if @roles_manager[:plugins] rescue false
85
- can :manage, :users if @roles_manager[:users] rescue false
86
- can :manage, :settings if @roles_manager[:settings] rescue false
87
- @roles_manager.try(:each) do |rol_manage_key, val_role|
88
- can :manage, rol_manage_key.to_sym if val_role.to_s.cama_true? rescue false
78
+ # others
79
+ can :manage, :media if @roles_manager[:media] rescue false
80
+ can :manage, :comments if @roles_manager[:comments] rescue false
81
+ # can :manage, :forms if @roles_manager[:forms] rescue false
82
+ can :manage, :themes if @roles_manager[:themes] rescue false
83
+ can :manage, :widgets if @roles_manager[:widgets] rescue false
84
+ can :manage, :nav_menu if @roles_manager[:nav_menu] rescue false
85
+ can :manage, :plugins if @roles_manager[:plugins] rescue false
86
+ can :manage, :users if @roles_manager[:users] rescue false
87
+ can :manage, :settings if @roles_manager[:settings] rescue false
88
+ @roles_manager.try(:each) do |rol_manage_key, val_role|
89
+ can :manage, rol_manage_key.to_sym if val_role.to_s.cama_true? rescue false
90
+ end
91
+ end
92
+ cannot :impersonate, CamaleonCms::User do |u|
93
+ u.id == user.id
89
94
  end
90
95
  end
91
- cannot :impersonate, CamaleonCms::User do |u|
92
- u.id == user.id
93
- end
94
- end
95
96
 
96
- # overwrite can method to support decorator class names
97
- def can?(action, subject, *extra_args)
98
- if subject.is_a?(Draper::Decorator)
99
- super(action,subject.model,*extra_args)
100
- else
101
- super(action, subject, *extra_args)
97
+ # overwrite can method to support decorator class names
98
+ def can?(action, subject, *extra_args)
99
+ if subject.is_a?(Draper::Decorator)
100
+ super(action,subject.model,*extra_args)
101
+ else
102
+ super(action, subject, *extra_args)
103
+ end
102
104
  end
103
- end
104
105
 
105
- # overwrite cannot method to support decorator class names
106
- def cannot?(*args)
107
- !can?(*args)
106
+ # overwrite cannot method to support decorator class names
107
+ def cannot?(*args)
108
+ !can?(*args)
109
+ end
108
110
  end
109
111
  end
@@ -1,51 +1,52 @@
1
- class CamaleonCms::Category < CamaleonCms::TermTaxonomy
2
- alias_attribute :site_id, :term_group
3
- alias_attribute :post_type_id, :status
4
-
5
- default_scope { where(taxonomy: :category) }
6
- scope :no_empty, -> { where('count > 0') } # return all categories that contains at least one post
7
- scope :empty, -> { where(count: [0, nil]) } # return all categories that does not contain any post
8
- # scope :parents, -> { where("term_taxonomy.parent_id IS NULL") }
9
-
10
- cama_define_common_relationships('Category')
11
- has_many :posts, foreign_key: :objectid, through: :term_relationships, source: :objects
12
- has_many :children, class_name: 'CamaleonCms::Category', foreign_key: :parent_id,
13
- dependent: :destroy
14
- belongs_to :parent, class_name: 'CamaleonCms::Category', foreign_key: :parent_id
15
- belongs_to :post_type_parent, class_name: 'CamaleonCms::PostType', foreign_key: :parent_id,
16
- inverse_of: :categories
17
- belongs_to :site, class_name: 'CamaleonCms::Site', foreign_key: :site_id
18
-
19
- before_save :set_site
20
- before_destroy :set_posts_in_default_category
21
-
22
- # return the post type of this category
23
- def post_type
24
- cama_fetch_cache('post_type') do
25
- ctg = self
26
- begin
27
- pt = ctg.post_type_parent
28
- ctg = ctg.parent
29
- end while ctg.present?
30
- pt
1
+ module CamaleonCms
2
+ class Category < CamaleonCms::TermTaxonomy
3
+ alias_attribute :site_id, :term_group
4
+ alias_attribute :post_type_id, :status
5
+
6
+ default_scope { where(taxonomy: :category) }
7
+ scope :no_empty, -> { where('count > 0') } # return all categories that contains at least one post
8
+ scope :empty, -> { where(count: [0, nil]) } # return all categories that does not contain any post
9
+ # scope :parents, -> { where("term_taxonomy.parent_id IS NULL") }
10
+
11
+ cama_define_common_relationships('Category')
12
+
13
+ has_many :posts, foreign_key: :objectid, through: :term_relationships, source: :object
14
+ has_many :children, class_name: 'CamaleonCms::Category', foreign_key: :parent_id, dependent: :destroy
15
+ belongs_to :parent, class_name: 'CamaleonCms::Category', foreign_key: :parent_id
16
+ belongs_to :post_type_parent, class_name: 'CamaleonCms::PostType', foreign_key: :parent_id, inverse_of: :categories
17
+ belongs_to :site
18
+
19
+ before_save :set_site
20
+ before_destroy :set_posts_in_default_category
21
+
22
+ # return the post type of this category
23
+ def post_type
24
+ cama_fetch_cache('post_type') do
25
+ ctg = self
26
+ begin
27
+ pt = ctg.post_type_parent
28
+ ctg = ctg.parent
29
+ end while ctg
30
+ pt
31
+ end
31
32
  end
32
- end
33
33
 
34
- private
34
+ private
35
35
 
36
- def set_site
37
- pt = self.post_type
38
- self.site_id = pt.site_id unless site_id.present?
39
- self.status = pt.id unless status.present?
40
- end
36
+ def set_site
37
+ self.site_id ||= post_type.site_id
38
+ self.status ||= post_type.id
39
+ end
40
+
41
+ # rescue all posts to assign into default category if they don't have any category assigned
42
+ def set_posts_in_default_category
43
+ category_default = post_type.default_category
44
+ return if category_default == self
41
45
 
42
- # rescue all posts to assign into default category if they don't have any category assigned
43
- def set_posts_in_default_category
44
- category_default = self.post_type.default_category
45
- return if category_default == self
46
- self.posts.each do |post|
47
- if post.categories.where.not(id: id).blank?
48
- post.assign_category(category_default.id)
46
+ posts.each do |post|
47
+ if post.categories.where.not(id: id).blank?
48
+ post.assign_category(category_default.id)
49
+ end
49
50
  end
50
51
  end
51
52
  end
@@ -1,35 +1,36 @@
1
- class CamaleonCms::CustomField < ActiveRecord::Base
2
- include CamaleonCms::Metas
1
+ module CamaleonCms
2
+ class CustomField < ActiveRecord::Base
3
+ include CamaleonCms::Metas
3
4
 
4
- self.primary_key = :id
5
- self.table_name = "#{PluginRoutes.static_system_info['db_prefix']}custom_fields"
5
+ self.primary_key = :id
6
+ self.table_name = "#{PluginRoutes.static_system_info['db_prefix']}custom_fields"
6
7
 
7
- alias_attribute :label, :name
8
+ alias_attribute :label, :name
8
9
 
9
- default_scope { order("#{CamaleonCms::CustomField.table_name}.field_order ASC") }
10
- scope :configuration, -> { where(parent_id: -1) }
11
- scope :visible_group, -> { where(status: nil) }
10
+ default_scope { order("#{CamaleonCms::CustomField.table_name}.field_order ASC") }
11
+ scope :configuration, -> { where(parent_id: -1) }
12
+ scope :visible_group, -> { where(status: nil) }
12
13
 
13
- # status: nil -> visible on list group fields
14
- # attr_accessible :object_class, :objectid, :description, :parent_id, :count, :name, :slug,
15
- # :field_order, :status, :is_repeat
16
- has_many :metas, -> { where(object_class: 'CustomField') }, class_name: 'CamaleonCms::Meta',
17
- foreign_key: :objectid, dependent: :destroy
18
- has_many :values, class_name: 'CamaleonCms::CustomFieldsRelationship',
19
- foreign_key: :custom_field_id, dependent: :destroy
20
- belongs_to :custom_field_group, class_name: 'CamaleonCms::CustomFieldGroup'
21
- belongs_to :parent, class_name: 'CamaleonCms::CustomField', foreign_key: :parent_id
14
+ # status: nil -> visible on list group fields
15
+ # attr_accessible :object_class, :objectid, :description, :parent_id, :count, :name, :slug,
16
+ # :field_order, :status, :is_repeat
17
+ has_many :metas, -> { where(object_class: 'CustomField') }, foreign_key: :objectid, dependent: :destroy
18
+ has_many :values, class_name: 'CamaleonCms::CustomFieldsRelationship',
19
+ foreign_key: :custom_field_id, dependent: :destroy
20
+ belongs_to :custom_field_group
21
+ belongs_to :parent, class_name: 'CamaleonCms::CustomField', foreign_key: :parent_id
22
22
 
23
- validates :name, :object_class, presence: true
24
- validates_uniqueness_of :slug, scope: [:parent_id, :object_class],
25
- unless: ->(o) { o.is_a?(CamaleonCms::CustomFieldGroup) }
23
+ validates :name, :object_class, presence: true
24
+ validates_uniqueness_of :slug, scope: [:parent_id, :object_class],
25
+ unless: ->(o) { o.is_a?(CamaleonCms::CustomFieldGroup) }
26
26
 
27
- before_validation :before_validating
27
+ before_validation :before_validating
28
28
 
29
- private
29
+ private
30
30
 
31
- def before_validating
32
- self.slug = name if slug.blank?
33
- self.slug = self.slug.to_s.parameterize
31
+ def before_validating
32
+ self.slug ||= name
33
+ self.slug = slug.to_s.parameterize
34
+ end
34
35
  end
35
36
  end
@@ -1,135 +1,136 @@
1
- class CamaleonCms::CustomFieldGroup < CamaleonCms::CustomField
2
- self.primary_key = :id
3
- # attrs required: name, slug, description
4
- alias_attribute :site_id, :parent_id
1
+ module CamaleonCms
2
+ class CustomFieldGroup < CamaleonCms::CustomField
3
+ self.primary_key = :id
4
+ # attrs required: name, slug, description
5
+ alias_attribute :site_id, :parent_id
5
6
 
6
- default_scope { where.not(object_class: '_fields')
7
- .reorder("#{CamaleonCms::CustomField.table_name}.field_order ASC") }
7
+ default_scope { where.not(object_class: '_fields')
8
+ .reorder("#{CamaleonCms::CustomField.table_name}.field_order ASC") }
8
9
 
9
- has_many :metas, -> { where(object_class: 'CustomFieldGroup') }, class_name: 'CamaleonCms::Meta',
10
- foreign_key: :objectid, dependent: :destroy
11
- has_many :fields, -> { where(object_class: '_fields') }, class_name: 'CamaleonCms::CustomField',
12
- foreign_key: :parent_id, dependent: :destroy
13
- belongs_to :site, class_name: 'CamaleonCms::Site', foreign_key: :parent_id
10
+ has_many :metas, -> { where(object_class: 'CustomFieldGroup') }, foreign_key: :objectid, dependent: :destroy
11
+ has_many :fields, -> { where(object_class: '_fields') }, class_name: 'CamaleonCms::CustomField',
12
+ foreign_key: :parent_id, dependent: :destroy
13
+ belongs_to :site, foreign_key: :parent_id
14
14
 
15
- validates_uniqueness_of :slug, scope: [:object_class, :objectid, :parent_id]
15
+ validates_uniqueness_of :slug, scope: [:object_class, :objectid, :parent_id]
16
16
 
17
- before_validation :before_validating
17
+ before_validation :before_validating
18
18
 
19
- # add fields to group
20
- # item:
21
- # - sample: {"name"=>"Label", "slug"=>"my_slug", "description"=>"my description (optional)"}
22
- # - options (textbox sample): {"field_key":"text_box","multiple":"1","required":"1",
23
- # "translate":"1"}
24
- # * field_key (string) | translate (boolean) | default_value (unique value) |
25
- # default_values (array - multiple values for this field) | label_eval (boolean) |
26
- # multiple_options (array)
27
- # * multiple_options (used for select, radio and checkboxes ): [{"title"=>"Option Title",
28
- # "value"=>"2", "default"=>"1"}, {"title"=>"abcde", "value"=>"3"}]
29
- # * label_eval: (Boolean, default false), true => will evaluate the label and description of
30
- # current field using (eval('my_label')) to have translatable|dynamic labels
31
- # ****** check all options for each case in Admin::CustomFieldsHelper ****
32
- # SAMPLE: my_model.add_field({"name"=>"Sub Title", "slug"=>"subtitle"}, {"field_key"=>"text_box",
33
- # "translate"=>true, default_value: "Get in Touch"})
34
- def add_manual_field(item, options)
35
- c = get_field(item[:slug] || item['slug'])
36
- return c if c.present?
19
+ # add fields to group
20
+ # item:
21
+ # - sample: {"name"=>"Label", "slug"=>"my_slug", "description"=>"my description (optional)"}
22
+ # - options (textbox sample): {"field_key":"text_box","multiple":"1","required":"1",
23
+ # "translate":"1"}
24
+ # * field_key (string) | translate (boolean) | default_value (unique value) |
25
+ # default_values (array - multiple values for this field) | label_eval (boolean) |
26
+ # multiple_options (array)
27
+ # * multiple_options (used for select, radio and checkboxes ): [{"title"=>"Option Title",
28
+ # "value"=>"2", "default"=>"1"}, {"title"=>"abcde", "value"=>"3"}]
29
+ # * label_eval: (Boolean, default false), true => will evaluate the label and description of
30
+ # current field using (eval('my_label')) to have translatable|dynamic labels
31
+ # ****** check all options for each case in Admin::CustomFieldsHelper ****
32
+ # SAMPLE: my_model.add_field({"name"=>"Sub Title", "slug"=>"subtitle"}, {"field_key"=>"text_box",
33
+ # "translate"=>true, default_value: "Get in Touch"})
34
+ def add_manual_field(item, options)
35
+ c = get_field(item[:slug] || item['slug'])
36
+ return c if c.present?
37
37
 
38
- field_item = self.fields.new(item)
39
- if field_item.save
40
- field_item.set_options(options)
41
- auto_save_default_values(field_item, options)
38
+ field_item = fields.new(item)
39
+ if field_item.save
40
+ field_item.set_options(options)
41
+ auto_save_default_values(field_item, options)
42
+ end
43
+ field_item
42
44
  end
43
- field_item
44
- end
45
- alias_method :add_field, :add_manual_field
45
+ alias_method :add_field, :add_manual_field
46
46
 
47
- # return a field with slug = slug from current group
48
- def get_field(slug)
49
- self.fields.find_by(slug: slug)
50
- end
47
+ # return a field with slug = slug from current group
48
+ def get_field(slug)
49
+ fields.find_by(slug: slug)
50
+ end
51
51
 
52
- # only used by form on admin panel (protected)
53
- # return array of failed_fields and full_fields [[failed fields], [all fields]]
54
- def add_fields(items, item_options)
55
- self.fields.where.not(id: items.to_h.map { |_k, obj| obj['id'] }.uniq).destroy_all
56
- cache_fields = []
57
- order_index = 0
58
- errors_saved = []
59
- if items.present?
60
- items.each do |i, item|
61
- item[:field_order] = order_index
62
- options = item_options[i] || {}
63
- if item[:id].present? && (field_item = self.fields.find_by(id: item[:id])).present?
64
- saved = field_item.update(item)
65
- cache_fields << field_item
66
- else
67
- field_item = self.fields.new(item)
68
- cache_fields << field_item
69
- saved = field_item.save
70
- auto_save_default_values(field_item, options) if saved
71
- errors_saved << field_item unless saved
72
- end
73
- if saved
74
- field_item.set_meta('_default', options)
75
- order_index += 1
52
+ # only used by form on admin panel (protected)
53
+ # return array of failed_fields and full_fields [[failed fields], [all fields]]
54
+ def add_fields(items, item_options)
55
+ fields.where.not(id: items.to_h.map { |_k, obj| obj['id'] }.uniq).destroy_all
56
+ cache_fields = []
57
+ order_index = 0
58
+ errors_saved = []
59
+ if items.present?
60
+ items.each do |i, item|
61
+ item[:field_order] = order_index
62
+ options = item_options[i] || {}
63
+ if item[:id].present? && (field_item = self.fields.find_by(id: item[:id])).present?
64
+ saved = field_item.update(item)
65
+ cache_fields << field_item
66
+ else
67
+ field_item = self.fields.new(item)
68
+ cache_fields << field_item
69
+ saved = field_item.save
70
+ auto_save_default_values(field_item, options) if saved
71
+ errors_saved << field_item unless saved
72
+ end
73
+ if saved
74
+ field_item.set_meta('_default', options)
75
+ order_index += 1
76
+ end
76
77
  end
77
78
  end
79
+ [errors_saved, cache_fields]
78
80
  end
79
- [errors_saved, cache_fields]
80
- end
81
81
 
82
- # generate the caption for this group
83
- def get_caption
84
- caption = ''
85
- begin
86
- case object_class
87
- when 'PostType_Post'
88
- caption = "Fields for Contents in <b>#{self.site.post_types.find(objectid).decorate.the_title}</b>"
89
- when 'PostType_Category'
90
- caption = "Fields for Categories in <b>#{self.site.post_types.find(objectid).decorate.the_title}</b>"
91
- when 'PostType_PostTag'
92
- caption = "Fields for Post tags in <b>#{self.site.post_types.find(objectid).decorate.the_title}</b>"
93
- when 'Widget::Main'
94
- caption = "Fields for Widget <b>(#{CamaleonCms::Widget::Main.find(objectid).name.translate})</b>"
95
- when 'Theme'
96
- caption = "Field settings for Theme <b>(#{self.site.themes.find(objectid).name rescue objectid})</b>"
97
- when 'NavMenu'
98
- caption = "Field settings for Menus <b>(#{CamaleonCms::NavMenu.find(objectid).name})</b>"
99
- when 'Site'
100
- caption = 'Field settings the site'
101
- when 'PostType'
102
- caption = 'Fields for all <b>Post_Types</b>'
103
- when 'Post'
104
- p = CamaleonCms::Post.find(objectid).decorate
105
- caption = "Fields for content <b>(#{p.the_title})</b>"
106
- else # 'Plugin' or other class
107
- caption = "Fields for <b>#{object_class}</b>"
82
+ # generate the caption for this group
83
+ def get_caption
84
+ caption = ''
85
+ begin
86
+ case object_class
87
+ when 'PostType_Post'
88
+ caption = "Fields for Contents in <b>#{site.post_types.find(objectid).decorate.the_title}</b>"
89
+ when 'PostType_Category'
90
+ caption = "Fields for Categories in <b>#{site.post_types.find(objectid).decorate.the_title}</b>"
91
+ when 'PostType_PostTag'
92
+ caption = "Fields for Post tags in <b>#{site.post_types.find(objectid).decorate.the_title}</b>"
93
+ when 'Widget::Main'
94
+ caption = "Fields for Widget <b>(#{CamaleonCms::Widget::Main.find(objectid).name.translate})</b>"
95
+ when 'Theme'
96
+ caption = "Field settings for Theme <b>(#{site.themes.find(objectid).name rescue objectid})</b>"
97
+ when 'NavMenu'
98
+ caption = "Field settings for Menus <b>(#{CamaleonCms::NavMenu.find(objectid).name})</b>"
99
+ when 'Site'
100
+ caption = 'Field settings the site'
101
+ when 'PostType'
102
+ caption = 'Fields for all <b>Post_Types</b>'
103
+ when 'Post'
104
+ p = CamaleonCms::Post.find(objectid).decorate
105
+ caption = "Fields for content <b>(#{p.the_title})</b>"
106
+ else # 'Plugin' or other class
107
+ caption = "Fields for <b>#{object_class}</b>"
108
+ end
109
+ rescue => e
110
+ Rails.logger.debug "Camaleon CMS - Menu Item Error: #{e.message} ==> Attrs: #{self.attributes}"
108
111
  end
109
- rescue => e
110
- Rails.logger.debug "Camaleon CMS - Menu Item Error: #{e.message} ==> Attrs: #{self.attributes}"
112
+ caption
111
113
  end
112
- caption
113
- end
114
114
 
115
- private
115
+ private
116
116
 
117
- def before_validating
118
- self.slug = "_group-#{name.to_s.parameterize}" unless slug.present?
119
- end
117
+ def before_validating
118
+ self.slug = "_group-#{name.to_s.parameterize}" unless slug.present?
119
+ end
120
120
 
121
- # auto save the default field values
122
- def auto_save_default_values(field, options)
123
- class_name = object_class.split("_").first
124
- if %w(Post Category Plugin Theme).include?(class_name) && objectid && (options[:default_value].present? || options[:default_values].present?)
125
- if class_name == 'Theme'
126
- owner = "CamaleonCms::#{class_name}".constantize.find(objectid) # owner model
127
- else
128
- owner = "CamaleonCms::#{class_name}".constantize.find(objectid) rescue "CamaleonCms::#{class_name}".constantize.find_by(slug: objectid) # owner model
129
- end
130
- (options[:default_values] || [options[:default_value]] || []).each do |value|
131
- owner.custom_field_values.create!(custom_field_id: field.id, custom_field_slug: field.slug,
132
- value: fix_meta_value(value)) if owner.present?
121
+ # auto save the default field values
122
+ def auto_save_default_values(field, options)
123
+ class_name = object_class.split("_").first
124
+ if %w(Post Category Plugin Theme).include?(class_name) && objectid && (options[:default_value].present? || options[:default_values].present?)
125
+ if class_name == 'Theme'
126
+ owner = "CamaleonCms::#{class_name}".constantize.find(objectid) # owner model
127
+ else
128
+ owner = "CamaleonCms::#{class_name}".constantize.find(objectid) rescue "CamaleonCms::#{class_name}".constantize.find_by(slug: objectid) # owner model
129
+ end
130
+ (options[:default_values] || [options[:default_value]] || []).each do |value|
131
+ owner.custom_field_values.create!(custom_field_id: field.id, custom_field_slug: field.slug,
132
+ value: fix_meta_value(value)) if owner.present?
133
+ end
133
134
  end
134
135
  end
135
136
  end