alchemy_cms 4.4.2 → 4.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +23 -17
  3. data/.rubocop.yml +7 -15
  4. data/CHANGELOG.md +36 -0
  5. data/alchemy_cms.gemspec +1 -0
  6. data/app/assets/javascripts/alchemy/admin.js +3 -0
  7. data/app/assets/javascripts/alchemy/alchemy.link_dialog.js.coffee +5 -5
  8. data/app/assets/javascripts/alchemy/alchemy.node_tree.js +66 -0
  9. data/app/assets/javascripts/alchemy/alchemy.utils.js +45 -0
  10. data/app/assets/javascripts/alchemy/templates/index.js +1 -0
  11. data/app/assets/javascripts/alchemy/templates/node_folder.hbs +3 -0
  12. data/app/assets/javascripts/alchemy/templates/page.hbs +1 -1
  13. data/app/assets/stylesheets/alchemy/_mixins.scss +2 -3
  14. data/app/assets/stylesheets/alchemy/_variables.scss +2 -2
  15. data/app/assets/stylesheets/alchemy/lists.scss +0 -8
  16. data/app/assets/stylesheets/alchemy/nodes.scss +6 -1
  17. data/app/assets/stylesheets/alchemy/sitemap.scss +59 -21
  18. data/app/controllers/alchemy/admin/dashboard_controller.rb +1 -1
  19. data/app/controllers/alchemy/admin/nodes_controller.rb +2 -10
  20. data/app/controllers/alchemy/admin/pages_controller.rb +0 -1
  21. data/app/controllers/alchemy/api/nodes_controller.rb +29 -0
  22. data/app/controllers/alchemy/api/pages_controller.rb +2 -0
  23. data/app/decorators/alchemy/content_editor.rb +55 -0
  24. data/app/helpers/alchemy/admin/pages_helper.rb +16 -16
  25. data/app/helpers/alchemy/pages_helper.rb +2 -2
  26. data/app/models/alchemy/content.rb +8 -22
  27. data/app/models/alchemy/node.rb +29 -5
  28. data/app/models/alchemy/page.rb +15 -1
  29. data/app/models/alchemy/page/url_path.rb +66 -0
  30. data/app/serializers/alchemy/node_serializer.rb +12 -0
  31. data/app/serializers/alchemy/page_serializer.rb +2 -1
  32. data/app/serializers/alchemy/page_tree_serializer.rb +4 -3
  33. data/app/views/alchemy/admin/layoutpages/index.html.erb +5 -1
  34. data/app/views/alchemy/admin/nodes/_form.html.erb +14 -8
  35. data/app/views/alchemy/admin/nodes/_node.html.erb +10 -20
  36. data/app/views/alchemy/admin/nodes/index.html.erb +7 -17
  37. data/app/views/alchemy/admin/pages/_form.html.erb +1 -1
  38. data/app/views/alchemy/admin/pages/_menu_fields.html.erb +33 -29
  39. data/app/views/alchemy/admin/pages/_page.html.erb +3 -6
  40. data/app/views/alchemy/admin/pages/_sitemap.html.erb +6 -0
  41. data/app/views/alchemy/admin/pages/info.html.erb +1 -1
  42. data/app/views/alchemy/admin/partials/_routes.html.erb +8 -0
  43. data/config/alchemy/config.yml +0 -6
  44. data/config/locales/alchemy.en.yml +14 -6
  45. data/config/routes.rb +8 -5
  46. data/db/migrate/20200226081535_add_site_id_to_alchemy_nodes.rb +15 -0
  47. data/lib/alchemy/config.rb +30 -2
  48. data/lib/alchemy/ssl_protection.rb +3 -1
  49. data/lib/alchemy/test_support/factories/node_factory.rb +1 -0
  50. data/lib/alchemy/upgrader/four_point_six.rb +50 -0
  51. data/lib/alchemy/version.rb +1 -1
  52. data/lib/rails/generators/alchemy/install/install_generator.rb +1 -1
  53. data/lib/rails/generators/alchemy/install/templates/menus.yml.tt +8 -0
  54. data/lib/rails/generators/alchemy/menus/menus_generator.rb +3 -3
  55. data/lib/rails/generators/alchemy/menus/templates/wrapper.html.haml +1 -1
  56. data/lib/rails/generators/alchemy/menus/templates/wrapper.html.slim +1 -1
  57. data/lib/tasks/alchemy/convert.rake +2 -0
  58. data/lib/tasks/alchemy/upgrade.rake +67 -46
  59. data/vendor/assets/javascripts/sortable/Sortable.min.js +2 -0
  60. metadata +28 -2
@@ -17,11 +17,7 @@ Alchemy::Engine.routes.draw do
17
17
  namespace :admin, {path: Alchemy.admin_path, constraints: Alchemy.admin_constraints} do
18
18
  resources :contents, only: [:create]
19
19
 
20
- resources :nodes do
21
- member do
22
- patch :toggle
23
- end
24
- end
20
+ resources :nodes
25
21
 
26
22
  resources :pages do
27
23
  resources :elements
@@ -152,6 +148,13 @@ Alchemy::Engine.routes.draw do
152
148
 
153
149
  get '/pages/*urlname(.:format)' => 'pages#show', as: 'page'
154
150
  get '/admin/pages/:id(.:format)' => 'pages#show', as: 'preview_page'
151
+
152
+ resources :nodes, only: [] do
153
+ member do
154
+ patch :move
155
+ patch :toggle_folded
156
+ end
157
+ end
155
158
  end
156
159
 
157
160
  get '/:locale' => 'pages#index',
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddSiteIdToAlchemyNodes < ActiveRecord::Migration[5.0]
4
+ def change
5
+ add_column :alchemy_nodes, :site_id, :integer, index: true
6
+ add_index :alchemy_nodes, :site_id
7
+ reversible do |dir|
8
+ dir.up do
9
+ Alchemy::Node.update_all(site_id: Alchemy::Site.first&.id)
10
+ change_column_null :alchemy_nodes, :site_id, false
11
+ end
12
+ end
13
+ add_foreign_key :alchemy_nodes, :alchemy_sites, column: :site_id, on_delete: :cascade
14
+ end
15
+ end
@@ -8,8 +8,10 @@ module Alchemy
8
8
  # @param name [String]
9
9
  #
10
10
  def get(name)
11
+ check_deprecation(name)
11
12
  show[name.to_s]
12
13
  end
14
+
13
15
  alias_method :parameter, :get
14
16
 
15
17
  # Returns a merged configuration of the following files
@@ -25,11 +27,22 @@ module Alchemy
25
27
  @config ||= merge_configs!(alchemy_config, main_app_config, env_specific_config)
26
28
  end
27
29
 
30
+ # A list of deprecated configurations
31
+ # a value of nil means there is no new default
32
+ # any not nil value is the new default
33
+ def deprecated_configs
34
+ {
35
+ url_nesting: true,
36
+ require_ssl: nil,
37
+ auto_logout_time: nil,
38
+ }
39
+ end
40
+
28
41
  private
29
42
 
30
43
  # Alchemy default configuration
31
44
  def alchemy_config
32
- read_file(File.join(File.dirname(__FILE__), '..', '..', 'config/alchemy/config.yml'))
45
+ read_file(File.join(File.dirname(__FILE__), "..", "..", "config/alchemy/config.yml"))
33
46
  end
34
47
 
35
48
  # Application specific configuration
@@ -54,11 +67,26 @@ module Alchemy
54
67
  # Merges all given configs together
55
68
  #
56
69
  def merge_configs!(*config_files)
57
- raise LoadError, 'No Alchemy config file found!' if config_files.map(&:blank?).all?
70
+ raise LoadError, "No Alchemy config file found!" if config_files.map(&:blank?).all?
71
+
58
72
  config = {}
59
73
  config_files.each { |h| config.merge!(h.stringify_keys!) }
60
74
  config
61
75
  end
76
+
77
+ def check_deprecation(name)
78
+ if deprecated_configs.key?(name.to_sym)
79
+ config = deprecated_configs[name.to_sym]
80
+ if config.nil?
81
+ Alchemy::Deprecation.warn("#{name} configuration is deprecated and will be removed from Alchemy 5.0")
82
+ else
83
+ value = show[name.to_s]
84
+ if value != config
85
+ Alchemy::Deprecation.warn("Setting #{name} configuration to #{value} is deprecated and will be always #{config} in Alchemy 5.0")
86
+ end
87
+ end
88
+ end
89
+ end
62
90
  end
63
91
  end
64
92
  end
@@ -26,7 +26,9 @@ module Alchemy
26
26
 
27
27
  # Redirects current request to https.
28
28
  def enforce_ssl
29
- redirect_to url_for(request.params.merge(protocol: 'https'))
29
+ redirect_to url_for(request.params.merge(protocol: "https"))
30
30
  end
31
+
32
+ deprecate :enforce_ssl, deprecator: Alchemy::Deprecation
31
33
  end
32
34
  end
@@ -6,6 +6,7 @@ require 'alchemy/test_support/factories/page_factory'
6
6
 
7
7
  FactoryBot.define do
8
8
  factory :alchemy_node, class: 'Alchemy::Node' do
9
+ site { Alchemy::Site.default }
9
10
  language { Alchemy::Language.default }
10
11
  name { 'A Node' }
11
12
 
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Alchemy
4
+ class Upgrader::FourPointSix < Upgrader
5
+ class << self
6
+ def alchemy_4_6_todos
7
+ notice = <<-NOTE.strip_heredoc
8
+
9
+ ℹ️ Page visible attribute is deprecated
10
+ ----------------------------------------
11
+
12
+ Page slugs will be visible in URLs of child pages all the time in the future.
13
+ Please use Menus and Tags instead to re-organize your pages if your page tree does not reflect the URL hierarchy.
14
+
15
+ A rake task to help with the migration is available.
16
+
17
+ bin/rake alchemy:upgrade:4.6:restructure_page_tree
18
+
19
+ NOTE
20
+ todo notice, "Alchemy v4.6 TODO"
21
+ end
22
+
23
+ def restructure_page_tree
24
+ desc "Move child pages of invisible pages to visible parent."
25
+ Alchemy::Deprecation.silence do
26
+ # All leaves can safely be marked visible
27
+ Alchemy::Page.leaves.update_all(visible: true)
28
+ Alchemy::Page.language_roots.each do |root_page|
29
+ # Root pages are always visible
30
+ root_page.update!(visible: true)
31
+ remove_invisible_children(root_page)
32
+ end
33
+ Alchemy::Page.update_all(visible: true)
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def remove_invisible_children(page)
40
+ page.children.each { |child| remove_invisible_children(child) }
41
+ if !page.visible
42
+ page.children.reload.reverse.each do |child|
43
+ puts "Moving #{child.urlname} to right of #{page.urlname}"
44
+ child.move_to_right_of(page)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Alchemy
4
- VERSION = "4.4.2"
4
+ VERSION = "4.6.1"
5
5
 
6
6
  def self.version
7
7
  VERSION
@@ -17,7 +17,7 @@ module Alchemy
17
17
  end
18
18
 
19
19
  def copy_yml_files
20
- %w(elements page_layouts).each do |file|
20
+ %w(elements page_layouts menus).each do |file|
21
21
  template "#{__dir__}/templates/#{file}.yml.tt", "config/alchemy/#{file}.yml"
22
22
  end
23
23
  end
@@ -0,0 +1,8 @@
1
+ # == In this configuration, you set up Alchemy's menu names.
2
+ #
3
+ # For further information please see http://guides.alchemy-cms.com/stable/menus.html
4
+
5
+ <%- unless @options[:skip_demo_files] -%>
6
+ - main_menu
7
+ - footer_menu
8
+ <%- end -%>
@@ -9,14 +9,14 @@ module Alchemy
9
9
  source_root File.expand_path('templates', __dir__)
10
10
 
11
11
  def create_partials
12
- menus = Alchemy::Node.roots
12
+ menus = Alchemy::Node.available_menu_names
13
13
  return unless menus
14
14
 
15
15
  menus.each do |menu|
16
16
  conditional_template "wrapper.html.#{template_engine}",
17
- "app/views/#{menu.view_folder_name}/_wrapper.html.#{template_engine}"
17
+ "app/views/alchemy/menus/#{menu}/_wrapper.html.#{template_engine}"
18
18
  conditional_template "node.html.#{template_engine}",
19
- "app/views/#{menu.view_folder_name}/_node.html.#{template_engine}"
19
+ "app/views/alchemy/menus/#{menu}/_node.html.#{template_engine}"
20
20
  end
21
21
  end
22
22
  end
@@ -3,4 +3,4 @@
3
3
  = render partial: options[:node_partial_name],
4
4
  collection: menu.children.includes(:page, :children),
5
5
  locals: { options: options },
6
- as: 'node' %>
6
+ as: 'node'
@@ -3,4 +3,4 @@
3
3
  = render partial: options[:node_partial_name],
4
4
  collection: menu.children.includes(:page, :children),
5
5
  locals: { options: options },
6
- as: 'node' %>
6
+ as: 'node'
@@ -3,6 +3,7 @@ namespace :alchemy do
3
3
  namespace :urlnames do
4
4
  desc "Converts the urlname of all pages to nested url paths."
5
5
  task to_nested: [:environment] do
6
+ Alchemy::Deprecation.warn('alchemy:convert:urlnames:to_nested task is deprecated and will be removed from Alchemy 5.0')
6
7
  unless Alchemy::Config.get(:url_nesting)
7
8
  raise "\nURL nesting is disabled! Please enable url_nesting in `config/alchemy/config.yml` first.\n\n"
8
9
  end
@@ -18,6 +19,7 @@ namespace :alchemy do
18
19
 
19
20
  desc "Converts the urlname of all pages to contain the slug only."
20
21
  task to_slug: [:environment] do
22
+ Alchemy::Deprecation.warn('alchemy:convert:urlnames:to_slug task is deprecated and will be removed from Alchemy 5.0')
21
23
  if Alchemy::Config.get(:url_nesting)
22
24
  raise "\nURL nesting is enabled! Please disable url_nesting in `config/alchemy/config.yml` first.\n\n"
23
25
  end
@@ -1,29 +1,32 @@
1
- require 'alchemy/upgrader'
2
- require 'alchemy/version'
1
+ # frozen_string_literal: true
2
+
3
+ require "alchemy/upgrader"
4
+ require "alchemy/version"
3
5
 
4
6
  namespace :alchemy do
5
7
  desc "Upgrades your app to AlchemyCMS v#{Alchemy::VERSION}."
6
8
  task upgrade: [
7
- 'alchemy:upgrade:prepare',
8
- 'alchemy:upgrade:4.1:run', 'alchemy:upgrade:4.1:todo',
9
- 'alchemy:upgrade:4.2:run', 'alchemy:upgrade:4.2:todo',
10
- 'alchemy:upgrade:4.4:run', 'alchemy:upgrade:4.4:todo'
9
+ "alchemy:upgrade:prepare",
10
+ "alchemy:upgrade:4.1:run", "alchemy:upgrade:4.1:todo",
11
+ "alchemy:upgrade:4.2:run", "alchemy:upgrade:4.2:todo",
12
+ "alchemy:upgrade:4.4:run", "alchemy:upgrade:4.4:todo",
13
+ "alchemy:upgrade:4.6:run", "alchemy:upgrade:4.6:todo",
11
14
  ] do
12
15
  Alchemy::Upgrader.display_todos
13
16
  end
14
17
 
15
18
  namespace :upgrade do
16
- desc 'Alchemy Upgrader: Prepares the database and updates Alchemys configuration file.'
19
+ desc "Alchemy Upgrader: Prepares the database and updates Alchemys configuration file."
17
20
  task prepare: [
18
- 'alchemy:upgrade:database',
19
- 'alchemy:upgrade:config'
21
+ "alchemy:upgrade:database",
22
+ "alchemy:upgrade:config",
20
23
  ]
21
24
 
22
25
  desc "Alchemy Upgrader: Prepares the database."
23
26
  task database: [
24
- 'alchemy:install:migrations',
25
- 'db:migrate',
26
- 'alchemy:db:seed'
27
+ "alchemy:install:migrations",
28
+ "db:migrate",
29
+ "alchemy:db:seed",
27
30
  ]
28
31
 
29
32
  desc "Alchemy Upgrader: Copy configuration file."
@@ -37,19 +40,19 @@ namespace :alchemy do
37
40
  end
38
41
  end
39
42
 
40
- desc 'Upgrade Alchemy to v4.1'
41
- task '4.1' => [
42
- 'alchemy:upgrade:prepare',
43
- 'alchemy:upgrade:4.1:run',
44
- 'alchemy:upgrade:4.1:todo'
43
+ desc "Upgrade Alchemy to v4.1"
44
+ task "4.1" => [
45
+ "alchemy:upgrade:prepare",
46
+ "alchemy:upgrade:4.1:run",
47
+ "alchemy:upgrade:4.1:todo",
45
48
  ] do
46
49
  Alchemy::Upgrader.display_todos
47
50
  end
48
51
 
49
- namespace '4.1' do
50
- task run: ['alchemy:upgrade:4.1:harden_acts_as_taggable_on_migrations']
52
+ namespace "4.1" do
53
+ task run: ["alchemy:upgrade:4.1:harden_acts_as_taggable_on_migrations"]
51
54
 
52
- desc 'Harden acts_as_taggable_on migrations'
55
+ desc "Harden acts_as_taggable_on migrations"
53
56
  task harden_acts_as_taggable_on_migrations: [:environment] do
54
57
  Alchemy::Upgrader::FourPointOne.harden_acts_as_taggable_on_migrations
55
58
  end
@@ -59,45 +62,45 @@ namespace :alchemy do
59
62
  end
60
63
  end
61
64
 
62
- desc 'Upgrade Alchemy to v4.2'
63
- task '4.2' => [
64
- 'alchemy:upgrade:prepare',
65
- 'alchemy:upgrade:4.2:run',
66
- 'alchemy:upgrade:4.2:todo'
65
+ desc "Upgrade Alchemy to v4.2"
66
+ task "4.2" => [
67
+ "alchemy:upgrade:prepare",
68
+ "alchemy:upgrade:4.2:run",
69
+ "alchemy:upgrade:4.2:todo",
67
70
  ] do
68
71
  Alchemy::Upgrader.display_todos
69
72
  end
70
73
 
71
- namespace '4.2' do
74
+ namespace "4.2" do
72
75
  task run: [
73
- 'alchemy:upgrade:4.2:convert_picture_galleries',
74
- 'alchemy:upgrade:4.2:migrate_picture_galleries',
75
- 'alchemy:upgrade:4.2:convert_cells',
76
- 'alchemy:upgrade:4.2:migrate_cells',
77
- 'alchemy:upgrade:4.2:update_element_partial_name_variable'
76
+ "alchemy:upgrade:4.2:convert_picture_galleries",
77
+ "alchemy:upgrade:4.2:migrate_picture_galleries",
78
+ "alchemy:upgrade:4.2:convert_cells",
79
+ "alchemy:upgrade:4.2:migrate_cells",
80
+ "alchemy:upgrade:4.2:update_element_partial_name_variable",
78
81
  ]
79
82
 
80
- desc 'Convert `picture_gallery` element definitions to `nestable_elements`.'
83
+ desc "Convert `picture_gallery` element definitions to `nestable_elements`."
81
84
  task convert_picture_galleries: [:environment] do
82
85
  Alchemy::Upgrader::FourPointTwo.convert_picture_galleries
83
86
  end
84
87
 
85
- desc 'Migrate `picture_gallery` elements to `nestable_elements`.'
88
+ desc "Migrate `picture_gallery` elements to `nestable_elements`."
86
89
  task migrate_picture_galleries: [:environment] do
87
90
  Alchemy::Upgrader::FourPointTwo.migrate_picture_galleries
88
91
  end
89
92
 
90
- desc 'Convert cells config to fixed nestable elements.'
93
+ desc "Convert cells config to fixed nestable elements."
91
94
  task convert_cells: [:environment] do
92
95
  Alchemy::Upgrader::FourPointTwo.convert_cells
93
96
  end
94
97
 
95
- desc 'Migrate existing cells to fixed nestable elements.'
96
- task migrate_cells: ['alchemy:install:migrations', 'db:migrate'] do
98
+ desc "Migrate existing cells to fixed nestable elements."
99
+ task migrate_cells: ["alchemy:install:migrations", "db:migrate"] do
97
100
  Alchemy::Upgrader::FourPointTwo.migrate_cells
98
101
  end
99
102
 
100
- desc 'Update element views to use element partial name variable.'
103
+ desc "Update element views to use element partial name variable."
101
104
  task :update_element_partial_name_variable do
102
105
  Alchemy::Upgrader::FourPointTwo.update_element_views_variable_name
103
106
  end
@@ -107,19 +110,19 @@ namespace :alchemy do
107
110
  end
108
111
  end
109
112
 
110
- desc 'Upgrade Alchemy to v4.4'
111
- task '4.4' => [
112
- 'alchemy:upgrade:prepare',
113
- 'alchemy:upgrade:4.4:run',
114
- 'alchemy:upgrade:4.4:todo'
113
+ desc "Upgrade Alchemy to v4.4"
114
+ task "4.4" => [
115
+ "alchemy:upgrade:prepare",
116
+ "alchemy:upgrade:4.4:run",
117
+ "alchemy:upgrade:4.4:todo",
115
118
  ] do
116
119
  Alchemy::Upgrader.display_todos
117
120
  end
118
121
 
119
- namespace '4.4' do
122
+ namespace "4.4" do
120
123
  task run: [
121
- 'alchemy:upgrade:4.4:rename_element_views',
122
- 'alchemy:upgrade:4.4:update_local_variable'
124
+ "alchemy:upgrade:4.4:rename_element_views",
125
+ "alchemy:upgrade:4.4:update_local_variable",
123
126
  ]
124
127
 
125
128
  desc "Remove '_view' suffix from element views."
@@ -127,7 +130,7 @@ namespace :alchemy do
127
130
  Alchemy::Upgrader::FourPointFour.rename_element_views
128
131
  end
129
132
 
130
- desc 'Update element views local variable to element name.'
133
+ desc "Update element views local variable to element name."
131
134
  task update_local_variable: [:environment] do
132
135
  Alchemy::Upgrader::FourPointFour.update_local_variable
133
136
  end
@@ -136,5 +139,23 @@ namespace :alchemy do
136
139
  Alchemy::Upgrader::FourPointFour.alchemy_4_4_todos
137
140
  end
138
141
  end
142
+
143
+ desc "Upgrade Alchemy to v4.6"
144
+ task "4.6" => [
145
+ "alchemy:upgrade:prepare",
146
+ ]
147
+
148
+ namespace "4.6" do
149
+ task run: []
150
+
151
+ desc "Move child pages of invisible pages to visible parent."
152
+ task restructure_page_tree: [:environment] do
153
+ Alchemy::Upgrader::FourPointSix.restructure_page_tree
154
+ end
155
+
156
+ task :todo do
157
+ Alchemy::Upgrader::FourPointSix.alchemy_4_6_todos
158
+ end
159
+ end
139
160
  end
140
161
  end