browsercms 3.4.2 → 3.5.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (367) hide show
  1. data/README.markdown +1 -0
  2. data/app/assets/images/cms/file-uploading.gif +0 -0
  3. data/app/assets/javascripts/cms/application.js +1 -0
  4. data/app/assets/javascripts/cms/attachment_manager.js.erb +87 -0
  5. data/app/assets/javascripts/cms/core_library.js.erb +38 -25
  6. data/app/assets/stylesheets/cms/application.css.erb +1 -0
  7. data/app/assets/stylesheets/cms/attachment_manager.css.scss +28 -0
  8. data/app/controllers/cms/application_controller.rb +1 -1
  9. data/app/controllers/cms/attachments_controller.rb +45 -10
  10. data/app/controllers/cms/cache_controller.rb +1 -1
  11. data/app/controllers/cms/content_block_controller.rb +134 -122
  12. data/app/controllers/cms/content_controller.rb +143 -155
  13. data/app/controllers/cms/dashboard_controller.rb +11 -9
  14. data/app/controllers/cms/error_handling.rb +19 -7
  15. data/app/controllers/cms/file_blocks_controller.rb +2 -2
  16. data/app/controllers/cms/home_controller.rb +3 -0
  17. data/app/controllers/cms/section_nodes_controller.rb +52 -44
  18. data/app/controllers/cms/sections_controller.rb +4 -2
  19. data/app/controllers/cms/toolbar_controller.rb +14 -10
  20. data/app/helpers/cms/application_helper.rb +23 -19
  21. data/app/helpers/cms/form_builder.rb +65 -18
  22. data/app/helpers/cms/mobile_helper.rb +19 -0
  23. data/app/helpers/cms/path_helper.rb +30 -4
  24. data/app/helpers/cms/rendering_helper.rb +9 -1
  25. data/app/models/cms/abstract_file_block.rb +6 -6
  26. data/app/models/cms/attachment.rb +196 -107
  27. data/app/models/cms/category.rb +3 -0
  28. data/app/models/cms/category_type.rb +2 -0
  29. data/app/models/cms/connector.rb +3 -0
  30. data/app/models/cms/content_type.rb +3 -0
  31. data/app/models/cms/content_type_group.rb +2 -0
  32. data/app/models/cms/dynamic_view.rb +4 -0
  33. data/app/models/cms/email_message.rb +2 -0
  34. data/app/models/cms/file_block.rb +9 -2
  35. data/app/models/cms/group.rb +5 -2
  36. data/app/models/cms/group_permission.rb +2 -0
  37. data/app/models/cms/group_section.rb +3 -0
  38. data/app/models/cms/group_type.rb +2 -0
  39. data/app/models/cms/group_type_permission.rb +2 -0
  40. data/app/models/cms/html_block.rb +3 -2
  41. data/app/models/cms/image_block.rb +13 -2
  42. data/app/models/cms/page.rb +14 -3
  43. data/app/models/cms/page_route.rb +4 -0
  44. data/app/models/cms/page_route_condition.rb +1 -0
  45. data/app/models/cms/page_route_option.rb +2 -0
  46. data/app/models/cms/page_route_requirement.rb +1 -0
  47. data/app/models/cms/permission.rb +3 -0
  48. data/app/models/cms/portlet.rb +2 -2
  49. data/app/models/cms/redirect.rb +2 -0
  50. data/app/models/cms/section.rb +15 -1
  51. data/app/models/cms/section_node.rb +1 -0
  52. data/app/models/cms/site.rb +3 -0
  53. data/app/models/cms/tag.rb +2 -0
  54. data/app/models/cms/tagging.rb +3 -0
  55. data/app/models/cms/task.rb +5 -1
  56. data/app/models/cms/user.rb +1 -1
  57. data/app/models/cms/user_group_membership.rb +3 -0
  58. data/app/views/cms/attachments/_attachment.html.erb +14 -0
  59. data/app/views/cms/attachments/_attachment_table.html.erb +17 -0
  60. data/app/views/cms/attachments/_attachment_wrapper.html.erb +4 -0
  61. data/app/views/cms/blocks/index.html.erb +2 -3
  62. data/app/views/cms/blocks/show.html.erb +1 -1
  63. data/app/views/cms/dynamic_views/index.html.erb +1 -1
  64. data/app/views/cms/email_messages/index.html.erb +1 -1
  65. data/app/views/cms/file_blocks/_form.html.erb +1 -27
  66. data/app/views/cms/file_blocks/_section_selector.html.erb +13 -0
  67. data/app/views/cms/file_blocks/render.html.erb +3 -3
  68. data/app/views/cms/form_builder/_cms_attachment_manager.html.erb +26 -0
  69. data/app/views/cms/form_builder/_cms_file_field.html.erb +27 -35
  70. data/app/views/cms/groups/index.html.erb +1 -1
  71. data/app/views/cms/image_blocks/_form.html.erb +1 -27
  72. data/app/views/cms/image_blocks/render.html.erb +4 -1
  73. data/app/views/cms/page_routes/index.html.erb +3 -0
  74. data/app/views/cms/shared/error.xml.erb +8 -0
  75. data/app/views/cms/tags/render.html.erb +1 -1
  76. data/app/views/cms/toolbar/_mobile_toggle.html.erb +33 -0
  77. data/app/views/cms/users/index.html.erb +1 -1
  78. data/app/views/layouts/_page_toolbar.html.erb +2 -1
  79. data/bin/bcms +21 -26
  80. data/config/routes.rb +3 -2
  81. data/db/browsercms.seeds.rb +2 -1
  82. data/db/migrate/20111130221145_browsercms340.rb +5 -4
  83. data/db/migrate/20120329144406_browsercms350.rb +32 -0
  84. data/{test/dummy/db → db}/schema.rb +97 -128
  85. data/{performance_tuning_notes.md → doc/performance_tuning_notes.md} +0 -0
  86. data/doc/release_notes.md +74 -0
  87. data/lib/browsercms.rb +3 -0
  88. data/lib/cms/acts/content_block.rb +10 -2
  89. data/lib/cms/addressable.rb +8 -0
  90. data/lib/cms/attachments/attachment_serving.rb +59 -0
  91. data/lib/cms/attachments/configuration.rb +88 -0
  92. data/lib/cms/behaviors/attaching.rb +305 -136
  93. data/lib/cms/behaviors/connecting.rb +3 -4
  94. data/lib/cms/behaviors/dynamic_attributes.rb +121 -118
  95. data/lib/cms/behaviors/flush_cache_on_change.rb +1 -3
  96. data/lib/cms/behaviors/naming.rb +16 -0
  97. data/lib/cms/behaviors/pagination.rb +4 -1
  98. data/lib/cms/behaviors/publishing.rb +9 -3
  99. data/lib/cms/behaviors/searching.rb +3 -8
  100. data/lib/cms/behaviors/soft_deleting.rb +1 -0
  101. data/lib/cms/behaviors/taggable.rb +2 -0
  102. data/lib/cms/behaviors/versioning.rb +73 -120
  103. data/lib/cms/caching.rb +53 -11
  104. data/lib/cms/commands/actions.rb +19 -2
  105. data/lib/cms/configuration.rb +44 -0
  106. data/lib/cms/content_rendering_support.rb +9 -6
  107. data/lib/cms/default_accessible.rb +13 -0
  108. data/lib/cms/domain_support.rb +22 -0
  109. data/lib/cms/engine.rb +40 -19
  110. data/lib/cms/engine_helper.rb +54 -0
  111. data/lib/cms/extensions/active_record/connection_adapters/abstract/schema_statements.rb +14 -2
  112. data/lib/cms/mobile_aware.rb +67 -0
  113. data/lib/cms/route_extensions.rb +3 -0
  114. data/lib/cms/upgrades/v3_5_0.rb +155 -0
  115. data/lib/cms/version.rb +6 -1
  116. data/lib/generators/cms/content_block/content_block_generator.rb +14 -9
  117. data/lib/generators/cms/content_block/templates/_form.html.erb +17 -6
  118. data/lib/generators/cms/content_block/templates/render.html.erb +12 -5
  119. data/lib/generators/cms/template/template_generator.rb +11 -2
  120. data/lib/tasks/cms.rake +23 -0
  121. data/lib/templates/active_record/model/model.rb +6 -0
  122. metadata +127 -517
  123. data/.gitignore +0 -24
  124. data/.rvmrc +0 -2
  125. data/Gemfile +0 -29
  126. data/Gemfile.lock +0 -196
  127. data/Rakefile +0 -97
  128. data/app/assets/images/browsercms/.gitkeep +0 -0
  129. data/app/controllers/browsercms/application_controller.rb +0 -4
  130. data/browsercms.gemspec +0 -35
  131. data/config/cucumber.yml +0 -8
  132. data/config/database.jdbcmysql.yml +0 -30
  133. data/config/database.mysql.yml +0 -27
  134. data/config/database.postgres.yml +0 -25
  135. data/config/database.sqlite3.yml +0 -11
  136. data/config/environment.rb +0 -6
  137. data/config/initializers/query_reviewer_patch.rb +0 -12
  138. data/config/initializers/rack_1_2_1_patch.rb +0 -12
  139. data/config/locales/en.yml +0 -5
  140. data/features/acts_as_content_page.feature +0 -62
  141. data/features/add_content_to_pages.feature +0 -45
  142. data/features/caching.feature +0 -13
  143. data/features/ckeditor.feature +0 -11
  144. data/features/commands/confirm_aruba_works.feature +0 -24
  145. data/features/commands/generate_module.feature +0 -54
  146. data/features/commands/install_browsercms.feature +0 -21
  147. data/features/commands/new_demo_project.feature +0 -30
  148. data/features/commands/new_projects.feature +0 -50
  149. data/features/commands/upgrade_modules_to_3_4_0_from_3_1_x.feature +0 -19
  150. data/features/commands/upgrade_project_to_3_4_0_from_3_3_x.feature +0 -52
  151. data/features/commands/upgrading_modules.feature +0 -67
  152. data/features/content_blocks/manage_custom_blocks.feature +0 -67
  153. data/features/content_blocks/manage_html_blocks.feature +0 -48
  154. data/features/content_blocks/manage_image_blocks.feature +0 -41
  155. data/features/content_files.feature +0 -37
  156. data/features/content_pages.feature +0 -21
  157. data/features/generators/content_blocks_for_modules.feature +0 -58
  158. data/features/generators/content_blocks_for_projects.feature +0 -109
  159. data/features/install_content.feature +0 -25
  160. data/features/jquery-testplan.txt +0 -12
  161. data/features/manage_groups.feature +0 -33
  162. data/features/manage_page_routes.feature +0 -72
  163. data/features/manage_redirects.feature +0 -20
  164. data/features/manage_sections.feature +0 -12
  165. data/features/manage_tasks.feature +0 -25
  166. data/features/manage_users.feature +0 -38
  167. data/features/page_templates.feature +0 -49
  168. data/features/portlets/email_friend_portlet.feature +0 -29
  169. data/features/portlets/portlets.feature +0 -100
  170. data/features/portlets/tag_cloud_portlet.feature +0 -28
  171. data/features/sitemap/create_pages.feature +0 -15
  172. data/features/sitemap/manage_links.feature +0 -29
  173. data/features/sitemap/sitemap.feature +0 -18
  174. data/features/step_definitions/acts_as_content_page_steps.rb.rb +0 -3
  175. data/features/step_definitions/ckeditor_steps.rb +0 -13
  176. data/features/step_definitions/command_line_steps.rb +0 -212
  177. data/features/step_definitions/content_pages_steps.rb +0 -170
  178. data/features/step_definitions/data_steps.rb +0 -48
  179. data/features/step_definitions/edit_page_templates_steps.rb +0 -21
  180. data/features/step_definitions/html_blocks_steps.rb +0 -9
  181. data/features/step_definitions/install_content_steps.rb +0 -4
  182. data/features/step_definitions/manage_content_blocks_steps.rb +0 -26
  183. data/features/step_definitions/manage_image_blocks_steps.rb +0 -31
  184. data/features/step_definitions/manage_sections_steps.rb +0 -18
  185. data/features/step_definitions/manage_user_steps.rb +0 -22
  186. data/features/step_definitions/more_custom_block_steps.rb +0 -34
  187. data/features/step_definitions/page_route_steps.rb +0 -65
  188. data/features/step_definitions/page_template_steps.rb +0 -5
  189. data/features/step_definitions/permissions_steps.rb +0 -13
  190. data/features/step_definitions/portlets_steps.rb +0 -64
  191. data/features/step_definitions/redirect_steps.rb +0 -12
  192. data/features/step_definitions/sitemap_steps.rb +0 -18
  193. data/features/step_definitions/tag_cloud_steps.rb +0 -11
  194. data/features/step_definitions/task_steps.rb +0 -4
  195. data/features/step_definitions/taxonomy_steps.rb +0 -16
  196. data/features/step_definitions/upgrade_module_steps.rb +0 -76
  197. data/features/step_definitions/web_steps.rb +0 -211
  198. data/features/support/async_support.rb +0 -17
  199. data/features/support/command_line_helpers.rb +0 -63
  200. data/features/support/debug_formatter.rb +0 -7
  201. data/features/support/debugging.rb +0 -28
  202. data/features/support/env.rb +0 -73
  203. data/features/support/git_api.rb +0 -9
  204. data/features/support/open_on_first_failure.rb +0 -25
  205. data/features/support/paths.rb +0 -32
  206. data/features/support/rails_api.rb +0 -8
  207. data/features/support/selectors.rb +0 -39
  208. data/features/support/transforms.rb +0 -7
  209. data/features/taxonomy/add_content_with_category.feature +0 -30
  210. data/features/taxonomy/manage_categories.feature +0 -20
  211. data/features/taxonomy/manage_category_types.feature +0 -16
  212. data/lib/cms/init.rb +0 -105
  213. data/lib/tasks/data.rake +0 -43
  214. data/lib/tasks/db.rake +0 -82
  215. data/public/styled_file_field/index.html +0 -72
  216. data/script/cucumber +0 -10
  217. data/script/rails +0 -6
  218. data/test/console_helper.rb +0 -5
  219. data/test/custom_assertions.rb +0 -84
  220. data/test/dummy/Rakefile +0 -7
  221. data/test/dummy/app/assets/javascripts/application.js +0 -9
  222. data/test/dummy/app/assets/javascripts/content_page.js +0 -2
  223. data/test/dummy/app/assets/stylesheets/application.css +0 -7
  224. data/test/dummy/app/assets/stylesheets/content_page.css +0 -4
  225. data/test/dummy/app/controllers/application_controller.rb +0 -3
  226. data/test/dummy/app/controllers/cms/products_controller.rb +0 -2
  227. data/test/dummy/app/controllers/cms/sample_blocks_controller.rb +0 -3
  228. data/test/dummy/app/controllers/content_page_controller.rb +0 -13
  229. data/test/dummy/app/helpers/application_helper.rb +0 -2
  230. data/test/dummy/app/helpers/content_page_helper.rb +0 -2
  231. data/test/dummy/app/mailers/.gitkeep +0 -0
  232. data/test/dummy/app/models/.gitkeep +0 -0
  233. data/test/dummy/app/models/cms/sample_block.rb +0 -22
  234. data/test/dummy/app/models/product.rb +0 -5
  235. data/test/dummy/app/views/cms/products/_form.html.erb +0 -7
  236. data/test/dummy/app/views/cms/products/render.html.erb +0 -3
  237. data/test/dummy/app/views/content_page/custom_page.html.erb +0 -3
  238. data/test/dummy/app/views/content_page/index.html.erb +0 -2
  239. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  240. data/test/dummy/app/views/layouts/templates/default.html.erb +0 -17
  241. data/test/dummy/app/views/layouts/templates/subpage.html.erb +0 -16
  242. data/test/dummy/app/views/test_route/index.html.erb +0 -14
  243. data/test/dummy/config.ru +0 -4
  244. data/test/dummy/config/application.rb +0 -45
  245. data/test/dummy/config/boot.rb +0 -10
  246. data/test/dummy/config/database.yml +0 -27
  247. data/test/dummy/config/environment.rb +0 -5
  248. data/test/dummy/config/environments/development.rb +0 -32
  249. data/test/dummy/config/environments/production.rb +0 -60
  250. data/test/dummy/config/environments/test.rb +0 -46
  251. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  252. data/test/dummy/config/initializers/browsercms.rb +0 -7
  253. data/test/dummy/config/initializers/inflections.rb +0 -10
  254. data/test/dummy/config/initializers/mime_types.rb +0 -5
  255. data/test/dummy/config/initializers/quiet_sprocket_assets.rb +0 -13
  256. data/test/dummy/config/initializers/secret_token.rb +0 -7
  257. data/test/dummy/config/initializers/session_store.rb +0 -8
  258. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  259. data/test/dummy/config/locales/en.yml +0 -5
  260. data/test/dummy/config/routes.rb +0 -23
  261. data/test/dummy/db/migrate/20111228141250_create_products.rb +0 -16
  262. data/test/dummy/db/seeds.rb +0 -1
  263. data/test/dummy/lib/assets/.gitkeep +0 -0
  264. data/test/dummy/public/404.html +0 -26
  265. data/test/dummy/public/422.html +0 -26
  266. data/test/dummy/public/500.html +0 -26
  267. data/test/dummy/public/favicon.ico +0 -0
  268. data/test/dummy/script/rails +0 -6
  269. data/test/dummy/test/functional/content_page_controller_test.rb +0 -9
  270. data/test/dummy/test/unit/helpers/content_page_helper_test.rb +0 -4
  271. data/test/factories.rb +0 -235
  272. data/test/fixtures/multipart/foo.jpg +0 -0
  273. data/test/fixtures/multipart/sample_upload.txt +0 -1
  274. data/test/fixtures/multipart/second_upload.txt +0 -1
  275. data/test/fixtures/multipart/test.jpg +0 -0
  276. data/test/fixtures/multipart/version1.txt +0 -1
  277. data/test/fixtures/multipart/version2.txt +0 -1
  278. data/test/functional/cms/cache_controller_test.rb +0 -16
  279. data/test/functional/cms/categories_controller_test.rb +0 -28
  280. data/test/functional/cms/connectors_controller_test.rb +0 -64
  281. data/test/functional/cms/content_block_controller_test.rb +0 -127
  282. data/test/functional/cms/content_controller_test.rb +0 -351
  283. data/test/functional/cms/dashboard_controller_test.rb +0 -20
  284. data/test/functional/cms/file_blocks_controller_test.rb +0 -55
  285. data/test/functional/cms/home_controller_test.rb +0 -160
  286. data/test/functional/cms/html_blocks_controller_test.rb +0 -159
  287. data/test/functional/cms/image_blocks_controller_test.rb +0 -78
  288. data/test/functional/cms/links_controller_test.rb +0 -92
  289. data/test/functional/cms/log/test.log +0 -0
  290. data/test/functional/cms/pages_controller_test.rb +0 -233
  291. data/test/functional/cms/portlets_controller_test.rb +0 -57
  292. data/test/functional/cms/sections_controller_test.rb +0 -234
  293. data/test/functional/cms/sessions_controller_test.rb +0 -80
  294. data/test/functional/cms/tasks_controller_test.rb +0 -64
  295. data/test/functional/cms/toolbar_controller_test.rb +0 -76
  296. data/test/functional/cms/users_controller_test.rb +0 -218
  297. data/test/integration/cms/password_management_test.rb +0 -66
  298. data/test/integration/sitemap_performance_test.rb +0 -26
  299. data/test/mock_file.rb +0 -33
  300. data/test/performance/browsing_test.rb +0 -9
  301. data/test/support/engine_controller_hacks.rb +0 -34
  302. data/test/support/factory_helpers.rb +0 -57
  303. data/test/support/rails_3_1_routes_hack.rb +0 -70
  304. data/test/test_helper.rb +0 -199
  305. data/test/test_logging.rb +0 -67
  306. data/test/unit/active_record_callbacks.rb +0 -50
  307. data/test/unit/behaviors/attaching_test.rb +0 -370
  308. data/test/unit/behaviors/cms_user_test.rb +0 -67
  309. data/test/unit/behaviors/connectable_test.rb +0 -32
  310. data/test/unit/behaviors/connecting_test.rb +0 -56
  311. data/test/unit/behaviors/dynamic_attributes_test.rb +0 -74
  312. data/test/unit/behaviors/namespacing_test.rb +0 -76
  313. data/test/unit/behaviors/publishable_test.rb +0 -83
  314. data/test/unit/behaviors/rendering_test.rb +0 -68
  315. data/test/unit/behaviors/searching_test.rb +0 -102
  316. data/test/unit/behaviors/taggable_test.rb +0 -110
  317. data/test/unit/behaviors/userstamping_test.rb +0 -27
  318. data/test/unit/behaviors/versioning_test.rb +0 -102
  319. data/test/unit/extensions/active_record/base_test.rb +0 -25
  320. data/test/unit/extensions/hash_test.rb +0 -26
  321. data/test/unit/extensions/integer_test.rb +0 -10
  322. data/test/unit/extensions/string_test.rb +0 -14
  323. data/test/unit/factories_test.rb +0 -50
  324. data/test/unit/generators/install_generator_test.rb +0 -15
  325. data/test/unit/helpers/application_helper_test.rb +0 -104
  326. data/test/unit/helpers/date_picker_test.rb +0 -17
  327. data/test/unit/helpers/menu_helper_test.rb +0 -240
  328. data/test/unit/helpers/page_helper_test.rb +0 -69
  329. data/test/unit/helpers/path_helper_test.rb +0 -38
  330. data/test/unit/helpers/rendering_helper_test.rb +0 -8
  331. data/test/unit/lib/acts_as_content_page_test.rb +0 -72
  332. data/test/unit/lib/cms/authentication/controller_test.rb +0 -20
  333. data/test/unit/lib/cms/engine_helper_test.rb +0 -119
  334. data/test/unit/lib/cms/sitemap_test.rb +0 -210
  335. data/test/unit/lib/cms_domain_support_test.rb +0 -44
  336. data/test/unit/lib/command_line_test.rb +0 -70
  337. data/test/unit/lib/content_block_test.rb +0 -304
  338. data/test/unit/lib/content_rendering_support_test.rb +0 -40
  339. data/test/unit/lib/generators_test.rb +0 -40
  340. data/test/unit/lib/routes_test.rb +0 -98
  341. data/test/unit/mock_file_test.rb +0 -19
  342. data/test/unit/models/attachment_test.rb +0 -160
  343. data/test/unit/models/category_test.rb +0 -40
  344. data/test/unit/models/category_type_test.rb +0 -8
  345. data/test/unit/models/connector_test.rb +0 -152
  346. data/test/unit/models/content_type_group_test.rb +0 -26
  347. data/test/unit/models/content_type_test.rb +0 -177
  348. data/test/unit/models/dynamic_views_test.rb +0 -36
  349. data/test/unit/models/email_page_portlet_test.rb +0 -20
  350. data/test/unit/models/file_block_test.rb +0 -246
  351. data/test/unit/models/group_test.rb +0 -29
  352. data/test/unit/models/html_block_test.rb +0 -121
  353. data/test/unit/models/image_block_test.rb +0 -35
  354. data/test/unit/models/link_test.rb +0 -52
  355. data/test/unit/models/namespaces_test.rb +0 -57
  356. data/test/unit/models/page_partial_test.rb +0 -37
  357. data/test/unit/models/page_route_test.rb +0 -113
  358. data/test/unit/models/page_template_test.rb +0 -50
  359. data/test/unit/models/page_test.rb +0 -879
  360. data/test/unit/models/permission_test.rb +0 -10
  361. data/test/unit/models/portlet_test.rb +0 -99
  362. data/test/unit/models/sections_test.rb +0 -278
  363. data/test/unit/models/site_test.rb +0 -50
  364. data/test/unit/models/task_test.rb +0 -150
  365. data/test/unit/models/user_test.rb +0 -358
  366. data/test/unit/schema_statements_test.rb +0 -137
  367. data/todo_list.markdown +0 -50
@@ -13,18 +13,18 @@ module Cms
13
13
  end
14
14
 
15
15
  def handle_not_found_on_page(exception)
16
- logger.warn "Page Not Found"
16
+ logger.warn "Resource not found: Returning the 404 page."
17
17
  handle_error_with_cms_page(Cms::ErrorPages::NOT_FOUND_PATH, exception, :not_found)
18
18
  end
19
19
 
20
20
  def handle_access_denied_on_page(exception)
21
- logger.warn "Access Denied"
21
+ logger.warn "Access denied for user '#{current_user.login}': Returning the 403 page."
22
22
  handle_error_with_cms_page(Cms::ErrorPages::FORBIDDEN_PATH, exception, :forbidden)
23
23
  end
24
24
 
25
25
  def handle_server_error_on_page(exception)
26
- logger.warn "Exception: #{exception.message}\n"
27
- logger.warn "#{exception.backtrace.join("\n")}\n"
26
+ logger.error "An Unexpected exception occurred: #{exception.message}\n"
27
+ logger.error "#{exception.backtrace.join("\n")}\n"
28
28
  handle_error_with_cms_page(Cms::ErrorPages::SERVER_ERROR_PATH, exception, :internal_server_error)
29
29
  end
30
30
 
@@ -43,7 +43,7 @@ module Cms
43
43
  # We must be showing the page outside of the CMS
44
44
  # So we will show the error page
45
45
  if @page = Cms::Page.find_live_by_path(error_page_path)
46
- logger.info "Rendering Error Page: #{@page.inspect}"
46
+ logger.debug "Rendering Error Page: #{@page.inspect}"
47
47
  @mode = "view"
48
48
  @show_page_toolbar = false
49
49
 
@@ -59,7 +59,10 @@ module Cms
59
59
  end
60
60
 
61
61
  prepare_connectables_for_render
62
- render :layout => @page.layout, :template => 'cms/content/show', :status => status
62
+
63
+ # The error pages are ALWAYS html since they are managed by the CMS as normal pages.
64
+ # So .gif or .jpg requests that throw errors will return html rather than a format warning.
65
+ render :layout => @page.layout, :template => 'cms/content/show', :status => status, :formats=>[:html]
63
66
  else
64
67
  handle_server_error(exception)
65
68
  end
@@ -0,0 +1,13 @@
1
+ module Cms
2
+ module DefaultAccessible
3
+
4
+ def self.included(model_class)
5
+ model_class.attribute_names.each do |name|
6
+ unless [:id, :type, :created_by_id, :updated_by_id, :created_at, :updated_at].include?(name.to_sym)
7
+ model_class.attr_accessible name
8
+ end
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -11,10 +11,32 @@ module Cms
11
11
  "cms"
12
12
  end
13
13
 
14
+ def request_is_for_cms_subdomain?
15
+ cms_site?
16
+ end
17
+
14
18
  def cms_site?
15
19
  subdomains = request.subdomains
16
20
  subdomains.shift if subdomains.first == "www"
17
21
  subdomains.first == cms_domain_prefix
18
22
  end
23
+
24
+ # Determines if users should be redirected between the public (www.) and admin (cms.) subdomains.
25
+ def using_cms_subdomains?
26
+ result = (wants_to_use_subdomains? && perform_caching)
27
+ #Rails.logger.debug {"Are we using cms subdomains? #{result} based on 'want subdomain: #{wants_to_use_subdomains?}' and perform_caching: '#{perform_caching}'"}
28
+ result
29
+ end
30
+
31
+ def should_write_to_page_cache?
32
+ using_cms_subdomains?
33
+ end
34
+
35
+ private
36
+
37
+ def wants_to_use_subdomains?
38
+ !Rails.configuration.cms.use_single_domain
39
+ end
40
+
19
41
  end
20
42
  end
data/lib/cms/engine.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rails'
2
2
  require 'cms/module'
3
- require 'cms/init'
3
+ require 'cms/configuration'
4
+ require 'cms/version'
4
5
  require 'browsercms'
5
6
 
6
7
  # Gem name is different than file name
@@ -9,52 +10,72 @@ require 'browsercms'
9
10
  require 'ckeditor-rails'
10
11
 
11
12
  # Explicitly require this, so that CMS projects do not need to add it to their Gemfile
12
- # Especially while upgrading
13
+ # especially while upgrading
13
14
  require 'jquery-rails'
14
15
 
15
16
  module Cms
16
17
 
17
- # Configuring BrowserCMS as an engine. This seems to work, but could probably be cleaned up.
18
- #
19
18
  class Engine < Rails::Engine
20
19
  include Cms::Module
21
20
  isolate_namespace Cms
22
21
 
22
+ config.cms = ActiveSupport::OrderedOptions.new
23
+ config.cms.attachments = ActiveSupport::OrderedOptions.new
23
24
 
24
- # Make sure we use our rails model template
25
+ # Make sure we use our rails model template (rather then its default) when `rails g cms:content_block` is run.
25
26
  config.app_generators do |g|
26
27
  path = File::expand_path('../../templates', __FILE__)
27
28
  g.templates.unshift path
28
29
  end
29
30
 
30
- Cms.add_generator_paths(Cms.root,
31
- "public/site/**/*",
32
- "db/seeds.rb")
33
-
34
- initializer 'browsercms.add_core_routes', :after => 'action_dispatch.prepare_dispatcher' do |app|
35
- Rails.logger.debug "Adding Cms::Routes to ActionDispatch"
36
- ActionDispatch::Routing::Mapper.send :include, Cms::RouteExtensions
31
+ # Ensure Attachments are configured:
32
+ # 1. Before every request in development mode
33
+ # 2. Once in production
34
+ config.to_prepare do
35
+ Attachments.configure
37
36
  end
38
37
 
39
- initializer 'browsercms.add_load_paths', :after => 'action_controller.deprecated_routes' do |app|
40
- Rails.logger.debug "Add Cms::Dependencies and other load_path configurations."
41
- ::Cms::Engine.add_cms_load_paths
38
+ # Set reasonable defaults
39
+ # These default values can be changed by developers in their projects in their application.rb or environment's files.
40
+ config.before_configuration do |app|
41
+
42
+ # Default cache directories.
43
+ app.config.cms.mobile_cache_directory = File.join(Rails.root, 'public', 'cache', 'mobile')
44
+ app.config.cms.page_cache_directory = File.join(Rails.root, 'public', 'cache', 'full')
45
+
46
+ # Default storage for uploaded files
47
+ app.config.cms.attachments.storage = :filesystem
48
+ app.config.cms.attachments.storage_directory = File.join(Rails.root, 'tmp', 'uploads')
49
+
50
+ # Determines if a single domain will be used (i.e. www) or multiple subdomains (www and cms). Enabling this will
51
+ # turn off page caching and not handle redirects between subdomains.
52
+ app.config.cms.use_single_domain = false
53
+
54
+ # Used to send emails with links back to the Cms Admin. In production, this should include the www. of the public site.
55
+ # Matters less in development, as emails generally aren't sent.
56
+ # I.e.
57
+ # config.cms.site_domain = "www.browsercms.org"
58
+ app.config.cms.site_domain = "localhost:3000"
42
59
  end
43
60
 
44
- initializer "browsercms.precompile_assets" do |app|
45
- app.config.assets.precompile += ['cms/application.css']
61
+ initializer 'browsercms.add_core_routes', :after => 'action_dispatch.prepare_dispatcher' do |app|
62
+ ActionDispatch::Routing::Mapper.send :include, Cms::RouteExtensions
46
63
  end
47
64
 
48
- def self.add_cms_load_paths
65
+ initializer 'browsercms.add_load_paths', :after => 'action_controller.deprecated_routes' do |app|
49
66
  ActiveSupport::Dependencies.autoload_paths += %W( #{self.root}/vendor #{self.root}/app/mailers #{self.root}/app/helpers)
50
67
  ActiveSupport::Dependencies.autoload_paths += %W( #{self.root}/app/controllers #{self.root}/app/models #{self.root}/app/portlets)
51
68
  ActiveSupport::Dependencies.autoload_paths += %W( #{Rails.root}/app/portlets )
52
69
  ActiveSupport::Dependencies.autoload_paths += %W( #{Rails.root}/app/portlets/helpers )
53
70
  ActionController::Base.append_view_path DynamicView.base_path
54
71
  ActionController::Base.append_view_path %W( #{self.root}/app/views)
55
-
56
72
  ActionView::Base.default_form_builder = Cms::FormBuilder
57
73
  require 'jdbc_adapter' if defined?(JRUBY_VERSION)
58
74
  end
75
+
76
+ initializer "browsercms.precompile_assets" do |app|
77
+ app.config.assets.precompile += ['cms/application.css']
78
+ end
79
+
59
80
  end
60
81
  end
@@ -1,4 +1,58 @@
1
1
  module Cms
2
+
3
+ class EngineAwarePathBuilder
4
+
5
+ def initialize(model_class_or_content_type_or_model)
6
+ # ContentType
7
+ if model_class_or_content_type_or_model.respond_to? :model_class
8
+ @path_subject = model_class_or_content_type_or_model.model_class
9
+ else # Class or Model
10
+ @path_subject = model_class_or_content_type_or_model
11
+ end
12
+ end
13
+
14
+ # The object that will be added to the constructed path.
15
+ def path_subject
16
+ @path_subject
17
+ end
18
+
19
+ def subject_class
20
+ if @path_subject.instance_of?(Class)
21
+ @path_subject
22
+ else
23
+ @path_subject.class
24
+ end
25
+ end
26
+
27
+ def build(view)
28
+ path = []
29
+ path << engine_name
30
+ path << "cms" if main_app_model?
31
+ path << path_subject
32
+
33
+ path[0] = view.send(path[0]) # Replace the engine name with an actual lookup of the proper Engine routeset
34
+ path
35
+ end
36
+
37
+ def main_app_model?
38
+ engine_name == "main_app"
39
+ end
40
+
41
+ # Determine which 'Engine' this model is from based on the class
42
+ def engine_name
43
+ name = EngineHelper.module_name(subject_class)
44
+ return "main_app" unless name
45
+
46
+ begin
47
+ engine = "#{name}::Engine".constantize
48
+ rescue NameError
49
+ # This means there is no Engine for this model, so its from the main Rails App.
50
+ return "main_app"
51
+ end
52
+ engine.engine_name
53
+ end
54
+ end
55
+
2
56
  module EngineHelper
3
57
 
4
58
  def main_app_model?
@@ -100,16 +100,22 @@ module ActiveRecord
100
100
 
101
101
  alias :drop_content_table :drop_versioned_table
102
102
 
103
+ # Rename a column for both its
104
+ def rename_content_column(table_name, old_name, new_name)
105
+ rename_column table_name, old_name, new_name
106
+ rename_column version_table_name(table_name), old_name, new_name
107
+ end
108
+
103
109
  # Adds a column to both the primary and versioned table. Save needing two calls.
104
110
  # This is only needed if your content block is versioned, otherwise add_column will work just fine.
105
111
  def add_content_column(table_name, column_name, type, options={})
106
112
  add_column table_name, column_name, type, options
107
- add_column "#{table_name.to_s.singularize}_versions".to_sym, column_name, type, options
113
+ add_column version_table_name(table_name), column_name, type, options
108
114
  end
109
115
 
110
116
  def remove_content_column(table_name, column_name)
111
117
  remove_column table_name, column_name
112
- remove_column "#{table_name.to_s.singularize}_versions".to_sym, column_name
118
+ remove_column version_table_name(table_name), column_name
113
119
  end
114
120
 
115
121
  # Will namespace the content table
@@ -117,6 +123,12 @@ module ActiveRecord
117
123
  table_exists?(Cms::Namespacing.prefixed_table_name(table_name))
118
124
  end
119
125
 
126
+ private
127
+
128
+ def version_table_name(table_name)
129
+ "#{table_name.to_s.singularize}_versions".to_sym
130
+ end
131
+
120
132
  end
121
133
  end
122
134
  end
@@ -0,0 +1,67 @@
1
+ module Cms
2
+
3
+ module MobileAware
4
+
5
+ include Cms::DefaultCaches
6
+
7
+ # Looks for a mobile template if the request is mobile, falling back to the html template if it can't be found.
8
+ #
9
+ # @return [String] relative path/name of the layout to be rendered by a page (i.e. 'layouts/templates/default')
10
+ def determine_page_layout
11
+ if respond_as_mobile?
12
+ mobile_exists = template_exists?(@page.layout_name, "layouts/mobile")
13
+ return @page.layout(:mobile) if mobile_exists
14
+ end
15
+ @page.layout(:full)
16
+ end
17
+
18
+ # This is changing a class attribute in order to write the page cache to a different directory based on mobile vs full page request.
19
+ # @warning - May not be thread safe?
20
+ def select_cache_directory
21
+ if respond_as_mobile?
22
+ self.class.page_cache_directory = mobile_cache_directory
23
+ else
24
+ self.class.page_cache_directory = cms_cache_directory
25
+ end
26
+ end
27
+
28
+ # Because of caching, CMS pages should only return mobile content on a separate subdomain.
29
+ # or if a CMS editor wants to see the mobile version of the page.
30
+ #
31
+ # @return [Boolean] true if this request is considered 'mobile', false otherwise
32
+ def respond_as_mobile?
33
+ log "For mobile optimization, checking the subdomain for '#{request.domain}' is '#{request.subdomain}'."
34
+ if params[:template] =='mobile'
35
+ session[:mobile_mode] = true
36
+ elsif params[:template] =='full'
37
+ session[:mobile_mode] = false
38
+ end
39
+
40
+ request.subdomain == "m" || (session[:mobile_mode] == true && current_user.able_to?(:edit_content))
41
+ end
42
+
43
+ private
44
+
45
+ def print_request_info
46
+ log "*" * 20
47
+ log "User Agent: #{request.user_agent}"
48
+ m = "Mobile Request?: "
49
+ if respond_as_mobile?
50
+ m += "Yes"
51
+ else
52
+ m += "No"
53
+ end
54
+ log m
55
+ end
56
+
57
+ def log(m)
58
+ logger.debug m
59
+ end
60
+
61
+ def banner(m)
62
+ log "*" * 20
63
+ log m
64
+ end
65
+ end
66
+
67
+ end
@@ -40,6 +40,9 @@ module Cms::RouteExtensions
40
40
  mount Cms::Engine => "/cms", :as => "cms"
41
41
 
42
42
  add_page_routes_defined_in_database
43
+
44
+ # Handle 'stock' attachments
45
+ match "/attachments/:id/:filename", :to=>"cms/attachments#download"
43
46
  match "/", :to=>"cms/content#show"
44
47
  match "*path", :to=>"cms/content#show"
45
48
  end
@@ -0,0 +1,155 @@
1
+ require 'fileutils'
2
+
3
+ module Cms
4
+ module Upgrades
5
+
6
+ module V3_5_0
7
+ def upgrade_to_3_5_0
8
+ gsub_file "config/environments/production.rb", /config.action_controller.page_cache_directory.+$/, ""
9
+ end
10
+
11
+ # Add additional methods to ActiveRecord::Migration when this file is required.
12
+ module FileStorageUpdates
13
+
14
+
15
+ # Old paths are:
16
+ # uploads/:year/:month/:day/:fingerprint
17
+ # i.e. uploads/2012/04/27/fb598......
18
+ #
19
+ # New paths use paperclip's :id_partition which creates paths like:
20
+ # uploads/000/000/001/:fingerprint
21
+ # where it splits the id into multiple directories
22
+ #
23
+ # @param [Cms::Attachment] attachment
24
+ # @return [String] path to location where an attachment should be (based on id)
25
+ def path_for_attachment(attachment)
26
+ new_id_dir = "#{Paperclip::Interpolations.id_partition(AttachmentWrapper.new(attachment), nil)}/original"
27
+ "#{new_id_dir}/#{attachment.data_fingerprint}"
28
+ end
29
+
30
+ # @return [String] Path to where an attachment should be
31
+ def path_to_attachment(attachment)
32
+ loc = path_for_attachment(attachment)
33
+ file_in_attachments_dir(loc)
34
+ end
35
+ # For a given class with an Attachment association (pre-3.5.0), migrate its attachment data to match the new
36
+ # table structure.
37
+ def migrate_attachment_for(klass)
38
+ klass.unscoped.find_each do |block|
39
+ Cms::Attachment.unscoped.update_all({:attachable_id => block.id,
40
+ :attachable_version => block.version,
41
+ :attachable_type => klass.name,
42
+ :attachment_name => "file",
43
+ :cardinality => 'single'},
44
+ {:id => block.attachment_id})
45
+ end
46
+
47
+ attachable_type = klass.name
48
+ # Special handling for File/Image blocks
49
+ if klass == Cms::FileBlock
50
+ attachable_type = "Cms::AbstractFileBlock"
51
+ elsif klass == Cms::ImageBlock
52
+ # Only need to do this once for both Image and File blocks since they share a table.
53
+ return
54
+ end
55
+
56
+ migrated_attachment_for_versioned_table(klass, attachable_type)
57
+
58
+ end
59
+
60
+ def migrated_attachment_for_versioned_table(model_class, attachable_type)
61
+ version_model = model_class.version_class
62
+
63
+ found = version_model.find_by_sql("SELECT original_record_id, attachment_id, attachment_version, version from #{version_model.table_name}")
64
+ found.each do |version_record|
65
+ Cms::Attachment::Version.unscoped.update_all({:attachable_id => version_record.original_record_id,
66
+ :attachable_version => version_record.version,
67
+ :attachable_type => attachable_type,
68
+ :attachment_name => "file",
69
+ :cardinality => 'single'},
70
+ {:original_record_id => version_record.attachment_id, :version => version_record.attachment_version})
71
+ end
72
+ end
73
+
74
+ # Move the attachment files from the old file path path to new one. Updates the Attachment record to match.
75
+ def migrate_attachment_files_to_new_location
76
+ migrate_attachments_file_location(Cms::Attachment)
77
+ migrate_attachments_file_location(Cms::Attachment::Version)
78
+ end
79
+
80
+ # Remove the attachment_version and attachment_id columns for all core CMS blocks.
81
+ def cleanup_attachment_columns_for_core_cms
82
+ cleanup_attachment_columns(Cms::FileBlock)
83
+ end
84
+
85
+ # The 'attachment_id and attachment_version are no longer stored in the model, but in the attachments table'
86
+ # @param [Class] model_class The model to have its columns cleaned up.
87
+ def cleanup_attachment_columns(model_class)
88
+ remove_content_column model_class.table_name, :attachment_id if column_exists?(model_class.table_name, :attachment_id)
89
+ remove_content_column model_class.table_name, :attachment_version if column_exists?(model_class.table_name, :attachment_id)
90
+ end
91
+
92
+ # Removes the cms_attachments.file_location column
93
+ #
94
+ # data_fingerprint is used to store the file name instead now.
95
+ def cleanup_attachments_file_location
96
+ remove_content_column :cms_attachments, :file_location if column_exists?(:cms_attachments, :file_location)
97
+ end
98
+
99
+ # Deletes the old file storage folders from the uploads directory.
100
+ #
101
+ def cleanup_attachment_file_storage
102
+ ["2009", "2010", "2011", "2012"].each do |year|
103
+ folder_to_remove = File.join(attachments_dir, year)
104
+ FileUtils.rm_rf(folder_to_remove, :verbose => true)
105
+ end
106
+ end
107
+
108
+ private
109
+
110
+ # Multiple version of attachments may point to the same file, so we need to test
111
+ # a file exists before moving. Failure to move isn't necessary an error, since it may have been moved in
112
+ # an earlier version
113
+ def migrate_attachments_file_location(model_class)
114
+ model_class.unscoped.each do |attachment|
115
+ from = File.join(attachments_dir, attachment.file_location)
116
+ to = path_to_attachment(attachment)
117
+ move_attachment_file(from, to)
118
+
119
+ new_fingerprint = attachment.file_location.split("/").last
120
+ model_class.unscoped.update_all({:data_fingerprint => new_fingerprint}, :id => attachment.id)
121
+ end
122
+ end
123
+
124
+ def file_in_attachments_dir(file_name)
125
+ File.join(Cms::Attachment.configuration.attachments_root, file_name)
126
+ end
127
+
128
+ def move_attachment_file(old_location, new_location)
129
+ if File.exists?(old_location)
130
+ FileUtils.mkdir_p(File.dirname(new_location), :verbose => false)
131
+ FileUtils.mv(old_location, new_location, :verbose => true)
132
+ else
133
+ puts "'#{old_location}' does not exist, and may have been moved already. Skipping move."
134
+ end
135
+ end
136
+
137
+ def attachments_dir
138
+ Cms::Attachment.configuration.attachments_root
139
+ end
140
+
141
+ # Allows us to use the Paperclip interpolations logic directly
142
+ class AttachmentWrapper
143
+ def initialize(attachment)
144
+ @attachment = attachment
145
+ end
146
+
147
+ def instance
148
+ @attachment
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
155
+ ActiveRecord::Migration.send(:include, Cms::Upgrades::V3_5_0::FileStorageUpdates) if defined?(ActiveRecord::Migration)