zena 0.15.2 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (284) hide show
  1. data/.gitignore +20 -0
  2. data/CREDITS +27 -0
  3. data/Capfile +3 -0
  4. data/DEVELOPERS +46 -0
  5. data/History.txt +15 -0
  6. data/MIT-LICENSE +19 -0
  7. data/Rakefile +44 -0
  8. data/TODO +24 -0
  9. data/TODO_ZENA_1_0 +23 -0
  10. data/app/controllers/application_controller.rb +3 -0
  11. data/app/controllers/documents_controller.rb +22 -56
  12. data/app/controllers/nodes_controller.rb +42 -27
  13. data/app/controllers/pings_controller.rb +19 -0
  14. data/app/controllers/relations_controller.rb +5 -1
  15. data/app/controllers/sites_controller.rb +1 -46
  16. data/app/controllers/user_sessions_controller.rb +47 -0
  17. data/app/controllers/users_controller.rb +1 -0
  18. data/app/controllers/versions_controller.rb +25 -7
  19. data/app/controllers/virtual_classes_controller.rb +1 -1
  20. data/app/helpers/application_helper.rb +1 -1
  21. data/app/models/comment.rb +2 -1
  22. data/app/models/contact_content.rb +2 -2
  23. data/app/models/data_entry.rb +5 -6
  24. data/app/models/document.rb +14 -10
  25. data/app/models/document_content.rb +4 -6
  26. data/app/models/iformat.rb +2 -2
  27. data/app/models/image_content.rb +6 -9
  28. data/app/models/node.rb +106 -164
  29. data/app/models/page.rb +0 -20
  30. data/app/models/site.rb +42 -12
  31. data/app/models/template.rb +3 -8
  32. data/app/models/template_content.rb +2 -0
  33. data/app/models/text_document.rb +13 -8
  34. data/app/models/user.rb +47 -100
  35. data/app/models/user_session.rb +4 -0
  36. data/app/models/version.rb +1 -1
  37. data/app/views/comments/create.rjs +3 -3
  38. data/app/views/comments/edit.rjs +1 -1
  39. data/app/views/comments/update.rjs +1 -1
  40. data/app/views/nodes/_import_results.rhtml +1 -1
  41. data/app/views/nodes/create.rjs +3 -3
  42. data/app/views/templates/document_create_tabs/_file.rhtml +1 -2
  43. data/app/views/templates/document_create_tabs/_import.rhtml +7 -2
  44. data/app/views/templates/edit_tabs/_document.rhtml +1 -3
  45. data/app/views/templates/edit_tabs/_image.rhtml +1 -3
  46. data/app/views/versions/_tr.rhtml +1 -1
  47. data/app/views/versions/edit.rhtml +2 -26
  48. data/bin/zena +6 -1
  49. data/bricks/delayed_job/README +18 -0
  50. data/bricks/delayed_job/migrate/20091104191643_create_delayed_jobs_table.rb +19 -0
  51. data/bricks/delayed_job/misc/init.rb +8 -0
  52. data/bricks/delayed_job/misc/tasks.rb +2 -0
  53. data/bricks/math/patch/application_helper.rb +1 -1
  54. data/bricks/sphinx/MIT-LICENSE +19 -0
  55. data/bricks/sphinx/README +19 -0
  56. data/bricks/sphinx/lib/use_sphinx.rb +78 -0
  57. data/bricks/sphinx/migrate/20091102171258_add_delta_for_sphinx.rb +9 -0
  58. data/bricks/sphinx/misc/deploy.rb +20 -0
  59. data/bricks/sphinx/misc/sphinx.yml +12 -0
  60. data/bricks/sphinx/misc/tasks.rb +21 -0
  61. data/bricks/sphinx/patch/node.rb +8 -0
  62. data/bricks/tags/lib/has_tags.rb +5 -3
  63. data/bricks/tags/test/zafu/tags.yml +13 -1
  64. data/config/bricks.yml +35 -0
  65. data/config/deploy.rb +8 -1
  66. data/config/environment.rb +1 -1
  67. data/config/environments/production.rb +1 -1
  68. data/config/gems.yml +28 -5
  69. data/config/sphinx.yml +12 -0
  70. data/db/init/base/skins/default/Node-+popupLayout.zafu +1 -16
  71. data/db/migrate/20091026161708_add_persistence_token.rb +13 -0
  72. data/db/migrate/20091101184952_add_session_table.rb +16 -0
  73. data/db/migrate/20091123175137_add_single_access_token.rb +9 -0
  74. data/db/migrate/20091124161608_rebuild_fullpath.rb +11 -0
  75. data/db/schema.rb +21 -8
  76. data/doc/README_FOR_APP +24 -0
  77. data/doc/fixtures.graffle +19568 -0
  78. data/doc/fixtures.pdf +0 -0
  79. data/doc/template/LICENSE +184 -0
  80. data/doc/template/README +37 -0
  81. data/doc/template/allison.css +283 -0
  82. data/doc/template/allison.js +307 -0
  83. data/doc/template/allison.rb +260 -0
  84. data/doc/template/cache/BODY +588 -0
  85. data/doc/template/cache/CLASS_INDEX +4 -0
  86. data/doc/template/cache/CLASS_PAGE +1 -0
  87. data/doc/template/cache/FILE_INDEX +4 -0
  88. data/doc/template/cache/FILE_PAGE +1 -0
  89. data/doc/template/cache/FONTS +1 -0
  90. data/doc/template/cache/FR_INDEX_BODY +1 -0
  91. data/doc/template/cache/IMGPATH +1 -0
  92. data/doc/template/cache/INDEX +1 -0
  93. data/doc/template/cache/JAVASCRIPT +307 -0
  94. data/doc/template/cache/METHOD_INDEX +4 -0
  95. data/doc/template/cache/METHOD_LIST +1 -0
  96. data/doc/template/cache/SRC_PAGE +1 -0
  97. data/doc/template/cache/STYLE +283 -0
  98. data/doc/template/cache/URL +1 -0
  99. data/doc/zafu_changes.yml +29 -0
  100. data/lib/base_additions.rb +1 -1
  101. data/lib/bricks.rb +9 -0
  102. data/lib/bricks/loader.rb +86 -0
  103. data/lib/bricks/requirements_validation.rb +71 -0
  104. data/lib/tasks/zena.rake +42 -4
  105. data/lib/zafu/action.rb +285 -0
  106. data/lib/zafu/ajax.rb +93 -0
  107. data/lib/zafu/attributes.rb +117 -0
  108. data/lib/zafu/calendar.rb +159 -0
  109. data/lib/zafu/context.rb +330 -0
  110. data/lib/zafu/core/html.rb +102 -0
  111. data/lib/zafu/core/move_to_parser.rb +167 -0
  112. data/lib/zafu/dates.rb +58 -0
  113. data/lib/zafu/display.rb +502 -0
  114. data/lib/zafu/eval.rb +66 -0
  115. data/lib/zafu/experimental.rb +66 -0
  116. data/lib/zafu/i18n.rb +64 -0
  117. data/lib/zafu/meta.rb +25 -0
  118. data/lib/zafu/refactor.rb +73 -0
  119. data/lib/zafu/support/context.rb +265 -0
  120. data/lib/zafu/support/dom.rb +145 -0
  121. data/lib/zafu/support/erb.rb +62 -0
  122. data/lib/zafu/support/flow.rb +401 -0
  123. data/lib/zafu/support/forms.rb +461 -0
  124. data/lib/zafu/support/links.rb +306 -0
  125. data/lib/zafu_parser.rb +26 -2
  126. data/lib/zena.rb +34 -15
  127. data/lib/zena/acts/multiversion.rb +2 -2
  128. data/lib/zena/acts/secure.rb +41 -30
  129. data/lib/zena/app.rb +7 -10
  130. data/lib/zena/controller/test_case.rb +12 -7
  131. data/lib/zena/crypto_provider/initial.rb +15 -0
  132. data/lib/zena/db.rb +6 -1
  133. data/lib/zena/deploy.rb +34 -6
  134. data/lib/zena/deploy/logrotate_app.rhtml +9 -0
  135. data/lib/zena/deploy/logrotate_host.rhtml +34 -0
  136. data/lib/zena/deploy/template.rb +1 -9
  137. data/lib/zena/foxy_parser.rb +1 -1
  138. data/lib/zena/info.rb +3 -1
  139. data/lib/zena/migrator.rb +1 -1
  140. data/lib/zena/parser.rb +12 -4
  141. data/lib/zena/parser/zazen_rules.rb +6 -6
  142. data/lib/zena/parser/zena_rules.rb +1 -7
  143. data/lib/zena/routes.rb +5 -5
  144. data/lib/zena/test_controller.rb +7 -2
  145. data/lib/zena/unit/test_case.rb +6 -8
  146. data/lib/zena/use/ajax.rb +10 -10
  147. data/lib/zena/use/authlogic.rb +93 -0
  148. data/lib/zena/use/dyn_attributes.rb +5 -0
  149. data/lib/zena/use/html_tags.rb +16 -34
  150. data/lib/zena/use/i18n.rb +4 -1
  151. data/lib/zena/use/node_query_finders.rb +8 -4
  152. data/lib/zena/use/refactor.rb +8 -20
  153. data/lib/zena/use/relations.rb +1 -0
  154. data/lib/zena/use/rendering.rb +4 -2
  155. data/lib/zena/use/search.rb +52 -0
  156. data/lib/zena/use/test_helper.rb +27 -28
  157. data/lib/zena/use/upload.rb +188 -0
  158. data/lib/zena/use/urls.rb +16 -14
  159. data/lib/zena/use/zafu.rb +16 -63
  160. data/lib/zena/use/zazen.rb +8 -8
  161. data/lib/zena/view/test_case.rb +8 -4
  162. data/locale/en/LC_MESSAGES/zena.mo +0 -0
  163. data/locale/en/zena.po +3 -3
  164. data/public/.htaccess +40 -0
  165. data/public/javascripts/upload-progress.js +17 -8
  166. data/public/javascripts/zena.js +8 -2
  167. data/public/stylesheets/popup.css +1 -0
  168. data/script/about +3 -0
  169. data/script/apache_logging +25 -0
  170. data/script/breakpointer +3 -0
  171. data/script/console +3 -0
  172. data/script/dbconsole +3 -0
  173. data/script/destroy +3 -0
  174. data/script/generate +3 -0
  175. data/script/performance/benchmarker +3 -0
  176. data/script/performance/profiler +3 -0
  177. data/script/plugin +3 -0
  178. data/script/process/inspector +3 -0
  179. data/script/process/reaper +3 -0
  180. data/script/process/spawner +3 -0
  181. data/script/runner +3 -0
  182. data/script/server +3 -0
  183. data/script/set_revision +29 -0
  184. data/spec/controllers/versions_controller_spec.rb +11 -0
  185. data/test/fixtures/files/Node-test.zafu +1 -1
  186. data/test/functional/nodes_controller_test.rb +25 -0
  187. data/test/functional/pings_controller_test.rb +8 -0
  188. data/test/functional/user_sessions_controller_test.rb +59 -0
  189. data/test/functional/users_controller_test.rb +81 -19
  190. data/test/helpers/node_query/filters.yml +5 -0
  191. data/test/helpers/node_query_test.rb +3 -3
  192. data/test/integration/multiple_hosts_test.rb +1 -1
  193. data/test/integration/navigation_test.rb +1 -1
  194. data/test/sites/complex/users.yml +1 -1
  195. data/test/sites/ocean/users.yml +3 -3
  196. data/test/sites/zena/users.yml +5 -4
  197. data/test/test_zena.rb +38 -38
  198. data/test/unit/cached_page_test.rb +2 -2
  199. data/test/unit/comment_test.rb +0 -1
  200. data/test/unit/document_test.rb +23 -11
  201. data/test/unit/helpers/ping_helper_test.rb +4 -0
  202. data/test/unit/multiversion_test.rb +24 -16
  203. data/test/unit/node_test.rb +32 -93
  204. data/test/unit/note_test.rb +9 -0
  205. data/test/unit/page_test.rb +2 -2
  206. data/test/unit/secure_test.rb +2 -12
  207. data/test/unit/site_test.rb +43 -24
  208. data/test/unit/template_test.rb +45 -3
  209. data/test/unit/text_document_test.rb +4 -3
  210. data/test/unit/user_test.rb +13 -33
  211. data/test/unit/zena/db_test.rb +8 -0
  212. data/test/unit/zena/parser/zazen.yml +4 -4
  213. data/test/unit/zena/use/dates_view_methods_test.rb +2 -1
  214. data/test/unit/zena/use/html_tags_test.rb +12 -4
  215. data/test/unit/zena/use/refactor_test.rb +4 -3
  216. data/test/unit/zena/use/rendering_test.rb +1 -0
  217. data/test/unit/zena/use/upload_test.rb +76 -0
  218. data/test/unit/zena/use/urls_test.rb +4 -0
  219. data/test/unit/zena/use/zafu_test.rb +8 -0
  220. data/test/unit/zena/workflow/status_version_test.rb +6 -0
  221. data/test/unit/zena/zena_tags/ajax.yml +4 -4
  222. data/test/unit/zena/zena_tags/basic.yml +21 -10
  223. data/test/unit/zena/zena_tags/relations.yml +0 -6
  224. data/test/unit/zena/zena_tags/rubyless.yml +35 -0
  225. data/test/unit/zena/zena_tags/zazen.yml +4 -4
  226. data/test/unit/zena/zena_tags_test.rb +36 -4
  227. data/vendor/TextMate/Zena.tmbundle/Commands/Run all yaml tests.tmCommand +1 -1
  228. data/vendor/TextMate/Zena.tmbundle/Commands/Run focused yaml test.tmCommand +2 -3
  229. data/vendor/TextMate/Zena.tmbundle/Support/RubyMate/catch_exception.rb +39 -0
  230. data/vendor/TextMate/Zena.tmbundle/Support/RubyMate/run_script.rb +102 -58
  231. data/vendor/TextMate/Zena.tmbundle/Support/RubyMate/stdin_dialog.rb +14 -0
  232. data/vendor/TextMate/Zena.tmbundle/info.plist +2 -0
  233. data/zena.gemspec +2085 -0
  234. metadata +265 -90
  235. data/app/controllers/sessions_controller.rb +0 -41
  236. data/app/views/sites/zena_up.html.erb +0 -11
  237. data/config/database.yml +0 -40
  238. data/db/production.sqlite3 +0 -0
  239. data/lib/bricks/patcher.rb +0 -68
  240. data/lib/zena/parser/zena_tags.rb +0 -3562
  241. data/lib/zena/use/authentification.rb +0 -120
  242. data/public/images/ext/contact_pv.png +0 -0
  243. data/public/images/ext/other_pv.png +0 -0
  244. data/public/images/ext/page_pv.png +0 -0
  245. data/public/images/ext/page_tiny.png +0 -0
  246. data/public/images/ext/pdf_pv.png +0 -0
  247. data/public/images/ext/post_pv.png +0 -0
  248. data/public/images/ext/post_tiny.png +0 -0
  249. data/public/images/ext/project_pv.png +0 -0
  250. data/public/images/ext/project_tiny.png +0 -0
  251. data/public/images/ext/tag_pv.png +0 -0
  252. data/public/images/ext/zip_pv.png +0 -0
  253. data/tasks/ann.rake +0 -80
  254. data/tasks/bones.rake +0 -20
  255. data/tasks/gem.rake +0 -201
  256. data/tasks/git.rake +0 -40
  257. data/tasks/notes.rake +0 -27
  258. data/tasks/post_load.rake +0 -34
  259. data/tasks/rdoc.rake +0 -51
  260. data/tasks/rubyforge.rake +0 -55
  261. data/tasks/setup.rb +0 -292
  262. data/tasks/spec.rake +0 -54
  263. data/tasks/svn.rake +0 -47
  264. data/tasks/test.rake +0 -40
  265. data/tasks/zentest.rake +0 -36
  266. data/test/fixtures/comments.yml +0 -126
  267. data/test/fixtures/contact_contents.yml +0 -132
  268. data/test/fixtures/data_entries.yml +0 -65
  269. data/test/fixtures/discussions.yml +0 -48
  270. data/test/fixtures/document_contents.yml +0 -108
  271. data/test/fixtures/dyn_attributes.yml +0 -66
  272. data/test/fixtures/groups.yml +0 -86
  273. data/test/fixtures/groups_users.yml +0 -81
  274. data/test/fixtures/iformats.yml +0 -29
  275. data/test/fixtures/links.yml +0 -313
  276. data/test/fixtures/nodes.yml +0 -2592
  277. data/test/fixtures/relations.yml +0 -126
  278. data/test/fixtures/sites.yml +0 -58
  279. data/test/fixtures/template_contents.yml +0 -172
  280. data/test/fixtures/users.yml +0 -167
  281. data/test/fixtures/versions.yml +0 -1911
  282. data/test/fixtures/virtual_classes.yml +0 -87
  283. data/test/fixtures/zips.yml +0 -15
  284. data/test/functional/sessions_controller_test.rb +0 -73
@@ -189,7 +189,7 @@ module Zena
189
189
 
190
190
  # VERSION
191
191
  def version=(v)
192
- if v.kind_of?(Version)
192
+ if v.kind_of?(Version) && !v.frozen? # TODO: remove !v.frozen? and find why this is loaded during template destroy
193
193
  v.node = self
194
194
  @version = v
195
195
  end
@@ -676,7 +676,7 @@ module Zena
676
676
  redaction_error(meth.to_s[0..-2], "could not be set (no redaction)")
677
677
  return
678
678
  end
679
-
679
+
680
680
  case target
681
681
  when 'c_'
682
682
  if recipient.content_class && recipient = recipient.redaction_content
@@ -104,7 +104,8 @@ Just doing the above will filter all result according to the logged in user.
104
104
  # we move all before_validation on update and create here so that it is triggered before multiversion's before_validation
105
105
  before_validation :secure_before_validation
106
106
 
107
- validate {|r| r.errors.add(:base, 'record not secured') unless r.instance_variable_get(:@visitor) }
107
+ validate :record_must_be_secured
108
+ #validate {|r| r.errors.add(:base, 'record not secured') unless r.instance_variable_get(:@visitor)}
108
109
  validate_on_update {|r| r.errors.add('site_id', 'cannot change') if r.site_id_changed? }
109
110
 
110
111
  validate_on_create :secure_on_create
@@ -121,6 +122,10 @@ Just doing the above will filter all result according to the logged in user.
121
122
 
122
123
  module InstanceMethods
123
124
 
125
+ def record_must_be_secured
126
+ errors.add(:base, 'record not secured') unless @visitor == Thread.current[:visitor]
127
+ end
128
+
124
129
  # Store visitor to produce scope when needed and to retrieve correct editions.
125
130
  def visitor=(visitor)
126
131
  @visitor = visitor
@@ -276,6 +281,7 @@ Just doing the above will filter all result according to the logged in user.
276
281
  else
277
282
  errors.add(:inherit, "bad inheritance mode")
278
283
  end
284
+
279
285
  end
280
286
 
281
287
  # 1. if dgroup changed from old, make sure user could do this and new group is valid
@@ -553,7 +559,7 @@ Just doing the above will filter all result according to the logged in user.
553
559
 
554
560
  # Set current visitor
555
561
  def visitor=(visitor)
556
- @visitor = visitor
562
+ Thread.current[:visitor] = visitor
557
563
  end
558
564
 
559
565
  # Secure scope for read access
@@ -571,17 +577,16 @@ Just doing the above will filter all result according to the logged in user.
571
577
  end
572
578
 
573
579
  def secure_write_scope
574
- if visitor.is_su? # super user
575
- "site_id = #{visitor.site.id}"
576
- else
577
- "site_id = #{visitor.site.id} AND wgroup_id IN (#{visitor.group_ids.join(',')})"
578
- end
580
+ scope = {:nodes => {:site_id => visitor.site[:id]}}
581
+ scope[:nodes] = {:wgroup_id => visitor.group_ids} unless visitor.is_su?
582
+ scope
579
583
  end
580
584
 
581
585
  # these methods are not actions that can be called from the web !!
582
586
  protected
583
587
  # secure find with scope (for read/write or publish access).
584
588
  def secure_with_scope(klass, node_find_scope)
589
+
585
590
  if ((klass.send(:scoped_methods)[0] || {})[:create] || {})[:visitor]
586
591
  # we are already in secure scope: this scope is the new 'exclusive' scope.
587
592
  last_scope = klass.send(:scoped_methods).shift
@@ -591,21 +596,20 @@ Just doing the above will filter all result according to the logged in user.
591
596
  find = scope[:find] ||= {}
592
597
  if klass.ancestors.include?(Zena::Acts::SecureNode::InstanceMethods)
593
598
  find[:conditions] = node_find_scope
594
- elsif klass.ancestors.include?(Version)
595
- ntbl = Node.table_name
596
- find[:joins] = "INNER JOIN #{ntbl} ON #{klass.table_name}.node_id = #{ntbl}.id"
599
+ elsif klass.ancestors.include?(::Version)
600
+ ntbl = ::Node.table_name
601
+ find[:joins] = :node
597
602
  find[:readonly] = false
598
603
  if node_find_scope =~ /publish_from/
599
604
  # read, we need to rewrite with node's table name
600
605
  find[:conditions] = secure_scope(ntbl)
601
606
  else
602
- # secure write or drive
603
- find[:conditions] = node_find_scope.sub('site_id', "#{ntbl}.site_id")
607
+ find[:conditions] = node_find_scope
604
608
  end
605
609
  elsif klass.column_names.include?('site_id')
606
- find[:conditions] = "#{klass.table_name}.site_id = #{visitor.site[:id]}"
607
- elsif klass.ancestors.include?(Site)
608
- find[:conditions] = "#{klass.table_name}.id = #{visitor.site[:id]}"
610
+ find[:conditions] = {klass.table_name => {:site_id => visitor.site[:id]}}
611
+ elsif klass.ancestors.include?(::Site)
612
+ find[:conditions] = {klass.table_name => {:id => visitor.site[:id]}}
609
613
  end
610
614
 
611
615
  # FIXME: 'with_scope' is protected now. Can we live with something cleaner like this ?
@@ -627,7 +631,7 @@ Just doing the above will filter all result according to the logged in user.
627
631
  def secure_result(klass,result)
628
632
  if result && result != []
629
633
  if result.kind_of?(Array)
630
- if result.first.kind_of?(Node)
634
+ if result.first.kind_of?(::Node)
631
635
  id_map, ids = construct_id_map(result)
632
636
  ::Version.find(ids).each do |v|
633
637
  if r = id_map[v.id]
@@ -635,7 +639,7 @@ Just doing the above will filter all result according to the logged in user.
635
639
  end
636
640
  end
637
641
  end
638
- elsif result.kind_of?(Node)
642
+ elsif result.kind_of?(::Node)
639
643
  visitor.visit(result)
640
644
  end
641
645
  result
@@ -696,7 +700,9 @@ Just doing the above will filter all result according to the logged in user.
696
700
  # * owner
697
701
  # * members of +write_group+ if node is published and the current date is greater or equal to the publication date
698
702
  def secure_write(obj, &block)
699
- secure_with_scope(obj, secure_write_scope, &block)
703
+ scope = {:nodes => {:site_id => visitor.site[:id]}}
704
+ scope[:nodes] = {:wgroup_id => visitor.group_ids} unless visitor.is_su?
705
+ secure_with_scope(obj, scope, &block)
700
706
  rescue ActiveRecord::RecordNotFound
701
707
  # Rails generated exceptions
702
708
  # TODO: monitor how often this happens and replace the finders concerned
@@ -722,11 +728,13 @@ Just doing the above will filter all result according to the logged in user.
722
728
  # * owner if +max_status+ <= red
723
729
  # * owner if private
724
730
  def secure_drive(obj, &block)
725
- scope = if visitor.is_su? # super user
726
- "site_id = #{visitor.site.id}"
727
- else
728
- "site_id = #{visitor.site.id} AND dgroup_id IN (#{visitor.group_ids.join(',')})"
729
- end
731
+ # scope = if visitor.is_su? # super user
732
+ # "site_id = #{visitor.site.id}"
733
+ # else
734
+ # "site_id = #{visitor.site.id} AND dgroup_id IN (#{visitor.group_ids.join(',')})"
735
+ # end
736
+ scope = { :nodes => {:site_id => visitor.site.id } }
737
+ scope[:nodes][:dgroup_id] = visitor.group_ids unless visitor.is_su?
730
738
  secure_with_scope(obj, scope, &block)
731
739
  rescue ActiveRecord::RecordNotFound
732
740
  # Rails generated exceptions
@@ -742,6 +750,10 @@ Just doing the above will filter all result according to the logged in user.
742
750
  raise ActiveRecord::RecordNotFound
743
751
  end
744
752
  end
753
+
754
+ def driveable?
755
+ respond_to?(:dgroup_id)
756
+ end
745
757
  end
746
758
  end
747
759
  # This exception handles all flagrant access violations or tentatives (like suppression of _su_ user)
@@ -758,17 +770,16 @@ Just doing the above will filter all result according to the logged in user.
758
770
  end
759
771
 
760
772
  ### ============== GLOBAL METHODS ACCESSIBLE TO ALL OBJECTS ============== ######
761
- # Return the current visitor. Raise an error if the visitor is not set.
762
- # For controllers, this method must be redefined in Application
763
- def visitor
764
- Thread.current.visitor
765
- rescue NoMethodError
766
- raise Zena::RecordNotSecured.new("Visitor not set, record not secured.")
767
- end
768
773
 
769
774
  # Return the current site. Raise an error if the visitor is not set.
770
775
  def current_site
771
776
  visitor.site
772
777
  end
773
778
 
779
+ # Return the current visitor. Raise an error if the visitor is not set.
780
+ # For controllers, this method must be redefined in Application
781
+ def visitor
782
+ Thread.current[:visitor] || Zena::RecordNotSecured.new("Visitor not set, record not secured.")
783
+ end
784
+
774
785
 
@@ -4,22 +4,17 @@ module Zena
4
4
  def self.included(base)
5
5
  base.prepend_view_path SITES_ROOT
6
6
  base.class_eval do
7
- include Zena::Use::Authentification::ControllerMethods
7
+ include Zena::Use::Authlogic::ControllerMethods
8
8
  include Zena::Use::Dates::ControllerMethods
9
9
  include Zena::Use::ErrorRendering::ControllerMethods
10
10
  include Zena::Use::I18n::ControllerMethods
11
11
  include Zena::Use::Refactor::ControllerMethods
12
12
  include Zena::Use::Rendering::ControllerMethods
13
+ include Zena::Use::Upload::ControllerMethods
13
14
  include Zena::Use::Urls::ControllerMethods
14
15
  include Zena::Use::Zafu::ControllerMethods
15
16
 
16
- # FIXME: could we move these into their modules ?
17
- before_filter :set_lang
18
- before_filter :authorize
19
- before_filter :check_lang
20
- after_filter :set_encoding
21
- layout false
22
-
17
+ helper Zena::Use::Authlogic::ViewMethods
23
18
  helper Zena::Acts::Secure
24
19
  helper Zena::Use::Ajax::ViewMethods
25
20
  helper Zena::Use::Calendar::ViewMethods
@@ -30,12 +25,14 @@ module Zena
30
25
  helper Zena::Use::NestedAttributesAlias::ViewMethods
31
26
  helper Zena::Use::Refactor::ViewMethods
32
27
  helper Zena::Use::Rendering::ViewMethods
28
+ helper Zena::Use::Upload::ViewMethods
33
29
  helper Zena::Use::Urls::ViewMethods
34
30
  helper Zena::Use::Zafu::ViewMethods
35
31
  helper Zena::Use::Zazen::ViewMethods
32
+ helper_method :render_to_string
36
33
  end
37
- Bricks::Patcher.apply_patches('application_controller.rb')
38
- Bricks::Patcher.apply_patches('application_helper.rb')
34
+ Bricks.apply_patches('application_controller.rb')
35
+ Bricks.apply_patches('application_helper.rb')
39
36
  end
40
37
  end
41
38
  end
@@ -4,16 +4,21 @@ module Zena
4
4
  include Zena::Use::Fixtures
5
5
  include Zena::Use::TestHelper
6
6
  include Zena::Acts::Secure
7
+ include ::Authlogic::TestCase
7
8
 
8
- def logout
9
- reset_session
9
+ def setup
10
+ activate_authlogic
10
11
  end
11
12
 
12
- alias login_without_controller login
13
-
14
- def login(*args)
15
- login_without_controller(*args)
16
- @controller.instance_eval { @visitor = Thread.current.visitor }
13
+ def login(fixture)
14
+ super
15
+ if defined?(@controller)
16
+ @controller.class_eval do
17
+ def set_visitor
18
+ # do nothing
19
+ end
20
+ end
21
+ end
17
22
  end
18
23
 
19
24
  def assert_css(match)
@@ -0,0 +1,15 @@
1
+ module Zena
2
+ module CryptoProvider
3
+ class Initial
4
+ def self.encrypt(*tokens)
5
+ # encrypt password (old bad method: SHA1, no stretching, no per-password salt)
6
+ Digest::SHA1.hexdigest((tokens.flatten.shift || '') + PASSWORD_SALT)
7
+ end
8
+
9
+ def self.matches?(crypted_password, *tokens)
10
+ # return true if the tokens match the crypted_password
11
+ encrypt(*tokens) == crypted_password
12
+ end
13
+ end
14
+ end
15
+ end
@@ -133,9 +133,14 @@ module Zena
133
133
 
134
134
  def fetch_ids(sql, attr_name='id')
135
135
  connection.select_all(sql, "#{name} Load").map! do |record|
136
- record[attr_name]
136
+ record[attr_name].to_i
137
137
  end
138
138
  end
139
+
140
+ def fetch_attributes(attributes, table_name, sql)
141
+ sql = "SELECT #{attributes.map{|a| connection.quote_column_name(a)}.join(',')} FROM #{table_name} WHERE #{sql}"
142
+ connection.select_all(sql)
143
+ end
139
144
 
140
145
  def fetch_attribute(attribute, sql)
141
146
  unless sql =~ /SELECT/i
@@ -23,8 +23,10 @@ And yes, 'pass' is not as intuitive as 'password' but we cannot use the latter b
23
23
 
24
24
  =end
25
25
  require 'erb'
26
- Capistrano::Configuration.instance(:must_exist).load do
26
+ require File.join(File.dirname(__FILE__), 'info')
27
+ require File.join(File.dirname(__FILE__), '..', 'bricks')
27
28
 
29
+ Capistrano::Configuration.instance(:must_exist).load do
28
30
  set :templates, File.join(File.dirname(__FILE__), 'deploy')
29
31
  self[:app_type] ||= :mongrel
30
32
  self[:app_root] ||= '/var/zena/current'
@@ -57,7 +59,7 @@ Capistrano::Configuration.instance(:must_exist).load do
57
59
 
58
60
  desc "set permissions to www-data"
59
61
  task :set_permissions, :roles => :app do
60
- run "chown -R www-data:www-data #{deploy_to}/current/public #{deploy_to}/current/log"
62
+ run "chown -R www-data:www-data #{deploy_to}/current/public #{deploy_to}/current/log #{deploy_to}/current/tmp"
61
63
  end
62
64
 
63
65
  "Update the currently released version of the software directly via an SCM update operation"
@@ -111,6 +113,7 @@ Capistrano::Configuration.instance(:must_exist).load do
111
113
  run "#{in_current} rake zena:mksite HOST='#{self[:host]}' PASSWORD='#{self[:pass]}' RAILS_ENV='production' LANG='#{self[:lang] || 'en'}'"
112
114
  create_vhost
113
115
  create_awstats
116
+ logrotate
114
117
  run "chown -R www-data:www-data #{sites_root}/#{self[:host]}"
115
118
  end
116
119
 
@@ -198,7 +201,7 @@ Capistrano::Configuration.instance(:must_exist).load do
198
201
  desc "Update awstats configuration file"
199
202
  task :create_awstats, :roles => :web do
200
203
  unless debian_host
201
- puts "skipping debian specific awstats"
204
+ puts "skipping 'create_awstats' (debian specific)"
202
205
  else
203
206
  unless self[:host] && self[:pass]
204
207
  puts "host or password not set (use -s host=... -s pass=...)"
@@ -224,6 +227,8 @@ Capistrano::Configuration.instance(:must_exist).load do
224
227
  # create .htpasswd file
225
228
  run "test ! -e #{sites_root}/#{self[:host]}/log/.awstatspw || rm #{sites_root}/#{self[:host]}/log/.awstatspw"
226
229
  run "htpasswd -c -b #{sites_root}/#{self[:host]}/log/.awstatspw 'admin' '#{self[:pass]}'"
230
+ run "chmod 600 #{sites_root}/#{self[:host]}/log/.awstatspw"
231
+ run "chown www-data:www-data #{sites_root}/#{self[:host]}/log/.awstatspw"
227
232
 
228
233
  # reload apache
229
234
  apache2_reload_cmd
@@ -231,12 +236,27 @@ Capistrano::Configuration.instance(:must_exist).load do
231
236
  end
232
237
  end
233
238
 
234
- desc "Rename a webhost"
235
- task :rename_host, :roles => :web do
239
+ desc "Setup log rotation for a given host"
240
+ task :logrotate, :roles => :web do
241
+ unless debian_host
242
+ puts "skipping 'logrotate' (debian specific)"
243
+ else
244
+ unless self[:host]
245
+ puts "host not set (use -s host=...)"
246
+ else
247
+ # create logrotate config file
248
+ logrotate_conf = render("#{templates}/logrotate_host.rhtml", :config => self )
249
+ put(logrotate_conf, "/etc/logrotate.d/#{self[:host]}")
250
+ end
251
+ end
252
+ end
253
+
254
+ desc "Rename a site and update vhost/awstats/etc"
255
+ task :rename_site, :roles => :web do
236
256
  unless self[:host] && self[:old_host] && self[:pass]
237
257
  puts "host or old_host not set (use -s host=... -s pass=... -s old_host=...)"
238
258
  else
239
- run "#{in_current} rake zena:rename_host OLD_HOST='#{self[:old_host]}' HOST='#{self[:host]}' RAILS_ENV='production'"
259
+ run "#{in_current} rake zena:rename_site OLD_HOST='#{self[:old_host]}' HOST='#{self[:host]}' RAILS_ENV='production'"
240
260
  old_vhosts = ["#{self[:old_host]}",
241
261
  "stats.#{self[:old_host]}",
242
262
  "www.#{self[:old_host]}"]
@@ -249,8 +269,12 @@ Capistrano::Configuration.instance(:must_exist).load do
249
269
  awstat_conf = "/etc/awstats/awstats.#{self[:old_host]}.conf"
250
270
  run "test -e#{awstat_conf} && rm #{awstat_conf} || true"
251
271
 
272
+ logrotate_conf = "/etc/logrotate.d/#{self[:old_host]}"
273
+ run "test -e #{logrotate_conf} && rm #{logrotate_conf} || true"
274
+
252
275
  create_vhost
253
276
  create_awstats
277
+ logrotate
254
278
  clear_zafu
255
279
  clear_cache
256
280
  set_permissions
@@ -261,8 +285,10 @@ Capistrano::Configuration.instance(:must_exist).load do
261
285
  task :apache2_setup, :roles => :web do
262
286
  self[:ports] = (mongrel_port.to_i...(mongrel_port.to_i + mongrel_count.to_i)).to_a
263
287
  httpd_conf = render("#{templates}/httpd.rhtml", :config => self)
288
+ log_rotate = render("#{templates}/logrotate_app.rhtml", :config => self)
264
289
  if debian_host
265
290
  put(httpd_conf, "/etc/apache2/conf.d/#{db_name}")
291
+ put(log_rotate, "/etc/logrotate.d/#{db_name}")
266
292
  else
267
293
  put(httpd_conf, "/etc/apache2/conf.d/#{db_name}")
268
294
  end
@@ -374,4 +400,6 @@ Capistrano::Configuration.instance(:must_exist).load do
374
400
  run "#{in_current} tar czf #{db_name}_data.tgz #{db_name}.sql.tgz sites_data.tgz zena_version.txt"
375
401
  get_backup
376
402
  end
403
+
404
+ Bricks.load_misc('deploy')
377
405
  end
@@ -0,0 +1,9 @@
1
+ <%= config[:app_root] %>/log/production.log {
2
+ weekly
3
+ missingok
4
+ rotate 9
5
+ compress
6
+ delaycompress
7
+ notifempty
8
+ copytruncate
9
+ }
@@ -0,0 +1,34 @@
1
+ <%= config[:sites_root] %>/<%= config[:host] %>/log/apache2.access.log {
2
+ weekly
3
+ missingok
4
+ rotate 52
5
+ compress
6
+ delaycompress
7
+ notifempty
8
+ create 640 www-data www-data
9
+ sharedscripts
10
+ prerotate
11
+ /usr/lib/cgi-bin/awstats.pl -update -config=<%= config[:host] %>
12
+ endscript
13
+ postrotate
14
+ if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then
15
+ /etc/init.d/apache2 reload > /dev/null
16
+ fi
17
+ endscript
18
+ }
19
+
20
+ <%= config[:sites_root] %>/<%= config[:host] %>/log/apache2.error.log {
21
+ weekly
22
+ missingok
23
+ rotate 52
24
+ compress
25
+ delaycompress
26
+ notifempty
27
+ create 640 www-data www-data
28
+ sharedscripts
29
+ postrotate
30
+ if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then
31
+ /etc/init.d/apache2 reload > /dev/null
32
+ fi
33
+ endscript
34
+ }
@@ -33,12 +33,4 @@ inside('app/controllers') do
33
33
  end
34
34
 
35
35
  rake 'zena:assets'
36
- rake 'db:create'
37
- rake 'zena:migrate'
38
- rake "zena:mksite HOST='localhost' PASSWORD='admin' LANG='en'"
39
- inside('.') do
40
- run 'rake zena:migrate RAILS_ENV=production'
41
- run "rake zena:mksite HOST='localhost' PASSWORD='admin' LANG='en' RAILS_ENV=production"
42
- run "#{Gem.win_platform? ? 'start' : 'open'} #{File.join(Zena::ROOT, 'lib/zena/deploy/start.html')}"
43
- exec "script/server -e production -p 3211"
44
- end
36
+