zena 1.0.0.beta3 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (418) hide show
  1. data/History.txt +29 -0
  2. data/Rakefile +2 -0
  3. data/TODO_ZENA_1_0 +13 -23
  4. data/app/controllers/columns_controller.rb +1 -1
  5. data/app/controllers/comments_controller.rb +4 -3
  6. data/app/controllers/documents_controller.rb +8 -11
  7. data/app/controllers/nodes_controller.rb +39 -21
  8. data/app/controllers/users_controller.rb +8 -3
  9. data/app/controllers/versions_controller.rb +2 -2
  10. data/app/controllers/virtual_classes_controller.rb +17 -11
  11. data/app/helpers/documents_helper.rb +0 -3
  12. data/app/helpers/users_helper.rb +17 -0
  13. data/app/models/cache.rb +36 -31
  14. data/app/models/column.rb +48 -5
  15. data/app/models/comment.rb +14 -5
  16. data/app/models/data_entry.rb +2 -2
  17. data/app/models/document.rb +23 -33
  18. data/app/models/idx_nodes_datetime.rb +4 -0
  19. data/app/models/idx_nodes_float.rb +4 -0
  20. data/app/models/idx_project.rb +3 -0
  21. data/app/models/node.rb +372 -308
  22. data/app/models/page.rb +1 -31
  23. data/app/models/relation.rb +4 -4
  24. data/app/models/relation_proxy.rb +128 -17
  25. data/app/models/role.rb +27 -2
  26. data/app/models/site.rb +64 -56
  27. data/app/models/template.rb +11 -12
  28. data/app/models/text_document.rb +6 -7
  29. data/app/models/user.rb +95 -46
  30. data/app/models/version.rb +2 -2
  31. data/app/models/virtual_class.rb +418 -73
  32. data/app/views/columns/_form.html.erb +1 -1
  33. data/app/views/columns/_li.html.erb +1 -1
  34. data/app/views/comments/_form.rhtml +1 -1
  35. data/app/views/comments/_li.rhtml +1 -1
  36. data/app/views/comments/_li_simple.rhtml +1 -1
  37. data/app/views/groups/_form.rhtml +1 -1
  38. data/app/views/links/_li.rhtml +1 -1
  39. data/app/views/nodes/_groups.rhtml +1 -1
  40. data/app/views/nodes/_import_results.rhtml +1 -1
  41. data/app/views/nodes/_parent.rhtml +1 -1
  42. data/app/views/nodes/_results.rhtml +1 -1
  43. data/app/views/nodes/create.rjs +4 -2
  44. data/app/views/relations/_li.erb +2 -2
  45. data/app/views/templates/document_create_tabs/_file.rhtml +1 -1
  46. data/app/views/templates/document_create_tabs/_template.rhtml +2 -2
  47. data/app/views/templates/document_create_tabs/_text_document.rhtml +2 -2
  48. data/app/views/templates/edit_tabs/_help.rhtml +1 -1
  49. data/app/views/templates/edit_tabs/_title.rhtml +0 -3
  50. data/app/views/users/_form.rhtml +2 -6
  51. data/app/views/users/_li.rhtml +1 -3
  52. data/app/views/users/create.rjs +4 -4
  53. data/app/views/users/preferences.html.erb +1 -4
  54. data/app/views/versions/custom_tab.rhtml +5 -0
  55. data/app/views/virtual_classes/_form.erb +20 -10
  56. data/app/views/virtual_classes/_li.erb +21 -8
  57. data/app/views/zafu/default/Node-+search.zafu +1 -1
  58. data/app/views/zafu/default/Node.zafu +3 -3
  59. data/bricks/captcha/lib/bricks/captcha.rb +1 -1
  60. data/bricks/mongrel/zena/deploy.rb +14 -0
  61. data/bricks/{data2pdf → pdf}/.document +0 -0
  62. data/bricks/pdf/README +33 -0
  63. data/bricks/{data2pdf → pdf}/Rakefile +0 -0
  64. data/bricks/pdf/VERSION +1 -0
  65. data/bricks/pdf/lib/bricks/pdf.rb +110 -0
  66. data/bricks/pdf/lib/bricks/pdf/engine/prince.rb +38 -0
  67. data/bricks/pdf/lib/bricks/pdf/engine/xhtml2pdf.rb +9 -0
  68. data/bricks/pdf/lib/bricks/pdf/install.rb +121 -0
  69. data/bricks/pdf/test/engines/test_prince.rb +15 -0
  70. data/bricks/pdf/test/engines/test_xhtml2pdf.rb +15 -0
  71. data/bricks/{data2pdf → pdf}/test/fixtures/application.css +0 -0
  72. data/bricks/{data2pdf → pdf}/test/fixtures/contact.html +0 -0
  73. data/bricks/{data2pdf → pdf}/test/fixtures/pisa-default.css +0 -0
  74. data/bricks/{data2pdf → pdf}/test/fixtures/sheet1.css +0 -0
  75. data/bricks/{data2pdf → pdf}/test/fixtures/sheet2.css +0 -0
  76. data/bricks/{data2pdf → pdf}/test/fixtures/simple-html.html +0 -0
  77. data/bricks/{data2pdf → pdf}/test/fixtures/simple-text.txt +0 -0
  78. data/bricks/{data2pdf → pdf}/test/helper.rb +4 -5
  79. data/bricks/pdf/test/shoulda_macros/shoulda_pdf.rb +72 -0
  80. data/bricks/pdf/zena/init.rb +5 -0
  81. data/bricks/pdf/zena/tasks.rb +17 -0
  82. data/bricks/sphinx/lib/{use_sphinx.rb → bricks/sphinx.rb} +1 -1
  83. data/bricks/tags/zena/init.rb +2 -2
  84. data/bricks/tags/zena/test/zafu/tags.yml +4 -4
  85. data/bricks/zena/zena/migrate/01_base.rb +482 -0
  86. data/config/bricks.yml +22 -6
  87. data/config/gems.yml +8 -6
  88. data/db/20100628074512_zena0x_to1x.rb +6 -1
  89. data/db/fix/024_correct_vclass_kpath.rb +11 -0
  90. data/db/fix/025_move_tag_into_vclass.rb +13 -0
  91. data/db/{migrate → fix}/026_rename_templates.rb +0 -0
  92. data/db/{migrate → fix}/045_avoid_star_in_templates.rb +0 -0
  93. data/db/{migrate → fix}/046_fix_zazen_image_tag.rb +0 -0
  94. data/db/{migrate → fix}/047_change_default_link_id_to_zero.rb +1 -3
  95. data/db/{migrate → fix}/049_fix_publish_from_is_null.rb +0 -0
  96. data/db/{migrate → fix}/20090924141459_zafu_fix_sept09.rb +0 -0
  97. data/db/{migrate → fix}/20091013100351_rename_publish_group_to_drive_group.rb +1 -3
  98. data/db/{migrate → fix}/20091124161608_rebuild_fullpath.rb +0 -1
  99. data/db/{migrate → fix}/20100115134729_rebuild_fullpath_after_fix.rb +0 -0
  100. data/db/{migrate → fix}/20100526090140_renamed_contact_model_to_base_contact.rb +2 -4
  101. data/db/{migrate → fix/old_migrations}/001_create_base.rb +0 -1
  102. data/db/{migrate → fix/old_migrations}/002_add_time_zone_to_users.rb +0 -0
  103. data/db/{migrate → fix/old_migrations}/003_add_custom_base_flag.rb +0 -0
  104. data/db/{migrate → fix/old_migrations}/004_rename_template_skin.rb +0 -0
  105. data/db/{migrate → fix/old_migrations}/005_create_cached_pages.rb +0 -0
  106. data/db/{migrate → fix/old_migrations}/006_create_sites.rb +0 -0
  107. data/db/{migrate → fix/old_migrations}/007_replace_id_by_zip.rb +0 -0
  108. data/db/{migrate → fix/old_migrations}/008_user_status.rb +0 -0
  109. data/db/{migrate → fix/old_migrations}/009_fulltext.rb +0 -0
  110. data/db/fix/old_migrations/010_create_template_content.rb +17 -0
  111. data/db/{migrate → fix/old_migrations}/011_project_to_section.rb +0 -0
  112. data/db/{migrate → fix/old_migrations}/012_add_project_id.rb +0 -0
  113. data/db/{migrate → fix/old_migrations}/013_remove_defaults.rb +0 -0
  114. data/db/{migrate → fix/old_migrations}/014_add_sort_field.rb +0 -0
  115. data/db/{migrate → fix/old_migrations}/015_add_dyn_attributes.rb +0 -0
  116. data/db/{migrate → fix/old_migrations}/016_remove_translations.rb +0 -0
  117. data/db/{migrate → fix/old_migrations}/017_rename_authorize.rb +0 -0
  118. data/db/{migrate → fix/old_migrations}/018_add_auth_option.rb +0 -0
  119. data/db/{migrate → fix/old_migrations}/019_remove_user_status.rb +0 -0
  120. data/db/{migrate → fix/old_migrations}/020_create_participation.rb +0 -0
  121. data/db/{migrate → fix/old_migrations}/021_create_relations.rb +0 -0
  122. data/db/{migrate → fix/old_migrations}/022_create_virtual_classes.rb +0 -0
  123. data/db/{migrate → fix/old_migrations}/023_ip_on_anonymous_comment.rb +0 -0
  124. data/db/{migrate → fix/old_migrations}/027_add_country_to_contacts.rb +0 -0
  125. data/db/{migrate → fix/old_migrations}/028_change_size_of_conten_type_field.rb +0 -0
  126. data/db/{migrate → fix/old_migrations}/029_create_data_entries.rb +0 -0
  127. data/db/{migrate → fix/old_migrations}/030_redit_auto_publish_site_settings.rb +0 -0
  128. data/db/{migrate → fix/old_migrations}/031_create_iformats.rb +0 -0
  129. data/db/{migrate → fix/old_migrations}/032_caches_context_as_hash.rb +0 -0
  130. data/db/{migrate → fix/old_migrations}/033_documents_kpath_change.rb +0 -0
  131. data/db/{migrate → fix/old_migrations}/034_change_file_storage.rb +0 -0
  132. data/db/{migrate → fix/old_migrations}/035_add_status_to_link.rb +0 -0
  133. data/db/{migrate → fix/old_migrations}/036_add_flag_fields_on_nodes.rb +0 -0
  134. data/db/{migrate → fix/old_migrations}/037_add_auto_create_discussion_to_v_class.rb +0 -0
  135. data/db/{migrate → fix/old_migrations}/038_create_site_attributes.rb +0 -0
  136. data/db/{migrate → fix/old_migrations}/039_default_position.rb +0 -0
  137. data/db/{migrate → fix/old_migrations}/040_second_value_for_data_entry.rb +0 -0
  138. data/db/{migrate → fix/old_migrations}/041_add_attributes_to_v_class.rb +0 -0
  139. data/db/{migrate → fix/old_migrations}/042_fix_position_should_be_float.rb +0 -0
  140. data/db/{migrate → fix/old_migrations}/043_move_user_lang_into_participation.rb +0 -0
  141. data/db/{migrate → fix/old_migrations}/044_remove_monolingual_site_option.rb +0 -0
  142. data/db/{migrate → fix/old_migrations}/048_link_source_target_can_be_null.rb +0 -0
  143. data/db/{migrate → fix/old_migrations}/050_date_in_links.rb +0 -0
  144. data/db/{migrate → fix/old_migrations}/051_add_exif_tags_to_images.rb +0 -0
  145. data/db/{migrate → fix/old_migrations}/20090825201159_insert_zero_link.rb +0 -0
  146. data/db/{migrate → fix/old_migrations}/20090825201200_merge_bricks_migrations_with_std_migrations.rb +0 -0
  147. data/db/{migrate → fix/old_migrations}/20090927125912_allow_null_in_text_fields.rb +0 -0
  148. data/db/{migrate → fix/old_migrations}/20090928133440_no_more_private_nodes.rb +0 -0
  149. data/db/{migrate → fix/old_migrations}/20090928143754_version_status_change.rb +0 -0
  150. data/db/{migrate → fix/old_migrations}/20091001084025_change_status_values_for_comments.rb +0 -0
  151. data/db/{migrate → fix/old_migrations}/20091009084057_add_vhash_in_node.rb +0 -0
  152. data/db/{migrate → fix/old_migrations}/20091014130833_fix_template_title.rb +0 -0
  153. data/db/{migrate → fix/old_migrations}/20091014183726_merge_participation_into_users.rb +0 -0
  154. data/db/{migrate → fix/old_migrations}/20091018200734_add_popup_info_to_image_format.rb +0 -0
  155. data/db/{migrate → fix/old_migrations}/20091026161708_add_persistence_token.rb +0 -0
  156. data/db/{migrate → fix/old_migrations}/20091101184952_add_session_table.rb +0 -0
  157. data/db/{migrate → fix/old_migrations}/20091123175137_add_single_access_token.rb +0 -0
  158. data/db/{migrate → fix/old_migrations}/20100125062254_add_dynamo_to_version.rb +0 -0
  159. data/db/{migrate → fix/old_migrations}/20100201133242_remove_default_status_on_version.rb +0 -0
  160. data/db/{migrate → fix/old_migrations}/20100208194210_create_attachments.rb +0 -0
  161. data/db/{migrate → fix/old_migrations}/20100210112319_change_dynamo_to_property.rb +0 -0
  162. data/db/{migrate → fix/old_migrations}/20100320145726_transform_template_contents_into_index.rb +0 -0
  163. data/db/{migrate → fix/old_migrations}/20100328125634_change_skin_name_to_id.rb +0 -0
  164. data/db/{migrate → fix/old_migrations}/20100417061257_add_properties_to_sites.rb +0 -0
  165. data/db/{migrate → fix/old_migrations}/20100419163149_rename_name_to_node_name.rb +0 -0
  166. data/db/{migrate → fix/old_migrations}/20100422091606_change_v_class_table_into_roles.rb +0 -0
  167. data/db/{migrate → fix/old_migrations}/20100422094048_node_habtm_roles.rb +0 -0
  168. data/db/{migrate → fix/old_migrations}/20100422115935_create_columns.rb +0 -0
  169. data/db/{migrate → fix/old_migrations}/20100513181529_add_site_id_to_columns.rb +0 -0
  170. data/db/{migrate → fix/old_migrations}/20100519091711_add_index_definition_to_columns.rb +0 -0
  171. data/db/{migrate → fix/old_migrations}/20100519091940_create_idx_nodes_string.rb +0 -0
  172. data/db/{migrate → fix/old_migrations}/20100519232432_create_idx_nodes_ml_string.rb +0 -0
  173. data/db/{migrate → fix/old_migrations}/20100525113858_add_porperties_to_users.rb +0 -0
  174. data/db/{migrate → fix/old_migrations}/20100527130937_change_column_index_to_string.rb +0 -0
  175. data/db/{migrate → fix/old_migrations}/20100531135128_add_fulltext_builder_fields.rb +0 -0
  176. data/db/{migrate → fix/old_migrations}/20100915062903_add_api_group_id_to_site.rb +0 -0
  177. data/db/fix/old_migrations/20100923154807_remove_base_contact.rb +84 -0
  178. data/db/fix/old_migrations/20100926192223_remove_su_user.rb +8 -0
  179. data/db/fix/old_migrations/20100927141658_add_eval_attributes_to_v_class.rb +12 -0
  180. data/db/fix/old_migrations/20100928185257_add_obvious_idx.rb +52 -0
  181. data/db/fix/old_migrations/20100929143111_remove_node_name.rb +11 -0
  182. data/db/fix/old_migrations/20101006090454_store_properties_in_long_text.rb +9 -0
  183. data/db/fix/old_migrations/20101014185753_remove_user_prototype_id.rb +9 -0
  184. data/db/fix/old_migrations/20101101084318_create_scope_index.rb +35 -0
  185. data/db/fix/old_migrations/20101109074232_create_idx_nodes_tables.rb +65 -0
  186. data/db/fix/old_migrations/20101110184235_add_role_update_to_site.rb +9 -0
  187. data/db/fix/old_migrations/20101116103920_change_scope_index.rb +31 -0
  188. data/db/fix/old_migrations/20101123125822_add_integer_idx.rb +17 -0
  189. data/db/fix/old_migrations/20101130134522_add_index_field.rb +13 -0
  190. data/db/fix/old_migrations/20101213133816_add_group_to_relation.rb +9 -0
  191. data/db/init/base/help.fr.zml +1 -1
  192. data/db/init/base/skins/default.zml +0 -1
  193. data/db/init/base/skins/default/Node-+search.zafu +1 -1
  194. data/db/init/base/skins/default/Node-tree.zafu +3 -3
  195. data/db/init/base/skins/default/Node.zafu +3 -3
  196. data/lib/bricks/loader.rb +4 -1
  197. data/lib/bricks/requirements_validation.rb +11 -6
  198. data/lib/log_recorder/lib/log_recorder.rb +2 -2
  199. data/lib/tasks/zena.rake +25 -15
  200. data/lib/zena.rb +42 -9
  201. data/lib/zena/acts/enrollable.rb +81 -99
  202. data/lib/zena/acts/secure.rb +27 -23
  203. data/lib/zena/acts/secure_node.rb +10 -55
  204. data/lib/zena/acts/serializable.rb +9 -10
  205. data/lib/zena/app.rb +0 -2
  206. data/lib/zena/code_syntax.rb +1 -1
  207. data/lib/zena/controller/test_case.rb +0 -5
  208. data/lib/zena/core_ext/string.rb +48 -20
  209. data/lib/zena/db.rb +10 -442
  210. data/lib/zena/db_helper/abstract_db.rb +184 -0
  211. data/lib/zena/db_helper/mysql.rb +150 -0
  212. data/lib/zena/db_helper/postgresql.rb +79 -0
  213. data/lib/zena/db_helper/sqlite3.rb +135 -0
  214. data/lib/zena/deploy.rb +4 -1
  215. data/lib/zena/deploy/httpd.rhtml +3 -3
  216. data/lib/zena/deploy/vhost.rhtml +1 -1
  217. data/lib/zena/foxy_parser.rb +37 -18
  218. data/lib/zena/info.rb +3 -13
  219. data/lib/zena/migrator.rb +0 -1
  220. data/lib/zena/parser/zafu_rules.rb +9 -4
  221. data/lib/zena/parser/zazen_rules.rb +5 -5
  222. data/lib/zena/parser/zena_rules.rb +1 -1
  223. data/lib/zena/remote/interface.rb +1 -1
  224. data/lib/zena/site_worker.rb +3 -3
  225. data/lib/zena/test_controller.rb +10 -10
  226. data/lib/zena/use/action.rb +66 -6
  227. data/lib/zena/use/ajax.rb +39 -13
  228. data/lib/zena/use/ancestry.rb +210 -0
  229. data/lib/zena/use/authlogic.rb +30 -1
  230. data/lib/zena/use/calendar.rb +158 -0
  231. data/lib/zena/use/conditional.rb +3 -2
  232. data/lib/zena/use/context.rb +42 -12
  233. data/lib/zena/use/dates.rb +15 -14
  234. data/lib/zena/use/display.rb +54 -7
  235. data/lib/zena/use/error_rendering.rb +1 -0
  236. data/lib/zena/use/field_index.rb +20 -0
  237. data/lib/zena/use/fixtures.rb +12 -9
  238. data/lib/zena/use/forms.rb +230 -106
  239. data/lib/zena/use/fulltext.rb +28 -14
  240. data/lib/zena/use/html_tags.rb +1 -24
  241. data/lib/zena/use/i18n.rb +69 -14
  242. data/lib/zena/use/kpath.rb +60 -0
  243. data/lib/zena/use/ml_index.rb +6 -4
  244. data/lib/zena/use/node_context.rb +63 -0
  245. data/lib/zena/use/prop_eval.rb +90 -0
  246. data/lib/zena/use/query_builder.rb +159 -29
  247. data/lib/zena/use/query_comment.rb +1 -1
  248. data/lib/zena/use/query_node.rb +147 -56
  249. data/lib/zena/use/recursion.rb +2 -2
  250. data/lib/zena/use/relations.rb +31 -19
  251. data/lib/zena/use/rendering.rb +111 -121
  252. data/lib/zena/use/scope_index.rb +230 -0
  253. data/lib/zena/use/search.rb +7 -7
  254. data/lib/zena/use/urls.rb +87 -25
  255. data/lib/zena/use/version_hash.rb +113 -113
  256. data/lib/zena/use/workflow.rb +5 -1
  257. data/lib/zena/use/zafu_attributes.rb +11 -14
  258. data/lib/zena/use/zafu_eval.rb +1 -1
  259. data/lib/zena/use/zafu_safe_definitions.rb +91 -9
  260. data/lib/zena/use/zafu_templates.rb +146 -102
  261. data/lib/zena/use/zazen.rb +5 -4
  262. data/lib/zena/zafu_compiler.rb +1 -0
  263. data/locale/en/LC_MESSAGES/zena.mo +0 -0
  264. data/locale/en/zena.po +0 -1
  265. data/locale/fr/LC_MESSAGES/zena.mo +0 -0
  266. data/locale/fr/zena.mo +0 -0
  267. data/locale/fr/zena.po +4 -4
  268. data/misc/zena +35 -0
  269. data/misc/zena_init +41 -0
  270. data/public/images/ext/{basecontact.png → contact.png} +0 -0
  271. data/public/javascripts/zena.js +35 -7
  272. data/public/stylesheets/admin.css +5 -2
  273. data/public/stylesheets/default.css +2 -1
  274. data/public/stylesheets/popup.css +1 -1
  275. data/public/stylesheets/zena.css +2 -2
  276. data/test/custom_queries/complex.host.yml +12 -5
  277. data/test/fixtures/files/Node-test.zafu +3 -3
  278. data/test/fixtures/files/translations_fr.yml +4 -2
  279. data/test/functional/documents_controller_test.rb +31 -0
  280. data/test/functional/nodes_controller_commit_test.rb +1 -5
  281. data/test/functional/nodes_controller_test.rb +92 -12
  282. data/test/functional/user_sessions_controller_test.rb +2 -2
  283. data/test/functional/users_controller_test.rb +31 -29
  284. data/test/functional/versions_controller_test.rb +2 -2
  285. data/test/functional/virtual_classes_controller_test.rb +2 -2
  286. data/test/integration/multiple_hosts_test.rb +19 -8
  287. data/test/integration/navigation_test.rb +91 -12
  288. data/test/integration/query_node/basic.yml +40 -37
  289. data/test/integration/query_node/complex.yml +23 -18
  290. data/test/integration/query_node/dates.yml +3 -3
  291. data/test/integration/query_node/errors.yml +7 -1
  292. data/test/integration/query_node/filters.yml +41 -35
  293. data/test/integration/query_node/idx_fields.yml +11 -0
  294. data/test/integration/query_node/idx_key_value.yml +77 -0
  295. data/test/integration/query_node/idx_scope.yml +33 -0
  296. data/test/integration/query_node/relations.yml +13 -13
  297. data/test/integration/query_node_test.rb +6 -10
  298. data/test/integration/zafu_compiler/action.yml +19 -6
  299. data/test/integration/zafu_compiler/ajax.yml +111 -51
  300. data/test/integration/zafu_compiler/apphelper.yml +1 -1
  301. data/test/integration/zafu_compiler/asset.yml +1 -1
  302. data/test/integration/zafu_compiler/basic.yml +42 -52
  303. data/test/integration/zafu_compiler/calendar.yml +3 -3
  304. data/test/integration/zafu_compiler/complex.yml +16 -16
  305. data/test/integration/zafu_compiler/complex_ok.yml +2 -2
  306. data/test/integration/zafu_compiler/conditional.yml +42 -33
  307. data/test/integration/zafu_compiler/data.yml +3 -3
  308. data/test/integration/zafu_compiler/dates.yml +25 -10
  309. data/test/integration/zafu_compiler/display.yml +49 -12
  310. data/test/integration/zafu_compiler/errors.yml +26 -6
  311. data/test/integration/zafu_compiler/eval.yml +4 -4
  312. data/test/integration/zafu_compiler/forms.yml +89 -15
  313. data/test/integration/zafu_compiler/i18n.yml +23 -18
  314. data/test/integration/zafu_compiler/idx_scope.yml +7 -0
  315. data/test/integration/zafu_compiler/later.yml +10 -16
  316. data/test/integration/zafu_compiler/off/off.yml +2 -2
  317. data/test/integration/zafu_compiler/query.yml +207 -0
  318. data/test/integration/zafu_compiler/recursion.yml +2 -2
  319. data/test/integration/zafu_compiler/relations.yml +144 -168
  320. data/test/integration/zafu_compiler/roles.yml +86 -10
  321. data/test/integration/zafu_compiler/rubyless.yml +49 -6
  322. data/test/integration/zafu_compiler/safe_definitions.yml +35 -6
  323. data/test/integration/zafu_compiler/search.yml +1 -1
  324. data/test/integration/zafu_compiler/security.yml +37 -0
  325. data/test/integration/zafu_compiler/urls.yml +50 -40
  326. data/test/integration/zafu_compiler/user.yml +21 -6
  327. data/test/integration/zafu_compiler/version.yml +6 -6
  328. data/test/integration/zafu_compiler/zafu_attributes.yml +43 -34
  329. data/test/integration/zafu_compiler/zazen.yml +10 -10
  330. data/test/integration/zafu_compiler_test.rb +19 -13
  331. data/test/sites/complex/nodes.yml +0 -2
  332. data/test/sites/complex/roles.yml +9 -1
  333. data/test/sites/complex/sites.yml +0 -1
  334. data/test/sites/complex/users.yml +2 -5
  335. data/test/sites/ocean/nodes.yml +2 -5
  336. data/test/sites/ocean/roles.yml +8 -0
  337. data/test/sites/ocean/sites.yml +0 -1
  338. data/test/sites/ocean/users.yml +0 -13
  339. data/test/sites/zena/columns.yml +27 -5
  340. data/test/sites/zena/idx_projects.yml +5 -0
  341. data/test/sites/zena/nodes.yml +8 -32
  342. data/test/sites/zena/relations.yml +5 -0
  343. data/test/sites/zena/roles.yml +25 -3
  344. data/test/sites/zena/sites.yml +2 -2
  345. data/test/sites/zena/users.yml +1 -21
  346. data/test/sites/zena/versions.yml +35 -12
  347. data/test/test_helper.rb +7 -0
  348. data/test/unit/after_commit_test.rb +7 -7
  349. data/test/unit/cache_test.rb +32 -0
  350. data/test/unit/cached_page_test.rb +1 -1
  351. data/test/unit/column_test.rb +31 -7
  352. data/test/unit/comment_test.rb +2 -2
  353. data/test/unit/core_ext_test.rb +38 -7
  354. data/test/unit/document_test.rb +14 -42
  355. data/test/unit/node_test.rb +311 -324
  356. data/test/unit/note_test.rb +23 -31
  357. data/test/unit/page_test.rb +16 -58
  358. data/test/unit/project_test.rb +2 -2
  359. data/test/unit/relation_proxy_test.rb +148 -21
  360. data/test/unit/relation_test.rb +23 -3
  361. data/test/unit/remote_test.rb +15 -9
  362. data/test/unit/role_test.rb +9 -0
  363. data/test/unit/site_test.rb +49 -47
  364. data/test/unit/skin_test.rb +16 -0
  365. data/test/unit/template_test.rb +60 -69
  366. data/test/unit/text_document_test.rb +15 -14
  367. data/test/unit/user_test.rb +101 -41
  368. data/test/unit/version_test.rb +4 -4
  369. data/test/unit/virtual_class_test.rb +577 -36
  370. data/test/unit/workflow_test.rb +58 -21
  371. data/test/unit/zena/acts/enrollable_test.rb +36 -127
  372. data/test/unit/zena/acts/secure_test.rb +6 -22
  373. data/test/unit/zena/acts/serializable_test.rb +18 -0
  374. data/test/unit/zena/db_test.rb +14 -14
  375. data/test/unit/zena/parser/zafu.yml +5 -3
  376. data/test/unit/zena/use/ancestry_test.rb +198 -0
  377. data/test/unit/zena/use/calendar_test.rb +8 -8
  378. data/test/unit/zena/use/dates_test.rb +2 -0
  379. data/test/unit/zena/use/fulltext_test.rb +9 -1
  380. data/test/unit/zena/use/html_tags_test.rb +2 -16
  381. data/test/unit/zena/use/i18n_test.rb +2 -2
  382. data/test/unit/zena/use/kpath_test.rb +13 -0
  383. data/test/unit/zena/use/ml_index_test.rb +60 -12
  384. data/test/unit/zena/use/prop_eval_test.rb +170 -0
  385. data/test/unit/zena/use/query_node_test.rb +9 -2
  386. data/test/unit/zena/use/rendering_test.rb +98 -1
  387. data/test/unit/zena/use/scope_index_test.rb +464 -0
  388. data/test/unit/zena/use/urls_test.rb +23 -13
  389. data/test/unit/zena/use/version_hash_test.rb +2 -2
  390. data/test/unit/zena/use/zafu_template_test.rb +21 -8
  391. data/test/unit/zena/use/zazen_test.rb +47 -47
  392. data/zena.gemspec +177 -143
  393. metadata +222 -141
  394. data/app/models/base_contact.rb +0 -79
  395. data/app/models/book.rb +0 -242
  396. data/app/models/contact_content.rb +0 -70
  397. data/app/models/contact_version.rb +0 -40
  398. data/app/models/reference.rb +0 -18
  399. data/app/views/templates/edit_tabs/_basecontact.rhtml +0 -8
  400. data/bricks/data2pdf/README +0 -19
  401. data/bricks/data2pdf/VERSION +0 -1
  402. data/bricks/data2pdf/lib/data2pdf.rb +0 -60
  403. data/bricks/data2pdf/lib/engines/prince.rb +0 -39
  404. data/bricks/data2pdf/lib/engines/xhtml2pdf.rb +0 -41
  405. data/bricks/data2pdf/lib/install.rb +0 -111
  406. data/bricks/data2pdf/test/engines/test_prince.rb +0 -14
  407. data/bricks/data2pdf/test/engines/test_xhtml2pdf.rb +0 -14
  408. data/bricks/data2pdf/test/shoulda_macros/shoulda_data2pdf.rb +0 -91
  409. data/bricks/data2pdf/test/unit/test_rendering.rb +0 -37
  410. data/config/routes.rb +0 -3
  411. data/db/migrate/010_create_template_content.rb +0 -17
  412. data/db/migrate/024_correct_vclass_kpath.rb +0 -13
  413. data/db/migrate/025_move_tag_into_vclass.rb +0 -15
  414. data/lib/version_off.rb +0 -323
  415. data/lib/zena/use/node_name.rb +0 -94
  416. data/test/integration/query_node/properties.yml +0 -41
  417. data/test/unit/base_contact_test.rb +0 -242
  418. data/test/unit/node_name_test.rb +0 -137
@@ -51,8 +51,8 @@ module Zena
51
51
  set_context_var('recursion', @name, {:proc_name => proc_name, :klass => klass})
52
52
  depth = get_var_name('recursion', 'depth')
53
53
  out "<% #{proc_name} = Proc.new do |#{depth}, #{var}| %>"
54
- out "<% next if #{depth} > #{inc.params[:depth] ? [inc.params[:depth].to_i,30].min : 5} -%>"
55
- @recursion_call = "<% end -%><% #{proc_name}.call(0,#{node}) %>"
54
+ out "<% next if #{depth} > #{inc.params[:depth] ? [inc.params[:depth].to_i,30].min : 5} %>"
55
+ @recursion_call = "<% end %><% #{proc_name}.call(0,#{node}) %>"
56
56
  @context[:node] = node.move_to(var, node.klass)
57
57
  @var = nil # avoid reuse of our 'var' as new var name
58
58
  end
@@ -11,7 +11,8 @@ module Zena
11
11
  DUMMY = Class.new do
12
12
  def other_id; nil; end
13
13
  def other_ids; []; end
14
- def other_zids; []; end
14
+ def other_zips; []; end
15
+ def to_s; 'nil'; end
15
16
  end.new.freeze
16
17
 
17
18
  def initialize(node)
@@ -37,11 +38,21 @@ module Zena
37
38
  module ClassMethods
38
39
 
39
40
  # All relations related to the current class/virtual_class with its ancestors.
40
- def all_relations(start=nil)
41
- rel_as_source = RelationProxy.find(:all, :conditions => ["site_id = ? AND source_kpath IN (?)", current_site[:id], split_kpath])
42
- rel_as_target = RelationProxy.find(:all, :conditions => ["site_id = ? AND target_kpath IN (?)", current_site[:id], split_kpath])
43
- rel_as_source.each {|rel| rel.source = start } if start
44
- rel_as_target.each {|rel| rel.target = start } if start
41
+ def all_relations(start=nil, group_filter=nil)
42
+ if group_filter
43
+ group_filter = "#{group_filter}%"
44
+ rel_as_source = RelationProxy.find(:all,
45
+ :conditions => ["site_id = ? AND source_kpath IN (?) AND rel_group LIKE ?", current_site[:id], split_kpath, group_filter])
46
+ rel_as_target = RelationProxy.find(:all,
47
+ :conditions => ["site_id = ? AND target_kpath IN (?) AND rel_group LIKE ?", current_site[:id], split_kpath, group_filter])
48
+ else
49
+ rel_as_source = RelationProxy.find(:all,
50
+ :conditions => ["site_id = ? AND source_kpath IN (?)", current_site[:id], split_kpath])
51
+ rel_as_target = RelationProxy.find(:all,
52
+ :conditions => ["site_id = ? AND target_kpath IN (?)", current_site[:id], split_kpath])
53
+ end
54
+ rel_as_source.each {|rel| rel.source = start }
55
+ rel_as_target.each {|rel| rel.target = start }
45
56
  (rel_as_source + rel_as_target).sort {|a,b| a.other_role <=> b.other_role}
46
57
  end
47
58
 
@@ -156,8 +167,11 @@ module Zena
156
167
  # FIXME: this method does an 'update' not only 'add'
157
168
  def add_link(role, hash)
158
169
  if rel = relation_proxy(role)
159
- rel.other_id = hash[:other_id] if hash.has_key?(:other_id)
160
- rel.other_ids = hash[:other_ids] if hash.has_key?(:other_ids)
170
+ rel.qb = hash[:qb] if hash.has_key?(:qb)
171
+ rel.other_id = hash[:other_id] if hash.has_key?(:other_id)
172
+ rel.other_ids = hash[:other_ids] if hash.has_key?(:other_ids)
173
+ rel.other_zip = hash[:other_zip] if hash.has_key?(:other_zip)
174
+ rel.other_zips = hash[:other_zips] if hash.has_key?(:other_zips)
161
175
  LINK_ATTRIBUTES.each do |k|
162
176
  rel.send("other_#{k}=", hash[k]) if hash.has_key?(k)
163
177
  end
@@ -187,11 +201,15 @@ module Zena
187
201
  elsif role =~ /^(.+)_attributes$/
188
202
  # key used as role
189
203
  definition['role'] ||= $1
190
- else
204
+ elsif definition.kind_of?(Hash)
191
205
  # key used as role, without the '_attributes'
192
206
  definition['role'] ||= role
207
+ else
208
+ # qb
209
+ definition = {'role' => role, 'qb' => definition}
193
210
  end
194
- add_link(definition.delete('role'), definition.symbolize_keys) # TODO: only use string keys
211
+ # TODO: only use string keys
212
+ add_link(definition.delete('role'), definition.symbolize_keys)
195
213
  end
196
214
  end
197
215
 
@@ -283,9 +301,9 @@ module Zena
283
301
  # icon_comment:: get comment field for link to icon
284
302
  # icon_for_ids:: get all node ids for which the image is an icon
285
303
  # icon_for_zips:: get all node zips for which the image is an icon
286
- def method_missing(meth, *args)
304
+ def method_missing(meth, *args, &block)
287
305
  # first try rails' version of method missing
288
- super
306
+ super(meth, *args, &block)
289
307
  rescue NoMethodError => err
290
308
  # 1. is this a method related to a relation ?
291
309
  if meth.to_s =~ LINK_REGEXP
@@ -296,12 +314,6 @@ module Zena
296
314
  if rel = relation_proxy(role)
297
315
  if mode == '='
298
316
  # set
299
- case field
300
- when 'zip', 'zips'
301
- # not used to set relations (must use 'translate_attributes' to chagen zip into id before call)
302
- raise err
303
- end
304
- # set value
305
317
  rel.send("other_#{field}=", args[0])
306
318
  else
307
319
  # get
@@ -341,7 +353,7 @@ module Zena
341
353
  @relation_proxies.each do |role, rel|
342
354
  next unless rel
343
355
  unless rel.attributes_to_update_valid?
344
- errors.add(role, rel.link_errors.join(', '))
356
+ errors.add(role, rel.link_errors.map {|k,v| "#{k} => #{v}"}.join(', '))
345
357
  end
346
358
  end
347
359
  end
@@ -14,11 +14,15 @@ module Zena
14
14
  js
15
15
  end
16
16
  end
17
+
18
+ def set_headers(params)
19
+ zafu_headers.merge!(params)
20
+ end
17
21
  end
18
22
 
19
23
  module ControllerMethods
20
24
  def self.included(base)
21
- base.send(:helper_attr, :js_data)
25
+ base.send(:helper_attr, :js_data, :zafu_headers)
22
26
  base.send(:layout, false)
23
27
  end
24
28
 
@@ -26,6 +30,10 @@ module Zena
26
30
  @js_data ||= []
27
31
  end
28
32
 
33
+ def zafu_headers
34
+ @zafu_headers ||= {}
35
+ end
36
+
29
37
  # TODO: test
30
38
  # Our own handling of exceptions
31
39
  def rescue_action_in_public(exception)
@@ -98,42 +106,83 @@ module Zena
98
106
  opts = {:skin => @node[:skin], :cache => true}.merge(options)
99
107
  opts[:mode ] ||= params[:mode]
100
108
  opts[:format] ||= params[:format].blank? ? 'html' : params[:format]
109
+ #
101
110
  # cleanup before rendering
102
111
  params.delete(:mode)
103
112
  if opts[:format] != 'html'
104
- # Document data or special renderings.
105
- content_type = (Zena::EXT_TO_TYPE[opts[:format]] || ['application/octet-stream'])[0]
106
- template_path = template_url(opts)
107
- data = render_to_string(:file => template_path, :layout=>false)
108
- # TODO: use plugins...
109
- #if opts[:format] == 'pdf' && ((Zena::ENABLE_LATEX && data =~ /\A% (latex)\n/) || (Zena::ENABLE_FOP && data =~ /\A<\?(xml)/))
110
- # render_pdf($1 == 'xml' ? 'fop' : $1)
111
113
 
112
- if opts[:format] == 'pdf'
113
- Data2pdf.engine = 'Xhtml2pdf'
114
- disposition = params['disposition'] || 'inline'
115
- if params.keys.include?("debug")
116
- render :text => data
114
+ method = "render_to_#{opts[:format]}"
115
+ if params.keys.include?('debug')
116
+ template_path = template_url(opts)
117
+ result = {
118
+ :data => render_to_string(:file => template_path, :layout=>false),
119
+ :disposition => params['disposition'] || 'inline',
120
+ :type => 'text/html',
121
+ }
122
+ opts[:cache] = false
123
+ elsif respond_to?(method)
124
+ # Call custom rendering engine 'render_to_pdf' for example.
125
+ result = send(method, opts)
126
+ else
127
+ template_path = template_url(opts)
128
+ # FIXME: Use Mime types to resolve content type...
129
+ content_type = (Zena::EXT_TO_TYPE[opts[:format]] || ['application/octet-stream'])[0]
130
+ result = {
131
+ :data => render_to_string(:file => template_path, :layout=>false),
132
+ :disposition => 'inline',
133
+ :type => content_type,
134
+ :filename => @node.title
135
+ }
136
+ end
137
+
138
+ if result[:type] == 'text/html'
139
+ # error reporting from rendering engine
140
+ opts[:cache] = false
141
+ render :text => result[:data]
142
+ else
143
+ if zafu_headers
144
+ if disposition = zafu_headers.delete('Content-Disposition')
145
+ result.delete(:filename) if disposition =~ /filename\s*=/
146
+ result[:disposition] = disposition
147
+ end
148
+
149
+ if type = zafu_headers.delete('Content-Type')
150
+ result[:type] = type
151
+ end
152
+
153
+ if filename = zafu_headers.delete('filename')
154
+ result[:filename] = filename
155
+ end
156
+
157
+ headers.merge!(zafu_headers)
158
+ end
159
+
160
+ if data = result.delete(:data)
161
+ send_data(data , result)
162
+ elsif file = result.delete(:file)
163
+ send_file(file , result)
117
164
  else
118
- pdf = Data2pdf.render(data)
119
- send_data(pdf, :type=> 'application/pdf', :disposition=>disposition)
165
+ # Should never happen
166
+ raise Exception.new("Render '#{params[:format]}' should return either :file or :data (none found).")
120
167
  end
121
- else
122
- # send data inline
123
- filepath = nil
124
- send_data( data , :filename=>@node.title, :type => content_type, :disposition=>'inline')
125
168
  end
126
169
 
127
- cache_page(:content_data => data, :content_path => filepath) if opts[:cache]
170
+ cache_page(:content_data => result[:data], :content_path => result[:file]) if opts[:cache]
128
171
  else
129
172
  # html
130
173
  render :file => template_url(opts), :layout=>false, :status => opts[:status]
174
+ headers.merge!(zafu_headers)
131
175
  cache_page(:url => opts[:cache_url]) if opts[:cache]
132
176
  end
133
177
  end
134
178
 
135
179
  # Cache page content into a static file in the current sites directory : SITES_ROOT/test.host/public
136
180
  def cache_page(opts={})
181
+ if cachestamp_format?(params['format'])
182
+ headers['Expires'] = (Time.now + 365*24*3600).strftime("%a, %d %b %Y %H:%M:%S GMT")
183
+ headers['Cache-Control'] = (!current_site.authentication? && @node.public?) ? 'public' : 'private'
184
+ end
185
+
137
186
  return unless perform_caching && caching_allowed(:authenticated => opts.delete(:authenticated))
138
187
  url = page_cache_file(opts.delete(:url))
139
188
  opts = {:expire_after => nil,
@@ -142,10 +191,6 @@ module Zena
142
191
  :node_id => @node[:id]
143
192
  }.merge(opts)
144
193
  secure!(CachedPage) { CachedPage.create(opts) }
145
- if cachestamp_format?(params['format'])
146
- headers['Expires'] = (Time.now + 365*24*3600).strftime("%a, %d %b %Y %H:%M:%S GMT")
147
- headers['Cache-Control'] = 'public'
148
- end
149
194
  end
150
195
 
151
196
  # Return true if we can cache the current page
@@ -160,6 +205,9 @@ module Zena
160
205
  path = ((path.empty? || path == "/") ? "/index" : URI.unescape(path))
161
206
  ext = params[:format].blank? ? 'html' : params[:format]
162
207
  path << ".#{ext}" unless path =~ /\.#{ext}(\?\d+|)$/
208
+ #
209
+ # QUERY_STRING in cached page ?
210
+ #
163
211
  # Do not cache filename with query or apache will not see it !
164
212
  # if cachestamp_format?(params['format'])
165
213
  # path << "?" << make_cachestamp(@node, params['mode'])
@@ -180,114 +228,56 @@ module Zena
180
228
  template_url(:mode=>'+popupLayout')
181
229
  end
182
230
 
231
+ # Return the window title to use.
232
+ def title_for_layout
233
+ return '' unless @node
234
+ @node.title + (@node.kind_of?(Document) ? ".#{@node.ext}" : '')
235
+ end
236
+
183
237
  # Use the current visitor as master node.
184
238
  def visitor_node
185
- @node = visitor.contact
186
- zafu_node('@node', BaseContact)
239
+ @node = visitor.node
240
+ zafu_node('@node', Node)
187
241
  end
188
242
 
189
- def render_pdf(rendering_egine)
190
- # 1. find cached PDF. If found, send data.
191
- if @node[:user_id] == visitor[:id]
192
- # owner
193
- filename = "u#{@node[:user_id]}.pdf"
194
- else
195
- # group
196
- filename = "g#{@node[:rgroup_id]}.pdf"
197
- end
198
- filepath = @node.asset_path(filename)
199
- if File.exist?(filepath)
200
- # ok send data
201
- data = File.read(filepath)
202
- send_data( data , :filename=>@node.title, :type => content_type, :disposition=>'inline')
203
- else
204
- # generate pdf
205
- FileUtils::mkpath(File.dirname(filepath)) unless File.exist?(File.dirname(filepath))
206
-
207
- tempf = Tempfile.new("#{@node[:id]}_#{@node.version.lang}")
208
- pdf_path = "#{tempf.path}.pdf"
209
- failure = nil
210
- case rendering_egine
211
- when 'latex'
212
- # Parse data to produce LateX
213
- data = data.gsub(/\\input/,'input not supported')
214
- data = data.gsub(/\\includegraphics(\*|)(\[[^\{]*\]|)\{([^\}]*?)(\.(\w+)|)\}/) do
215
- cmd_name = "includegraphics#{$1}"
216
- img_opts = $2
217
- img_id = $3
218
- img_mode = $5
219
- if id = Node.translate_pseudo_id(img_id)
220
- img = secure(Image) { Image.find_by_id(id) }
221
- if img
222
- if img_mode
223
- format = Iformat[img_mode]
224
- img_path = img.filepath(format)
225
- if !File.exists?(img_path)
226
- img_file = img.file(format) # force rendering of image
227
- img_file.close
228
- end
229
- else
230
- img_path = img.filepath(nil)
231
- end
232
- end
233
- "\\includegraphics#{img_opts}{#{img_path}}"
234
- else
235
- "(image '#{img_id}' not found)"
236
- end
237
- end
238
-
239
- tempf = Tempfile.new("#{@node[:id]}_#{@node.version.lang}")
240
- tex_path = "#{tempf.path}.tex"
241
- pdf_path = "#{tempf.path}.pdf"
242
- File.open(tex_path, 'wb') { |f| f.syswrite(data) }
243
- if !system("pdflatex -halt-on-error -output-directory '#{File.dirname(tex_path)}' '#{tex_path}' &> '#{tempf.path}'")
244
- failure = tempf.read
245
- end
246
- when 'fop'
247
- # FOP rendering
248
- xml_path = "#{tempf.path}.xml"
249
- fo_path = "#{tempf.path}.fo"
250
-
251
- # write xml to file
252
- File.open(xml_path, 'wb') { |f| f.syswrite(data) }
253
-
254
- # find stylesheet path is in the zafu folder
255
- xsl_path = template_path.sub(/\.erb\Z/,'.xsl')
256
- raise Excpetion.new("xsl content not found #{xsl_path.inspect} while rendering #{template_path.inspect} (node #{@node[:id]})") unless File.exist?(xsl_path)
257
-
258
- # run xsl with 'xml' content and stylesheet ==> 'xsl-fo' file
259
- if !system("xsltproc -o '#{fo_path}' '#{xsl_path}' '#{xml_path}' &> '#{tempf.path}'")
260
- failure = tempf.read
243
+ private
244
+ # This is called before rendering for special formats (pdf) in order to rewrite
245
+ # urls to localhost (the rendering engine is external to Zena and will need to
246
+ # make calls to get assets).
247
+ def baseurl
248
+ if Zena::ASSET_PORT
249
+ if Zena::ASSET_PORT == request.port
250
+ raise Exception.new("Custom rendering not allowed on this process (port == asset_port).")
261
251
  else
262
- # run fop ==> PDF
263
- if !system("fop '#{fo_path}' '#{pdf_path}' &> '#{tempf.path}'")
264
- failure = tempf.read
265
- end
252
+ "http://localhost:#{Zena::ASSET_PORT}"
266
253
  end
267
- end
268
-
269
- if !failure
270
- if data =~ /<!-- xsl_id:(\d+)/
271
- # make sure changes in xsl stylesheet expires cached PDF
272
- expire_with_ids = visitor.visited_node_ids + [$1.to_i]
273
- else
274
- expire_with_ids = visitor.visited_node_ids
275
- end
276
-
277
- data = File.read(pdf_path)
278
- # cache pdf data
279
- filepath = filepath[(SITES_ROOT.size)..-1]
280
- secure!(CachedPage) { CachedPage.create(:expire_after => nil, :path => filepath, :content_data => data, :node_id => @node[:id], :expire_with_ids => expire_with_ids) }
281
- send_data( data , :filename=>@node.title, :type => content_type, :disposition=>'inline')
282
254
  else
283
- # failure: send log
284
- send_data( failure , :filename=>"#{@node.title} - error", :type => 'text/plain', :disposition=>'inline')
255
+ raise Exception.new("Using custom rendering without an asset host ('asset_port' setting in bricks.yml).")
285
256
  end
286
- #system("rm -rf #{tempf.path.inspect} #{(tempf.path + '.*').inspect}")
287
257
  end
288
- end
289
258
 
259
+ def get_render_auth_params
260
+ {
261
+ :http_user => visitor.id,
262
+ :http_password => visitor.persistence_token,
263
+ :baseurl => baseurl
264
+ }
265
+ end
290
266
  end # ControllerMethods
267
+
268
+ module ZafuMethods
269
+ def r_headers
270
+ headers = []
271
+ @params.each do |k, v|
272
+ headers << "#{k.to_s.inspect} => #{RubyLess.translate_string(self, v)}"
273
+ end
274
+ if headers.empty?
275
+ out ""
276
+ else
277
+ out "<% set_headers(#{headers.join(', ')}) %>"
278
+ end
279
+ end
280
+ end # ZafuMethods
291
281
  end # Rendering
292
282
  end # Use
293
283
  end # Zena
@@ -0,0 +1,230 @@
1
+ module Zena
2
+ module Use
3
+ module ScopeIndex
4
+ AVAILABLE_MODELS = []
5
+
6
+ def self.models_for_form
7
+ [''] + AVAILABLE_MODELS.map(&:to_s)
8
+ end
9
+
10
+ module VirtualClassMethods
11
+ def self.included(base)
12
+ base.validate :validate_idx_class, :validate_idx_scope
13
+ base.attr_accessible :idx_class
14
+ base.attr_accessible :idx_scope
15
+ end
16
+
17
+ protected
18
+ def validate_idx_class
19
+ self[:idx_class] = nil if self[:idx_class].blank?
20
+
21
+ if model_name = self[:idx_class]
22
+ if model_name =~ /\A[A-Z][a-zA-Z]+\Z/
23
+ if klass = Zena.const_get(model_name) rescue NilClass
24
+ if klass < Zena::Use::ScopeIndex::IndexMethods
25
+ # ok
26
+ else
27
+ errors.add('idx_class', 'invalid class (should include ScopeIndex::IndexMethods)')
28
+ end
29
+ else
30
+ errors.add('idx_class', 'invalid class')
31
+ end
32
+ else
33
+ errors.add('idx_class', 'invalid class name')
34
+ end
35
+ end
36
+ end
37
+
38
+ def validate_idx_scope
39
+ self[:idx_scope] = nil if self[:idx_scope].blank?
40
+ if scopes = self[:idx_scope]
41
+ # Try to compile query in instance of class self
42
+ begin
43
+ scopes = new_instance.safe_eval self[:idx_scope]
44
+ if scopes.kind_of?(Hash)
45
+ scopes.each do |keys, query|
46
+ unless keys.kind_of?(String) &&
47
+ (
48
+ query.kind_of?(String) ||
49
+ (query.kind_of?(Array) && query.inject(true){|s,k| s && k.kind_of?(String)}))
50
+ errors.add('idx_scope', "Invalid entry: keys should be a String and query should be a String or an Array of strings (#{keys.inspect} => #{query.inspect})")
51
+ next
52
+ end
53
+ begin
54
+ Array(query).each do |q|
55
+ real_class.build_query(:all, q,
56
+ :node_name => 'self',
57
+ :main_class => self,
58
+ :rubyless_helper => self
59
+ )
60
+ end
61
+ rescue ::QueryBuilder::Error => err
62
+ errors.add('idx_scope', "Invalid query: #{err.message}")
63
+ end
64
+ end
65
+ else
66
+ errors.add('idx_scope', "Invalid type: should be a hash.")
67
+ end
68
+ rescue ::RubyLess::Error => err
69
+ errors.add('idx_scope', "Invalid rubyless: #{err.message}")
70
+ end
71
+ end
72
+ end
73
+ end # VirtualClassMethods
74
+
75
+ module IndexMethods
76
+ def self.included(base)
77
+ AVAILABLE_MODELS << base
78
+
79
+ class << base
80
+ attr_accessor :groups
81
+ end
82
+
83
+ base.class_eval do
84
+ include RubyLess
85
+ before_validation :set_site_id
86
+ validates_presence_of :node_id
87
+ end
88
+
89
+ groups = base.groups = {}
90
+ base.column_names.each do |name|
91
+ next if %{created_at updated_at id node_id site_id}.include?(name)
92
+ if name =~ %r{\A([^_]+)_(.+)\Z}
93
+ (groups[$1] ||= []) << $2
94
+ unless $2 == 'id'
95
+ base.safe_attribute name
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ # The given node has been updated in the owner's project. Update index
102
+ # entries with this node's content if necessary.
103
+ def update_with(node, keys, force_create = false)
104
+ attrs = {}
105
+ prop_column_names = node.schema.column_names
106
+ groups = self.class.groups
107
+ keys.each do |group_key|
108
+ next unless list = groups[group_key]
109
+ next unless should_update_group?(group_key, node)
110
+ list.each do |key|
111
+ if prop_column_names.include?(key)
112
+ attrs["#{group_key}_#{key}"] = node.prop[key]
113
+ elsif node.respond_to?(key)
114
+ attrs["#{group_key}_#{key}"] = node.send(key)
115
+ end
116
+ end
117
+ end
118
+
119
+ if !attrs.empty? || force_create
120
+ self.attributes = attrs
121
+ save
122
+ end
123
+ end
124
+
125
+ # Return true if the indices from the given group should be altered by the node.
126
+ def should_update_group?(group_key, node)
127
+ node.id >= self["#{group_key}_id"].to_i
128
+ end
129
+
130
+ def set_site_id
131
+ self[:site_id] = current_site.id
132
+ end
133
+ end # ModelMethods
134
+
135
+ module ModelMethods
136
+ def self.included(base)
137
+ base.after_save :update_scope_indices
138
+ base.safe_context :scope_index => scope_index_proc
139
+ base.alias_method_chain :rebuild_index!, :scope_index
140
+ end
141
+
142
+ def self.scope_index_proc
143
+ Proc.new do |helper, receiver, signature|
144
+ if receiver.respond_to?('idx_class') && receiver.idx_class && klass = Zena.resolve_const(receiver.idx_class) rescue nil
145
+ {:method => 'scope_index', :nil => true, :class => klass}
146
+ else
147
+ raise RubyLess::NoMethodError.new(receiver, receiver, signature)
148
+ end
149
+ end
150
+ end
151
+
152
+ # FIXME: test !
153
+ def rebuild_index_with_scope_index!
154
+ rebuild_index_without_scope_index!
155
+ update_scope_indices
156
+ end
157
+
158
+ # Access the index model inside the Project or Section.
159
+ def scope_index
160
+ @scope_index ||= begin
161
+ vclass = virtual_class
162
+ if vclass && klass = vclass.idx_class
163
+ if klass = Zena.resolve_const(klass) rescue nil
164
+ klass.find(:first, :conditions => {:node_id => self.id, :site_id => current_site.id}) || klass.new(:node_id => self.id)
165
+ else
166
+ nil
167
+ end
168
+ else
169
+ nil
170
+ end
171
+ end
172
+ end
173
+
174
+ protected
175
+ # Update scope indices (project/section).
176
+ def update_scope_indices
177
+ return unless version.status == Zena::Status[:pub]
178
+ update_scope_indices_on_prop_change
179
+ update_scope_indices_on_link_change
180
+ rescue ::QueryBuilder::Error
181
+ # log and ignore: we cannot recover here ?
182
+ # FIXME: raise when we have transactional save.
183
+ end
184
+
185
+ def update_scope_indices_on_prop_change
186
+ if virtual_class && scopes = virtual_class.idx_scope
187
+ scopes = safe_eval(scopes)
188
+ return unless scopes.kind_of?(Hash)
189
+ mapped_scopes = []
190
+ scopes.each do |keys, queries|
191
+ # Change key ('project,contract') to an array
192
+ keys = keys.split(',').map(&:strip) if keys.kind_of?(String)
193
+ Array(queries).each do |query|
194
+ mapped_scopes << [keys, query]
195
+ end
196
+ end
197
+
198
+ mapped_scopes.each do |keys, query|
199
+ next unless query.kind_of?(String) && keys.kind_of?(Array) && keys.inject(true) {|s,k| s && k.kind_of?(String) }
200
+ if query.strip == 'self'
201
+ models_to_update = [self]
202
+ else
203
+ models_to_update = find(:all, query) || []
204
+ end
205
+
206
+ models_to_update.each do |m|
207
+ if idx_model = m.scope_index
208
+ # force creation of index record
209
+ idx_model.update_with(self, keys, true)
210
+ end
211
+ end
212
+ end
213
+ end
214
+ end
215
+
216
+ def update_scope_indices_on_link_change
217
+ (@relation_proxies || {}).values.compact.each do |rel|
218
+ if add_links = rel.add_links
219
+ add_links.each do |hash|
220
+ if node = hash[:node]
221
+ node.update_scope_indices
222
+ end
223
+ end
224
+ end
225
+ end
226
+ end
227
+ end # ModelMethods
228
+ end # ScopeIndex
229
+ end # Acts
230
+ end # Zena