webficient-browsercms 3.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. data/app/controllers/cms/content_block_controller.rb +25 -2
  2. data/app/controllers/cms/content_controller.rb +2 -1
  3. data/app/controllers/cms/dashboard_controller.rb +2 -1
  4. data/app/controllers/cms/error_handling.rb +3 -3
  5. data/app/controllers/cms/sections_controller.rb +5 -2
  6. data/app/models/attachment.rb +9 -1
  7. data/app/models/content_type.rb +2 -2
  8. data/app/models/link.rb +2 -2
  9. data/app/models/page.rb +10 -0
  10. data/app/models/user.rb +34 -16
  11. data/app/views/cms/blocks/_toolbar_for_member.html.erb +3 -3
  12. data/app/views/cms/blocks/index.html.erb +10 -6
  13. data/app/views/cms/content/show.html.erb +0 -1
  14. data/app/views/cms/dashboard/_recently_updated.html.erb +50 -0
  15. data/app/views/cms/dashboard/index.html.erb +9 -1
  16. data/app/views/cms/sections/_form.html.erb +36 -34
  17. data/app/views/layouts/_page_toolbar.html.erb +5 -5
  18. data/browsercms.gemspec +1289 -1283
  19. data/lib/cms/acts/content_block.rb +1 -1
  20. data/lib/cms/behaviors/publishing.rb +11 -1
  21. data/lib/cms/behaviors/versioning.rb +8 -2
  22. data/lib/cms/routes.rb +8 -1
  23. data/lib/tasks/db.rake +1 -1
  24. data/public/stylesheets/cms/dashboard.css +18 -1
  25. data/test/functional/cms/content_block_controller_test.rb +120 -0
  26. data/test/functional/cms/content_controller_test.rb +10 -1
  27. data/test/functional/cms/links_controller_test.rb +5 -0
  28. data/test/functional/cms/pages_controller_test.rb +8 -0
  29. data/test/functional/cms/sections_controller_test.rb +29 -3
  30. data/test/unit/lib/routes_test.rb +57 -0
  31. data/test/unit/models/content_type_test.rb +22 -1
  32. data/test/unit/models/page_test.rb +19 -2
  33. data/test/unit/models/user_test.rb +114 -40
  34. metadata +8 -5
@@ -28,4 +28,4 @@ module Cms
28
28
  end
29
29
  end
30
30
  end
31
- end
31
+ end
@@ -23,7 +23,17 @@ module Cms
23
23
  after_save :publish_for_non_versioned
24
24
 
25
25
  named_scope :published, :conditions => {:published => true}
26
- named_scope :unpublished, :conditions => {:published => false}
26
+ named_scope :unpublished, lambda {
27
+ if versioned?
28
+ { :joins => :versions,
29
+ :conditions =>
30
+ "#{connection.quote_table_name(version_table_name)}.#{connection.quote_column_name('version')} > " +
31
+ "#{connection.quote_table_name(table_name)}.#{connection.quote_column_name('version')}",
32
+ :select => "distinct #{connection.quote_table_name(table_name)}.*" }
33
+ else
34
+ { :conditions => { :published => false } }
35
+ end
36
+ }
27
37
  end
28
38
  end
29
39
  module ClassMethods
@@ -22,7 +22,9 @@ module Cms
22
22
  before_validation_on_create :initialize_version
23
23
 
24
24
  attr_accessor :revert_to_version
25
-
25
+
26
+ versioned_class = self
27
+
26
28
  #Define the version class
27
29
  const_set("Version", Class.new(ActiveRecord::Base)).class_eval do
28
30
  class << self; attr_accessor :versioned_class end
@@ -35,7 +37,11 @@ module Cms
35
37
  end
36
38
  def versioned_object
37
39
  send(versioned_class.name.underscore.to_sym)
38
- end
40
+ end
41
+
42
+ named_scope :recent_updates, :order => "updated_at desc", :limit => 10,
43
+ :joins => versioned_class.table_name.singularize.to_sym,
44
+ :conditions => { "#{versioned_class.table_name}.deleted" => false }
39
45
  end
40
46
 
41
47
  version_class.versioned_class = self
data/lib/cms/routes.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  module Cms::Routes
2
-
2
+
3
+ #
4
+ # content_block_name - Should be a plural symbol matching the name of the content_block, like :dogs or donation_statuses
5
+ #
3
6
  def content_blocks(content_block_name, options={}, &block)
4
7
  content_block = content_block_name.to_s.classify.constantize
5
8
  resources(*[content_block_name, default_routes_for_content_block(content_block).deep_merge(options)], &block)
@@ -129,6 +132,10 @@ module Cms::Routes
129
132
  :enable => :put
130
133
  }
131
134
 
135
+ if RAILS_ENV == "test" && File.expand_path(RAILS_ROOT) == File.expand_path(File.dirname(__FILE__) + "/../..")
136
+ cms.content_blocks :content_block
137
+ end
138
+
132
139
  end
133
140
 
134
141
  if PageRoute.table_exists?
data/lib/tasks/db.rake CHANGED
@@ -18,7 +18,7 @@ namespace :db do
18
18
  puts "Models: " + models.join(', ')
19
19
 
20
20
  models.each do |m|
21
- model = m.classify.constantize
21
+ model = m.tableize.classify.constantize
22
22
  create_fixture(model)
23
23
  create_fixture(model.version_class) if model.versioned?
24
24
  end
@@ -4,6 +4,11 @@ margin: -4px 5px 0 5px;
4
4
  background-color: #FFFFFF;
5
5
  }
6
6
 
7
+ .dashboard_unit.wide {
8
+ clear: both;
9
+ width: 990px;
10
+ }
11
+
7
12
  .dashboard_unit h2 {
8
13
  height: 12px;
9
14
  color: #FFF;
@@ -13,12 +18,18 @@ font-size: 10pt;
13
18
  text-transform: uppercase;
14
19
  letter-spacing: 1px;
15
20
  }
21
+ .dashboard_unit h2 {
22
+ background: #4679B8 url(/images/cms/dashboard/header_bg.gif) repeat-x 0 0;
23
+ }
16
24
  .dashboard_unit h2.left {
17
25
  background: #4679B8 url(/images/cms/dashboard/header_left_bg.gif) no-repeat 0 0;
18
26
  }
19
27
 
28
+ .dashboard_unit .roundedcorners {
29
+ margin: 6px;
30
+ }
20
31
  .dashboard_unit form {
21
- padding: 6px;
32
+ padding: 0;
22
33
  }
23
34
 
24
35
  .dashboard_unit {
@@ -113,6 +124,12 @@ background: transparent url(/images/cms/dashboard/bottom_cap_content.png) no-rep
113
124
  div.top_cap {
114
125
  background: url(/images/cms/dashboard/top_cap.png) no-repeat 0 0;
115
126
  }
127
+ div.wide_top_cap {
128
+ background: url(/images/cms/top_cap.png) no-repeat 0 0;
129
+ width: 1000px;
130
+ height: 9px;
131
+ margin: 20px 0 0 0;
132
+ }
116
133
  #contentwrapbig {
117
134
  background: none;
118
135
  }
@@ -0,0 +1,120 @@
1
+ require File.join(File.dirname(__FILE__), '/../../test_helper')
2
+
3
+ class PermissionsForContentBlockControllerTest < ActionController::TestCase
4
+ include Cms::ControllerTestHelper
5
+ tests Cms::ContentBlockController
6
+
7
+ # We're stubbing a lot because we *just* want to isolate the behaviour for checking permissions
8
+ def setup
9
+ login_as_cms_admin
10
+ @user = User.first
11
+ @controller.stubs(:current_user).returns(@user)
12
+ @controller.stubs(:render)
13
+ @controller.stubs(:model_class).returns(ContentBlock)
14
+ @controller.stubs(:set_default_category)
15
+ @controller.stubs(:blocks_path).returns("/cms/content_block")
16
+ @controller.stubs(:redirect_to_first).returns("/cms/content_block")
17
+
18
+ @block = stub_everything("block")
19
+ @block.stubs(:as_of_draft_version).returns(@block)
20
+ @block.stubs(:as_of_version).returns(@block)
21
+ @block.stubs(:connected_pages).returns(stub(:all => stub))
22
+
23
+ ContentBlock.stubs(:find).returns(@block)
24
+ ContentBlock.stubs(:new).returns(@block)
25
+ ContentBlock.stubs(:paginate)
26
+ end
27
+
28
+ def expect_access_denied
29
+ @controller.expects(:render).with(has_entry(:status => 403))
30
+ end
31
+
32
+ def expect_success
33
+ expect_access_denied.never
34
+ end
35
+
36
+ test "GET index allows any user" do
37
+ expect_success
38
+ get :index
39
+ end
40
+
41
+ test "GET show allows any user" do
42
+ expect_success
43
+ get :show, :id => 5
44
+ end
45
+
46
+ test "GET new allows any user" do
47
+ expect_success
48
+ get :new
49
+ end
50
+
51
+ test "POST create allows any user" do
52
+ expect_success
53
+ post :create
54
+ end
55
+
56
+ test "GET version allows any user" do
57
+ expect_success
58
+ get :version, :id => 5, :version => 3
59
+ end
60
+
61
+ test "GET versions allows any user" do
62
+ expect_success
63
+ get :versions, :id => 5
64
+ end
65
+
66
+ test "GET usages allows any user" do
67
+ expect_success
68
+ get :usages, :id => 5
69
+ end
70
+
71
+ test "GET edit allows only users who are able to edit the block" do
72
+ @user.stubs(:able_to_edit?).with(@block).returns(false)
73
+ expect_access_denied
74
+ get :edit, :id => 5
75
+
76
+ @user.stubs(:able_to_edit?).with(@block).returns(true)
77
+ expect_success
78
+ get :edit, :id => 5
79
+ end
80
+
81
+ test "PUT update allows only users who are able to edit the block" do
82
+ @user.stubs(:able_to_edit?).with(@block).returns(false)
83
+ expect_access_denied
84
+ put :update, :id => 5
85
+
86
+ @user.stubs(:able_to_edit?).with(@block).returns(true)
87
+ expect_success
88
+ put :update, :id => 5
89
+ end
90
+
91
+ test "DELETE destroy allows only users who are able to publish the block" do
92
+ @user.stubs(:able_to_publish?).with(@block).returns(false)
93
+ expect_access_denied
94
+ delete :destroy, :id => 5
95
+
96
+ @user.stubs(:able_to_publish?).with(@block).returns(true)
97
+ expect_success
98
+ delete :destroy, :id => 5
99
+ end
100
+
101
+ test "PUT publish allows only users who are able to publish the block" do
102
+ @user.stubs(:able_to_publish?).with(@block).returns(false)
103
+ expect_access_denied
104
+ put :publish, :id => 5
105
+
106
+ @user.stubs(:able_to_publish?).with(@block).returns(true)
107
+ expect_success
108
+ put :publish, :id => 5
109
+ end
110
+
111
+ test "PUT revert_to allows only users who are able to publish the block" do
112
+ @user.stubs(:able_to_publish?).with(@block).returns(false)
113
+ expect_access_denied
114
+ put :revert_to, :id => 5, :version => 1
115
+
116
+ @user.stubs(:able_to_publish?).with(@block).returns(true)
117
+ expect_success
118
+ put :revert_to, :id => 5, :version => 1
119
+ end
120
+ end
@@ -109,6 +109,15 @@ class Cms::ContentControllerTest < ActionController::TestCase
109
109
  assert_equal "This is a test", streaming_file_contents
110
110
  end
111
111
 
112
+ def test_use_x_sendfile
113
+ create_file
114
+ Attachment.use_x_sendfile = true
115
+ get :show, :path => ["test.txt"]
116
+ assert_response :success
117
+ assert_equal @file_block.attachment.full_file_location, @response.headers["X-Sendfile"]
118
+ Attachment.use_x_sendfile = false
119
+ end
120
+
112
121
  def test_show_page_route
113
122
  @page_template = Factory(:page_template, :name => "test_show_page_route")
114
123
  @page = Factory(:page,
@@ -376,4 +385,4 @@ class Cms::ContentCachingDisabledControllerTest < ActionController::TestCase
376
385
  assert_select "iframe"
377
386
  end
378
387
 
379
- end
388
+ end
@@ -97,6 +97,7 @@ class Cms::LinksControllerPermissionsTest < ActionController::TestCase
97
97
 
98
98
  get :new, :section_id => @noneditable_section
99
99
  assert_response 403
100
+ assert_template "cms/shared/access_denied"
100
101
  end
101
102
 
102
103
  def test_create_permissions
@@ -107,6 +108,7 @@ class Cms::LinksControllerPermissionsTest < ActionController::TestCase
107
108
 
108
109
  post :create, :section_id => @noneditable_section, :name => "Another non-editable link"
109
110
  assert_response 403
111
+ assert_template "cms/shared/access_denied"
110
112
  end
111
113
 
112
114
  def test_edit_permissions
@@ -117,6 +119,7 @@ class Cms::LinksControllerPermissionsTest < ActionController::TestCase
117
119
 
118
120
  get :edit, :id => @noneditable_link
119
121
  assert_response 403
122
+ assert_template "cms/shared/access_denied"
120
123
  end
121
124
 
122
125
  def test_update_permissions
@@ -127,6 +130,7 @@ class Cms::LinksControllerPermissionsTest < ActionController::TestCase
127
130
 
128
131
  put :update, :id => @noneditable_link, :name => "Modified non-editable link"
129
132
  assert_response 403
133
+ assert_template "cms/shared/access_denied"
130
134
  end
131
135
 
132
136
  def test_destroy_permissions
@@ -137,6 +141,7 @@ class Cms::LinksControllerPermissionsTest < ActionController::TestCase
137
141
 
138
142
  delete :destroy, :id => @noneditable_link
139
143
  assert_response 403
144
+ assert_template "cms/shared/access_denied"
140
145
  end
141
146
  end
142
147
 
@@ -126,6 +126,7 @@ class Cms::PagesControllerPermissionsTest < ActionController::TestCase
126
126
 
127
127
  get :new, :section_id => @noneditable_section
128
128
  assert_response 403
129
+ assert_template "cms/shared/access_denied"
129
130
  end
130
131
 
131
132
  def test_create_permissions
@@ -136,6 +137,7 @@ class Cms::PagesControllerPermissionsTest < ActionController::TestCase
136
137
 
137
138
  post :create, :section_id => @noneditable_section, :name => "Another non-editable page"
138
139
  assert_response 403
140
+ assert_template "cms/shared/access_denied"
139
141
  end
140
142
 
141
143
  def test_edit_permissions
@@ -146,6 +148,7 @@ class Cms::PagesControllerPermissionsTest < ActionController::TestCase
146
148
 
147
149
  get :edit, :id => @noneditable_page
148
150
  assert_response 403
151
+ assert_template "cms/shared/access_denied"
149
152
  end
150
153
 
151
154
  def test_update_permissions
@@ -157,6 +160,7 @@ class Cms::PagesControllerPermissionsTest < ActionController::TestCase
157
160
 
158
161
  put :update, :id => @noneditable_page, :name => "Modified non-editable page"
159
162
  assert_response 403
163
+ assert_template "cms/shared/access_denied"
160
164
 
161
165
  # archive
162
166
  put :archive, :id => @editable_page
@@ -164,6 +168,7 @@ class Cms::PagesControllerPermissionsTest < ActionController::TestCase
164
168
 
165
169
  put :archive, :id => @noneditable_page
166
170
  assert_response 403
171
+ assert_template "cms/shared/access_denied"
167
172
 
168
173
  # hide
169
174
  put :hide, :id => @editable_page
@@ -171,6 +176,7 @@ class Cms::PagesControllerPermissionsTest < ActionController::TestCase
171
176
 
172
177
  put :hide, :id => @noneditable_page
173
178
  assert_response 403
179
+ assert_template "cms/shared/access_denied"
174
180
 
175
181
  # publish
176
182
  put :publish, :id => @editable_page
@@ -178,6 +184,7 @@ class Cms::PagesControllerPermissionsTest < ActionController::TestCase
178
184
 
179
185
  put :publish, :id => @noneditable_page
180
186
  assert_response 403
187
+ assert_template "cms/shared/access_denied"
181
188
 
182
189
  # revert_to
183
190
  # can't find route...
@@ -196,6 +203,7 @@ class Cms::PagesControllerPermissionsTest < ActionController::TestCase
196
203
 
197
204
  delete :destroy, :id => @noneditable_page
198
205
  assert_response 403
206
+ assert_template "cms/shared/access_denied"
199
207
  end
200
208
  end
201
209
 
@@ -13,6 +13,13 @@ class Cms::SectionsControllerTest < ActionController::TestCase
13
13
  assert_select "input[name=?][value=?]", "section[name]", root_section.name
14
14
  end
15
15
 
16
+ test "GET new should set the groups to the parent section's groups by default" do
17
+ @group = Factory(:group, :name => "Test", :group_type => Factory(:group_type, :name => "CMS User", :cms_access => true))
18
+ get :new, :section_id => root_section.to_param
19
+ assert_equal root_section.groups, assigns(:section).groups
20
+ assert !assigns(:section).groups.include?(@group)
21
+ end
22
+
16
23
  def test_update
17
24
  @section = Factory(:section, :name => "V1", :parent => root_section)
18
25
 
@@ -115,6 +122,15 @@ class Cms::SectionsControllerPermissionsTest < ActionController::TestCase
115
122
 
116
123
  get :new, :section_id => @noneditable_section
117
124
  assert_response 403
125
+ assert_template "cms/shared/access_denied"
126
+ end
127
+
128
+ test "POST create should set the groups to the parent section's groups for non-admin user" do
129
+ @group = Factory(:group, :name => "Test", :group_type => Factory(:group_type, :name => "CMS User", :cms_access => true))
130
+ login_as(@user)
131
+ get :new, :section_id => @editable_section
132
+ assert_equal @editable_section.groups, assigns(:section).groups
133
+ assert !assigns(:section).groups.include?(@group)
118
134
  end
119
135
 
120
136
  def test_create_permissions
@@ -125,6 +141,7 @@ class Cms::SectionsControllerPermissionsTest < ActionController::TestCase
125
141
 
126
142
  post :create, :section_id => @noneditable_section, :name => "Another non-editable subsection"
127
143
  assert_response 403
144
+ assert_template "cms/shared/access_denied"
128
145
  end
129
146
 
130
147
  def test_edit_permissions
@@ -135,6 +152,7 @@ class Cms::SectionsControllerPermissionsTest < ActionController::TestCase
135
152
 
136
153
  get :edit, :id => @noneditable_section
137
154
  assert_response 403
155
+ assert_template "cms/shared/access_denied"
138
156
  end
139
157
 
140
158
  def test_update_permissions
@@ -145,6 +163,15 @@ class Cms::SectionsControllerPermissionsTest < ActionController::TestCase
145
163
 
146
164
  put :update, :id => @noneditable_section, :name => "Modified non-editable subsection"
147
165
  assert_response 403
166
+ assert_template "cms/shared/access_denied"
167
+ end
168
+
169
+ test "PUT update should set the groups to the parent section's groups for non-admin user" do
170
+ @group = Factory(:group, :name => "Test", :group_type => Factory(:group_type, :name => "CMS User", :cms_access => true))
171
+ login_as(@user)
172
+ put :update, :id => @editable_subsection
173
+ assert_equal @editable_section.groups, assigns(:section).groups
174
+ assert !assigns(:section).groups.include?(@group)
148
175
  end
149
176
 
150
177
  def test_destroy_permissions
@@ -155,7 +182,6 @@ class Cms::SectionsControllerPermissionsTest < ActionController::TestCase
155
182
 
156
183
  delete :destroy, :id => @noneditable_section
157
184
  assert_response 403
185
+ assert_template "cms/shared/access_denied"
158
186
  end
159
- end
160
-
161
-
187
+ end
@@ -0,0 +1,57 @@
1
+ require File.join(File.dirname(__FILE__), '/../../test_helper')
2
+
3
+ class RouteBuilder
4
+ include Cms::Routes
5
+ end
6
+
7
+ class Bear < ActiveRecord::Base
8
+ acts_as_content_block
9
+ end
10
+
11
+ class Kindness < ActiveRecord::Base
12
+ acts_as_content_block
13
+ end
14
+
15
+ class RoutesTest < ActiveSupport::TestCase
16
+
17
+ test "Verify behavior of classify, and how it works with already pluralized symbols" do
18
+ assert_equal "Kindness", :kindnesses.to_s.classify, "routes will pass 'plural' symbols to 'content_block', rather than single"
19
+ end
20
+
21
+
22
+ test "behavior of 'content_blocks' route generator" do
23
+ rb = RouteBuilder.new
24
+
25
+ # Expect
26
+ rb.expects(:resources).with(:bears, {:member => {:publish => :put, :usages => :get, :versions => :get}})
27
+ rb.expects(:version_cms_bears).with("/cms/bears/:id/version/:version", :controller => "cms/bears", :action => "version", :conditions => {:method => :get})
28
+ rb.expects(:revert_to_cms_bears).with(
29
+ "/cms/bears/:id/revert_to/:version",
30
+ :controller => "cms/bears",
31
+ :action => "revert_to",
32
+ :conditions => {:method => :put})
33
+
34
+ rb.content_blocks :bears
35
+
36
+ # Verifies the exact messages being passed to the route generator
37
+ end
38
+
39
+ test "behavior of 'content_blocks' route generator with model names with s at the end" do
40
+ rb = RouteBuilder.new
41
+
42
+ # Expect
43
+ rb.expects(:resources).with(:kindnesses, {:member => {:publish => :put, :usages => :get, :versions => :get}})
44
+ rb.expects(:version_cms_kindnesses).with("/cms/kindnesses/:id/version/:version", :controller => "cms/kindnesses", :action => "version", :conditions => {:method => :get})
45
+ rb.expects(:revert_to_cms_kindnesses).with(
46
+ "/cms/kindnesses/:id/revert_to/:version",
47
+ :controller => "cms/kindnesses",
48
+ :action => "revert_to",
49
+ :conditions => {:method => :put})
50
+
51
+ rb.content_blocks :kindnesses
52
+
53
+ # Verifies the exact messages being passed to the route generator
54
+ end
55
+
56
+
57
+ end
@@ -1,5 +1,10 @@
1
1
  require File.join(File.dirname(__FILE__), '/../../test_helper')
2
2
 
3
+ # Sample Model for testing naming/model classes
4
+ class Kindness < ActiveRecord::Base
5
+ acts_as_content_block
6
+ end
7
+
3
8
  class ContentTypeTest < ActiveSupport::TestCase
4
9
  def setup
5
10
  @c = ContentType.new(:name => "HtmlBlock")
@@ -20,4 +25,20 @@ class ContentTypeTest < ActiveSupport::TestCase
20
25
  def test_content_block_type
21
26
  assert_equal "html_blocks", @c.content_block_type
22
27
  end
23
- end
28
+
29
+ test "find_by_key handles names that end with s correctly" do
30
+ ContentType.create!(:name => "Kindness", :group_name => "Anything")
31
+
32
+ ct = ContentType.find_by_key("kindness")
33
+ assert_not_nil ct
34
+ assert_equal "Kindness", ct.display_name
35
+ end
36
+
37
+ test "calculate the model_class name with s" do
38
+ ct = ContentType.new(:name=>"Kindness")
39
+ assert_equal Kindness, ct.model_class
40
+ end
41
+
42
+
43
+ end
44
+
@@ -237,9 +237,15 @@ class PageTest < ActiveRecord::TestCase
237
237
  assert_equal 1, @page.connectors.for_page_version(@page.draft.version).count
238
238
  assert !@page.live?
239
239
  assert !@block.live?
240
-
241
240
  end
242
-
241
+
242
+ def test_internal_name
243
+ @page = Factory(:page, :name => 'Foo')
244
+ assert_equal 'foo', @page.internal_name
245
+
246
+ @page = Factory(:page, :name => 'Foo Bar')
247
+ assert_equal 'foo_bar', @page.internal_name
248
+ end
243
249
  end
244
250
 
245
251
  class PageVersioningTest < ActiveRecord::TestCase
@@ -724,3 +730,14 @@ class PortletsDontHaveDraftsTest < ActiveRecord::TestCase
724
730
  end
725
731
  end
726
732
 
733
+ class PageInSectionTest < ActiveRecord::TestCase
734
+ def test_deleting_page_in_section
735
+ @section = Factory(:section)
736
+ @page = Factory(:page, :section => @section)
737
+
738
+ assert_equal 1, @section.child_nodes.length
739
+ @page.destroy
740
+ @section.reload
741
+ assert_equal 0, @section.child_nodes.length
742
+ end
743
+ end