alchemy_cms 4.0.0.beta → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -7
  3. data/CHANGELOG.md +23 -0
  4. data/README.md +1 -1
  5. data/alchemy_cms.gemspec +1 -1
  6. data/app/assets/javascripts/alchemy/alchemy.dragndrop.js.coffee +2 -2
  7. data/app/assets/stylesheets/alchemy/_extends.scss +3 -5
  8. data/app/assets/stylesheets/alchemy/_mixins.scss +1 -1
  9. data/app/assets/stylesheets/alchemy/base.scss +2 -2
  10. data/app/assets/stylesheets/alchemy/buttons.scss +2 -2
  11. data/app/assets/stylesheets/alchemy/dialogs.scss +3 -3
  12. data/app/assets/stylesheets/alchemy/elements.scss +2 -2
  13. data/app/assets/stylesheets/alchemy/image_library.scss +10 -10
  14. data/app/assets/stylesheets/alchemy/jquery.datetimepicker.scss +2 -2
  15. data/app/assets/stylesheets/alchemy/lists.scss +2 -1
  16. data/app/assets/stylesheets/alchemy/sitemap.scss +1 -16
  17. data/app/assets/stylesheets/alchemy/tables.scss +1 -1
  18. data/app/assets/stylesheets/tinymce/skins/alchemy/skin.min.css.scss +4 -4
  19. data/app/controllers/alchemy/admin/attachments_controller.rb +10 -10
  20. data/app/controllers/alchemy/admin/base_controller.rb +10 -19
  21. data/app/controllers/alchemy/admin/clipboard_controller.rb +20 -7
  22. data/app/controllers/alchemy/admin/contents_controller.rb +5 -19
  23. data/app/controllers/alchemy/admin/dashboard_controller.rb +5 -3
  24. data/app/controllers/alchemy/admin/elements_controller.rb +7 -1
  25. data/app/controllers/alchemy/admin/essence_files_controller.rb +2 -2
  26. data/app/controllers/alchemy/admin/essence_pictures_controller.rb +8 -13
  27. data/app/controllers/alchemy/admin/languages_controller.rb +2 -0
  28. data/app/controllers/alchemy/admin/layoutpages_controller.rb +2 -0
  29. data/app/controllers/alchemy/admin/legacy_page_urls_controller.rb +2 -0
  30. data/app/controllers/alchemy/admin/pages_controller.rb +3 -1
  31. data/app/controllers/alchemy/admin/pictures_controller.rb +11 -9
  32. data/app/controllers/alchemy/admin/resources_controller.rb +25 -4
  33. data/app/controllers/alchemy/admin/sites_controller.rb +2 -0
  34. data/app/controllers/alchemy/admin/tags_controller.rb +2 -0
  35. data/app/controllers/alchemy/admin/trash_controller.rb +2 -0
  36. data/app/controllers/alchemy/api/base_controller.rb +2 -0
  37. data/app/controllers/alchemy/api/contents_controller.rb +2 -0
  38. data/app/controllers/alchemy/api/elements_controller.rb +2 -0
  39. data/app/controllers/alchemy/api/pages_controller.rb +2 -0
  40. data/app/controllers/alchemy/attachments_controller.rb +2 -0
  41. data/app/controllers/alchemy/base_controller.rb +3 -1
  42. data/app/controllers/alchemy/elements_controller.rb +2 -0
  43. data/app/controllers/alchemy/messages_controller.rb +2 -0
  44. data/app/controllers/alchemy/pages_controller.rb +11 -2
  45. data/app/controllers/concerns/alchemy/admin/uploader_responses.rb +2 -0
  46. data/app/controllers/concerns/alchemy/legacy_page_redirects.rb +2 -0
  47. data/app/controllers/concerns/alchemy/locale_redirects.rb +2 -0
  48. data/app/controllers/concerns/alchemy/page_redirects.rb +2 -0
  49. data/app/controllers/concerns/alchemy/site_redirects.rb +2 -0
  50. data/app/helpers/alchemy/admin/attachments_helper.rb +2 -0
  51. data/app/helpers/alchemy/admin/base_helper.rb +2 -28
  52. data/app/helpers/alchemy/admin/contents_helper.rb +2 -0
  53. data/app/helpers/alchemy/admin/elements_helper.rb +2 -0
  54. data/app/helpers/alchemy/admin/essences_helper.rb +2 -0
  55. data/app/helpers/alchemy/admin/form_helper.rb +2 -0
  56. data/app/helpers/alchemy/admin/navigation_helper.rb +2 -0
  57. data/app/helpers/alchemy/admin/pages_helper.rb +2 -0
  58. data/app/helpers/alchemy/admin/pictures_helper.rb +2 -0
  59. data/app/helpers/alchemy/admin/tags_helper.rb +24 -76
  60. data/app/helpers/alchemy/base_helper.rb +2 -0
  61. data/app/helpers/alchemy/deprecated_pages_helper.rb +2 -0
  62. data/app/helpers/alchemy/elements_block_helper.rb +2 -0
  63. data/app/helpers/alchemy/elements_helper.rb +2 -0
  64. data/app/helpers/alchemy/essences_helper.rb +2 -0
  65. data/app/helpers/alchemy/pages_helper.rb +2 -0
  66. data/app/helpers/alchemy/url_helper.rb +2 -0
  67. data/app/mailers/alchemy/base_mailer.rb +2 -0
  68. data/app/mailers/alchemy/messages_mailer.rb +2 -0
  69. data/app/models/alchemy.rb +2 -0
  70. data/app/models/alchemy/attachment.rb +6 -4
  71. data/app/models/alchemy/cell.rb +4 -2
  72. data/app/models/alchemy/content.rb +7 -5
  73. data/app/models/alchemy/content/factory.rb +7 -7
  74. data/app/models/alchemy/element.rb +21 -28
  75. data/app/models/alchemy/element/definitions.rb +4 -2
  76. data/app/models/alchemy/element/element_contents.rb +3 -1
  77. data/app/models/alchemy/element/element_essences.rb +2 -0
  78. data/app/models/alchemy/element/presenters.rb +2 -0
  79. data/app/models/alchemy/element_to_page.rb +2 -0
  80. data/app/models/alchemy/essence_boolean.rb +2 -0
  81. data/app/models/alchemy/essence_date.rb +2 -0
  82. data/app/models/alchemy/essence_file.rb +2 -0
  83. data/app/models/alchemy/essence_html.rb +2 -0
  84. data/app/models/alchemy/essence_link.rb +6 -4
  85. data/app/models/alchemy/essence_picture.rb +13 -11
  86. data/app/models/alchemy/essence_picture_view.rb +2 -0
  87. data/app/models/alchemy/essence_richtext.rb +2 -0
  88. data/app/models/alchemy/essence_select.rb +3 -1
  89. data/app/models/alchemy/essence_text.rb +6 -4
  90. data/app/models/alchemy/folded_page.rb +4 -2
  91. data/app/models/alchemy/language.rb +9 -6
  92. data/app/models/alchemy/language/code.rb +2 -0
  93. data/app/models/alchemy/legacy_page_url.rb +3 -1
  94. data/app/models/alchemy/message.rb +2 -0
  95. data/app/models/alchemy/page.rb +3 -2
  96. data/app/models/alchemy/page/fixed_attributes.rb +2 -0
  97. data/app/models/alchemy/page/page_cells.rb +2 -0
  98. data/app/models/alchemy/page/page_elements.rb +3 -1
  99. data/app/models/alchemy/page/page_naming.rb +2 -0
  100. data/app/models/alchemy/page/page_natures.rb +2 -1
  101. data/app/models/alchemy/page/page_scopes.rb +2 -0
  102. data/app/models/alchemy/page/page_users.rb +2 -0
  103. data/app/models/alchemy/picture.rb +2 -0
  104. data/app/models/alchemy/picture/transformations.rb +2 -0
  105. data/app/models/alchemy/picture/url.rb +2 -0
  106. data/app/models/alchemy/site.rb +4 -2
  107. data/app/models/alchemy/site/layout.rb +2 -0
  108. data/app/models/alchemy/tag.rb +5 -2
  109. data/app/models/alchemy/tree_node.rb +2 -0
  110. data/app/serializers/alchemy/attachment_serializer.rb +2 -0
  111. data/app/serializers/alchemy/base_serializer.rb +2 -0
  112. data/app/serializers/alchemy/cell_serializer.rb +2 -0
  113. data/app/serializers/alchemy/content_serializer.rb +2 -0
  114. data/app/serializers/alchemy/element_serializer.rb +2 -0
  115. data/app/serializers/alchemy/essence_boolean_serializer.rb +2 -0
  116. data/app/serializers/alchemy/essence_date_serializer.rb +2 -0
  117. data/app/serializers/alchemy/essence_file_serializer.rb +2 -0
  118. data/app/serializers/alchemy/essence_html_serializer.rb +2 -0
  119. data/app/serializers/alchemy/essence_link_serializer.rb +2 -0
  120. data/app/serializers/alchemy/essence_picture_serializer.rb +2 -0
  121. data/app/serializers/alchemy/essence_richtext_serializer.rb +2 -0
  122. data/app/serializers/alchemy/essence_select_serializer.rb +2 -0
  123. data/app/serializers/alchemy/essence_text_serializer.rb +2 -0
  124. data/app/serializers/alchemy/legacy_element_serializer.rb +2 -0
  125. data/app/serializers/alchemy/page_serializer.rb +2 -0
  126. data/app/serializers/alchemy/page_tree_serializer.rb +2 -0
  127. data/app/serializers/alchemy/picture_serializer.rb +2 -0
  128. data/app/views/alchemy/admin/attachments/_archive_overlay.html.erb +1 -1
  129. data/app/views/alchemy/admin/attachments/_file_to_assign.html.erb +1 -1
  130. data/app/views/alchemy/admin/attachments/_filter_bar.html.erb +1 -3
  131. data/app/views/alchemy/admin/attachments/_tag_list.html.erb +1 -1
  132. data/app/views/alchemy/admin/contents/_missing.html.erb +1 -1
  133. data/app/views/alchemy/admin/contents/create.js.erb +9 -13
  134. data/app/views/alchemy/admin/contents/new.html.erb +1 -1
  135. data/app/views/alchemy/admin/elements/_picture_gallery_editor.html.erb +4 -4
  136. data/app/views/alchemy/admin/essence_files/assign.js.erb +1 -1
  137. data/app/views/alchemy/admin/essence_pictures/assign.js.erb +1 -1
  138. data/app/views/alchemy/admin/essence_pictures/crop.html.erb +1 -1
  139. data/app/views/alchemy/admin/essence_pictures/destroy.js.erb +10 -7
  140. data/app/views/alchemy/admin/essence_pictures/edit.html.erb +8 -6
  141. data/app/views/alchemy/admin/essence_pictures/update.js.erb +1 -1
  142. data/app/views/alchemy/admin/partials/_remote_search_form.html.erb +2 -2
  143. data/app/views/alchemy/admin/pictures/_filter_and_size_bar.html.erb +4 -4
  144. data/app/views/alchemy/admin/pictures/_filter_bar.html.erb +1 -3
  145. data/app/views/alchemy/admin/pictures/_overlay_picture_list.html.erb +1 -1
  146. data/app/views/alchemy/admin/pictures/_picture_to_assign.html.erb +1 -1
  147. data/app/views/alchemy/admin/pictures/_tag_list.html.erb +1 -1
  148. data/app/views/alchemy/admin/resources/_filter_bar.html.erb +1 -3
  149. data/app/views/alchemy/admin/resources/_tag_list.html.erb +1 -1
  150. data/app/views/alchemy/admin/uploader/_button.html.erb +1 -1
  151. data/app/views/alchemy/essences/_essence_file_editor.html.erb +2 -2
  152. data/app/views/alchemy/essences/_essence_picture_editor.html.erb +2 -2
  153. data/app/views/alchemy/essences/shared/_essence_picture_tools.html.erb +3 -3
  154. data/app/views/alchemy/navigation/_renderer.html.erb +1 -2
  155. data/config/brakeman.ignore +65 -0
  156. data/db/migrate/20130827094554_alchemy_two_point_six.rb +1 -1
  157. data/db/migrate/20130828121054_remove_do_not_index_from_alchemy_essence_texts.rb +1 -1
  158. data/db/migrate/20130828121120_remove_do_not_index_from_alchemy_essence_richtexts.rb +1 -1
  159. data/db/migrate/20130918201742_add_published_at_to_alchemy_pages.rb +1 -1
  160. data/db/migrate/20150608204610_add_parent_element_id_to_alchemy_elements.rb +1 -1
  161. data/db/migrate/20150729151825_add_link_text_to_alchemy_essence_files.rb +1 -1
  162. data/db/migrate/20150906195818_add_locale_to_alchemy_languages.rb +1 -1
  163. data/db/migrate/20160108174834_add_timebased_publishing_columns_to_pages.rb +1 -1
  164. data/db/migrate/20160422195310_add_image_file_format_to_alchemy_pictures.rb +1 -1
  165. data/db/migrate/20160617224938_change_alchemy_pages_locked_to_locked_at.rb +1 -1
  166. data/db/migrate/20160912223112_add_index_to_alchemy_pages_rgt.rb +1 -1
  167. data/db/migrate/20160927205604_add_foreign_key_indices_and_null_constraints.rb +1 -1
  168. data/db/migrate/20160928080104_add_foreign_keys.rb +1 -1
  169. data/lib/alchemy/ability_helper.rb +2 -0
  170. data/lib/alchemy/admin/locale.rb +2 -0
  171. data/lib/alchemy/auth_accessors.rb +2 -0
  172. data/lib/alchemy/cache_digests/template_tracker.rb +2 -0
  173. data/lib/alchemy/config.rb +2 -0
  174. data/lib/alchemy/configuration_methods.rb +2 -0
  175. data/lib/alchemy/controller_actions.rb +2 -0
  176. data/lib/alchemy/deprecation.rb +3 -0
  177. data/lib/alchemy/errors.rb +2 -0
  178. data/lib/alchemy/essence.rb +2 -0
  179. data/lib/alchemy/filetypes.rb +2 -0
  180. data/lib/alchemy/forms/builder.rb +2 -0
  181. data/lib/alchemy/hints.rb +2 -0
  182. data/lib/alchemy/i18n.rb +2 -0
  183. data/lib/alchemy/logger.rb +2 -0
  184. data/lib/alchemy/modules.rb +2 -0
  185. data/lib/alchemy/name_conversions.rb +2 -0
  186. data/lib/alchemy/on_page_layout.rb +2 -0
  187. data/lib/alchemy/on_page_layout/callbacks_runner.rb +2 -0
  188. data/lib/alchemy/page_layout.rb +3 -1
  189. data/lib/alchemy/paths.rb +2 -0
  190. data/lib/alchemy/permissions.rb +2 -0
  191. data/lib/alchemy/picture_attributes.rb +2 -0
  192. data/lib/alchemy/resource.rb +2 -0
  193. data/lib/alchemy/resources_helper.rb +14 -12
  194. data/lib/alchemy/routing_constraints.rb +2 -0
  195. data/lib/alchemy/ssl_protection.rb +2 -0
  196. data/lib/alchemy/test_support/controller_requests.rb +20 -0
  197. data/lib/alchemy/test_support/essence_shared_examples.rb +3 -21
  198. data/lib/alchemy/tinymce.rb +2 -0
  199. data/lib/alchemy/touching.rb +2 -0
  200. data/lib/alchemy/upgrader/three_point_four.rb +20 -3
  201. data/lib/alchemy/userstamp.rb +2 -0
  202. data/lib/alchemy/version.rb +3 -1
  203. data/lib/alchemy_cms.rb +1 -0
  204. data/lib/tasks/alchemy/upgrade.rake +5 -1
  205. metadata +7 -5
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  module Admin
3
5
  class ClipboardController < Alchemy::Admin::BaseController
6
+ REMARKABLE_TYPES = %w(elements pages)
7
+
4
8
  authorize_resource class: :alchemy_admin_clipboard
5
9
  before_action :set_clipboard
6
10
 
@@ -12,10 +16,10 @@ module Alchemy
12
16
  end
13
17
 
14
18
  def insert
15
- @item = model_class.find(params[:remarkable_id])
16
- unless @clipboard.detect { |item| item['id'] == params[:remarkable_id] }
19
+ @item = model_class.find(remarkable_params[:remarkable_id])
20
+ unless @clipboard.detect { |item| item['id'] == remarkable_params[:remarkable_id] }
17
21
  @clipboard << {
18
- 'id' => params[:remarkable_id],
22
+ 'id' => remarkable_params[:remarkable_id],
19
23
  'action' => params[:remove] ? 'cut' : 'copy'
20
24
  }
21
25
  end
@@ -25,8 +29,8 @@ module Alchemy
25
29
  end
26
30
 
27
31
  def remove
28
- @item = model_class.find(params[:remarkable_id])
29
- @clipboard.delete_if { |item| item['id'] == params[:remarkable_id] }
32
+ @item = model_class.find(remarkable_params[:remarkable_id])
33
+ @clipboard.delete_if { |item| item['id'] == remarkable_params[:remarkable_id] }
30
34
  respond_to do |format|
31
35
  format.js
32
36
  end
@@ -39,11 +43,20 @@ module Alchemy
39
43
  private
40
44
 
41
45
  def set_clipboard
42
- @clipboard = get_clipboard(params[:remarkable_type])
46
+ @clipboard = get_clipboard(remarkable_type)
43
47
  end
44
48
 
45
49
  def model_class
46
- "alchemy/#{params[:remarkable_type]}".classify.constantize
50
+ raise ActionController::BadRequest unless remarkable_type
51
+ "alchemy/#{remarkable_type}".classify.constantize
52
+ end
53
+
54
+ def remarkable_params
55
+ params.permit(:remarkable_type, :remarkable_id)
56
+ end
57
+
58
+ def remarkable_type
59
+ remarkable_params.keep_if { |_k, type| type.in? REMARKABLE_TYPES }[:remarkable_type]
47
60
  end
48
61
  end
49
62
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  module Admin
3
5
  class ContentsController < Alchemy::Admin::BaseController
@@ -7,23 +9,21 @@ module Alchemy
7
9
 
8
10
  def new
9
11
  @element = Element.find(params[:element_id])
10
- @options = options_from_params
11
12
  @content = @element.contents.build
12
13
  end
13
14
 
14
15
  def create
15
16
  @element = Element.find(params[:content][:element_id])
16
17
  @content = Content.create_from_scratch(@element, content_params)
17
- @options = options_from_params
18
18
  @html_options = params[:html_options] || {}
19
19
  if picture_gallery_editor?
20
20
  @content.update_essence(picture_id: params[:picture_id])
21
- @options = options_for_picture_gallery
21
+ @gallery_pictures = @element.contents.gallery_pictures
22
+ options_from_params[:sortable] = @gallery_pictures.size > 1
22
23
  @content_dom_id = "#add_picture_#{@element.id}"
23
24
  else
24
25
  @content_dom_id = "#add_content_for_element_#{@element.id}"
25
26
  end
26
- @locals = essence_editor_locals
27
27
  end
28
28
 
29
29
  def update
@@ -54,21 +54,7 @@ module Alchemy
54
54
  end
55
55
 
56
56
  def picture_gallery_editor?
57
- params[:content][:essence_type] == 'Alchemy::EssencePicture' && @options[:grouped] == 'true'
58
- end
59
-
60
- def options_for_picture_gallery
61
- @gallery_pictures = @element.contents.gallery_pictures
62
- @dragable = @gallery_pictures.size > 1
63
- @options.merge(dragable: @dragable)
64
- end
65
-
66
- def essence_editor_locals
67
- {
68
- content: @content,
69
- options: @options.symbolize_keys,
70
- html_options: @html_options.symbolize_keys
71
- }
57
+ params[:content][:essence_type] == 'Alchemy::EssencePicture' && options_from_params[:grouped] == 'true'
72
58
  end
73
59
  end
74
60
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'net/http'
2
4
  require 'alchemy/version'
3
5
 
@@ -26,12 +28,12 @@ module Alchemy
26
28
  def update_check
27
29
  @alchemy_version = Alchemy.version
28
30
  if @alchemy_version < latest_alchemy_version
29
- render text: 'true'
31
+ render plain: 'true'
30
32
  else
31
- render text: 'false'
33
+ render plain: 'false'
32
34
  end
33
35
  rescue UpdateServiceUnavailable => e
34
- render text: e, status: 503
36
+ render plain: e, status: 503
35
37
  end
36
38
 
37
39
  private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  module Admin
3
5
  class ElementsController < Alchemy::Admin::BaseController
@@ -39,7 +41,7 @@ module Alchemy
39
41
  @element = paste_element_from_clipboard
40
42
  @cell = @element.cell
41
43
  else
42
- @element = Element.new_from_scratch(params[:element])
44
+ @element = Element.new_from_scratch(create_element_params)
43
45
  if @page.can_have_cells?
44
46
  @cell = find_or_create_cell
45
47
  @element.cell = @cell
@@ -173,6 +175,10 @@ module Alchemy
173
175
  params.fetch(:element, {})
174
176
  end
175
177
  end
178
+
179
+ def create_element_params
180
+ params.require(:element).permit(:name, :page_id, :parent_element_id)
181
+ end
176
182
  end
177
183
  end
178
184
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  module Admin
3
5
  class EssenceFilesController < Alchemy::Admin::BaseController
@@ -9,7 +11,6 @@ module Alchemy
9
11
 
10
12
  def edit
11
13
  @content = @essence_file.content
12
- @options = options_from_params
13
14
  end
14
15
 
15
16
  def update
@@ -24,7 +25,6 @@ module Alchemy
24
25
  @content = Content.find_by(id: params[:content_id])
25
26
  @attachment = Attachment.find_by(id: params[:attachment_id])
26
27
  @content.essence.attachment = @attachment
27
- @options = options_from_params
28
28
 
29
29
  # We need to update timestamp here because we don't save yet,
30
30
  # but the cache needs to be get invalid.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  module Admin
3
5
  class EssencePicturesController < Alchemy::Admin::BaseController
@@ -6,7 +8,6 @@ module Alchemy
6
8
 
7
9
  before_action :load_essence_picture, only: [:edit, :crop, :update]
8
10
  before_action :load_content, only: [:edit, :update, :assign]
9
- before_action :load_options
10
11
 
11
12
  helper 'alchemy/admin/contents'
12
13
  helper 'alchemy/admin/essences'
@@ -18,7 +19,7 @@ module Alchemy
18
19
  def crop
19
20
  if @picture = @essence_picture.picture
20
21
  @content = @essence_picture.content
21
- @options[:format] ||= (configuration(:image_store_format) || 'png')
22
+ options_from_params[:format] ||= (configuration(:image_store_format) || 'png')
22
23
 
23
24
  @min_size = sizes_from_essence_or_params
24
25
  @ratio = ratio_from_size_or_params
@@ -35,7 +36,7 @@ module Alchemy
35
36
  @essence_picture.update(essence_picture_params)
36
37
  end
37
38
 
38
- # Assigns picture, but does not saves it.
39
+ # Assigns picture, but does not save it.
39
40
  #
40
41
  # When the user saves the element the content gets updated as well.
41
42
  #
@@ -43,8 +44,6 @@ module Alchemy
43
44
  @picture = Picture.find_by(id: params[:picture_id])
44
45
  @content.essence.picture = @picture
45
46
  @element = @content.element
46
- @dragable = @options[:grouped]
47
- @options = @options.merge(dragable: @dragable)
48
47
 
49
48
  # We need to update timestamp here because we don't save yet,
50
49
  # but the cache needs to be get invalid.
@@ -63,10 +62,6 @@ module Alchemy
63
62
 
64
63
  private
65
64
 
66
- def load_options
67
- @options = options_from_params
68
- end
69
-
70
65
  def load_essence_picture
71
66
  @essence_picture = EssencePicture.find(params[:id])
72
67
  end
@@ -82,8 +77,8 @@ module Alchemy
82
77
  def sizes_from_essence_or_params
83
78
  if @essence_picture.render_size?
84
79
  @essence_picture.sizes_from_string(@essence_picture.render_size)
85
- elsif @options[:size]
86
- @essence_picture.sizes_from_string(@options[:size])
80
+ elsif options_from_params[:size]
81
+ @essence_picture.sizes_from_string(options_from_params[:size])
87
82
  else
88
83
  { width: 0, height: 0 }
89
84
  end
@@ -93,8 +88,8 @@ module Alchemy
93
88
  # aspect ratio, don't specify a size or only width or height.
94
89
  #
95
90
  def ratio_from_size_or_params
96
- if @min_size.value?(0) && @options[:fixed_ratio].to_s =~ FLOAT_REGEX
97
- @options[:fixed_ratio].to_f
91
+ if @min_size.value?(0) && options_from_params[:fixed_ratio].to_s =~ FLOAT_REGEX
92
+ options_from_params[:fixed_ratio].to_f
98
93
  elsif !@min_size[:width].zero? && !@min_size[:height].zero?
99
94
  @min_size[:width].to_f / @min_size[:height].to_f
100
95
  else
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  module Admin
3
5
  class LanguagesController < ResourcesController
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  module Admin
3
5
  class LayoutpagesController < Alchemy::Admin::BaseController
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  class Admin::LegacyPageUrlsController < Alchemy::Admin::ResourcesController
3
5
  before_action :load_page
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  module Admin
3
5
  class PagesController < Alchemy::Admin::BaseController
@@ -187,7 +189,7 @@ module Alchemy
187
189
  # fetching page via before filter
188
190
  @page.publish!
189
191
  flash[:notice] = Alchemy.t(:page_published, name: @page.name)
190
- redirect_back_or_to_default(admin_pages_path)
192
+ redirect_back(fallback_location: admin_pages_path)
191
193
  end
192
194
 
193
195
  def copy_language_tree
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  module Admin
3
5
  class PicturesController < Alchemy::Admin::ResourcesController
@@ -127,7 +129,6 @@ module Alchemy
127
129
  def archive_overlay
128
130
  @content = Content.select('id').find_by(id: params[:content_id])
129
131
  @element = Element.select('id').find_by(id: params[:element_id])
130
- @options = options_from_params
131
132
 
132
133
  respond_to do |format|
133
134
  format.html { render partial: 'archive_overlay' }
@@ -136,16 +137,17 @@ module Alchemy
136
137
  end
137
138
 
138
139
  def redirect_to_index
139
- do_redirect_to admin_pictures_path(search_params)
140
+ do_redirect_to admin_pictures_path(search_filter_params)
140
141
  end
141
142
 
142
- def search_params
143
- params.except(:id, :picture_ids).permit(
144
- :filter,
145
- :page,
146
- {q: resource_handler.search_field_name},
147
- :size,
148
- :tagged_with
143
+ def search_filter_params
144
+ params.except(*COMMON_SEARCH_FILTER_EXCLUDES + [:picture_ids]).permit(
145
+ *common_search_filter_includes + [
146
+ :size,
147
+ :element_id,
148
+ :swap,
149
+ :content_id
150
+ ]
149
151
  )
150
152
  end
151
153
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'csv'
2
4
  require 'alchemy/resource'
3
5
  require 'alchemy/resources_helper'
@@ -5,17 +7,17 @@ require 'alchemy/resources_helper'
5
7
  module Alchemy
6
8
  module Admin
7
9
  class ResourcesController < Alchemy::Admin::BaseController
10
+ COMMON_SEARCH_FILTER_EXCLUDES = [:id, :utf8, :_method, :_].freeze
11
+
8
12
  include Alchemy::ResourcesHelper
9
13
 
10
14
  helper Alchemy::ResourcesHelper, TagsHelper
11
- helper_method :resource_handler
15
+ helper_method :resource_handler, :search_filter_params
12
16
 
13
17
  before_action :load_resource,
14
18
  only: [:show, :edit, :update, :destroy]
15
19
 
16
- before_action do
17
- authorize!(action_name.to_sym, resource_instance_variable || resource_handler.model)
18
- end
20
+ before_action :authorize_resource
19
21
 
20
22
  def index
21
23
  @query = resource_handler.model.ransack(params[:q])
@@ -112,6 +114,10 @@ module Alchemy
112
114
  instance_variable_set("@#{resource_handler.resource_name}", resource_handler.model.find(params[:id]))
113
115
  end
114
116
 
117
+ def authorize_resource
118
+ authorize!(action_name.to_sym, resource_instance_variable || resource_handler.model)
119
+ end
120
+
115
121
  # Permits all parameters as default!
116
122
  #
117
123
  # THIS IS INSECURE! Although only signed in admin users can send requests anyway, but we should change this.
@@ -129,6 +135,21 @@ module Alchemy
129
135
  filter == params[:filter]
130
136
  end || :all
131
137
  end
138
+
139
+ def search_filter_params
140
+ params.except(*COMMON_SEARCH_FILTER_EXCLUDES).permit(*common_search_filter_includes)
141
+ end
142
+
143
+ def common_search_filter_includes
144
+ [
145
+ # contrary to Rails' documentation passing an empty hash to permit all keys does not work
146
+ {options: options_from_params.keys},
147
+ {q: resource_handler.search_field_name},
148
+ :tagged_with,
149
+ :filter,
150
+ :page
151
+ ].freeze
152
+ end
132
153
  end
133
154
  end
134
155
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  module Admin
3
5
  class SitesController < ResourcesController
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  module Admin
3
5
  class TagsController < ResourcesController
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  module Admin
3
5
  class TrashController < Alchemy::Admin::BaseController
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  class Api::BaseController < Alchemy::BaseController
3
5
  layout false
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  class Api::ContentsController < Api::BaseController
3
5
  # Returns all contents as json object
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  class Api::ElementsController < Api::BaseController
3
5
  # Returns all elements as json object
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  class Api::PagesController < Api::BaseController
3
5
  before_action :load_page, only: [:show]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Alchemy
2
4
  class AttachmentsController < BaseController
3
5
  before_action :load_attachment
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This is the main Alchemy controller all other controllers inherit from.
2
4
  #
3
5
  module Alchemy
@@ -76,7 +78,7 @@ module Alchemy
76
78
  if request.xhr?
77
79
  respond_to do |format|
78
80
  format.js do
79
- render text: flash.discard(:warning), status: 403
81
+ render plain: flash.discard(:warning), status: 403
80
82
  end
81
83
  format.html do
82
84
  render partial: 'alchemy/admin/partials/flash',