Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interference Marketable Routes & ActiveStorage fixed #3385

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pages/lib/refinery/pages/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Pages
:cache_pages_full, :layout_template_whitelist,
:use_layout_templates, :page_title, :absolute_page_links, :types,
:auto_expand_admin_tree, :show_title_in_body,
:friendly_id_reserved_words, :layout_templates_pattern, :view_templates_pattern,
:friendly_id_reserved_words, :reserved_paths, :layout_templates_pattern, :view_templates_pattern,
:add_whitelist_elements, :add_whitelist_attributes, :whitelist_elements, :whitelist_attributes,
:home_page_path

Expand Down Expand Up @@ -61,9 +61,10 @@ def layout_template_whitelist
self.absolute_page_links = false
self.types = Types.registered
self.auto_expand_admin_tree = true
self.reserved_paths = %w(/rails/active_storage)
self.friendly_id_reserved_words = %w(
index new session login logout users refinery admin images
)
) + self.reserved_paths.map { |path| path.split('/') }.flatten.uniq - [""]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably just need to add rails because we already just add refinery or admin in friendly_id_reserved_words even if there are sub path to these paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now add only the first elements from each element of reserved_paths to friendly_id_reserved_words, so in the case we have only one element '/rails/active_storage' it will only take 'rails'. If you add several paths it will remove all 'root'-fragments of the paths

Copy link
Member

@parndt parndt Jul 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we could use:

self.friendly_id_reserved_words = %w(
  index new session login logout users refinery admin images
) | reserved_paths.map { |path| path.split('/') }.flatten.uniq.reject(&:blank?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to

self.friendly_id_reserved_words = %w(
  index new session login logout users refinery admin images
) | self.reserved_paths.map { |path| path.split('/').reject(&:blank?).first}.flatten.uniq

to take only the all root_fragments of the reserved paths.

self.layout_templates_pattern = 'app', 'views', '{layouts,refinery/layouts}', '*html*'
self.view_templates_pattern = 'app', 'views', '{pages,refinery/pages}', '*html*'
end
Expand Down
3 changes: 2 additions & 1 deletion pages/lib/refinery/pages/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class Engine < ::Rails::Engine

def append_marketable_routes
Refinery::Core::Engine.routes.append do
get '*path', :to => 'pages#show', :as => :marketable_page
get '*path', :to => 'pages#show', :as => :marketable_page,
constraints: lambda { |request| !Refinery::Pages.config.reserved_paths.any? { |path| request.path.start_with?(path) } }
end
end

Expand Down
6 changes: 6 additions & 0 deletions pages/spec/controllers/refinery/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ module Refinery
expect(response).to render_template("show")
end
end

describe "#show" do
it "does not interfere with active storage" do
expect(:get => "/rails/active_storage").not_to be_routable
end
end
end
end