browsercms 3.5.2 → 3.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,9 +3,9 @@ module Cms
3
3
 
4
4
  layout "cms/toolbar"
5
5
 
6
- helper MobileHelper
6
+ helper Cms::MobileHelper
7
7
 
8
- def index
8
+ def index
9
9
  if params[:page_toolbar] != "0"
10
10
  @mode = params[:mode]
11
11
  @page_toolbar_enabled = true
@@ -12,9 +12,14 @@ module Cms
12
12
  render :partial => 'cms/attachments/attachment_table', :locals => { :block => content, :can_delete => false }
13
13
  end
14
14
 
15
+ # Determines if a user is currently editing this page
16
+ def is_editing_page?(page)
17
+ logged_in? && @mode == "edit" && current_user.able_to_edit?(page)
18
+ end
19
+
15
20
  def render_connector_and_connectable(connector, connectable)
16
21
  logger.debug "Rendering #{connectable} "
17
- if logged_in? && @mode == "edit" && current_user.able_to_edit?(connector.page)
22
+ if is_editing_page?(connector.page)
18
23
  render(:partial => 'cms/pages/edit_connector', :locals => { :connector => connector, :connectable => connectable})
19
24
  else
20
25
  render_connectable(connectable)
@@ -138,6 +138,14 @@ module Cms
138
138
  end
139
139
 
140
140
  #----- Portlet Action Related Methods ----------------------------------------
141
+
142
+ # Used by portlets to set a custom title, typically in the render body.
143
+ # For example, this allows a page with a single portlet that might display a content block to set the page name to
144
+ # that block name.
145
+ def page_title(new_title)
146
+ controller.current_page.title = new_title
147
+ end
148
+
141
149
  def instance_name
142
150
  "#{self.class.name.demodulize.underscore}_#{id}"
143
151
  end
@@ -1,7 +1,13 @@
1
- <% page_title @page.page_title %>
2
-
3
1
  <%= content_for :html_head do %>
4
2
  <meta name="generator" content="BrowserCMS <%= Cms.version %>"/>
3
+ <% if is_editing_page?(current_page) %>
4
+ <%= javascript_include_tag 'cms/core_library' %>
5
+ <% if @authenticity_token_loaded.nil? && protect_against_forgery? %><script type="text/javascript">
6
+ jQuery(function($){
7
+ $.cms.authenticity_token = '<%= form_authenticity_token %>'
8
+ })
9
+ </script><% end %><% @authenticity_token_loaded = true %>
10
+ <% end %>
5
11
  <% end %>
6
12
  <% if @show_toolbar %>
7
13
  <% flash.keep %>
@@ -16,12 +16,4 @@
16
16
  :style => "text-decoration: none; padding: 0 2px 0 0; background: none; margin: 0; float: none; border: 0; position: absolute; top: -1px; right: 10px;" %>
17
17
  </div>
18
18
  <%= render_connectable connectable %>
19
- </div>
20
- <%= content_for :html_head do %>
21
- <%= javascript_include_tag 'cms/core_library' %>
22
- <% if @authenticity_token_loaded.nil? && protect_against_forgery? %><script type="text/javascript">
23
- jQuery(function($){
24
- $.cms.authenticity_token = '<%= form_authenticity_token %>'
25
- })
26
- </script><% end %><% @authenticity_token_loaded = true %>
27
- <% end %>
19
+ </div>
@@ -0,0 +1,20 @@
1
+ require 'cms/upgrades/v3_4_0'
2
+
3
+ # Retroactively fix for changes that were merged into 3.1.5/3.3.0/3.4.0.
4
+ # This originally was for 3.4.0, but needs to be run prior to 3.1.5 migrations.
5
+ class Browsercms314 < ActiveRecord::Migration
6
+ include Cms::Upgrades::V3_4_0::SchemaStatements
7
+
8
+ def change
9
+ standardize_foreign_keys_from_versions_tables_to_original_table
10
+
11
+ end
12
+
13
+ private
14
+ def standardize_foreign_keys_from_versions_tables_to_original_table
15
+ models = %w[attachment dynamic_view file_block html_block link page ]
16
+ models.each do |model|
17
+ standardize_version_id_column(model)
18
+ end
19
+ end
20
+ end
@@ -69,7 +69,7 @@ class Browsercms315 < ActiveRecord::Migration
69
69
 
70
70
  all_nodes_but_root = Cms::SectionNode.find(:all, :conditions=>["section_id IS NOT NULL"])
71
71
  all_nodes_but_root.each do |sn|
72
- parent_node = Cms::SectionNode.find(:first, :conditions => ["node_id = ? and node_type = 'Section'", sn.section_id])
72
+ parent_node = Cms::SectionNode.find(:first, :conditions => ["node_id = ? and (node_type = 'Section' or node_type = 'Cms::Section')", sn.section_id])
73
73
  sn.temp_parent_id = parent_node.id
74
74
  sn.save!
75
75
  end
@@ -12,7 +12,6 @@ class Browsercms340 < ActiveRecord::Migration
12
12
 
13
13
  update_sitemap
14
14
  update_files
15
- standardize_foreign_keys_from_versions_tables_to_original_table
16
15
  end
17
16
 
18
17
  private
@@ -53,10 +52,5 @@ class Browsercms340 < ActiveRecord::Migration
53
52
  end
54
53
  end
55
54
 
56
- def standardize_foreign_keys_from_versions_tables_to_original_table
57
- models = %w[attachment dynamic_view file_block html_block link page ]
58
- models.each do |model|
59
- standardize_version_id_column(model)
60
- end
61
- end
55
+
62
56
  end
@@ -0,0 +1,19 @@
1
+ require 'cms/upgrades/v3_5_0'
2
+
3
+ class Browsercms353 < ActiveRecord::Migration
4
+ def change
5
+ namespace_templates
6
+
7
+ # Some older projects may have AbstractFileBlock rather than File/ImageBlock connectors
8
+ v3_5_0_update_connector_namespaces("Cms", "AbstractFileBlock")
9
+
10
+ end
11
+
12
+ private
13
+
14
+ def namespace_templates
15
+ ["PageTemplate", "PagePartial"].each do |view|
16
+ Cms::DynamicView.update_all("type = 'Cms::#{view}'", "type = '#{view}'" )
17
+ end
18
+ end
19
+ end
data/doc/release_notes.md CHANGED
@@ -1,3 +1,18 @@
1
+ v3.5.3
2
+ ======
3
+
4
+ Bug fixes, with some improvements for upgrading projects from older versions of the CMS.
5
+
6
+ * [#461] Allow portlets to easily set the page title. This makes it easy for one portlet to render multiple different content blocks, and change the displayed <title> attribute to match the name of the block. For example:
7
+
8
+ def render
9
+ @block = Product.find(params[:id])
10
+ page_title @block.name
11
+ end
12
+ * [#536] Fix bug to make PortletHelpers available in the render.html.erb.
13
+ * [#534] Bug Fix - Ensure image/file blocks can be deleted from the content library.
14
+ * Migrations - Add another migration to handle Rails 2->3 updates (v3.1.4) which should retroactivealy added before v315.
15
+
1
16
  v3.5.2
2
17
  ======
3
18
 
@@ -15,23 +15,18 @@
15
15
  module Cms
16
16
  module Acts
17
17
 
18
+ # Override some of the behavior defined in Cms::PageHelper so templates display correctly Rails Controllers
18
19
  module PageHelper
19
20
 
20
- # By default, the Name of the controller (minus 'Controller' will be the page name.)
21
- # Unless @page_title is set in the controller action
22
- def page_title(title=nil)
23
- if title
24
- @page_title = title
25
- end
26
- return controller.class.name.gsub("Controller", "").titleize unless @page_title
27
- @page_title
28
- end
29
-
30
-
31
21
  # Do not show the toolbar on Acts::As::ContentPages
32
22
  def cms_toolbar
33
23
  ""
34
24
  end
25
+
26
+ # If we are showing an error page, use that. Otherwise, just a blank page object that has a default title.
27
+ def current_page
28
+ super ? super : OpenStruct.new(page_title: controller.class.name.gsub("Controller", ""))
29
+ end
35
30
  end
36
31
  module ContentPage
37
32
 
@@ -120,7 +120,10 @@ module Cms
120
120
  def validates_attachment_presence(name, options = {})
121
121
  message = options[:message] || "Must provide at least one #{name}"
122
122
  validate(options) do |record|
123
- record.errors.add(:attachment, message) unless record.attachments.any? { |a| a.attachment_name == name.to_s }
123
+ return if record.deleted?
124
+ unless record.attachments.any? { |a| a.attachment_name == name.to_s }
125
+ record.errors.add(:attachment, message)
126
+ end
124
127
  end
125
128
  end
126
129
 
@@ -130,6 +130,8 @@ module Cms
130
130
  # Create, Instantiate and Initialize the view
131
131
  action_view = Cms::ViewContext.new(@controller, assigns_for_view)
132
132
 
133
+ add_content_helpers_if_defined(action_view)
134
+
133
135
  # Determine if this content should render from a file system template or inline (i.e. database based template)
134
136
  if respond_to?(:inline_options) && self.inline_options && self.inline_options.has_key?(:inline)
135
137
  options = self.inline_options
@@ -152,6 +154,18 @@ module Cms
152
154
  end
153
155
 
154
156
  protected
157
+
158
+ # Add the helper class for this particular object, if its defined
159
+ # This is mostly for portlets, and should not fail if no helper is defined.
160
+ def add_content_helpers_if_defined(action_view)
161
+ begin
162
+ helper_module = self.class.helper_class
163
+ action_view.extend(helper_module)
164
+ rescue NameError => error
165
+ logger.debug "No helper class named '#{error.missing_name}' was found. This isn't necessarily an error as '#{self.class}' doesn't NEED a separate helper.'"
166
+ end
167
+ end
168
+
155
169
  def copy_instance_variables_from_controller!
156
170
  if @controller.respond_to?(:instance_variables_for_rendering)
157
171
  @controller.instance_variables_for_rendering.each do |iv|
@@ -21,8 +21,14 @@ module Cms
21
21
  table_prefix = module_name.underscore
22
22
  model_name = model_class_name.underscore
23
23
 
24
- rename_table model_name.pluralize, "#{table_prefix}_#{model_name.pluralize}"
25
- rename_table "#{model_name}_versions", "#{table_prefix}_#{model_name}_versions"
24
+ old_content_table = model_name.pluralize
25
+ new_content_table = "#{table_prefix}_#{model_name.pluralize}"
26
+ rename_table old_content_table, new_content_table if have_not_renamed(old_content_table, new_content_table)
27
+
28
+
29
+ old_versions_table = "#{model_name}_versions"
30
+ new_versions_table = "#{table_prefix}_#{model_name}_versions"
31
+ rename_table old_versions_table, new_versions_table if have_not_renamed(old_versions_table, new_versions_table)
26
32
  v3_5_0_standardize_version_id_column(table_prefix, model_name)
27
33
  v3_5_0_namespace_model_data(module_name, model_class_name)
28
34
  v3_5_0_update_connector_namespaces(module_name, model_class_name)
@@ -53,6 +59,21 @@ module Cms
53
59
  def v3_5_0_namespace_model(module_name, model_class_name)
54
60
  "#{module_name}::#{model_class_name}"
55
61
  end
62
+
63
+ private
64
+
65
+ # If we already renamed these tables, they should be skipped
66
+ def have_not_renamed(old_table, new_table)
67
+ unless table_exists?(old_table)
68
+ puts "Table #{old_table} does not exist. Skipping rename."
69
+ return false
70
+ end
71
+ unless !table_exists?(new_table)
72
+ puts "Table #{new_table} already exists. Skipping rename."
73
+ return false
74
+ end
75
+ true
76
+ end
56
77
  end
57
78
 
58
79
  # Add additional methods to ActiveRecord::Migration when this file is required.
@@ -71,13 +92,7 @@ module Cms
71
92
  # @return [String] path to location where an attachment should be (based on id)
72
93
  def path_for_attachment(attachment)
73
94
  new_id_dir = "#{Paperclip::Interpolations.id_partition(AttachmentWrapper.new(attachment), nil)}/original"
74
- "#{new_id_dir}/#{attachment.data_fingerprint}"
75
- end
76
-
77
- # @return [String] Path to where an attachment should be
78
- def path_to_attachment(attachment)
79
- loc = path_for_attachment(attachment)
80
- file_in_attachments_dir(loc)
95
+ File.join(attachments_dir, new_id_dir, fingerprint_for_file_location(attachment))
81
96
  end
82
97
 
83
98
  # For a given class with an Attachment association (pre-3.5.0), migrate its attachment data to match the new
@@ -161,18 +176,19 @@ module Cms
161
176
  def migrate_attachments_file_location(model_class)
162
177
  model_class.unscoped.each do |attachment|
163
178
  from = File.join(attachments_dir, attachment.file_location)
164
- to = path_to_attachment(attachment)
179
+ to = path_for_attachment(attachment)
165
180
  move_attachment_file(from, to)
166
181
 
167
- new_fingerprint = attachment.file_location.split("/").last
182
+ new_fingerprint = fingerprint_for_file_location(attachment)
168
183
  model_class.unscoped.update_all({:data_fingerprint => new_fingerprint}, :id => attachment.id)
169
184
  end
170
185
  end
171
186
 
172
- def file_in_attachments_dir(file_name)
173
- File.join(Cms::Attachment.configuration.attachments_root, file_name)
187
+ # Given a CMS <3.5 file_location, figure out the fingerprint, which should just be the file name.
188
+ def fingerprint_for_file_location(attachment)
189
+ attachment.file_location.split("/").last
174
190
  end
175
-
191
+
176
192
  def move_attachment_file(old_location, new_location)
177
193
  if File.exists?(old_location)
178
194
  FileUtils.mkdir_p(File.dirname(new_location), :verbose => false)
@@ -182,10 +198,15 @@ module Cms
182
198
  end
183
199
  end
184
200
 
201
+ # Return the location of the attachment's upload directory.
185
202
  def attachments_dir
186
- Cms::Attachment.configuration.attachments_root
203
+ Cms::Attachments::Serving.send_attachments_with.attachments_storage_location
187
204
  end
188
-
205
+
206
+ # def attachments_dir
207
+ # Cms::Attachment.configuration.attachments_root
208
+ # end
209
+
189
210
  # Allows us to use the Paperclip interpolations logic directly
190
211
  class AttachmentWrapper
191
212
  def initialize(attachment)
data/lib/cms/version.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # Allows the precise version of BrowserCMS to be determined programatically.
3
3
  #
4
4
  module Cms
5
- VERSION = "3.5.2"
5
+ VERSION = "3.5.3"
6
6
 
7
7
  # Return the current version of the CMS.
8
8
  def self.version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browsercms
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.2
4
+ version: 3.5.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-07 00:00:00.000000000 Z
12
+ date: 2012-07-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -637,10 +637,12 @@ files:
637
637
  - db/browsercms.seeds.rb
638
638
  - db/migrate/20080815014337_browsercms_3_0_0.rb
639
639
  - db/migrate/20091109175123_browsercms_3_0_5.rb
640
+ - db/migrate/20100117144038_browsercms314.rb
640
641
  - db/migrate/20100117144039_browsercms315.rb
641
642
  - db/migrate/20100705083859_browsercms_3_3_0.rb
642
643
  - db/migrate/20111130221145_browsercms340.rb
643
644
  - db/migrate/20120329144406_browsercms350.rb
645
+ - db/migrate/20120717182827_browsercms353.rb
644
646
  - db/schema.rb
645
647
  - db/seeds.rb
646
648
  - doc/design/blue_button.psd
@@ -773,7 +775,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
773
775
  version: '0'
774
776
  segments:
775
777
  - 0
776
- hash: -1523236011724183372
778
+ hash: -3887349942334149807
777
779
  requirements: []
778
780
  rubyforge_project:
779
781
  rubygems_version: 1.8.24