From 4fa540ea675925dcdbc92b24feb3663144fc014f Mon Sep 17 00:00:00 2001 From: Philip Arndt Date: Fri, 25 May 2012 18:29:35 +1200 Subject: [PATCH 01/10] Fixes #1673 by adding support for not including the record itself in the nesting and passing :uncached_nested_url as the attribute to access on the record for its nesting. Sneaky. --- core/lib/refinery/activity.rb | 23 ++++++++++++++----- .../refinery/admin/dashboard_helper.rb | 2 +- pages/lib/refinery/pages/engine.rb | 6 ++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/core/lib/refinery/activity.rb b/core/lib/refinery/activity.rb index fd61f43fc6..e847ac4875 100644 --- a/core/lib/refinery/activity.rb +++ b/core/lib/refinery/activity.rb @@ -9,6 +9,7 @@ class Activity # Total number of activies to show for a given class of activity attr_accessor :limit + # Other objects, like parents, to include in the nesting structure attr_accessor :nested_with # SQL order by string to specify how to order the activities in the activity feed for @@ -21,6 +22,10 @@ class Activity # Image asset to use to represent updated instance of the class thisa activity represents attr_accessor :updated_image + # Boolean; whether or not to use the record itself when constructing the nesting + # Default true + attr_accessor :use_record_in_nesting + # Creates a new instance of Activity for a registered Refinery Plugin. An optional # hash of options can be specified to customize the values of each attribute # accessor defined on this class. Each key specified in the options hash should be a @@ -31,7 +36,8 @@ class Activity # Activity.new(:limit => 10, :title => "Newest Activity!") # # Warning: - # for the nested_with option, pass in the reverse order of ancestry e.g. [parent.parent_of_parent, parent] + # for the nested_with option, pass in the reverse order of ancestry + # e.g. [parent.parent_of_parent, parent] def initialize(options = {}) { :class_name => nil, @@ -43,7 +49,8 @@ def initialize(options = {}) :title => "title", :updated_image => "edit.png", :url => nil, - :url_prefix => "edit" + :url_prefix => "edit", + :use_record_in_nesting => true }.merge(options).each { |key, value| self.send(:"#{key}=", value) } end @@ -80,11 +87,15 @@ def klass end # to use in a URL like edit_refinery_admin_group_individuals_path(record.group, record) - # which will help you if you're using nested routed. + # which will help you if you're using nested routes. def nesting(record_string = "record") - self.nested_with.inject("") { |nest_chain, nesting| - nest_chain << "#{record_string}.#{nesting}," - } + @nesting ||= begin + chain = self.nested_with.inject([]) { |nest_chain, nesting| + nest_chain << "#{record_string}.#{nesting}" + } + chain << record_string if self.use_record_in_nesting + chain.join(',') + end end attr_writer :url_prefix diff --git a/dashboard/app/helpers/refinery/admin/dashboard_helper.rb b/dashboard/app/helpers/refinery/admin/dashboard_helper.rb index 748cbfb75a..f468f15915 100644 --- a/dashboard/app/helpers/refinery/admin/dashboard_helper.rb +++ b/dashboard/app/helpers/refinery/admin/dashboard_helper.rb @@ -16,7 +16,7 @@ def activity_message_for(record) :what => record.send(activity.title), :kind => record.class.model_name.human, :action => t("with_article \"#{article}\"", :scope => "refinery.#{action}") - ).downcase.capitalize, eval("#{activity.url}(#{activity.nesting("record")}record)") + ).downcase.capitalize, eval("#{activity.url}(#{activity.nesting("record")})") end end diff --git a/pages/lib/refinery/pages/engine.rb b/pages/lib/refinery/pages/engine.rb index 5b349d7e1c..4ee4ea4d39 100644 --- a/pages/lib/refinery/pages/engine.rb +++ b/pages/lib/refinery/pages/engine.rb @@ -24,7 +24,11 @@ class Engine < ::Rails::Engine plugin.name = 'refinery_pages' plugin.version = %q{2.0.0} plugin.menu_match = %r{refinery/page(_part|s_dialog)?s$} - plugin.activity = { :class_name => :'refinery/page' } + plugin.activity = { + :class_name => :'refinery/page', + :nested_with => [:uncached_nested_url], + :use_record_in_nesting => false + } plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.admin_pages_path } end end From ab1b4f1d951c82ad4484f3f7764aa96e86ebecc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=A3is=20Ozols?= Date: Mon, 21 May 2012 11:02:44 +0300 Subject: [PATCH 02/10] Add failing spec for #1673. --- .../spec/requests/refinery/admin/dashboard_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dashboard/spec/requests/refinery/admin/dashboard_spec.rb b/dashboard/spec/requests/refinery/admin/dashboard_spec.rb index ad06e978c1..bcf7bf002c 100644 --- a/dashboard/spec/requests/refinery/admin/dashboard_spec.rb +++ b/dashboard/spec/requests/refinery/admin/dashboard_spec.rb @@ -46,5 +46,15 @@ 3.times { |n| page.should have_content("Ugisozols#{n} user was added") } 3.times { |n| page.should have_content("Refinery cms #{n} page was added") } end + + # see https://github.com/resolve/refinerycms/issues/1673 + it "uses proper link for nested pages" do + parent = FactoryGirl.create :page, :title => "Parent" + nested = FactoryGirl.create :page, :title => "I'm nested", :parent_id => parent.id + + visit refinery.admin_dashboard_path + + page.should have_selector("a[href='#{refinery.edit_admin_page_path(nested.uncached_nested_url)}']") + end end end From 5aad5d3283f9fdb0ea86ddb4972aad64bbaf5c8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=A3is=20Ozols?= Date: Mon, 21 May 2012 11:04:54 +0300 Subject: [PATCH 03/10] Simplify failing dashboard spec. --- dashboard/spec/requests/refinery/admin/dashboard_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dashboard/spec/requests/refinery/admin/dashboard_spec.rb b/dashboard/spec/requests/refinery/admin/dashboard_spec.rb index bcf7bf002c..9e6e83e46d 100644 --- a/dashboard/spec/requests/refinery/admin/dashboard_spec.rb +++ b/dashboard/spec/requests/refinery/admin/dashboard_spec.rb @@ -49,8 +49,7 @@ # see https://github.com/resolve/refinerycms/issues/1673 it "uses proper link for nested pages" do - parent = FactoryGirl.create :page, :title => "Parent" - nested = FactoryGirl.create :page, :title => "I'm nested", :parent_id => parent.id + nested = FactoryGirl.create :page, :parent_id => Refinery::Page.last.id visit refinery.admin_dashboard_path From d3dcb330484718ba09126e3b0abd0d541bcbf65c Mon Sep 17 00:00:00 2001 From: Philip Arndt Date: Fri, 25 May 2012 18:33:02 +1200 Subject: [PATCH 04/10] Fixes seeding bug introduced by me in be6ff4acca0d0de5351587ab6707c0489495bff4 --- pages/db/seeds.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/db/seeds.rb b/pages/db/seeds.rb index d195757157..5569b8d387 100644 --- a/pages/db/seeds.rb +++ b/pages/db/seeds.rb @@ -1,4 +1,4 @@ -(Refinery.i18n_enabled ? Refinery::I18n.frontend_locales : [:en]).each do |lang| +(Refinery.i18n_enabled? ? Refinery::I18n.frontend_locales : [:en]).each do |lang| I18n.locale = lang if Refinery::Page.where(:menu_match => "^/$").empty? From 806601b2dfa361282105a8ed1d281a6c9d423478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=A3is=20Ozols?= Date: Fri, 25 May 2012 09:58:33 +0300 Subject: [PATCH 05/10] Fix failing mysql spec by increasing nested page updated_at timestamp. --- dashboard/spec/requests/refinery/admin/dashboard_spec.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dashboard/spec/requests/refinery/admin/dashboard_spec.rb b/dashboard/spec/requests/refinery/admin/dashboard_spec.rb index 9e6e83e46d..6ee1a974b1 100644 --- a/dashboard/spec/requests/refinery/admin/dashboard_spec.rb +++ b/dashboard/spec/requests/refinery/admin/dashboard_spec.rb @@ -49,10 +49,13 @@ # see https://github.com/resolve/refinerycms/issues/1673 it "uses proper link for nested pages" do - nested = FactoryGirl.create :page, :parent_id => Refinery::Page.last.id + # we need to increase updated_at because dashboard entries are sorted by + # updated_at column and we need this page to be at the top of the list + nested = FactoryGirl.create(:page, :parent_id => Refinery::Page.last.id, + :updated_at => Time.now + 10.seconds) visit refinery.admin_dashboard_path - + page.should have_selector("a[href='#{refinery.edit_admin_page_path(nested.uncached_nested_url)}']") end end From 14aa588666529edcae63e0506c8c1d42fd7861e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=A3is=20Ozols?= Date: Fri, 25 May 2012 10:29:04 +0300 Subject: [PATCH 06/10] Add note to changelog about #1673. --- changelog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 105f46aae8..1cc4d2f2a6 100644 --- a/changelog.md +++ b/changelog.md @@ -8,8 +8,8 @@ * Use new page part names (:body, :side_body) when generating extensions. [Uģis Ozols](https://github.com/ugisozols) * Now extension generator will merge two seeds file in case user generates multiple resources for one extension. [#1532](https://github.com/resolve/refinerycms/issues/1532). [Uģis Ozols](https://github.com/ugisozols) * Fix refinery:override bug where it won't match js files with more than extension. [#1685](https://github.com/resolve/refinerycms/issues/1685). [Uģis Ozols](https://github.com/ugisozols) and [Philip Arndt](https://github.com/parndt) -* Now `refinerycms-images` and `refinerycms-resources` will inherit the s3_region configuration from `refinerycms-core`. -[#1687](https://github.com/resolve/refinerycms/pull/1687). [Julien Palmas](https://github.com/bartocc) +* Now `refinerycms-images` and `refinerycms-resources` will inherit the s3_region configuration from `refinerycms-core`. [#1687](https://github.com/resolve/refinerycms/pull/1687). [Julien Palmas](https://github.com/bartocc) +* Fixed dashboard bug where it wasn't producing proper links for nested pages. [#1696](https://github.com/resolve/refinerycms/pull/1696). [Philip Arndt](https://github.com/parndt) ## 2.0.4 [14 May 2012] * IMPORTANT: Fixed a security issue whereby the user could bypass some access restrictions in the backend. [#1636](https://github.com/resolve/refinerycms/pull/1636). [Rob Yurkowski](https://github.com/robyurkowski) and [Uģis Ozols](https://github.com/ugisozols) From 64dcb29120e2f40c29cb1ed62a8578986699db6a Mon Sep 17 00:00:00 2001 From: Philip Arndt Date: Fri, 25 May 2012 20:15:02 +1200 Subject: [PATCH 07/10] Match only &dialog, ?dialog, &width, ?width, &height, ?height which fixes #1397 --- core/app/assets/javascripts/refinery/admin.js.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/app/assets/javascripts/refinery/admin.js.erb b/core/app/assets/javascripts/refinery/admin.js.erb index 09ceeab729..808055e377 100644 --- a/core/app/assets/javascripts/refinery/admin.js.erb +++ b/core/app/assets/javascripts/refinery/admin.js.erb @@ -70,9 +70,9 @@ init_modal_dialogs = function(){ height = parseInt($(href.match("height=([0-9]*)")).last().get(0), 10)||473, title = $anchor.attr('title') || $anchor.attr('name') || $anchor.html() || null; - href = href.replace(/(\&(amp\;)?)?dialog\=true/, '') - .replace(/(\&(amp\;)?)?width\=\d+/, '') - .replace(/(\&(amp\;)?)?height\=\d+/, '') + href = href.replace(/((\&(amp\;)?)|\?)dialog\=true/, '') + .replace(/((\&(amp\;)?)|\?)width\=\d+/, '') + .replace(/((\&(amp\;)?)|\?)height\=\d+/, '') .replace(/(\?&(amp\;)?)/, '?') .replace(/\?$/, ''); From ed84d68aa2c5bd28e5bf9a2d491ddaf83971ea03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=A3is=20Ozols?= Date: Fri, 25 May 2012 12:08:35 +0300 Subject: [PATCH 08/10] Add note to changelog about #1397. --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 1cc4d2f2a6..b5c552399b 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ * Fix refinery:override bug where it won't match js files with more than extension. [#1685](https://github.com/resolve/refinerycms/issues/1685). [Uģis Ozols](https://github.com/ugisozols) and [Philip Arndt](https://github.com/parndt) * Now `refinerycms-images` and `refinerycms-resources` will inherit the s3_region configuration from `refinerycms-core`. [#1687](https://github.com/resolve/refinerycms/pull/1687). [Julien Palmas](https://github.com/bartocc) * Fixed dashboard bug where it wasn't producing proper links for nested pages. [#1696](https://github.com/resolve/refinerycms/pull/1696). [Philip Arndt](https://github.com/parndt) +* Match only &dialog, ?dialog, &width, ?width, &height and ?height in dialog querystrings. [#1397](https://github.com/resolve/refinerycms/issues/1397). [Philip Arndt](https://github.com/parndt) ## 2.0.4 [14 May 2012] * IMPORTANT: Fixed a security issue whereby the user could bypass some access restrictions in the backend. [#1636](https://github.com/resolve/refinerycms/pull/1636). [Rob Yurkowski](https://github.com/robyurkowski) and [Uģis Ozols](https://github.com/ugisozols) From ae07be4ca12a85373975683d3c26ef6356ed9297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=A3is=20Ozols?= Date: Fri, 25 May 2012 13:36:18 +0300 Subject: [PATCH 09/10] Add note to changelog about #1694. --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index b5c552399b..c0499c2701 100644 --- a/changelog.md +++ b/changelog.md @@ -11,6 +11,7 @@ * Now `refinerycms-images` and `refinerycms-resources` will inherit the s3_region configuration from `refinerycms-core`. [#1687](https://github.com/resolve/refinerycms/pull/1687). [Julien Palmas](https://github.com/bartocc) * Fixed dashboard bug where it wasn't producing proper links for nested pages. [#1696](https://github.com/resolve/refinerycms/pull/1696). [Philip Arndt](https://github.com/parndt) * Match only &dialog, ?dialog, &width, ?width, &height and ?height in dialog querystrings. [#1397](https://github.com/resolve/refinerycms/issues/1397). [Philip Arndt](https://github.com/parndt) +* Added multiple language support (specified by `Refinery::I18n.frontend_locales`) in `Refinery::Page` seeds file. [#1694](https://github.com/resolve/refinerycms/pull/1694). [Ole Reifschneider](https://github.com/Tranquility) ## 2.0.4 [14 May 2012] * IMPORTANT: Fixed a security issue whereby the user could bypass some access restrictions in the backend. [#1636](https://github.com/resolve/refinerycms/pull/1636). [Rob Yurkowski](https://github.com/robyurkowski) and [Uģis Ozols](https://github.com/ugisozols) From f8b113ed97897c09c63e87750163f7136b0739c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=A3is=20Ozols?= Date: Fri, 25 May 2012 13:47:46 +0300 Subject: [PATCH 10/10] Support multiple languages for seed data in extension and form generated seeds file. --- .../refinery/engine/templates/db/seeds.rb | 40 +++++++++------- .../refinery/form/templates/db/seeds.rb | 48 ++++++++++--------- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/core/lib/generators/refinery/engine/templates/db/seeds.rb b/core/lib/generators/refinery/engine/templates/db/seeds.rb index a47a0160a6..e635366f34 100644 --- a/core/lib/generators/refinery/engine/templates/db/seeds.rb +++ b/core/lib/generators/refinery/engine/templates/db/seeds.rb @@ -1,23 +1,27 @@ -if defined?(::Refinery::User) - ::Refinery::User.all.each do |user| - if user.plugins.where(:name => 'refinerycms-<%= namespacing.underscore %>').blank? - user.plugins.create(:name => 'refinerycms-<%= namespacing.underscore %>', - :position => (user.plugins.maximum(:position) || -1) +1) +(Refinery.i18n_enabled? ? Refinery::I18n.frontend_locales : [:en]).each do |lang| + I18n.locale = lang + + if defined?(Refinery::User) + Refinery::User.all.each do |user| + if user.plugins.where(:name => 'refinerycms-<%= namespacing.underscore %>').blank? + user.plugins.create(:name => 'refinerycms-<%= namespacing.underscore %>', + :position => (user.plugins.maximum(:position) || -1) +1) + end end end -end -<% unless skip_frontend? %> -url = "/<%= [(namespacing.underscore if namespacing.underscore != plural_name), plural_name].compact.join('/') %>" -if defined?(::Refinery::Page) && ::Refinery::Page.where(:link_url => url).empty? - page = ::Refinery::Page.create( - :title => '<%= class_name.pluralize.underscore.titleize %>', - :link_url => url, - :deletable => false, - :menu_match => "^#{url}(\/|\/.+?|)$" - ) - Refinery::Pages.default_parts.each_with_index do |default_page_part, index| - page.parts.create(:title => default_page_part, :body => nil, :position => index) +<% unless skip_frontend? -%> + url = "/<%= [(namespacing.underscore if namespacing.underscore != plural_name), plural_name].compact.join('/') %>" + if defined?(Refinery::Page) && Refinery::Page.where(:link_url => url).empty? + page = Refinery::Page.create( + :title => '<%= class_name.pluralize.underscore.titleize %>', + :link_url => url, + :deletable => false, + :menu_match => "^#{url}(\/|\/.+?|)$" + ) + Refinery::Pages.default_parts.each_with_index do |default_page_part, index| + page.parts.create(:title => default_page_part, :body => nil, :position => index) + end end +<% end -%> end -<% end %> diff --git a/core/lib/generators/refinery/form/templates/db/seeds.rb b/core/lib/generators/refinery/form/templates/db/seeds.rb index e74da83746..d8af691f1a 100644 --- a/core/lib/generators/refinery/form/templates/db/seeds.rb +++ b/core/lib/generators/refinery/form/templates/db/seeds.rb @@ -1,27 +1,31 @@ -if defined?(::Refinery::User) - ::Refinery::User.all.each do |user| - if user.plugins.find_by_name('<%= plural_name %>').nil? - user.plugins.create(:name => "<%= plural_name %>", - :position => (user.plugins.maximum(:position) || -1) +1) +(Refinery.i18n_enabled? ? Refinery::I18n.frontend_locales : [:en]).each do |lang| + I18n.locale = lang + + if defined?(Refinery::User) + Refinery::User.all.each do |user| + if user.plugins.find_by_name('<%= plural_name %>').nil? + user.plugins.create(:name => "<%= plural_name %>", + :position => (user.plugins.maximum(:position) || -1) +1) + end end end -end -if defined?(::Refinery::Page) - page = ::Refinery::Page.create( - :title => "<%= class_name.pluralize.underscore.titleize %>", - :link_url => "/<%= plural_name %>/new", - :deletable => false, - :menu_match => "^/<%= plural_name %>(\/|\/.+?|)$" - ) - thank_you_page = page.children.create( - :title => "Thank You", - :link_url => "/<%= plural_name %>/thank_you", - :deletable => false, - :show_in_menu => false - ) - Refinery::Pages.default_parts.each do |default_page_part| - page.parts.create(:title => default_page_part, :body => nil) - thank_you_page.parts.create(:title => default_page_part, :body => nil) + if defined?(Refinery::Page) + page = Refinery::Page.create( + :title => "<%= class_name.pluralize.underscore.titleize %>", + :link_url => "/<%= plural_name %>/new", + :deletable => false, + :menu_match => "^/<%= plural_name %>(\/|\/.+?|)$" + ) + thank_you_page = page.children.create( + :title => "Thank You", + :link_url => "/<%= plural_name %>/thank_you", + :deletable => false, + :show_in_menu => false + ) + Refinery::Pages.default_parts.each do |default_page_part| + page.parts.create(:title => default_page_part, :body => nil) + thank_you_page.parts.create(:title => default_page_part, :body => nil) + end end end