authorails 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (347) hide show
  1. data/AUTHORAILS_README +20 -0
  2. data/CHANGELOG +1366 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README +182 -0
  5. data/Rakefile +334 -0
  6. data/bin/about +3 -0
  7. data/bin/authorails +19 -0
  8. data/bin/breakpointer +3 -0
  9. data/bin/console +3 -0
  10. data/bin/destroy +3 -0
  11. data/bin/generate +3 -0
  12. data/bin/performance/benchmarker +3 -0
  13. data/bin/performance/profiler +3 -0
  14. data/bin/plugin +3 -0
  15. data/bin/process/inspector +3 -0
  16. data/bin/process/reaper +3 -0
  17. data/bin/process/spawner +3 -0
  18. data/bin/runner +3 -0
  19. data/bin/server +3 -0
  20. data/builtin/rails_info/rails/info.rb +123 -0
  21. data/builtin/rails_info/rails/info_controller.rb +9 -0
  22. data/builtin/rails_info/rails/info_helper.rb +2 -0
  23. data/builtin/rails_info/rails_info_controller.rb +2 -0
  24. data/configs/apache.conf +40 -0
  25. data/configs/databases/frontbase.yml +28 -0
  26. data/configs/databases/mysql.yml +48 -0
  27. data/configs/databases/oracle.yml +39 -0
  28. data/configs/databases/postgresql.yml +44 -0
  29. data/configs/databases/sqlite2.yml +16 -0
  30. data/configs/databases/sqlite3.yml +19 -0
  31. data/configs/empty.log +0 -0
  32. data/configs/lighttpd.conf +54 -0
  33. data/configs/routes.rb +23 -0
  34. data/controllers/accounts_controller.rb +11 -0
  35. data/controllers/admin_controller.rb +76 -0
  36. data/controllers/begin_controller.rb +5 -0
  37. data/controllers/login_controller.rb +101 -0
  38. data/controllers/permission_controller.rb +91 -0
  39. data/controllers/roles_controller.rb +58 -0
  40. data/controllers/tables_controller.rb +714 -0
  41. data/dispatches/dispatch.fcgi +24 -0
  42. data/dispatches/dispatch.rb +10 -0
  43. data/dispatches/gateway.cgi +97 -0
  44. data/doc/README_FOR_APP +2 -0
  45. data/environments/boot.rb +45 -0
  46. data/environments/development.rb +21 -0
  47. data/environments/environment.rb +63 -0
  48. data/environments/production.rb +18 -0
  49. data/environments/test.rb +19 -0
  50. data/fresh_rakefile +10 -0
  51. data/helpers/application.rb +607 -0
  52. data/helpers/application_helper.rb +315 -0
  53. data/helpers/permission_helper.rb +27 -0
  54. data/helpers/test_helper.rb +28 -0
  55. data/html/404.html +30 -0
  56. data/html/500.html +30 -0
  57. data/html/favicon.ico +0 -0
  58. data/html/images/ArrowDn.png +0 -0
  59. data/html/images/ArrowUp.png +0 -0
  60. data/html/images/arrow.gif +0 -0
  61. data/html/images/authorails_logo.gif +0 -0
  62. data/html/images/delete.png +0 -0
  63. data/html/images/edit.png +0 -0
  64. data/html/images/minus.gif +0 -0
  65. data/html/images/plus.gif +0 -0
  66. data/html/images/rails.png +0 -0
  67. data/html/images/show.png +0 -0
  68. data/html/images/spinner.gif +0 -0
  69. data/html/index.html +273 -0
  70. data/html/javascripts/application.js +2 -0
  71. data/html/javascripts/controls.js +833 -0
  72. data/html/javascripts/dragdrop.js +942 -0
  73. data/html/javascripts/effects.js +1088 -0
  74. data/html/javascripts/live_validation.js +4 -0
  75. data/html/javascripts/prototype.js +2515 -0
  76. data/html/robots.txt +1 -0
  77. data/lib/authorails/version.rb +9 -0
  78. data/lib/binding_of_caller.rb +85 -0
  79. data/lib/breakpoint.rb +553 -0
  80. data/lib/breakpoint_client.rb +196 -0
  81. data/lib/code_statistics.rb +107 -0
  82. data/lib/commands.rb +17 -0
  83. data/lib/commands/about.rb +2 -0
  84. data/lib/commands/breakpointer.rb +1 -0
  85. data/lib/commands/console.rb +25 -0
  86. data/lib/commands/destroy.rb +6 -0
  87. data/lib/commands/generate.rb +6 -0
  88. data/lib/commands/ncgi/listener +86 -0
  89. data/lib/commands/ncgi/tracker +69 -0
  90. data/lib/commands/performance/benchmarker.rb +24 -0
  91. data/lib/commands/performance/profiler.rb +50 -0
  92. data/lib/commands/plugin.rb +918 -0
  93. data/lib/commands/process/inspector.rb +68 -0
  94. data/lib/commands/process/reaper.rb +149 -0
  95. data/lib/commands/process/spawner.rb +209 -0
  96. data/lib/commands/process/spinner.rb +57 -0
  97. data/lib/commands/runner.rb +48 -0
  98. data/lib/commands/server.rb +39 -0
  99. data/lib/commands/servers/base.rb +19 -0
  100. data/lib/commands/servers/lighttpd.rb +94 -0
  101. data/lib/commands/servers/mongrel.rb +65 -0
  102. data/lib/commands/servers/webrick.rb +59 -0
  103. data/lib/commands/update.rb +4 -0
  104. data/lib/console_app.rb +27 -0
  105. data/lib/console_sandbox.rb +6 -0
  106. data/lib/console_with_helpers.rb +23 -0
  107. data/lib/dispatcher.rb +173 -0
  108. data/lib/fcgi_handler.rb +225 -0
  109. data/lib/initializer.rb +702 -0
  110. data/lib/rails_generator.rb +43 -0
  111. data/lib/rails_generator/base.rb +261 -0
  112. data/lib/rails_generator/commands.rb +581 -0
  113. data/lib/rails_generator/generated_attribute.rb +42 -0
  114. data/lib/rails_generator/generators/applications/app/USAGE +16 -0
  115. data/lib/rails_generator/generators/applications/app/app_generator.rb +341 -0
  116. data/lib/rails_generator/generators/components/controller/USAGE +30 -0
  117. data/lib/rails_generator/generators/components/controller/controller_generator.rb +37 -0
  118. data/lib/rails_generator/generators/components/controller/templates/controller.rb +10 -0
  119. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +18 -0
  120. data/lib/rails_generator/generators/components/controller/templates/helper.rb +2 -0
  121. data/lib/rails_generator/generators/components/controller/templates/view.rhtml +2 -0
  122. data/lib/rails_generator/generators/components/integration_test/USAGE +14 -0
  123. data/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +16 -0
  124. data/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +10 -0
  125. data/lib/rails_generator/generators/components/mailer/USAGE +18 -0
  126. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +34 -0
  127. data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +3 -0
  128. data/lib/rails_generator/generators/components/mailer/templates/mailer.rb +13 -0
  129. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +37 -0
  130. data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +3 -0
  131. data/lib/rails_generator/generators/components/migration/USAGE +14 -0
  132. data/lib/rails_generator/generators/components/migration/migration_generator.rb +7 -0
  133. data/lib/rails_generator/generators/components/migration/templates/migration.rb +7 -0
  134. data/lib/rails_generator/generators/components/model/USAGE +26 -0
  135. data/lib/rails_generator/generators/components/model/model_generator.rb +38 -0
  136. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +11 -0
  137. data/lib/rails_generator/generators/components/model/templates/migration.rb +13 -0
  138. data/lib/rails_generator/generators/components/model/templates/model.rb +2 -0
  139. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +10 -0
  140. data/lib/rails_generator/generators/components/observer/USAGE +15 -0
  141. data/lib/rails_generator/generators/components/observer/observer_generator.rb +16 -0
  142. data/lib/rails_generator/generators/components/observer/templates/observer.rb +2 -0
  143. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +10 -0
  144. data/lib/rails_generator/generators/components/plugin/USAGE +35 -0
  145. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +38 -0
  146. data/lib/rails_generator/generators/components/plugin/templates/README +4 -0
  147. data/lib/rails_generator/generators/components/plugin/templates/Rakefile +22 -0
  148. data/lib/rails_generator/generators/components/plugin/templates/USAGE +8 -0
  149. data/lib/rails_generator/generators/components/plugin/templates/generator.rb +8 -0
  150. data/lib/rails_generator/generators/components/plugin/templates/init.rb +1 -0
  151. data/lib/rails_generator/generators/components/plugin/templates/install.rb +1 -0
  152. data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +1 -0
  153. data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +4 -0
  154. data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +1 -0
  155. data/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +8 -0
  156. data/lib/rails_generator/generators/components/resource/resource_generator.rb +76 -0
  157. data/lib/rails_generator/generators/components/resource/templates/USAGE +18 -0
  158. data/lib/rails_generator/generators/components/resource/templates/controller.rb +2 -0
  159. data/lib/rails_generator/generators/components/resource/templates/fixtures.yml +11 -0
  160. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +20 -0
  161. data/lib/rails_generator/generators/components/resource/templates/helper.rb +2 -0
  162. data/lib/rails_generator/generators/components/resource/templates/migration.rb +13 -0
  163. data/lib/rails_generator/generators/components/resource/templates/model.rb +2 -0
  164. data/lib/rails_generator/generators/components/resource/templates/unit_test.rb +10 -0
  165. data/lib/rails_generator/generators/components/scaffold/USAGE +32 -0
  166. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +208 -0
  167. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +134 -0
  168. data/lib/rails_generator/generators/components/scaffold/templates/form.rhtml +3 -0
  169. data/lib/rails_generator/generators/components/scaffold/templates/form_scaffolding.rhtml +35 -0
  170. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +102 -0
  171. data/lib/rails_generator/generators/components/scaffold/templates/helper.rb +2 -0
  172. data/lib/rails_generator/generators/components/scaffold/templates/layout.rhtml +17 -0
  173. data/lib/rails_generator/generators/components/scaffold/templates/partial_list_elements.rhtml +127 -0
  174. data/lib/rails_generator/generators/components/scaffold/templates/style.css +74 -0
  175. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.rhtml +75 -0
  176. data/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +30 -0
  177. data/lib/rails_generator/generators/components/scaffold/templates/view_new.rhtml +8 -0
  178. data/lib/rails_generator/generators/components/scaffold/templates/view_show.rhtml +37 -0
  179. data/lib/rails_generator/generators/components/scaffold_resource/USAGE +29 -0
  180. data/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb +92 -0
  181. data/lib/rails_generator/generators/components/scaffold_resource/templates/controller.rb +79 -0
  182. data/lib/rails_generator/generators/components/scaffold_resource/templates/fixtures.yml +11 -0
  183. data/lib/rails_generator/generators/components/scaffold_resource/templates/functional_test.rb +57 -0
  184. data/lib/rails_generator/generators/components/scaffold_resource/templates/helper.rb +2 -0
  185. data/lib/rails_generator/generators/components/scaffold_resource/templates/layout.rhtml +17 -0
  186. data/lib/rails_generator/generators/components/scaffold_resource/templates/migration.rb +13 -0
  187. data/lib/rails_generator/generators/components/scaffold_resource/templates/model.rb +2 -0
  188. data/lib/rails_generator/generators/components/scaffold_resource/templates/style.css +74 -0
  189. data/lib/rails_generator/generators/components/scaffold_resource/templates/unit_test.rb +10 -0
  190. data/lib/rails_generator/generators/components/scaffold_resource/templates/view_edit.rhtml +19 -0
  191. data/lib/rails_generator/generators/components/scaffold_resource/templates/view_index.rhtml +24 -0
  192. data/lib/rails_generator/generators/components/scaffold_resource/templates/view_new.rhtml +18 -0
  193. data/lib/rails_generator/generators/components/scaffold_resource/templates/view_show.rhtml +10 -0
  194. data/lib/rails_generator/generators/components/session_migration/USAGE +15 -0
  195. data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +18 -0
  196. data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +16 -0
  197. data/lib/rails_generator/generators/components/web_service/USAGE +28 -0
  198. data/lib/rails_generator/generators/components/web_service/templates/api_definition.rb +5 -0
  199. data/lib/rails_generator/generators/components/web_service/templates/controller.rb +8 -0
  200. data/lib/rails_generator/generators/components/web_service/templates/functional_test.rb +19 -0
  201. data/lib/rails_generator/generators/components/web_service/web_service_generator.rb +29 -0
  202. data/lib/rails_generator/lookup.rb +209 -0
  203. data/lib/rails_generator/manifest.rb +53 -0
  204. data/lib/rails_generator/options.rb +143 -0
  205. data/lib/rails_generator/scripts.rb +83 -0
  206. data/lib/rails_generator/scripts/destroy.rb +7 -0
  207. data/lib/rails_generator/scripts/generate.rb +7 -0
  208. data/lib/rails_generator/scripts/update.rb +12 -0
  209. data/lib/rails_generator/simple_logger.rb +46 -0
  210. data/lib/rails_generator/spec.rb +44 -0
  211. data/lib/railties_path.rb +1 -0
  212. data/lib/ruby_version_check.rb +17 -0
  213. data/lib/rubyprof_ext.rb +35 -0
  214. data/lib/tasks/databases.rake +187 -0
  215. data/lib/tasks/documentation.rake +82 -0
  216. data/lib/tasks/framework.rake +112 -0
  217. data/lib/tasks/log.rake +9 -0
  218. data/lib/tasks/misc.rake +4 -0
  219. data/lib/tasks/pre_namespace_aliases.rake +53 -0
  220. data/lib/tasks/rails.rb +8 -0
  221. data/lib/tasks/statistics.rake +18 -0
  222. data/lib/tasks/testing.rake +120 -0
  223. data/lib/tasks/tmp.rake +37 -0
  224. data/lib/test_help.rb +19 -0
  225. data/lib/webrick_server.rb +166 -0
  226. data/libs/migration_helper.rb +11 -0
  227. data/migrations/001_create_logins.rb +22 -0
  228. data/migrations/002_create_admins.rb +16 -0
  229. data/migrations/003_create_roles.rb +13 -0
  230. data/migrations/004_create_tables.rb +11 -0
  231. data/migrations/005_create_attr_types.rb +13 -0
  232. data/migrations/006_create_table_fields.rb +22 -0
  233. data/migrations/007_create_tab_operations.rb +13 -0
  234. data/migrations/008_create_attr_operations.rb +13 -0
  235. data/migrations/009_create_tab_permissions.rb +21 -0
  236. data/migrations/010_create_attr_permissions.rb +21 -0
  237. data/migrations/011_create_relations.rb +23 -0
  238. data/migrations/012_create_scaffolds.rb +11 -0
  239. data/migrations/013_create_relation_permissions.rb +20 -0
  240. data/models/admin.rb +38 -0
  241. data/models/attr_operation.rb +3 -0
  242. data/models/attr_permission.rb +5 -0
  243. data/models/attr_type.rb +3 -0
  244. data/models/login.rb +51 -0
  245. data/models/relation.rb +5 -0
  246. data/models/relation_permission.rb +4 -0
  247. data/models/role.rb +13 -0
  248. data/models/scaffold.rb +2 -0
  249. data/models/tab_operation.rb +3 -0
  250. data/models/tab_permission.rb +5 -0
  251. data/models/table.rb +18 -0
  252. data/models/table_field.rb +6 -0
  253. data/plugins/redhillonrails_core/CHANGELOG +186 -0
  254. data/plugins/redhillonrails_core/MIT-LICENSE +20 -0
  255. data/plugins/redhillonrails_core/README +152 -0
  256. data/plugins/redhillonrails_core/init.rb +1 -0
  257. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb +54 -0
  258. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/abstract_adapter.rb +46 -0
  259. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/column.rb +21 -0
  260. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb +26 -0
  261. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/index_definition.rb +11 -0
  262. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/mysql_adapter.rb +94 -0
  263. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/mysql_column.rb +8 -0
  264. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/postgresql_adapter.rb +131 -0
  265. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/schema_statements.rb +23 -0
  266. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/sqlite3_adapter.rb +9 -0
  267. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/table_definition.rb +27 -0
  268. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema.rb +25 -0
  269. data/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb +58 -0
  270. data/plugins/redhillonrails_core/lib/redhillonrails_core.rb +19 -0
  271. data/plugins/redhillonrails_core/tasks/db/comments.rake +9 -0
  272. data/plugins/schema_validations/CHANGELOG +149 -0
  273. data/plugins/schema_validations/MIT-LICENSE +20 -0
  274. data/plugins/schema_validations/README +54 -0
  275. data/plugins/schema_validations/about.yml +5 -0
  276. data/plugins/schema_validations/init.rb +1 -0
  277. data/plugins/schema_validations/install.rb +1 -0
  278. data/plugins/schema_validations/lib/red_hill_consulting/schema_validations/active_record/base.rb +108 -0
  279. data/plugins/schema_validations/lib/schema_validations.rb +1 -0
  280. data/plugins/svn/README +69 -0
  281. data/plugins/svn/Rakefile +22 -0
  282. data/plugins/svn/assets/javascripts/live_validation.js +4 -0
  283. data/plugins/svn/assets/stylesheets/live_validation.css +28 -0
  284. data/plugins/svn/init.rb +2 -0
  285. data/plugins/svn/install.rb +1 -0
  286. data/plugins/svn/lib/form_helpers.rb +49 -0
  287. data/plugins/svn/lib/live_validations.rb +73 -0
  288. data/plugins/svn/tasks/live_validation_tasks.rake +17 -0
  289. data/plugins/svn/test/form_helpers_test.rb +214 -0
  290. data/plugins/svn/test/live_validations_test.rb +124 -0
  291. data/plugins/svn/test/resource.rb +17 -0
  292. data/plugins/svn/uninstall.rb +1 -0
  293. data/stylesheets/live_validation.css +28 -0
  294. data/stylesheets/print.css +72 -0
  295. data/stylesheets/scaffold.css +175 -0
  296. data/views/accounts/index.rhtml +12 -0
  297. data/views/accounts/show.rhtml +5 -0
  298. data/views/admin/_form.rhtml +15 -0
  299. data/views/admin/add_user.rhtml +21 -0
  300. data/views/admin/change_pwd.rhtml +23 -0
  301. data/views/admin/edit_user.rhtml +12 -0
  302. data/views/admin/index.rhtml +19 -0
  303. data/views/begin/index.rhtml +0 -0
  304. data/views/layouts/general.rhtml +59 -0
  305. data/views/layouts/login.rhtml +18 -0
  306. data/views/login/change_pwd.rhtml +21 -0
  307. data/views/login/expired_pwd.rhtml +19 -0
  308. data/views/login/index.rhtml +15 -0
  309. data/views/permission/index.rhtml +17 -0
  310. data/views/permission/relations.rhtml +28 -0
  311. data/views/permission/roles.rhtml +45 -0
  312. data/views/permission/tables.rhtml +53 -0
  313. data/views/roles/_form.rhtml +8 -0
  314. data/views/roles/edit.rhtml +11 -0
  315. data/views/roles/list.rhtml +28 -0
  316. data/views/roles/new.rhtml +8 -0
  317. data/views/roles/show.rhtml +14 -0
  318. data/views/shared_views/_advanced_search.rhtml +35 -0
  319. data/views/shared_views/_child_elements.rhtml +30 -0
  320. data/views/shared_views/_childs.rhtml +20 -0
  321. data/views/shared_views/_father_elements.rhtml +27 -0
  322. data/views/shared_views/_fathers.rhtml +21 -0
  323. data/views/shared_views/_fathers_header.rhtml +58 -0
  324. data/views/shared_views/_many_to_many_elements.rhtml +50 -0
  325. data/views/shared_views/_many_to_manys.rhtml +18 -0
  326. data/views/shared_views/_one_to_one_elements.rhtml +24 -0
  327. data/views/shared_views/_one_to_one_father_elements.rhtml +26 -0
  328. data/views/shared_views/_one_to_ones.rhtml +42 -0
  329. data/views/shared_views/_one_to_ones_header.rhtml +117 -0
  330. data/views/shared_views/edit_child.rhtml +89 -0
  331. data/views/shared_views/edit_many.rhtml +75 -0
  332. data/views/tables/_cascade.rhtml +10 -0
  333. data/views/tables/_field.rhtml +10 -0
  334. data/views/tables/_fk.rhtml +9 -0
  335. data/views/tables/_form.rhtml +9 -0
  336. data/views/tables/_join_table_name.rhtml +16 -0
  337. data/views/tables/_relation_types.rhtml +5 -0
  338. data/views/tables/_tables.rhtml +15 -0
  339. data/views/tables/attributes.rhtml +15 -0
  340. data/views/tables/edit.rhtml +11 -0
  341. data/views/tables/edit_field.rhtml +18 -0
  342. data/views/tables/list.rhtml +39 -0
  343. data/views/tables/new.rhtml +8 -0
  344. data/views/tables/new_field.rhtml +25 -0
  345. data/views/tables/relations.rhtml +24 -0
  346. data/views/tables/show.rhtml +24 -0
  347. metadata +518 -0
@@ -0,0 +1,24 @@
1
+ #!/usr/local/bin/ruby
2
+ #
3
+ # You may specify the path to the FastCGI crash log (a log of unhandled
4
+ # exceptions which forced the FastCGI instance to exit, great for debugging)
5
+ # and the number of requests to process before running garbage collection.
6
+ #
7
+ # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log
8
+ # and the GC period is nil (turned off). A reasonable number of requests
9
+ # could range from 10-100 depending on the memory footprint of your app.
10
+ #
11
+ # Example:
12
+ # # Default log path, normal GC behavior.
13
+ # RailsFCGIHandler.process!
14
+ #
15
+ # # Default log path, 50 requests between GC.
16
+ # RailsFCGIHandler.process! nil, 50
17
+ #
18
+ # # Custom log path, normal GC behavior.
19
+ # RailsFCGIHandler.process! '/var/log/myapp_fcgi_crash.log'
20
+ #
21
+ require File.dirname(__FILE__) + "/../config/environment"
22
+ require 'fcgi_handler'
23
+
24
+ RailsFCGIHandler.process!
@@ -0,0 +1,10 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
4
+
5
+ # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
6
+ # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired
7
+ require "dispatcher"
8
+
9
+ ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun)
10
+ Dispatcher.dispatch
@@ -0,0 +1,97 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'drb'
4
+
5
+ # This file includes an experimental gateway CGI implementation. It will work
6
+ # only on platforms which support both fork and sockets.
7
+ #
8
+ # To enable it edit public/.htaccess and replace dispatch.cgi with gateway.cgi.
9
+ #
10
+ # Next, create the directory log/drb_gateway and grant the apache user rw access
11
+ # to said directory.
12
+ #
13
+ # On the next request to your server, the gateway tracker should start up, along
14
+ # with a few listener processes. This setup should provide you with much better
15
+ # speeds than dispatch.cgi.
16
+ #
17
+ # Keep in mind that the first request made to the server will be slow, as the
18
+ # tracker and listeners will have to load. Also, the tracker and listeners will
19
+ # shutdown after a period if inactivity. You can set this value below -- the
20
+ # default is 90 seconds.
21
+
22
+ TrackerSocket = File.expand_path(File.join(File.dirname(__FILE__), '../log/drb_gateway/tracker.sock'))
23
+ DieAfter = 90 # Seconds
24
+ Listeners = 3
25
+
26
+ def message(s)
27
+ $stderr.puts "gateway.cgi: #{s}" if ENV && ENV["DEBUG_GATEWAY"]
28
+ end
29
+
30
+ def listener_socket(number)
31
+ File.expand_path(File.join(File.dirname(__FILE__), "../log/drb_gateway/listener_#{number}.sock"))
32
+ end
33
+
34
+ unless File.exists? TrackerSocket
35
+ message "Starting tracker and #{Listeners} listeners"
36
+ fork do
37
+ Process.setsid
38
+ STDIN.reopen "/dev/null"
39
+ STDOUT.reopen "/dev/null", "a"
40
+
41
+ root = File.expand_path(File.dirname(__FILE__) + '/..')
42
+
43
+ message "starting tracker"
44
+ fork do
45
+ ARGV.clear
46
+ ARGV << TrackerSocket << Listeners.to_s << DieAfter.to_s
47
+ load File.join(root, 'script', 'tracker')
48
+ end
49
+
50
+ message "starting listeners"
51
+ require File.join(root, 'config/environment.rb')
52
+ Listeners.times do |number|
53
+ fork do
54
+ ARGV.clear
55
+ ARGV << listener_socket(number) << DieAfter.to_s
56
+ load File.join(root, 'script', 'listener')
57
+ end
58
+ end
59
+ end
60
+
61
+ message "waiting for tracker and listener to arise..."
62
+ ready = false
63
+ 10.times do
64
+ sleep 0.5
65
+ break if (ready = File.exists?(TrackerSocket) && File.exists?(listener_socket(0)))
66
+ end
67
+
68
+ if ready
69
+ message "tracker and listener are ready"
70
+ else
71
+ message "Waited 5 seconds, listener and tracker not ready... dropping request"
72
+ Kernel.exit 1
73
+ end
74
+ end
75
+
76
+ DRb.start_service
77
+
78
+ message "connecting to tracker"
79
+ tracker = DRbObject.new_with_uri("drbunix:#{TrackerSocket}")
80
+
81
+ input = $stdin.read
82
+ $stdin.close
83
+
84
+ env = ENV.inspect
85
+
86
+ output = nil
87
+ tracker.with_listener do |number|
88
+ message "connecting to listener #{number}"
89
+ socket = listener_socket(number)
90
+ listener = DRbObject.new_with_uri("drbunix:#{socket}")
91
+ output = listener.process(env, input)
92
+ message "listener #{number} has finished, writing output"
93
+ end
94
+
95
+ $stdout.write output
96
+ $stdout.flush
97
+ $stdout.close
@@ -0,0 +1,2 @@
1
+ Use this README file to introduce your application and point to useful places in the API for learning more.
2
+ Run "rake appdoc" to generate API documentation for your models and controllers.
@@ -0,0 +1,45 @@
1
+ # Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb
2
+
3
+ unless defined?(RAILS_ROOT)
4
+ root_path = File.join(File.dirname(__FILE__), '..')
5
+
6
+ unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
7
+ require 'pathname'
8
+ root_path = Pathname.new(root_path).cleanpath(true).to_s
9
+ end
10
+
11
+ RAILS_ROOT = root_path
12
+ end
13
+
14
+ unless defined?(Rails::Initializer)
15
+ if File.directory?("#{RAILS_ROOT}/vendor/authorails")
16
+ require "#{RAILS_ROOT}/vendor/authorails/railties/lib/initializer"
17
+ else
18
+ require 'rubygems'
19
+
20
+ environment_without_comments = IO.readlines(File.dirname(__FILE__) + '/environment.rb').reject { |l| l =~ /^#/ }.join
21
+ environment_without_comments =~ /[^#]AUTHORAILS_GEM_VERSION = '([\d.]+)'/
22
+ authorails_gem_version = $1
23
+
24
+ if version = defined?(AUTHORAILS_GEM_VERSION) ? AUTHORAILS_GEM_VERSION : authorails_gem_version
25
+ # Asking for 1.1.6 will give you 1.1.6.5206, if available -- makes it easier to use beta gems
26
+ authorails_gem = Gem.cache.search('authorails', "~>#{version}.0").sort_by { |g| g.version.version }.last
27
+
28
+ if authorails_gem
29
+ gem "authorails", "=#{authorails_gem.version.version}"
30
+ require authorails_gem.full_gem_path + '/lib/initializer'
31
+ else
32
+ STDERR.puts %(Cannot find gem for AuthoRails ~>#{version}.0:
33
+ Install the missing gem with 'gem install -v=#{version} authorails', or
34
+ change environment.rb to define AUTHORAILS_GEM_VERSION with your desired version.
35
+ )
36
+ exit 1
37
+ end
38
+ else
39
+ gem "authorails"
40
+ require 'initializer'
41
+ end
42
+ end
43
+
44
+ Rails::Initializer.run(:set_load_path)
45
+ end
@@ -0,0 +1,21 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # In the development environment your application's code is reloaded on
4
+ # every request. This slows down response time but is perfect for development
5
+ # since you don't have to restart the webserver when you make code changes.
6
+ config.cache_classes = false
7
+
8
+ # Log error messages when you accidentally call methods on nil.
9
+ config.whiny_nils = true
10
+
11
+ # Enable the breakpoint server that script/breakpointer connects to
12
+ config.breakpoint_server = true
13
+
14
+ # Show full error reports and disable caching
15
+ config.action_controller.consider_all_requests_local = true
16
+ config.action_controller.perform_caching = false
17
+ config.action_view.cache_template_extensions = false
18
+ config.action_view.debug_rjs = true
19
+
20
+ # Don't care if the mailer can't send
21
+ config.action_mailer.raise_delivery_errors = false
@@ -0,0 +1,63 @@
1
+ # Be sure to restart your web server when you modify this file.
2
+
3
+ # Uncomment below to force Rails into production mode when
4
+ # you don't control web/app server and can't set it the proper way
5
+ # ENV['RAILS_ENV'] ||= 'production'
6
+
7
+ # Specifies gem version of Rails to use when vendor/rails is not present
8
+ AUTHORAILS_GEM_VERSION = '1.0.0' unless defined? AUTHORAILS_GEM_VERSION
9
+
10
+ # Bootstrap the Rails environment, frameworks, and default configuration
11
+ require File.join(File.dirname(__FILE__), 'boot')
12
+
13
+ Rails::Initializer.run do |config|
14
+ # Settings in config/environments/* take precedence over those specified here
15
+
16
+ # Skip frameworks you're not going to use (only works if using vendor/rails)
17
+ # config.frameworks -= [ :action_web_service, :action_mailer ]
18
+
19
+ # Only load the plugins named here, by default all plugins in vendor/plugins are loaded
20
+ # config.plugins = %W( exception_notification ssl_requirement )
21
+
22
+ # Add additional load paths for your own custom dirs
23
+ # config.load_paths += %W( #{RAILS_ROOT}/extras )
24
+
25
+ # Force all environments to use the same logger level
26
+ # (by default production uses :info, the others :debug)
27
+ # config.log_level = :debug
28
+
29
+ # Use the database for sessions instead of the file system
30
+ # (create the session table with 'rake db:sessions:create')
31
+ # config.action_controller.session_store = :active_record_store
32
+
33
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
34
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
35
+ # like if you have constraints or database-specific column types
36
+ # config.active_record.schema_format = :sql
37
+
38
+ # Activate observers that should always be running
39
+ # config.active_record.observers = :cacher, :garbage_collector
40
+
41
+ # Make Active Record use UTC-base instead of local time
42
+ # config.active_record.default_timezone = :utc
43
+
44
+ # See Rails::Configuration for more options
45
+ end
46
+
47
+ #Enables input live validation. Switch to false to disable it
48
+ ActionView::live_validations = true
49
+
50
+ # Add new inflection rules using the following format
51
+ # (all these examples are active by default):
52
+ # Inflector.inflections do |inflect|
53
+ # inflect.plural /^(ox)$/i, '\1en'
54
+ # inflect.singular /^(ox)en/i, '\1'
55
+ # inflect.irregular 'person', 'people'
56
+ # inflect.uncountable %w( fish sheep )
57
+ # end
58
+
59
+ # Add new mime types for use in respond_to blocks:
60
+ # Mime::Type.register "text/richtext", :rtf
61
+ # Mime::Type.register "application/x-mobile", :mobile
62
+
63
+ # Include your application configuration below
@@ -0,0 +1,18 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The production environment is meant for finished, "live" apps.
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Use a different logger for distributed setups
8
+ # config.logger = SyslogLogger.new
9
+
10
+ # Full error reports are disabled and caching is turned on
11
+ config.action_controller.consider_all_requests_local = false
12
+ config.action_controller.perform_caching = true
13
+
14
+ # Enable serving of images, stylesheets, and javascripts from an asset server
15
+ # config.action_controller.asset_host = "http://assets.example.com"
16
+
17
+ # Disable delivery errors, bad email addresses will be ignored
18
+ # config.action_mailer.raise_delivery_errors = false
@@ -0,0 +1,19 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The test environment is used exclusively to run your application's
4
+ # test suite. You never need to work with it otherwise. Remember that
5
+ # your test database is "scratch space" for the test suite and is wiped
6
+ # and recreated between test runs. Don't rely on the data there!
7
+ config.cache_classes = true
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.action_controller.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Tell ActionMailer not to deliver emails to the real world.
17
+ # The :test delivery method accumulates sent emails in the
18
+ # ActionMailer::Base.deliveries array.
19
+ config.action_mailer.delivery_method = :test
@@ -0,0 +1,10 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ require 'tasks/rails'
@@ -0,0 +1,607 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ # Pick a unique cookie name to distinguish our session data from others'
6
+ session :session_key => '_<%= app_name%>_session_id'
7
+
8
+
9
+ layout 'general' #all views will share this layout
10
+ #:authorize checks if the user is logged
11
+ before_filter :authorize
12
+ before_filter :find_relations
13
+ #:initialize loads necessary variables; :privileges checks all user's privileges
14
+ before_filter :initialize,:privileges
15
+ before_filter :find_fkeys,:only => [:new,:create,:edit,:update]
16
+ before_filter :privileges_for_create, :only => [:new,:create] #check if the user can create
17
+ before_filter :privileges_for_destroy, :only => [:destroy] #check if the user can destroy
18
+ before_filter :check_privileges_for_update, :only => [:update] #against attempting to edit fields without permission
19
+
20
+
21
+ def edit_child
22
+ @child_table = params[:child_table]
23
+ @father = controller_name.singularize.camelize.constantize.find(params[:id])
24
+ if session[:superuser]
25
+ @all = @child_table.singularize.camelize.constantize.find_all
26
+ else
27
+ @all=[]
28
+ all_rows_of_related_table=[]
29
+ @child_table.singularize.camelize.constantize.find_all.each {|r| all_rows_of_related_table << r.id}
30
+
31
+ role=Login.find_by_usernameMail(session[:username]).role_id
32
+ relation=Relation.find_by_sql("SELECT r.id as id
33
+ FROM relations r,table_fields tf,tables t1,tables t2
34
+ WHERE r.table_field_id=tf.id and tf.table_id=t1.id and r.table_id=t2.id and ((t1.name=\"#{controller_name}\" and t2.name=\"#{@child_table}\") or (t2.name=\"#{controller_name}\" and t1.name=\"#{@child_table}\"))")
35
+ relation=relation[0].id unless relation.empty?
36
+
37
+ #if user can create a relation, he can show the rows not even related with the current element
38
+ if RelationPermission.find_by_role_id_and_relation_id_and_action(role,relation,"create")
39
+ already_defined=[] #rows related with the current element
40
+ @child_table.singularize.camelize.constantize.find(:all,:conditions => "#{controller_name.singularize.foreign_key}=#{params[:id]}").each {|r| already_defined << r.id}
41
+ to_show = all_rows_of_related_table - already_defined
42
+ to_show.each {|r| @all << @child_table.singularize.camelize.constantize.find(r)}
43
+ end
44
+
45
+ #if user can destroy a relation, he can show the rows related with the current element
46
+ if RelationPermission.find_by_role_id_and_relation_id_and_action(role,relation,"destroy")
47
+ @child_table.singularize.camelize.constantize.find(:all,:conditions => "#{controller_name.singularize.foreign_key}=#{params[:id]}").each {|r| @all << @child_table.singularize.camelize.constantize.find(r)}
48
+ end
49
+ end
50
+ render :template => 'shared_views/edit_child'
51
+ end
52
+
53
+ def update_child
54
+ @child_table = params[:child_table]
55
+ @father = controller_name.singularize.camelize.constantize.find(params[:id])
56
+ @childs= params[@child_table]
57
+ @child_as_class = @child_table.singularize.camelize.constantize
58
+ @child_as_class.transaction do
59
+ fk_name = controller_name.singularize.foreign_key
60
+
61
+ unless session[:superuser]
62
+ role=Login.find_by_usernameMail(session[:username]).role_id
63
+ relation=Relation.find_by_sql("SELECT r.id as id
64
+ FROM relations r,table_fields tf,tables t1,tables t2
65
+ WHERE r.table_field_id=tf.id and tf.table_id=t1.id and r.table_id=t2.id and ((t1.name=\"#{controller_name}\" and t2.name=\"#{@child_table}\") or (t2.name=\"#{controller_name}\" and t1.name=\"#{@child_table}\"))")[0].id
66
+ end
67
+ if session[:superuser] or RelationPermission.find_by_role_id_and_relation_id_and_action(role,relation,"destroy")
68
+ #deleting old childs
69
+ @child_as_class.find(:all, :conditions => "#{fk_name} = #{@father.id}").each {|child| child.update_attribute fk_name, nil}
70
+ end
71
+
72
+ unless @childs.nil?
73
+ @childs.each do |one|
74
+ @child_as_class.find(one).update_attribute fk_name, @father.id
75
+ end
76
+ end
77
+ end
78
+ flash[:notice] = @child_table.titleize + " succesfully updated."
79
+ redirect_to :action => 'show', :id => @father
80
+ end
81
+
82
+ def edit_many
83
+ @table = params[:table]
84
+ @join_table = params[:join_table]
85
+ @current = controller_name.singularize.camelize.constantize.find(params[:id],:include => @childs)
86
+ if session[:superuser]
87
+ @all = @table.singularize.camelize.constantize.find_all
88
+ else
89
+ @all=[]
90
+ all_rows_of_related_table=[]
91
+ @table.singularize.camelize.constantize.find_all.each {|r| all_rows_of_related_table << r.id}
92
+
93
+ role=Login.find_by_usernameMail(session[:username]).role_id
94
+ relation=Relation.find_by_sql("SELECT r.id as id
95
+ FROM relations r,table_fields tf,tables t1,tables t2
96
+ WHERE r.table_field_id=tf.id and tf.table_id=t1.id and r.table_id=t2.id and ((t1.name=\"#{controller_name}\" and t2.name=\"#{@table}\") or (t2.name=\"#{controller_name}\" and t1.name=\"#{@table}\"))")
97
+ relation=relation[0].id unless relation.empty?
98
+
99
+ #if user can create a relation, he can show the rows not even related with the current element
100
+ if RelationPermission.find_by_role_id_and_relation_id_and_action(role,relation,"create")
101
+ already_defined=[] #rows related with the current element
102
+ @join_table.singularize.camelize.constantize.find(:all,:conditions => "#{controller_name.singularize.foreign_key}=#{params[:id]}").each {|r| already_defined << r.send(@table.singularize.foreign_key)}
103
+ to_show = all_rows_of_related_table - already_defined
104
+ to_show.each {|r| @all << @table.singularize.camelize.constantize.find(r)}
105
+ end
106
+
107
+ #if user can destroy a relation, he can show the rows related with the current element
108
+ if RelationPermission.find_by_role_id_and_relation_id_and_action(role,relation,"destroy")
109
+ @join_table.singularize.camelize.constantize.find(:all,:conditions => "#{controller_name.singularize.foreign_key}=#{params[:id]}").each {|r| @all << @table.singularize.camelize.constantize.find(r.send(@table.singularize.foreign_key))}
110
+ end
111
+ end
112
+ render :template => 'shared_views/edit_many'
113
+ end
114
+
115
+ def update_many
116
+ @table = params[:table]
117
+ @join_table = params[:join_table]
118
+ @current = controller_name.singularize.camelize.constantize.find(params[:id],:include => @childs)
119
+ @related = params[@table]
120
+ @join_table_as_class = @join_table.singularize.camelize.constantize
121
+ fk_name1 = controller_name.singularize.foreign_key
122
+ fk_name2 = @table.singularize.foreign_key
123
+ @new_ids=[] #list of rows choosed
124
+ unless @related.nil?
125
+ @related.each {|r| @new_ids << r.to_i}
126
+ end
127
+ @all = [] #list of all related rows already present
128
+ @current.send(@join_table).each {|r| @all << r.send(@table.singularize).id.to_i unless r.send(@table.singularize).nil?}#all related rows
129
+ @to_insert = @new_ids - @all #new rows that needs to be insert
130
+ @to_delete = @all - @new_ids #old rows that needs to be erased
131
+ @join_table_as_class.transaction do
132
+ @to_insert.each {|r| @join_table_as_class.create(
133
+ fk_name1 => @current.id,
134
+ fk_name2 => r
135
+ )}
136
+
137
+ unless session[:superuser]
138
+ role=Login.find_by_usernameMail(session[:username]).role_id
139
+ relation=Relation.find_by_sql("SELECT r.id as id
140
+ FROM relations r,table_fields tf,tables t1,tables t2
141
+ WHERE r.table_field_id=tf.id and tf.table_id=t1.id and r.table_id=t2.id and ((t1.name=\"#{controller_name}\" and t2.name=\"#{@table}\") or (t2.name=\"#{controller_name}\" and t1.name=\"#{@table}\"))")[0].id
142
+ end
143
+ if session[:superuser] or RelationPermission.find_by_role_id_and_relation_id_and_action(role,relation,"destroy")
144
+ @to_delete.each {|r| @join_table_as_class.find(:first,:conditions => "#{fk_name1}=#{@current.id} and #{fk_name2}=#{r}").destroy}
145
+ end
146
+ end
147
+ flash[:notice] = @table.titleize + " succesfully updated."
148
+ redirect_to :action => 'show', :id => @current
149
+ end
150
+
151
+ def show_related #for hide/show associated elements from the show action
152
+ object = controller_name.singularize.camelize.constantize.find(params[:id])
153
+ case params[:relation]
154
+ when "one-to-one"
155
+ render :partial => 'shared_views/one_to_one_elements', :locals => {:one => params[:referenced], :object => object}
156
+ when "one-to-one-father"
157
+ render :partial => 'shared_views/one_to_one_father_elements', :locals => {:one => params[:referenced], :object => object}
158
+ when "one-to-many"
159
+ render :partial => 'shared_views/father_elements', :locals => {:father => params[:referenced], :object => object}
160
+ when "one-to-many-child"
161
+ render :partial => 'shared_views/child_elements', :locals => {:child => params[:referenced], :object => object}
162
+ when "many-to-many"
163
+ render :partial => 'shared_views/many_to_many_elements', :locals => {:many => { :join_table => params[:join_table], :name => params[:referenced]}, :object => object}
164
+ end
165
+ end
166
+
167
+ private
168
+
169
+ def authorize #action for login
170
+ if !session[:superuser] #if the user is not the superuser
171
+ unless @user=Login.find_by_usernameMail(session[:username])
172
+ flash[:notice] = "Please login first!"
173
+ redirect_to(:controller => "login") and return false
174
+ end
175
+ end
176
+ end
177
+
178
+ def initialize
179
+ @tables=Table.find(:all) #application table's list
180
+
181
+ end
182
+
183
+ def privileges
184
+ unless session[:superuser]
185
+ @fields_readable={
186
+ :self => check_field_level_privilege("read",controller_name) #finding readable fields of the current table
187
+ }
188
+ #for each father,loading the fields readable
189
+ @fathers.each {|father| @fields_readable[father] = check_field_level_privilege("read",father.pluralize)}
190
+ #for each father in a one-to-one relation, loading the fields readable
191
+ @one_to_one_fathers.each {|one_father| @fields_readable[one_father] = check_field_level_privilege("read",one_father.pluralize)}
192
+ #for each child in a one-to-one relation, loading the fields readable
193
+ @one_to_ones.each {|one| @fields_readable[one] = check_field_level_privilege("read",one.pluralize)}
194
+ @childs.each {|child| @fields_readable[child] = check_field_level_privilege("read",child)}
195
+ @many_to_manys.each {|many|
196
+ @fields_readable[many[:name]] = check_field_level_privilege("read",many[:name])
197
+ @fields_readable[many[:join_table]] = check_field_level_privilege("read",many[:join_table])
198
+ }
199
+
200
+ editables = check_field_level_privilege("update",controller_name)
201
+ editables.each {|f|
202
+ @fields_editable << f.name
203
+ }
204
+
205
+ @can_create=can?("create")
206
+ @can_destroy=can?("destroy")
207
+ end
208
+ end
209
+
210
+ def can?(operation)
211
+ find_role_table_operation(operation)
212
+ return check_privilege
213
+ end
214
+
215
+ def find_role_table_operation(op)
216
+ @role=Login.find_by_usernameMail(session[:username]).role_id
217
+ @table=Table.find_by_name(controller_name).id
218
+ @operation=TabOperation.find_by_operation(op).id
219
+ end
220
+
221
+ def check_privilege
222
+ TabPermission.find_by_role_id_and_table_id_and_tab_operation_id(@role,@table,@operation)
223
+ end
224
+
225
+ def privileges_for_create
226
+ check_table_level_privilege("create")
227
+ end
228
+
229
+ def privileges_for_destroy
230
+ check_table_level_privilege("destroy")
231
+ end
232
+
233
+ def check_table_level_privilege(op)
234
+ if !session[:superuser]
235
+ find_role_table_operation(op)
236
+ unless check_privilege
237
+ flash[:notice] = "Not enough privileges for #{op}!"
238
+ redirect_to(:action => "list")
239
+ end
240
+ end
241
+ end
242
+
243
+ def check_field_level_privilege(oper,table)
244
+ begin
245
+ if !session[:superuser]
246
+ find_fields(oper,table)
247
+ end
248
+ rescue
249
+ flash[:notice] = "No table fields in database!"
250
+ redirect_to(:action => "list")
251
+ end
252
+ end
253
+
254
+ def find_fkeys #helpful for create a select with associated tables
255
+ @fkeys=Relation.find_by_sql(
256
+ "SELECT tf.name,t2.name as referenced_table
257
+ FROM relations r,table_fields tf,tables t1,tables t2
258
+ WHERE r.table_field_id=tf.id and tf.table_id=t1.id and r.table_id=t2.id and t1.name=\"#{controller_name}\" and relation_type <> \"many-to-many\"")
259
+ @rows=[]
260
+ @fkeys.each {|key|
261
+ row={
262
+ :name => key.name,
263
+ :referented_table => key.referenced_table,
264
+ :object => key.referenced_table.singularize.camelize.constantize.find(:all).map {|u| [columns_of(u,key.referenced_table),u.id] }
265
+ }
266
+ @rows << row
267
+ }
268
+ @one_to_one_for_select=[]
269
+ @one_to_ones.each {|one|
270
+ row={
271
+ :name => one,
272
+ :object => one.camelize.constantize.find(:all).map {|u| [columns_of(u,one.pluralize),u.id] }
273
+ }
274
+ @one_to_one_for_select << row
275
+ }
276
+ end
277
+
278
+ def columns_of(object,ref_table)
279
+ string=""
280
+ columns=TableField.find(:all,:include => :table,:conditions => "tables.name=\"#{ref_table}\" and table_fields.name <> \"id\" and table_fields.name not like \"%_id\"")
281
+ columns.each {|col|
282
+ if session[:superuser]
283
+ string += "#{object.send(col.name)} "
284
+ else
285
+ unless @fields_readable[ref_table.singularize].empty?
286
+ @fields_readable[ref_table.singularize].each do |field|
287
+ if col.name == field.name
288
+ string += "#{object.send(col.name)} "
289
+ end
290
+ end
291
+ end
292
+ end
293
+ }
294
+ return string
295
+ end
296
+
297
+ def find_fields(oper,table)
298
+ role=Login.find_by_usernameMail(session[:username]).role_id
299
+ #query for select the field-level privileges
300
+ return Table.find_by_sql(
301
+ "SELECT tf.name FROM tables t,table_fields tf,attr_permissions a,attr_operations op
302
+ where t.id=tf.table_id and tf.id=a.table_field_id and a.attr_operation_id=op.id
303
+ and op.operation=\"#{oper}\" and a.role_id=#{role} and t.name=\"#{table}\""
304
+ )
305
+ end
306
+
307
+ def check_privileges_for_update
308
+ begin
309
+ if !session[:superuser]
310
+ unless params[controller_name.singularize].nil?
311
+ @string=""
312
+ params[controller_name.singularize].each do |p|
313
+ permission = false
314
+ @string=p[0]
315
+ #we skip the columns that acts as foreign key
316
+ if p[0] =~ /_id$/
317
+ permission = true
318
+ end
319
+ @fields_editable.each do |field|
320
+ if field == p[0] #if user can update the field
321
+ permission = true
322
+ end
323
+ #dates are splitten in date(1i),date(2i),date(3i)
324
+ if p[0] =~ /#{field}(\(.i\))$/
325
+ permission = true
326
+ end
327
+ end
328
+
329
+ unless permission #se invece non ce l'ha,viene reindirizzato all'azione list
330
+ flash[:notice] = "Attempting to update a field without permission."
331
+ redirect_to :action => 'list'+@string and return #return to avoid multiple redirect
332
+ end
333
+ end
334
+ end
335
+ end
336
+ rescue
337
+ flash[:notice] = "No table fields in database!"
338
+ redirect_to(:action => "list")
339
+ end
340
+ end
341
+
342
+ def find_relations
343
+ unless session[:superuser]
344
+ @role=Login.find_by_usernameMail(session[:username]).role_id
345
+ end
346
+ @fields_editable = [] #will contain all fields editable
347
+ @rel_permissions=[] #will contain all relations between tables that user can define
348
+ @relations_to_create=[] #will contain all relations that user can create
349
+ @relations_to_destroy=[] #will contain all relations that user can destroy
350
+ @relations_to_update=[] #will contain all relations that user can update
351
+ @child_relations=Relation.find(:all,:conditions => "tables.name=\"#{controller_name}\" and relation_type <> \"many-to-many\" and for_join_table <> \"yes\"",:include => :table)
352
+ @childs=[] #will contain child tables with a one-to-many relation
353
+ @one_to_ones=[] #will contain child tables with a one-to-one relation
354
+ @child_relations.each do |child|
355
+ case child.relation_type
356
+ when "one-to-one"
357
+ @one_to_ones << child.table_field.table.name.singularize
358
+ if session[:superuser] or RelationPermission.find_by_role_id_and_relation_id(@role,child.id)
359
+ @rel_permissions << child.table_field.table.name
360
+ unless session[:superuser]
361
+ @fields_editable << child.table_field.table.name #so we can add a select when editing an element
362
+ if RelationPermission.find_by_role_id_and_relation_id_and_action(@role,child.id,'create')
363
+ @relations_to_create << child.table_field.table.name
364
+ end
365
+ if RelationPermission.find_by_role_id_and_relation_id_and_action(@role,child.id,'destroy')
366
+ @relations_to_destroy << child.table_field.table.name
367
+ end
368
+ if RelationPermission.find_by_role_id_and_relation_id_and_action(@role,child.id,'update')
369
+ @relations_to_update << child.table_field.table.name
370
+ end
371
+ end
372
+ end
373
+ when "one-to-many"
374
+ @childs << child.table_field.table.name
375
+ if session[:superuser] or RelationPermission.find_by_role_id_and_relation_id(@role,child.id)
376
+ @rel_permissions << child.table_field.table.name
377
+ unless session[:superuser]
378
+ if RelationPermission.find_by_role_id_and_relation_id_and_action(@role,child.id,'create')
379
+ @relations_to_create << child.table_field.table.name
380
+ end
381
+ if RelationPermission.find_by_role_id_and_relation_id_and_action(@role,child.id,'destroy')
382
+ @relations_to_destroy << child.table_field.table.name
383
+ end
384
+ end
385
+ end
386
+ end
387
+ end
388
+
389
+
390
+ @father_relations=Relation.find_by_sql(
391
+ "SELECT r.id as id,t2.name as referenced_table,relation_type
392
+ FROM relations r,table_fields tf,tables t1,tables t2
393
+ where r.table_field_id=tf.id and tf.table_id=t1.id and r.table_id=t2.id and t1.name=\"#{controller_name}\" and relation_type <> \"many-to-many\"")
394
+ @fathers=[]
395
+ @one_to_one_fathers=[]
396
+ @father_relations.each {|father|
397
+ if father.relation_type=="one-to-many"
398
+ @fathers << father.referenced_table.singularize
399
+ if session[:superuser] or RelationPermission.find_by_role_id_and_relation_id(@role,father.id)
400
+ @rel_permissions << father.referenced_table
401
+ unless session[:superuser]
402
+ @fields_editable << father.referenced_table
403
+ if RelationPermission.find_by_role_id_and_relation_id_and_action(@role,father.id,'create')
404
+ @relations_to_create << father.referenced_table
405
+ end
406
+ if RelationPermission.find_by_role_id_and_relation_id_and_action(@role,father.id,'destroy')
407
+ @relations_to_destroy << father.referenced_table
408
+ end
409
+ if RelationPermission.find_by_role_id_and_relation_id_and_action(@role,father.id,'update')
410
+ @relations_to_update << father.referenced_table
411
+ end
412
+ end
413
+ end
414
+ end
415
+ if father.relation_type=="one-to-one"
416
+ @one_to_one_fathers << father.referenced_table.singularize
417
+ if session[:superuser] or RelationPermission.find_by_role_id_and_relation_id(@role,father.id)
418
+ @rel_permissions << father.referenced_table
419
+ unless session[:superuser]
420
+ @fields_editable << father.referenced_table
421
+ if RelationPermission.find_by_role_id_and_relation_id_and_action(@role,father.id,'create')
422
+ @relations_to_create << father.referenced_table
423
+ end
424
+ if RelationPermission.find_by_role_id_and_relation_id_and_action(@role,father.id,'destroy')
425
+ @relations_to_destroy << father.referenced_table
426
+ end
427
+ if RelationPermission.find_by_role_id_and_relation_id_and_action(@role,father.id,'update')
428
+ @relations_to_update << father.referenced_table
429
+ end
430
+ end
431
+ end
432
+ end
433
+ }
434
+
435
+ #many to many associated tables from a verse
436
+ @many_to_many_relations_1=Relation.find_by_sql("SELECT r.id as id,t1.name as name,join_table
437
+ FROM relations r,tables t1,tables t2,table_fields tf
438
+ WHERE r.table_field_id=tf.id and r.table_id=t1.id and tf.table_id=t2.id and relation_type=\"many-to-many\" and t2.name=\"#{controller_name}\"")
439
+ @many_to_manys=[]
440
+ @many_to_many_relations_1.each {|many|
441
+ row={
442
+ :name => many.name,
443
+ :join_table => many.join_table
444
+ }
445
+ @many_to_manys << row
446
+ if session[:superuser] or RelationPermission.find_by_role_id_and_relation_id(@role,many.id)
447
+ @rel_permissions << many.name
448
+
449
+ end
450
+ }
451
+
452
+ #many to many associated tables from the other verse
453
+ @many_to_many_relations_2=Relation.find_by_sql("SELECT r.id as id,t2.name as name,join_table
454
+ FROM relations r,tables t1,tables t2,table_fields tf
455
+ WHERE r.table_field_id=tf.id and r.table_id=t1.id and tf.table_id=t2.id and relation_type=\"many-to-many\" and t1.name=\"#{controller_name}\"")
456
+ @many_to_many_relations_2.each { |many|
457
+ row={
458
+ :name => many.name,
459
+ :join_table => many.join_table
460
+ }
461
+ @many_to_manys << row
462
+ if session[:superuser] or RelationPermission.find_by_role_id_and_relation_id(@role,many.id)
463
+ @rel_permissions << many.name
464
+ end
465
+ }
466
+ end
467
+
468
+ def find_related_columns
469
+ @fathers.each {|f|
470
+ for column in f.camelize.constantize.content_columns
471
+ if session[:superuser]
472
+ @columns << "#{f.camelize.constantize.table_name}.#{column.name}"
473
+ else
474
+ @fields_readable[f].each do |field|
475
+ if column.name == field.name
476
+ @columns << "#{f.camelize.constantize.table_name}.#{column.name}"
477
+ end
478
+ end
479
+ end
480
+ end
481
+ }
482
+ @one_to_ones.each {|one|
483
+ for column in one.camelize.constantize.content_columns
484
+ if session[:superuser]
485
+ @columns << "#{one.camelize.constantize.table_name}.#{column.name}"
486
+ else
487
+ @fields_readable[one].each do |f|
488
+ if column.name == f.name
489
+ @columns << "#{one.camelize.constantize.table_name}.#{column.name}"
490
+ end
491
+ end
492
+ end
493
+ end
494
+ }
495
+ @one_to_one_fathers.each {|one|
496
+ for column in one.camelize.constantize.content_columns
497
+ if session[:superuser]
498
+ @columns << "#{one.camelize.constantize.table_name}.#{column.name}"
499
+ else
500
+ @fields_readable[one].each do |f|
501
+ if column.name == f.name
502
+ @columns << "#{one.camelize.constantize.table_name}.#{column.name}"
503
+ end
504
+ end
505
+ end
506
+ end
507
+ }
508
+ end
509
+
510
+ def find_conditions_for_search
511
+ if params[:order]==""
512
+ @order = ""
513
+ else
514
+ @order = params[:order]
515
+ end
516
+ @conditions= ""
517
+ if params[:search_type].nil? or params[:search_type].empty? #if an advanced query isn't done
518
+ @filter=params[:query]
519
+ @filter="" if @filter.nil?
520
+ i=1
521
+ unless @filter.empty?
522
+ @conditions_string="Showing rows where each column like '%#{@filter}%'"
523
+ end
524
+ @columns.each {|c|
525
+ @conditions += "#{c} LIKE :filter"
526
+ @conditions += " or " unless i==@columns.length
527
+ i+=1
528
+ }
529
+ @conditions = "true" if @conditions=="" #else an exception will be thrown
530
+ else #an advanced query is done
531
+ @query_advanced=params[:query_advanced]
532
+ @criteria=params[:criteria]
533
+ @search_type=params[:search_type]
534
+ @selected_columns=params[:columns]
535
+ @min=params[:min]
536
+ @max=params[:max]
537
+ if params[:columns].is_a?(String)
538
+ @selected_columns=Array.new
539
+ params[:columns].split("/").each do |col|
540
+ @selected_columns << col
541
+ end
542
+ end
543
+ if !@selected_columns.nil? and ((!@query_advanced.nil? and !@query_advanced.empty? and @search_type=="unilateral") or ((!@min.nil? and !@min.empty? and @search_type=="bilateral") or (!@max.nil? and !@max.empty? and @search_type=="bilateral")))
544
+ @conditions_string="Showing rows where:<br />"
545
+ i=1
546
+ if @search_type == "unilateral"
547
+ unless params[:not_for_unilateral_search].nil? #the checkbox for the negation has been checked
548
+ case @criteria
549
+ when "like" then @criteria="not like"
550
+ when "=" then @criteria="<>"
551
+ when "<" then @criteria=">="
552
+ when ">" then @criteria="<="
553
+ end
554
+ end
555
+ @selected_columns.each do |column|
556
+ @conditions_string += "- #{column} #{@criteria} '#{@query_advanced}'"
557
+ @conditions += "#{column} #{@criteria} :filter"
558
+ @conditions += " or " unless i==@selected_columns.length
559
+ @conditions_string += "<br />&nbsp;&nbsp;&nbsp;&nbsp;Or<br />" unless i==@selected_columns.length
560
+ i+=1
561
+ end
562
+ elsif @search_type == "bilateral"
563
+ @selected_columns.each do |column|
564
+ if !@min.nil? and !@min.empty? and !@max.nil? and !@max.empty?
565
+ unless params[:not_for_interval_search].nil? #the checkbox for the negation has been checked
566
+ @conditions += "(#{column} <= :min or #{column} >= :max)"
567
+ @conditions_string += "- #{column} not between [#{@min},#{@max}]"
568
+ else
569
+ @conditions += "(#{column} >= :min and #{column} <= :max)"
570
+ @conditions_string += "- #{column} between [#{@min},#{@max}]"
571
+ end
572
+ elsif !@min.nil? and !@min.empty?
573
+ if params[:not_for_interval_search].nil?
574
+ @conditions += "(#{column} >= :min)"
575
+ @conditions_string += "- #{column} between [#{@min},inf]"
576
+ else
577
+ @conditions += "(#{column} < :min)"
578
+ @conditions_string += "- #{column} not between [#{@min},inf]"
579
+ end
580
+ else
581
+ if params[:not_for_interval_search].nil?
582
+ @conditions += "(#{column} <= :max)"
583
+ @conditions_string += "- #{column} between [-inf,#{@max}]"
584
+ else
585
+ @conditions += "(#{column} > :max)"
586
+ @conditions_string += "- #{column} not between [-inf,#{@max}]"
587
+ end
588
+ end
589
+ @conditions += " or " unless i==@selected_columns.length
590
+ @conditions_string += "<br />&nbsp;&nbsp;&nbsp;&nbsp;Or<br />" unless i==@selected_columns.length
591
+ i+=1
592
+ end
593
+ end
594
+ @conditions_string += "<br />Search type: #{@search_type}"
595
+ else
596
+ if @selected_columns.nil? #if no columns has been selected
597
+ flash[:notice] = "No columns selected for searching. Showing all rows."
598
+ else #if no filter has been written
599
+ flash[:notice] = "No filter text has been written for #{@search_type} search. Showing all rows."
600
+ end
601
+ end
602
+ @conditions = "true" if @conditions=="" #else an exception will be thrown
603
+
604
+ end
605
+ end
606
+
607
+ end