typus 3.0.6 → 3.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (295) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +15 -0
  3. data/Gemfile +9 -5
  4. data/Rakefile +34 -21
  5. data/app/controllers/admin/base_controller.rb +0 -4
  6. data/app/controllers/admin/resources_controller.rb +77 -213
  7. data/app/controllers/admin/session_controller.rb +1 -1
  8. data/app/helpers/admin/base_helper.rb +4 -4
  9. data/app/helpers/admin/dashboard_helper.rb +1 -3
  10. data/app/helpers/admin/display_helper.rb +49 -0
  11. data/app/helpers/admin/file_preview_helper.rb +10 -12
  12. data/app/helpers/admin/filters_helper.rb +1 -1
  13. data/app/helpers/admin/form_helper.rb +2 -13
  14. data/app/helpers/admin/list_helper.rb +14 -3
  15. data/app/helpers/admin/relationships_helper.rb +79 -62
  16. data/app/helpers/admin/resources_helper.rb +17 -16
  17. data/app/helpers/admin/search_helper.rb +1 -1
  18. data/app/helpers/admin/sidebar_helper.rb +1 -2
  19. data/app/helpers/admin/table_helper.rb +9 -4
  20. data/app/views/admin/helpers/_file_preview.html.erb +1 -1
  21. data/app/views/admin/helpers/base/_apps.html.erb +23 -0
  22. data/app/views/admin/helpers/{_flash_message.html.erb → base/_flash_message.html.erb} +0 -0
  23. data/app/views/admin/helpers/{_header.html.erb → base/_header.html.erb} +0 -0
  24. data/app/views/admin/helpers/{_login_info.html.erb → base/_login_info.html.erb} +0 -0
  25. data/app/views/admin/helpers/resources/_display_link_to_previous.html.erb +1 -1
  26. data/app/views/admin/resources/show.html.erb +4 -27
  27. data/app/views/admin/templates/_belongs_to_with_autocomplete.html.erb +11 -0
  28. data/app/views/admin/templates/_has_n.html.erb +1 -1
  29. data/app/views/admin/templates/_has_one.html.erb +3 -3
  30. data/app/views/admin/templates/_relate_form.html.erb +1 -1
  31. data/app/views/admin/templates/_relate_form_with_autocomplete.html.erb +24 -0
  32. data/app/views/layouts/admin/base.html.erb +15 -9
  33. data/app/views/layouts/admin/headless.html.erb +44 -0
  34. data/app/views/layouts/admin/session.html.erb +3 -2
  35. data/doc/hudson_setup.md +19 -0
  36. data/lib/generators/typus/assets_generator.rb +0 -4
  37. data/lib/generators/typus/config_generator.rb +107 -0
  38. data/lib/generators/typus/controller_generator.rb +0 -4
  39. data/lib/generators/typus/initializers_generator.rb +22 -0
  40. data/lib/generators/typus/migration_generator.rb +0 -4
  41. data/lib/generators/typus/typus_generator.rb +8 -101
  42. data/lib/generators/typus/views_generator.rb +0 -4
  43. data/lib/support/active_record.rb +8 -2
  44. data/lib/support/fake_user.rb +2 -0
  45. data/lib/support/hash.rb +1 -1
  46. data/lib/support/string.rb +3 -3
  47. data/lib/tasks/typus.rake +1 -1
  48. data/lib/typus.rb +15 -6
  49. data/lib/typus/controller/actions.rb +69 -0
  50. data/lib/typus/controller/associations.rb +82 -0
  51. data/lib/typus/controller/autocomplete.rb +16 -0
  52. data/lib/typus/controller/filters.rb +24 -0
  53. data/lib/typus/controller/format.rb +70 -0
  54. data/lib/typus/orm/active_record.rb +9 -240
  55. data/lib/typus/orm/active_record/class_methods.rb +227 -0
  56. data/lib/typus/orm/active_record/instance_methods.rb +13 -0
  57. data/lib/typus/orm/active_record/search.rb +17 -5
  58. data/lib/typus/orm/active_record/user.rb +157 -0
  59. data/lib/typus/regex.rb +11 -0
  60. data/lib/typus/version.rb +1 -1
  61. data/test/app/controllers/admin/account_controller_test.rb +104 -0
  62. data/test/app/controllers/admin/assets_controller_test.rb +153 -0
  63. data/test/app/controllers/admin/base_controller_test.rb +41 -0
  64. data/test/app/controllers/admin/birds_controller_test.rb +42 -0
  65. data/test/app/controllers/admin/cases_controller_test.rb +21 -0
  66. data/test/app/controllers/admin/categories_controller_test.rb +141 -0
  67. data/test/app/controllers/admin/comments_controller_test.rb +79 -0
  68. data/test/app/controllers/admin/dashboard_controller_test.rb +162 -0
  69. data/test/app/controllers/admin/image_holders_controller_test.rb +75 -0
  70. data/test/app/controllers/admin/invoices_controller_test.rb +78 -0
  71. data/test/app/controllers/admin/orders_controller_test.rb +18 -0
  72. data/test/app/controllers/admin/pages_controller_test.rb +37 -0
  73. data/test/app/controllers/admin/posts_controller_test.rb +745 -0
  74. data/test/app/controllers/admin/projects_controller_test.rb +52 -0
  75. data/test/app/controllers/admin/session_controller_test.rb +92 -0
  76. data/test/app/controllers/admin/status_controller_test.rb +54 -0
  77. data/test/app/controllers/admin/typus_users_controller_test.rb +160 -0
  78. data/test/app/controllers/admin/users_controller_test.rb +106 -0
  79. data/test/app/helpers/admin/base_helper_test.rb +83 -0
  80. data/test/app/helpers/admin/dashboard_helper_test.rb +32 -0
  81. data/test/app/helpers/admin/file_preview_helper_test.rb +82 -0
  82. data/test/app/helpers/admin/filters_helper_test.rb +161 -0
  83. data/test/app/helpers/admin/form_helper_test.rb +126 -0
  84. data/test/app/helpers/admin/list_helper_test.rb +59 -0
  85. data/test/app/helpers/admin/relationships_helper_test.rb +19 -0
  86. data/test/app/helpers/admin/resources_helper_test.rb +46 -0
  87. data/test/app/helpers/admin/search_helper_test.rb +60 -0
  88. data/test/app/helpers/admin/sidebar_helper_test.rb +34 -0
  89. data/test/app/helpers/admin/table_helper_test.rb +215 -0
  90. data/test/app/mailers/admin/mailer_test.rb +32 -0
  91. data/test/app/models/typus_user_roles_test.rb +124 -0
  92. data/test/app/models/typus_user_test.rb +194 -0
  93. data/test/config/routes_test.rb +29 -0
  94. data/test/factories.rb +111 -0
  95. data/test/fixtures/config/broken/application.yml +68 -0
  96. data/test/fixtures/config/broken/application_roles.yml +20 -0
  97. data/test/fixtures/config/broken/empty.yml +0 -0
  98. data/test/fixtures/config/broken/empty_roles.yml +0 -0
  99. data/test/fixtures/config/broken/undefined.yml +3 -0
  100. data/test/fixtures/config/broken/undefined_roles.yml +6 -0
  101. data/test/fixtures/config/default/typus.yml +13 -0
  102. data/test/fixtures/config/default/typus_roles.yml +2 -0
  103. data/test/fixtures/config/empty/empty_01.yml +0 -0
  104. data/test/fixtures/config/empty/empty_01_roles.yml +0 -0
  105. data/test/fixtures/config/empty/empty_02.yml +0 -0
  106. data/test/fixtures/config/empty/empty_02_roles.yml +0 -0
  107. data/test/fixtures/config/locales/es.yml +10 -0
  108. data/test/fixtures/config/namespaced/application.yml +5 -0
  109. data/test/fixtures/config/namespaced/application_roles.yml +2 -0
  110. data/test/fixtures/config/ordered/001_roles.yml +2 -0
  111. data/test/fixtures/config/ordered/002_roles.yml +2 -0
  112. data/test/fixtures/config/unordered/app_one_roles.yml +2 -0
  113. data/test/fixtures/config/unordered/app_two_roles.yml +2 -0
  114. data/test/fixtures/rails_app/.gitignore +4 -0
  115. data/test/fixtures/rails_app/Capfile +6 -0
  116. data/test/fixtures/rails_app/README +256 -0
  117. data/test/fixtures/rails_app/Rakefile +7 -0
  118. data/test/fixtures/rails_app/app/controllers/admin/animals_controller.rb +2 -0
  119. data/test/fixtures/rails_app/app/controllers/admin/articles_controller.rb +2 -0
  120. data/test/fixtures/rails_app/app/controllers/admin/assets_controller.rb +51 -0
  121. data/test/fixtures/rails_app/app/controllers/admin/birds_controller.rb +2 -0
  122. data/test/fixtures/rails_app/app/controllers/admin/cases_controller.rb +2 -0
  123. data/test/fixtures/rails_app/app/controllers/admin/categories_controller.rb +2 -0
  124. data/test/fixtures/rails_app/app/controllers/admin/comments_controller.rb +2 -0
  125. data/test/fixtures/rails_app/app/controllers/admin/dogs_controller.rb +2 -0
  126. data/test/fixtures/rails_app/app/controllers/admin/entries_controller.rb +2 -0
  127. data/test/fixtures/rails_app/app/controllers/admin/image_holders_controller.rb +2 -0
  128. data/test/fixtures/rails_app/app/controllers/admin/invoices_controller.rb +2 -0
  129. data/test/fixtures/rails_app/app/controllers/admin/orders_controller.rb +2 -0
  130. data/test/fixtures/rails_app/app/controllers/admin/pages_controller.rb +7 -0
  131. data/test/fixtures/rails_app/app/controllers/admin/posts_controller.rb +2 -0
  132. data/test/fixtures/rails_app/app/controllers/admin/project_collaborators_controller.rb +2 -0
  133. data/test/fixtures/rails_app/app/controllers/admin/projects_controller.rb +2 -0
  134. data/test/fixtures/rails_app/app/controllers/admin/status_controller.rb +2 -0
  135. data/test/fixtures/rails_app/app/controllers/admin/typus_users_controller.rb +2 -0
  136. data/test/fixtures/rails_app/app/controllers/admin/users_controller.rb +2 -0
  137. data/test/fixtures/rails_app/app/controllers/admin/views_controller.rb +2 -0
  138. data/test/fixtures/rails_app/app/controllers/admin/watch_dog_controller.rb +2 -0
  139. data/test/fixtures/rails_app/app/controllers/application_controller.rb +3 -0
  140. data/test/fixtures/rails_app/app/helpers/application_helper.rb +2 -0
  141. data/test/fixtures/rails_app/app/helpers/form_helper.rb +3 -0
  142. data/test/fixtures/rails_app/app/models/animal.rb +21 -0
  143. data/test/fixtures/rails_app/app/models/article.rb +10 -0
  144. data/test/fixtures/rails_app/app/models/asset.rb +39 -0
  145. data/test/fixtures/rails_app/app/models/bird.rb +2 -0
  146. data/test/fixtures/rails_app/app/models/case.rb +2 -0
  147. data/test/fixtures/rails_app/app/models/category.rb +31 -0
  148. data/test/fixtures/rails_app/app/models/comment.rb +17 -0
  149. data/test/fixtures/rails_app/app/models/delayed/task.rb +5 -0
  150. data/test/fixtures/rails_app/app/models/dog.rb +2 -0
  151. data/test/fixtures/rails_app/app/models/entry.rb +23 -0
  152. data/test/fixtures/rails_app/app/models/image_holder.rb +21 -0
  153. data/test/fixtures/rails_app/app/models/invoice.rb +10 -0
  154. data/test/fixtures/rails_app/app/models/order.rb +9 -0
  155. data/test/fixtures/rails_app/app/models/page.rb +24 -0
  156. data/test/fixtures/rails_app/app/models/post.rb +32 -0
  157. data/test/fixtures/rails_app/app/models/project.rb +17 -0
  158. data/test/fixtures/rails_app/app/models/project_collaborator.rb +16 -0
  159. data/test/fixtures/rails_app/app/models/typus_user.rb +22 -0
  160. data/test/fixtures/rails_app/app/models/user.rb +10 -0
  161. data/test/fixtures/rails_app/app/models/view.rb +17 -0
  162. data/test/fixtures/rails_app/app/views/admin/assets/_index.html.erb +3 -0
  163. data/test/fixtures/rails_app/app/views/admin/cases/_index.html.erb +3 -0
  164. data/test/fixtures/rails_app/app/views/admin/categories/_index.html.erb +3 -0
  165. data/test/fixtures/rails_app/app/views/admin/dashboard/_sidebar.html.erb +11 -0
  166. data/test/fixtures/rails_app/app/views/admin/entries/_index.html.erb +3 -0
  167. data/test/fixtures/rails_app/app/views/admin/pages/_index.html.erb +3 -0
  168. data/test/fixtures/rails_app/app/views/admin/posts/_edit.html.erb +1 -0
  169. data/test/fixtures/rails_app/app/views/admin/posts/_index.html.erb +5 -0
  170. data/test/fixtures/rails_app/app/views/admin/posts/_new.html.erb +1 -0
  171. data/test/fixtures/rails_app/app/views/admin/posts/_show.html.erb +1 -0
  172. data/test/fixtures/rails_app/app/views/admin/resources/_sidebar.html.erb +1 -0
  173. data/test/fixtures/rails_app/app/views/admin/status/index.html.erb +9 -0
  174. data/test/fixtures/rails_app/app/views/admin/templates/_datepicker.html.erb +1 -0
  175. data/test/fixtures/rails_app/app/views/admin/watch_dog/index.html.erb +9 -0
  176. data/test/fixtures/rails_app/app/views/layouts/admin/headless.html.erb +38 -0
  177. data/test/fixtures/rails_app/config.ru +4 -0
  178. data/test/fixtures/rails_app/config/application.rb +44 -0
  179. data/test/fixtures/rails_app/config/boot.rb +13 -0
  180. data/test/fixtures/rails_app/config/database.yml +34 -0
  181. data/test/fixtures/rails_app/config/deploy.rb +32 -0
  182. data/test/fixtures/rails_app/config/environment.rb +5 -0
  183. data/test/fixtures/rails_app/config/environments/development.rb +32 -0
  184. data/test/fixtures/rails_app/config/environments/production.rb +54 -0
  185. data/test/fixtures/rails_app/config/environments/test.rb +40 -0
  186. data/test/fixtures/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  187. data/test/fixtures/rails_app/config/initializers/dragonfly.rb +1 -0
  188. data/test/fixtures/rails_app/config/initializers/inflections.rb +12 -0
  189. data/test/fixtures/rails_app/config/initializers/mime_types.rb +5 -0
  190. data/test/fixtures/rails_app/config/initializers/secret_token.rb +7 -0
  191. data/test/fixtures/rails_app/config/initializers/session_store.rb +8 -0
  192. data/test/fixtures/rails_app/config/initializers/typus.rb +5 -0
  193. data/test/fixtures/rails_app/config/initializers/typus_resources.rb +27 -0
  194. data/test/fixtures/rails_app/config/locales/en.yml +5 -0
  195. data/test/fixtures/rails_app/config/routes.rb +61 -0
  196. data/test/fixtures/rails_app/config/typus/README +68 -0
  197. data/test/fixtures/rails_app/config/typus/crud_basic.yml +10 -0
  198. data/test/fixtures/rails_app/config/typus/crud_basic_roles.yml +2 -0
  199. data/test/fixtures/rails_app/config/typus/crud_extended.yml +64 -0
  200. data/test/fixtures/rails_app/config/typus/crud_extended_roles.yml +18 -0
  201. data/test/fixtures/rails_app/config/typus/has_many.yml +0 -0
  202. data/test/fixtures/rails_app/config/typus/has_many_roles.yml +0 -0
  203. data/test/fixtures/rails_app/config/typus/has_many_through.yml +23 -0
  204. data/test/fixtures/rails_app/config/typus/has_many_through_roles.yml +4 -0
  205. data/test/fixtures/rails_app/config/typus/has_one.yml +12 -0
  206. data/test/fixtures/rails_app/config/typus/has_one_roles.yml +3 -0
  207. data/test/fixtures/rails_app/config/typus/polymorphic.yml +17 -0
  208. data/test/fixtures/rails_app/config/typus/polymorphic_roles.yml +5 -0
  209. data/test/fixtures/rails_app/config/typus/resource_roles.yml +7 -0
  210. data/test/fixtures/rails_app/config/typus/sti.yml +5 -0
  211. data/test/fixtures/rails_app/config/typus/sti_roles.yml +2 -0
  212. data/test/fixtures/rails_app/config/typus/typus.yml +13 -0
  213. data/test/fixtures/rails_app/config/typus/typus_roles.yml +2 -0
  214. data/test/fixtures/rails_app/config/typus/unknown.yml +3 -0
  215. data/test/fixtures/rails_app/config/typus/unknown_roles.yml +5 -0
  216. data/test/fixtures/rails_app/db/.gitkeep +0 -0
  217. data/test/fixtures/rails_app/db/schema.rb +174 -0
  218. data/test/fixtures/rails_app/db/seeds.rb +54 -0
  219. data/test/fixtures/rails_app/db/seeds/assets/000.jpg +0 -0
  220. data/test/fixtures/rails_app/db/seeds/assets/001.jpg +0 -0
  221. data/test/fixtures/rails_app/db/seeds/assets/002.jpg +0 -0
  222. data/test/fixtures/rails_app/db/seeds/assets/003.jpg +0 -0
  223. data/test/fixtures/rails_app/db/seeds/assets/004.jpg +0 -0
  224. data/test/fixtures/rails_app/public/404.html +26 -0
  225. data/test/fixtures/rails_app/public/422.html +26 -0
  226. data/test/fixtures/rails_app/public/500.html +26 -0
  227. data/test/fixtures/rails_app/public/favicon.ico +0 -0
  228. data/test/fixtures/rails_app/public/images/rails.png +0 -0
  229. data/test/fixtures/rails_app/public/javascripts/application.js +2 -0
  230. data/test/fixtures/rails_app/public/javascripts/controls.js +965 -0
  231. data/test/fixtures/rails_app/public/javascripts/dragdrop.js +974 -0
  232. data/test/fixtures/rails_app/public/javascripts/effects.js +1123 -0
  233. data/test/fixtures/rails_app/public/javascripts/prototype.js +6001 -0
  234. data/test/fixtures/rails_app/public/javascripts/rails.js +175 -0
  235. data/test/fixtures/rails_app/public/robots.txt +5 -0
  236. data/test/fixtures/rails_app/public/stylesheets/.gitkeep +0 -0
  237. data/test/fixtures/rails_app/script/rails +6 -0
  238. data/test/lib/support/active_record_test.rb +150 -0
  239. data/test/lib/support/fake_user_test.rb +59 -0
  240. data/test/lib/support/hash_test.rb +29 -0
  241. data/test/lib/support/object_test.rb +17 -0
  242. data/test/lib/support/string_test.rb +116 -0
  243. data/test/lib/typus/configuration_test.rb +46 -0
  244. data/test/lib/typus/controller/actions_test.rb +141 -0
  245. data/test/lib/typus/controller/associations_test.rb +7 -0
  246. data/test/lib/typus/controller/autocomplete_test.rb +7 -0
  247. data/test/lib/typus/controller/filters_test.rb +73 -0
  248. data/test/lib/typus/controller/format_test.rb +7 -0
  249. data/test/lib/typus/i18n_test.rb +9 -0
  250. data/test/lib/typus/orm/active_record/class_methods_test.rb +378 -0
  251. data/test/lib/typus/orm/active_record/search_test.rb +330 -0
  252. data/test/lib/typus/regex_test.rb +53 -0
  253. data/test/lib/typus/resources_test.rb +41 -0
  254. data/test/lib/typus_test.rb +141 -0
  255. data/test/test_helper.rb +15 -0
  256. data/typus.gemspec +25 -0
  257. metadata +586 -64
  258. data/Gemfile.lock +0 -149
  259. data/app/views/admin/helpers/_apps.html.erb +0 -9
  260. data/lib/generators/templates/public/admin/javascripts/application.js +0 -2
  261. data/lib/generators/templates/public/admin/javascripts/jquery-1.4.4.min.js +0 -167
  262. data/lib/generators/templates/public/admin/javascripts/jquery.application.js +0 -16
  263. data/lib/generators/templates/public/admin/javascripts/jquery.rails.js +0 -160
  264. data/lib/generators/templates/public/admin/javascripts/jquery.searchField.js +0 -91
  265. data/lib/generators/templates/public/admin/stylesheets/application.css +0 -11
  266. data/lib/generators/templates/public/admin/stylesheets/screen.css +0 -367
  267. data/lib/generators/templates/public/admin/vendor/fancybox/blank.gif +0 -0
  268. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_close.png +0 -0
  269. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_loading.png +0 -0
  270. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_nav_left.png +0 -0
  271. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_nav_right.png +0 -0
  272. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_e.png +0 -0
  273. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_n.png +0 -0
  274. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_ne.png +0 -0
  275. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_nw.png +0 -0
  276. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_s.png +0 -0
  277. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_se.png +0 -0
  278. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_sw.png +0 -0
  279. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_shadow_w.png +0 -0
  280. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_left.png +0 -0
  281. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_main.png +0 -0
  282. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_over.png +0 -0
  283. data/lib/generators/templates/public/admin/vendor/fancybox/fancy_title_right.png +0 -0
  284. data/lib/generators/templates/public/admin/vendor/fancybox/fancybox-x.png +0 -0
  285. data/lib/generators/templates/public/admin/vendor/fancybox/fancybox-y.png +0 -0
  286. data/lib/generators/templates/public/admin/vendor/fancybox/fancybox.png +0 -0
  287. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.easing-1.3.pack.js +0 -72
  288. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.css +0 -359
  289. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.js +0 -1156
  290. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.fancybox-1.3.4.pack.js +0 -46
  291. data/lib/generators/templates/public/admin/vendor/fancybox/jquery.mousewheel-3.0.4.pack.js +0 -14
  292. data/lib/typus/actions.rb +0 -41
  293. data/lib/typus/filters.rb +0 -12
  294. data/lib/typus/format.rb +0 -70
  295. data/lib/typus/user.rb +0 -157
@@ -0,0 +1,13 @@
1
+ module Typus
2
+ module Orm
3
+ module ActiveRecord
4
+ module InstanceMethods
5
+
6
+ def owned_by?(user)
7
+ send(Typus.user_fk) == user.id
8
+ end
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,18 +1,25 @@
1
1
  module Typus
2
2
  module Orm
3
- module ClassMethods
3
+ module ActiveRecord
4
4
  module Search
5
5
 
6
6
  def build_search_conditions(key, value)
7
7
  Array.new.tap do |search|
8
- query = ActiveRecord::Base.connection.quote_string(value.downcase)
9
- typus_search_fields.each do |key, value|
8
+ query = ::ActiveRecord::Base.connection.quote_string(value.downcase)
9
+
10
+ search_fields = typus_search_fields
11
+ search_fields = search_fields.empty? ? { "name" => "@" } : search_fields
12
+
13
+ search_fields.each do |key, value|
10
14
  _query = case value
11
15
  when "=" then query
12
16
  when "^" then "#{query}%"
13
17
  when "@" then "%#{query}%"
14
18
  end
15
- table_key = (adapter == 'postgresql') ? "LOWER(TEXT(#{table_name}.#{key}))" : "#{table_name}.#{key}"
19
+
20
+ column_name = (key.match('\.') ? key : "#{table_name}.#{key}")
21
+ table_key = (adapter == 'postgresql') ? "LOWER(TEXT(#{column_name}))" : "#{column_name}"
22
+
16
23
  search << "#{table_key} LIKE '#{_query}'"
17
24
  end
18
25
  end.join(" OR ")
@@ -70,7 +77,12 @@ module Typus
70
77
  def build_conditions(params)
71
78
  Array.new.tap do |conditions|
72
79
  query_params = params.dup
73
- query_params.reject! { |k, v| !model_fields.keys.include?(k.to_sym) && !model_relationships.keys.include?(k.to_sym) && !(k.to_sym == :search) }
80
+
81
+ query_params.reject! do |k, v|
82
+ !model_fields.keys.include?(k.to_sym) &&
83
+ !model_relationships.keys.include?(k.to_sym) &&
84
+ !(k.to_sym == :search)
85
+ end
74
86
 
75
87
  query_params.compact.each do |key, value|
76
88
  filter_type = model_fields[key.to_sym] || model_relationships[key.to_sym] || key
@@ -0,0 +1,157 @@
1
+ module Typus
2
+ module Orm
3
+ module ActiveRecord
4
+ module User
5
+
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+
12
+ def enable_as_typus_user
13
+
14
+ extend ClassMethodsMixin
15
+
16
+ attr_accessor :password
17
+ attr_protected :status
18
+
19
+ validates :email,
20
+ :presence => true,
21
+ :uniqueness => true,
22
+ :format => { :with => Typus::Regex::Email }
23
+
24
+ validates :password,
25
+ :confirmation => { :if => :password_required? },
26
+ :presence => { :if => :password_required? }
27
+
28
+ validates_length_of :password, :within => 6..40, :if => :password_required?
29
+
30
+ validates :role, :presence => true
31
+
32
+ before_save :initialize_salt, :encrypt_password, :initialize_token
33
+
34
+ serialize :preferences
35
+
36
+ include InstanceMethods
37
+
38
+ end
39
+
40
+ end
41
+
42
+ module ClassMethodsMixin
43
+
44
+ def authenticate(email, password)
45
+ user = find_by_email_and_status(email, true)
46
+ user && user.authenticated?(password) ? user : nil
47
+ end
48
+
49
+ def generate(*args)
50
+ options = args.extract_options!
51
+
52
+ options[:password] ||= ActiveSupport::SecureRandom.hex(4)
53
+ options[:role] ||= Typus.master_role
54
+
55
+ new :email => options[:email],
56
+ :password => options[:password],
57
+ :password_confirmation => options[:password],
58
+ :role => options[:role],
59
+ :preferences => { :locale => ::I18n.default_locale.to_s }
60
+ end
61
+
62
+ end
63
+
64
+ module InstanceMethods
65
+
66
+ def name
67
+ full_name = [first_name, last_name].delete_if { |s| s.blank? }
68
+ full_name.any? ? full_name.join(" ") : email
69
+ end
70
+
71
+ def authenticated?(password)
72
+ crypted_password == encrypt(password)
73
+ end
74
+
75
+ def resources
76
+ Typus::Configuration.roles[role].compact
77
+ end
78
+
79
+ def applications
80
+ Typus.applications.delete_if { |a| application(a).empty? }
81
+ end
82
+
83
+ def application(name)
84
+ Typus.application(name).delete_if { |r| !resources.keys.include?(r) }
85
+ end
86
+
87
+ def can?(action, resource, options = {})
88
+ resource = resource.model_name if resource.is_a?(Class)
89
+
90
+ return false if !resources.include?(resource)
91
+ return true if resources[resource].include?("all")
92
+
93
+ action = options[:special] ? action : action.acl_action_mapper
94
+
95
+ resources[resource].extract_settings.include?(action)
96
+ end
97
+
98
+ def cannot?(*args)
99
+ !can?(*args)
100
+ end
101
+
102
+ def is_root?
103
+ role == Typus.master_role
104
+ end
105
+
106
+ def is_not_root?
107
+ !is_root?
108
+ end
109
+
110
+ def locale
111
+ (preferences && preferences[:locale]) ? preferences[:locale] : ::I18n.default_locale
112
+ end
113
+
114
+ def locale=(locale)
115
+ options = { :locale => locale }
116
+ self.preferences ||= {}
117
+ self.preferences[:locale] = locale
118
+ end
119
+
120
+ protected
121
+
122
+ # TODO: Update the hash generation by a harder one ...
123
+ def generate_hash(string)
124
+ Digest::SHA1.hexdigest(string)
125
+ end
126
+
127
+ def encrypt_password
128
+ return if password.blank?
129
+ self.crypted_password = encrypt(password)
130
+ end
131
+
132
+ def encrypt(string)
133
+ generate_hash("--#{salt}--#{string}--")
134
+ end
135
+
136
+ def initialize_salt
137
+ self.salt = generate_hash("--#{Time.zone.now.to_s(:number)}--#{email}--") if new_record?
138
+ end
139
+
140
+ def initialize_token
141
+ generate_token if new_record?
142
+ end
143
+
144
+ def generate_token
145
+ self.token = encrypt("--#{Time.zone.now.to_s(:number)}--#{password}--").first(12)
146
+ end
147
+
148
+ def password_required?
149
+ crypted_password.blank? || !password.blank?
150
+ end
151
+
152
+ end
153
+
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,11 @@
1
+ module Typus
2
+
3
+ module Regex
4
+
5
+ Email = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/
6
+
7
+ Url = /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix
8
+
9
+ end
10
+
11
+ end
data/lib/typus/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Typus
2
- VERSION = "3.0.6"
2
+ VERSION = "3.0.7"
3
3
  end
@@ -0,0 +1,104 @@
1
+ require "test_helper"
2
+
3
+ =begin
4
+
5
+ What's being tested here?
6
+
7
+ - Create first user. (/admin/account/new)
8
+ - Stuff that happens when there are already users.
9
+
10
+ =end
11
+
12
+ class Admin::AccountControllerTest < ActionController::TestCase
13
+
14
+ context "No users" do
15
+
16
+ should "render new when there are not admin users" do
17
+ get :new
18
+
19
+ assert_response :success
20
+ assert_template "new"
21
+ assert_equal "Enter your email below to create the first user.", flash[:notice]
22
+ end
23
+
24
+ should "render session layout" do
25
+ get :new
26
+ assert_template "new"
27
+ assert_template "layouts/admin/session"
28
+ end
29
+
30
+ should "verify forgot_password redirects to new when there are no admin users" do
31
+ get :forgot_password
32
+
33
+ assert_response :redirect
34
+ assert_redirected_to new_admin_account_path
35
+ end
36
+
37
+ should "verify send_password redirects to new when there are no admin users"
38
+
39
+ should "not sign_up invalid emails" do
40
+ post :create, :typus_user => { :email => "example.com" }
41
+
42
+ assert_response :redirect
43
+ assert_redirected_to :action => :new
44
+ assert flash.empty?
45
+ end
46
+
47
+ should "sign_up a valid email" do
48
+ assert_difference('TypusUser.count') do
49
+ post :create, :typus_user => { :email => "john@example.com" }
50
+ end
51
+
52
+ assert_response :redirect
53
+ assert_redirected_to :action => "show", :id => TypusUser.find_by_email("john@example.com").token
54
+ end
55
+
56
+ end
57
+
58
+ context "There are users" do
59
+
60
+ setup do
61
+ @typus_user = Factory(:typus_user)
62
+ end
63
+
64
+ should "new redirect new admin session when there are admin users" do
65
+ get :new
66
+ assert_response :redirect
67
+ assert_redirected_to new_admin_session_path
68
+ end
69
+
70
+ should "verify forgot_password is rendered when there are admin users" do
71
+ get :forgot_password
72
+ assert_response :success
73
+ assert_template "forgot_password"
74
+ end
75
+
76
+ should "not_send_recovery_password_link_to_unexisting_user" do
77
+ post :send_password, { :typus_user => { :email => "unexisting" } }
78
+ assert_response :success
79
+ assert flash.empty?
80
+ end
81
+
82
+ should "test_should_send_recovery_password_link_to_existing_user" do
83
+ post :send_password, { :typus_user => { :email => @typus_user.email } }
84
+
85
+ assert_response :redirect
86
+ assert_redirected_to new_admin_session_path
87
+ assert_equal "Password recovery link sent to your email.", flash[:notice]
88
+ end
89
+
90
+ should "test_should_create_admin_user_session_and_redirect_user_to_its_details" do
91
+ get :show, { :id => @typus_user.token }
92
+
93
+ assert_equal @typus_user.id, @request.session[:typus_user_id]
94
+ assert_response :redirect
95
+ assert_redirected_to :controller => "/admin/typus_users", :action => "edit", :id => @typus_user.id
96
+ end
97
+
98
+ should "test_should_return_404_on_reset_passsword_if_token_is_not_valid" do
99
+ assert_raise(ActiveRecord::RecordNotFound) { get :show, { :id => "unexisting" } }
100
+ end
101
+
102
+ end
103
+
104
+ end
@@ -0,0 +1,153 @@
1
+ require "test_helper"
2
+
3
+ =begin
4
+
5
+ What's being tested here?
6
+
7
+ - Asset management like attach (edit) and detach (update).
8
+ - Assets runnings with a custom template.
9
+
10
+ =end
11
+
12
+ class Admin::AssetsControllerTest < ActionController::TestCase
13
+
14
+ setup do
15
+ @request.session[:typus_user_id] = Factory(:typus_user).id
16
+ @post = Factory(:post)
17
+ end
18
+
19
+ context "edit" do
20
+
21
+ setup do
22
+ @asset = Factory(:asset)
23
+ @request.env['HTTP_REFERER'] = "/admin/assets/edit/#{@asset.id}"
24
+ end
25
+
26
+ should "verify there is a file link" do
27
+ get :edit, { :id => @asset.id }
28
+ assert_match /media/, @response.body
29
+ end
30
+
31
+ should "verify dragonfly can be removed" do
32
+ get :edit, { :id => @asset.id }
33
+ assert_match /Remove/, @response.body
34
+
35
+ assert @asset.dragonfly_uid.present?
36
+
37
+ get :update, { :id => @asset.id, :attribute => "dragonfly" }
38
+ assert_response :redirect
39
+ assert_redirected_to "/admin/assets/edit/#{@asset.id}"
40
+ assert_equal "Asset successfully updated.", flash[:notice]
41
+
42
+ @asset.reload
43
+ assert @asset.dragonfly_uid.blank?
44
+ end
45
+
46
+ should "verify dragonfly_required can not removed" do
47
+ get :edit, { :id => @asset.id }
48
+ assert_no_match /Remove required file/, @response.body
49
+
50
+ get :update, { :id => @asset.id, :attribute => "dragonfly_required" }
51
+ assert_response :success
52
+
53
+ @asset.reload
54
+ assert @asset.dragonfly_required.present?
55
+ end
56
+
57
+ should "verify message on polymorphic relationship" do
58
+ asset = Factory(:asset)
59
+ get :edit, { :id => asset.id, :resource => @post.class.name, :resource_id => @post.id }
60
+ assert_select 'body div#flash', "Cancel adding a new asset?"
61
+ end
62
+
63
+ end
64
+
65
+ context "Headless" do
66
+
67
+ should "render index with a custom layout" do
68
+ get :index, { :layout => "admin/headless" }
69
+ assert_response :success
70
+ assert_template "admin/headless"
71
+ end
72
+
73
+ should "render new with a custom layout" do
74
+ get :new, { :layout => "admin/headless" }
75
+ assert_response :success
76
+ assert_template "admin/headless"
77
+ end
78
+
79
+ should "render edit with a custom layout" do
80
+ asset = Factory(:asset)
81
+ get :edit, { :id => asset.id, :layout => "admin/headless" }
82
+ assert_response :success
83
+ assert_template "admin/headless"
84
+ end
85
+
86
+ context "create" do
87
+
88
+ should "redirect to edit with custom layout" do
89
+ asset = {:caption => "My Caption", :dragonfly_required => File.new("#{Rails.root}/public/images/rails.png")}
90
+
91
+ assert_difference('Asset.count') do
92
+ post :create, { :asset => asset, :layout => "admin/headless" }
93
+ end
94
+
95
+ assert_response :redirect
96
+ assert_redirected_to :action => "edit", :id => Asset.last.id, :layout => "admin/headless"
97
+ end
98
+
99
+ should "redirect to index with custom layout" do
100
+ Typus::Resources.expects(:action_after_save).returns("index")
101
+ asset = {:caption => "My Caption", :dragonfly_required => File.new("#{Rails.root}/public/images/rails.png")}
102
+
103
+ assert_difference('Asset.count') do
104
+ post :create, { :asset => asset, :layout => "admin/headless" }
105
+ end
106
+
107
+ assert_response :redirect
108
+ assert_redirected_to :action => "index", :layout => "admin/headless"
109
+ end
110
+
111
+ should "render new with custom layout after an error" do
112
+ post :create, { :asset => {}, :layout => "admin/headless" }
113
+ assert_response :success
114
+ assert_template "new"
115
+ assert_template "admin/headless"
116
+ end
117
+
118
+ end
119
+
120
+ context "update" do
121
+
122
+ setup do
123
+ @asset = Factory(:asset)
124
+ end
125
+
126
+ should "redirect to edit with custom layout" do
127
+ asset = {:caption => "My Caption", :dragonfly_required => File.new("#{Rails.root}/public/images/rails.png")}
128
+ post :update, { :id => @asset.id, :asset => asset, :layout => "admin/headless" }
129
+ assert_response :redirect
130
+ assert_redirected_to :action => "edit", :id => @asset.id, :layout => "admin/headless"
131
+ end
132
+
133
+ should "render update with custom layout after an error" do
134
+ post :update, { :id => @asset.id, :asset => { :caption => nil }, :layout => "admin/headless" }
135
+ assert_response :success
136
+ assert_template "admin/helpers/resources/_errors"
137
+ assert_template "admin/resources/edit"
138
+ assert_template "admin/headless"
139
+ end
140
+
141
+ should "redirect to index with custom layout" do
142
+ Typus::Resources.expects(:action_after_save).returns("index")
143
+ asset = {:caption => "My Caption", :dragonfly_required => File.new("#{Rails.root}/public/images/rails.png")}
144
+ post :update, { :id => @asset.id, :asset => asset, :layout => "admin/headless" }
145
+ assert_response :redirect
146
+ assert_redirected_to :action => "index", :layout => "admin/headless"
147
+ end
148
+
149
+ end
150
+
151
+ end
152
+
153
+ end