cantango 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (578) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +58 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.textile +211 -0
  6. data/Rakefile +48 -0
  7. data/VERSION +1 -0
  8. data/cantango.gemspec +658 -0
  9. data/ideas/feature_list.markdown +58 -0
  10. data/lib/cantango.rb +32 -0
  11. data/lib/cantango/ability.rb +56 -0
  12. data/lib/cantango/ability/cache.rb +95 -0
  13. data/lib/cantango/ability/cache/base_cache.rb +26 -0
  14. data/lib/cantango/ability/cache/kompiler.rb +24 -0
  15. data/lib/cantango/ability/cache/moneta_cache.rb +32 -0
  16. data/lib/cantango/ability/cache/session_cache.rb +38 -0
  17. data/lib/cantango/ability/class_methods.rb +27 -0
  18. data/lib/cantango/ability/masquerade_helpers.rb +19 -0
  19. data/lib/cantango/ability/permission_helpers.rb +20 -0
  20. data/lib/cantango/ability/permit_helpers.rb +27 -0
  21. data/lib/cantango/ability/role_helpers.rb +26 -0
  22. data/lib/cantango/ability/scope.rb +20 -0
  23. data/lib/cantango/ability/user_helpers.rb +22 -0
  24. data/lib/cantango/api.rb +5 -0
  25. data/lib/cantango/api/aliases.rb +8 -0
  26. data/lib/cantango/api/aliases/account_permit.rb +8 -0
  27. data/lib/cantango/api/aliases/license.rb +7 -0
  28. data/lib/cantango/api/aliases/permit.rb +9 -0
  29. data/lib/cantango/api/aliases/role_group_permit.rb +7 -0
  30. data/lib/cantango/api/aliases/role_permit.rb +7 -0
  31. data/lib/cantango/api/aliases/user_permit.rb +8 -0
  32. data/lib/cantango/api/common.rb +10 -0
  33. data/lib/cantango/api/options.rb +16 -0
  34. data/lib/cantango/api/user.rb +20 -0
  35. data/lib/cantango/api/user/ability.rb +38 -0
  36. data/lib/cantango/api/user/can.rb +26 -0
  37. data/lib/cantango/api/user/scope.rb +29 -0
  38. data/lib/cantango/api/user_account.rb +20 -0
  39. data/lib/cantango/api/user_account/ability.rb +44 -0
  40. data/lib/cantango/api/user_account/can.rb +26 -0
  41. data/lib/cantango/api/user_account/scope.rb +29 -0
  42. data/lib/cantango/cache.rb +6 -0
  43. data/lib/cantango/cache/moneta_cache.rb +68 -0
  44. data/lib/cantango/cancan/rule.rb +6 -0
  45. data/lib/cantango/configuration.rb +83 -0
  46. data/lib/cantango/configuration/ability.rb +13 -0
  47. data/lib/cantango/configuration/autoload.rb +38 -0
  48. data/lib/cantango/configuration/categories.rb +55 -0
  49. data/lib/cantango/configuration/engines.rb +49 -0
  50. data/lib/cantango/configuration/engines/cache.rb +20 -0
  51. data/lib/cantango/configuration/engines/engine.rb +31 -0
  52. data/lib/cantango/configuration/engines/permission.rb +49 -0
  53. data/lib/cantango/configuration/engines/permit.rb +26 -0
  54. data/lib/cantango/configuration/engines/store.rb +24 -0
  55. data/lib/cantango/configuration/factory.rb +59 -0
  56. data/lib/cantango/configuration/guest.rb +57 -0
  57. data/lib/cantango/configuration/hash_registry.rb +62 -0
  58. data/lib/cantango/configuration/models.rb +48 -0
  59. data/lib/cantango/configuration/registry.rb +53 -0
  60. data/lib/cantango/configuration/role_groups.rb +15 -0
  61. data/lib/cantango/configuration/role_registry.rb +43 -0
  62. data/lib/cantango/configuration/roles.rb +16 -0
  63. data/lib/cantango/configuration/user.rb +47 -0
  64. data/lib/cantango/configuration/user_account.rb +23 -0
  65. data/lib/cantango/configuration/user_accounts.rb +7 -0
  66. data/lib/cantango/configuration/users.rb +7 -0
  67. data/lib/cantango/helpers.rb +5 -0
  68. data/lib/cantango/helpers/role_methods.rb +26 -0
  69. data/lib/cantango/permission_engine.rb +7 -0
  70. data/lib/cantango/permission_engine/builder.rb +6 -0
  71. data/lib/cantango/permission_engine/collector.rb +43 -0
  72. data/lib/cantango/permission_engine/compiler.rb +67 -0
  73. data/lib/cantango/permission_engine/evaluator.rb +34 -0
  74. data/lib/cantango/permission_engine/factory.rb +60 -0
  75. data/lib/cantango/permission_engine/loader.rb +7 -0
  76. data/lib/cantango/permission_engine/loader/base.rb +39 -0
  77. data/lib/cantango/permission_engine/loader/categories.rb +50 -0
  78. data/lib/cantango/permission_engine/loader/permissions.rb +66 -0
  79. data/lib/cantango/permission_engine/moneta_store.rb +30 -0
  80. data/lib/cantango/permission_engine/parser.rb +32 -0
  81. data/lib/cantango/permission_engine/parser/categories.rb +18 -0
  82. data/lib/cantango/permission_engine/parser/category.rb +34 -0
  83. data/lib/cantango/permission_engine/parser/default.rb +20 -0
  84. data/lib/cantango/permission_engine/parser/ownership.rb +32 -0
  85. data/lib/cantango/permission_engine/parser/permissions.rb +33 -0
  86. data/lib/cantango/permission_engine/parser/regex.rb +35 -0
  87. data/lib/cantango/permission_engine/parser/relationship.rb +23 -0
  88. data/lib/cantango/permission_engine/parser/rule.rb +31 -0
  89. data/lib/cantango/permission_engine/permission.rb +40 -0
  90. data/lib/cantango/permission_engine/selector.rb +16 -0
  91. data/lib/cantango/permission_engine/selector/base.rb +19 -0
  92. data/lib/cantango/permission_engine/selector/licenses.rb +19 -0
  93. data/lib/cantango/permission_engine/selector/role_groups.rb +24 -0
  94. data/lib/cantango/permission_engine/selector/roles.rb +25 -0
  95. data/lib/cantango/permission_engine/selector/users.rb +22 -0
  96. data/lib/cantango/permission_engine/statement.rb +14 -0
  97. data/lib/cantango/permission_engine/statements.rb +35 -0
  98. data/lib/cantango/permission_engine/store.rb +33 -0
  99. data/lib/cantango/permission_engine/yaml_store.rb +108 -0
  100. data/lib/cantango/permit_engine.rb +8 -0
  101. data/lib/cantango/permit_engine/account_permit.rb +41 -0
  102. data/lib/cantango/permit_engine/account_permit/builder.rb +22 -0
  103. data/lib/cantango/permit_engine/account_permit/finder.rb +20 -0
  104. data/lib/cantango/permit_engine/builder.rb +8 -0
  105. data/lib/cantango/permit_engine/builder/base.rb +50 -0
  106. data/lib/cantango/permit_engine/builder/special_permits.rb +20 -0
  107. data/lib/cantango/permit_engine/compatibility.rb +20 -0
  108. data/lib/cantango/permit_engine/executor.rb +7 -0
  109. data/lib/cantango/permit_engine/executor/abstract.rb +40 -0
  110. data/lib/cantango/permit_engine/executor/base.rb +51 -0
  111. data/lib/cantango/permit_engine/executor/system.rb +13 -0
  112. data/lib/cantango/permit_engine/factory.rb +45 -0
  113. data/lib/cantango/permit_engine/finder.rb +39 -0
  114. data/lib/cantango/permit_engine/license.rb +37 -0
  115. data/lib/cantango/permit_engine/license/loader.rb +19 -0
  116. data/lib/cantango/permit_engine/license/rules.rb +17 -0
  117. data/lib/cantango/permit_engine/permit.rb +149 -0
  118. data/lib/cantango/permit_engine/role_group_permit.rb +37 -0
  119. data/lib/cantango/permit_engine/role_group_permit/builder.rb +47 -0
  120. data/lib/cantango/permit_engine/role_group_permit/finder.rb +20 -0
  121. data/lib/cantango/permit_engine/role_matcher.rb +13 -0
  122. data/lib/cantango/permit_engine/role_permit.rb +38 -0
  123. data/lib/cantango/permit_engine/role_permit/builder.rb +46 -0
  124. data/lib/cantango/permit_engine/role_permit/finder.rb +19 -0
  125. data/lib/cantango/permit_engine/user_permit.rb +40 -0
  126. data/lib/cantango/permit_engine/user_permit/builder.rb +21 -0
  127. data/lib/cantango/permit_engine/user_permit/finder.rb +20 -0
  128. data/lib/cantango/permit_engine/util.rb +19 -0
  129. data/lib/cantango/rails.rb +5 -0
  130. data/lib/cantango/rails/base_helpers.rb +26 -0
  131. data/lib/cantango/rails/controller_helpers.rb +15 -0
  132. data/lib/cantango/rails/engine.rb +47 -0
  133. data/lib/cantango/rails/railtie.rb +7 -0
  134. data/lib/cantango/rails/view_helpers.rb +15 -0
  135. data/lib/cantango/rspec.rb +1 -0
  136. data/lib/cantango/rspec/config.rb +9 -0
  137. data/lib/cantango/rspec/matchers.rb +9 -0
  138. data/lib/cantango/rspec/matchers/be_allowed_to.rb +26 -0
  139. data/lib/cantango/rspec/matchers/have_license.rb +11 -0
  140. data/lib/cantango/rspec/matchers/have_license_class.rb +14 -0
  141. data/lib/cantango/rspec/matchers/have_license_file.rb +82 -0
  142. data/lib/cantango/rules.rb +23 -0
  143. data/lib/cantango/rules/adaptor.rb +32 -0
  144. data/lib/cantango/rules/adaptor/active_record.rb +13 -0
  145. data/lib/cantango/rules/adaptor/generic.rb +16 -0
  146. data/lib/cantango/rules/adaptor/mongoid.rb +13 -0
  147. data/lib/cantango/rules/dsl.rb +24 -0
  148. data/lib/cantango/rules/rule_class.rb +11 -0
  149. data/lib/cantango/rules/scope.rb +24 -0
  150. data/lib/cantango/rules/user_relation.rb +68 -0
  151. data/lib/cantango/users.rb +5 -0
  152. data/lib/cantango/users/macros.rb +9 -0
  153. data/lib/cantango/users/masquerade.rb +22 -0
  154. data/lib/cantango/users/masquerade/session_active_user.rb +18 -0
  155. data/lib/cantango/users/user.rb +30 -0
  156. data/lib/cantango/users/user_account.rb +23 -0
  157. data/lib/generators/cantango/base.rb +52 -0
  158. data/lib/generators/cantango/license/license_generator.rb +34 -0
  159. data/lib/generators/cantango/license/templates/license.erb +10 -0
  160. data/lib/generators/cantango/license_base.rb +15 -0
  161. data/lib/generators/cantango/licenses/licenses_generator.rb +31 -0
  162. data/lib/generators/cantango/permit_generator.rb +36 -0
  163. data/lib/generators/cantango/role_permit/role_permit_generator.rb +42 -0
  164. data/lib/generators/cantango/role_permit/templates/account_permit.erb +4 -0
  165. data/lib/generators/cantango/role_permit/templates/role_group_permit.erb +14 -0
  166. data/lib/generators/cantango/role_permit/templates/role_permit.erb +13 -0
  167. data/lib/generators/cantango/role_permits/role_permits_generator.rb +127 -0
  168. data/spec/Note_on_licenses.textile +44 -0
  169. data/spec/Refactor_into_engines.textile +115 -0
  170. data/spec/TODO +7 -0
  171. data/spec/active_record/AR_README.textile +20 -0
  172. data/spec/active_record/config_helper.rb +108 -0
  173. data/spec/active_record/db/database.yml +4 -0
  174. data/spec/active_record/helper/ar_config.rb +19 -0
  175. data/spec/active_record/helper/permits_config.rb +12 -0
  176. data/spec/active_record/helper/rails_config.rb +6 -0
  177. data/spec/active_record/helper/rspec_config.rb +20 -0
  178. data/spec/active_record/migrations/001_create_user.rb +14 -0
  179. data/spec/active_record/migrations/002_create_comment.rb +13 -0
  180. data/spec/active_record/migrations/003_create_post.rb +13 -0
  181. data/spec/active_record/migrations/004_create_article.rb +13 -0
  182. data/spec/active_record/migrations/005_create_account.rb +13 -0
  183. data/spec/active_record/migrations/006_create_todo.rb +12 -0
  184. data/spec/active_record/migrations/007_create_user_todos.rb +13 -0
  185. data/spec/active_record/scenarios/SCENARIOS README.textile +19 -0
  186. data/spec/active_record/scenarios/engines/permission_engine/cantango_permissions.yml +63 -0
  187. data/spec/active_record/scenarios/engines/permission_engine/categories.yml +6 -0
  188. data/spec/active_record/scenarios/engines/permission_engine/tango_permission_yml_spec.rb +77 -0
  189. data/spec/active_record/scenarios/engines/permission_engine/users.rb +88 -0
  190. data/spec/active_record/scenarios/engines/permit_engine/licenses_spec.rb +37 -0
  191. data/spec/active_record/scenarios/engines/permit_engine/role_groups_permits_spec.rb +35 -0
  192. data/spec/active_record/scenarios/guest_user_admin/admin_user_spec.rb +19 -0
  193. data/spec/active_record/scenarios/guest_user_admin/docs/GUEST_ADMIN_USER_SCENARIO.textile +20 -0
  194. data/spec/active_record/scenarios/guest_user_admin/editor_spec.rb +19 -0
  195. data/spec/active_record/scenarios/guest_user_admin/guest_user_spec.rb +16 -0
  196. data/spec/active_record/scenarios/guest_user_admin/user_having_user_and_editor_roles_spec.rb +19 -0
  197. data/spec/active_record/scenarios/guest_user_admin/user_spec.rb +32 -0
  198. data/spec/active_record/scenarios/masquerading/masquerading_for_admin_account_spec.rb +41 -0
  199. data/spec/active_record/scenarios/masquerading/masquerading_for_admin_user_spec.rb +38 -0
  200. data/spec/active_record/scenarios/shared/api.rb +4 -0
  201. data/spec/active_record/scenarios/shared/can_tango.rb +2 -0
  202. data/spec/active_record/scenarios/shared/examples/user_accounts.rb +47 -0
  203. data/spec/active_record/scenarios/shared/examples/users.rb +85 -0
  204. data/spec/active_record/scenarios/shared/licenses/musicians_license.rb +12 -0
  205. data/spec/active_record/scenarios/shared/models/items.rb +26 -0
  206. data/spec/active_record/scenarios/shared/models/todo.rb +4 -0
  207. data/spec/active_record/scenarios/shared/models/user_todo.rb +4 -0
  208. data/spec/active_record/scenarios/shared/models/users.rb +46 -0
  209. data/spec/active_record/scenarios/shared/permits/PERMITS README.textile +3 -0
  210. data/spec/active_record/scenarios/shared/permits/account_permits/admin_account_permit.rb +30 -0
  211. data/spec/active_record/scenarios/shared/permits/account_permits/guest_account_permit.rb +16 -0
  212. data/spec/active_record/scenarios/shared/permits/account_permits/user_account_permit.rb +46 -0
  213. data/spec/active_record/scenarios/shared/permits/role/admin_permit.rb +11 -0
  214. data/spec/active_record/scenarios/shared/permits/role/editor_permit.rb +42 -0
  215. data/spec/active_record/scenarios/shared/permits/role/guest_permit.rb +26 -0
  216. data/spec/active_record/scenarios/shared/permits/role/super_admin_permit.rb +9 -0
  217. data/spec/active_record/scenarios/shared/permits/role/user_permit.rb +49 -0
  218. data/spec/active_record/scenarios/shared/permits/role_group/bloggers_permit.rb +8 -0
  219. data/spec/active_record/scenarios/shared/permits/role_group/musicians_permit.rb +9 -0
  220. data/spec/active_record/scenarios/shared/permits/special/any_role_permit.rb +10 -0
  221. data/spec/active_record/scenarios/shared/permits/special/system_role_permit.rb +10 -0
  222. data/spec/active_record/scenarios/user_accounts/admin_account_spec.rb +34 -0
  223. data/spec/active_record/scenarios/user_accounts/config/account_permits.yml +0 -0
  224. data/spec/active_record/scenarios/user_accounts/docs/USER_ACCOUNTS_SCENARIO.textile +20 -0
  225. data/spec/active_record/scenarios/user_accounts/docs/basic_rules_spec_possible_samples.txt +84 -0
  226. data/spec/active_record/scenarios/user_accounts/guest_account_spec.rb +34 -0
  227. data/spec/active_record/scenarios/user_accounts/helpers.rb +5 -0
  228. data/spec/active_record/scenarios/user_accounts/helpers/account_setup.rb +41 -0
  229. data/spec/active_record/scenarios/user_accounts/helpers/user_factory.rb +19 -0
  230. data/spec/active_record/scenarios/user_accounts/permits/admin_account_permit.rb +28 -0
  231. data/spec/active_record/scenarios/user_accounts/permits/guest_account_permit.rb +14 -0
  232. data/spec/active_record/scenarios/user_accounts/permits/user_account_permit.rb +43 -0
  233. data/spec/active_record/scenarios/user_accounts/user_account_spec.rb +36 -0
  234. data/spec/active_record/spec_helper.rb +19 -0
  235. data/spec/cantango/README.textile +3 -0
  236. data/spec/cantango/ability/cache/compiler_spec.rb +45 -0
  237. data/spec/cantango/ability/cache/session_cache_spec.rb +11 -0
  238. data/spec/cantango/ability/cache_spec.rb +107 -0
  239. data/spec/cantango/ability_filters_spec.rb +128 -0
  240. data/spec/cantango/ability_spec.rb +74 -0
  241. data/spec/cantango/api/current_user_accounts.rb +14 -0
  242. data/spec/cantango/api/current_users.rb +10 -0
  243. data/spec/cantango/api/user/ability_api_spec.rb +44 -0
  244. data/spec/cantango/api/user/can_api_spec.rb +109 -0
  245. data/spec/cantango/api/user/scope_api_spec.rb +65 -0
  246. data/spec/cantango/api/user_account/ability_api_spec.rb +29 -0
  247. data/spec/cantango/api/user_account/can_api_spec.rb +82 -0
  248. data/spec/cantango/api/user_account/scope_api_spec.rb +0 -0
  249. data/spec/cantango/api/user_account_api_spec.rb +0 -0
  250. data/spec/cantango/api/user_api_spec.rb +0 -0
  251. data/spec/cantango/configuration/ability_spec.rb +13 -0
  252. data/spec/cantango/configuration/autoload_spec.rb +53 -0
  253. data/spec/cantango/configuration/categories_spec.rb +60 -0
  254. data/spec/cantango/configuration/engines/cache_spec.rb +19 -0
  255. data/spec/cantango/configuration/engines/engine_shared.rb +22 -0
  256. data/spec/cantango/configuration/engines/permission_spec.rb +31 -0
  257. data/spec/cantango/configuration/engines/permit_spec.rb +16 -0
  258. data/spec/cantango/configuration/engines/store_engine_shared.rb +16 -0
  259. data/spec/cantango/configuration/engines/store_shared.rb +36 -0
  260. data/spec/cantango/configuration/engines_spec.rb +41 -0
  261. data/spec/cantango/configuration/factory_spec.rb +20 -0
  262. data/spec/cantango/configuration/guest/find_guest_default_way_spec.rb +33 -0
  263. data/spec/cantango/configuration/guest_spec.rb +62 -0
  264. data/spec/cantango/configuration/hash_registry_spec.rb +17 -0
  265. data/spec/cantango/configuration/registry_spec.rb +17 -0
  266. data/spec/cantango/configuration/role_groups_spec.rb +15 -0
  267. data/spec/cantango/configuration/roles_spec.rb +16 -0
  268. data/spec/cantango/configuration/shared/factory_ex.rb +40 -0
  269. data/spec/cantango/configuration/shared/hash_registry_ex.rb +65 -0
  270. data/spec/cantango/configuration/shared/registry_ex.rb +39 -0
  271. data/spec/cantango/configuration/shared/role_registry_ex.rb +22 -0
  272. data/spec/cantango/configuration/user_account_spec.rb +26 -0
  273. data/spec/cantango/configuration/user_spec.rb +46 -0
  274. data/spec/cantango/configuration_spec.rb +42 -0
  275. data/spec/cantango/license/save_license_spec.rb +24 -0
  276. data/spec/cantango/models/items.rb +12 -0
  277. data/spec/cantango/models/users.rb +13 -0
  278. data/spec/cantango/moneta_spec.rb +31 -0
  279. data/spec/cantango/parser/categories_spec.rb +0 -0
  280. data/spec/cantango/parser/permissions_spec.rb +0 -0
  281. data/spec/cantango/permission_engine/PERMISSION_STORE.textile +75 -0
  282. data/spec/cantango/permission_engine/categories_store_spec.rb +10 -0
  283. data/spec/cantango/permission_engine/compiler_spec.rb +32 -0
  284. data/spec/cantango/permission_engine/loader/categories_spec.rb +19 -0
  285. data/spec/cantango/permission_engine/loader/permissions/cantango_permissions_loader.rb +27 -0
  286. data/spec/cantango/permission_engine/loader/permissions/shared.rb +9 -0
  287. data/spec/cantango/permission_engine/moneta_store_spec.rb +0 -0
  288. data/spec/cantango/permission_engine/parser_spec.rb +39 -0
  289. data/spec/cantango/permission_engine/permission_spec.rb +35 -0
  290. data/spec/cantango/permission_engine/permission_store_spec.rb +10 -0
  291. data/spec/cantango/permission_engine/shared_examples.rb +22 -0
  292. data/spec/cantango/permission_engine/store_spec.rb +8 -0
  293. data/spec/cantango/permission_engine/user_permission_store_spec.rb +12 -0
  294. data/spec/cantango/permission_engine/yaml_store_spec.rb +83 -0
  295. data/spec/cantango/permit_engine/account_permit_spec.rb +47 -0
  296. data/spec/cantango/permit_engine/builder/role_group_permits_spec.rb +63 -0
  297. data/spec/cantango/permit_engine/builder/role_permits_spec.rb +58 -0
  298. data/spec/cantango/permit_engine/builder/special_permits_spec.rb +42 -0
  299. data/spec/cantango/permit_engine/executor/system_spec.rb +61 -0
  300. data/spec/cantango/permit_engine/factory_spec.rb +50 -0
  301. data/spec/cantango/permit_engine/finder_spec.rb +70 -0
  302. data/spec/cantango/permit_engine/permit/permit_static_and_dynamic_rules_spec.rb +74 -0
  303. data/spec/cantango/permit_engine/role_group_permit_spec.rb +43 -0
  304. data/spec/cantango/permit_engine/role_permit_spec.rb +44 -0
  305. data/spec/cantango/permit_engine/user_permit_spec.rb +41 -0
  306. data/spec/cantango/rules_spec.rb +55 -0
  307. data/spec/devise-dummy/Rakefile +7 -0
  308. data/spec/devise-dummy/app/controllers/accounts_controller.rb +25 -0
  309. data/spec/devise-dummy/app/controllers/application_controller.rb +3 -0
  310. data/spec/devise-dummy/app/controllers/articles_controller.rb +48 -0
  311. data/spec/devise-dummy/app/controllers/comments_controller.rb +40 -0
  312. data/spec/devise-dummy/app/controllers/concertos_controller.rb +49 -0
  313. data/spec/devise-dummy/app/controllers/main_controller.rb +8 -0
  314. data/spec/devise-dummy/app/controllers/posts_controller.rb +49 -0
  315. data/spec/devise-dummy/app/controllers/users_controller.rb +25 -0
  316. data/spec/devise-dummy/app/helpers/application_helper.rb +2 -0
  317. data/spec/devise-dummy/app/models/account_setup.rb +41 -0
  318. data/spec/devise-dummy/app/models/admin.rb +11 -0
  319. data/spec/devise-dummy/app/models/article.rb +6 -0
  320. data/spec/devise-dummy/app/models/comment.rb +5 -0
  321. data/spec/devise-dummy/app/models/concerto.rb +6 -0
  322. data/spec/devise-dummy/app/models/guest.rb +34 -0
  323. data/spec/devise-dummy/app/models/improvisation.rb +2 -0
  324. data/spec/devise-dummy/app/models/post.rb +5 -0
  325. data/spec/devise-dummy/app/models/song.rb +3 -0
  326. data/spec/devise-dummy/app/models/tune.rb +3 -0
  327. data/spec/devise-dummy/app/models/user.rb +22 -0
  328. data/spec/devise-dummy/app/permits/accounts/admin/roles/editor_permit.rb +15 -0
  329. data/spec/devise-dummy/app/permits/licenses/bloggers_license.rb +12 -0
  330. data/spec/devise-dummy/app/permits/licenses/musicians_license.rb +13 -0
  331. data/spec/devise-dummy/app/permits/role_groups/editor_permit.rb +13 -0
  332. data/spec/devise-dummy/app/permits/roles/admin_permit.rb +12 -0
  333. data/spec/devise-dummy/app/permits/roles/guest_permit.rb +12 -0
  334. data/spec/devise-dummy/app/permits/roles/user_permit.rb +14 -0
  335. data/spec/devise-dummy/app/views/articles/admin.html.haml +20 -0
  336. data/spec/devise-dummy/app/views/articles/admin_account.html.haml +20 -0
  337. data/spec/devise-dummy/app/views/articles/guest.html.haml +20 -0
  338. data/spec/devise-dummy/app/views/articles/index.html.haml +23 -0
  339. data/spec/devise-dummy/app/views/articles/show.html.haml +10 -0
  340. data/spec/devise-dummy/app/views/comments/guest.html.haml +20 -0
  341. data/spec/devise-dummy/app/views/comments/index.html.haml +20 -0
  342. data/spec/devise-dummy/app/views/concertos/admin.html.haml +19 -0
  343. data/spec/devise-dummy/app/views/concertos/admin_account.html.haml +20 -0
  344. data/spec/devise-dummy/app/views/concertos/guest.html.haml +20 -0
  345. data/spec/devise-dummy/app/views/concertos/index.html.haml +19 -0
  346. data/spec/devise-dummy/app/views/concertos/show.html.haml +10 -0
  347. data/spec/devise-dummy/app/views/devise/confirmations/new.html.erb +12 -0
  348. data/spec/devise-dummy/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  349. data/spec/devise-dummy/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  350. data/spec/devise-dummy/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  351. data/spec/devise-dummy/app/views/devise/passwords/edit.html.erb +16 -0
  352. data/spec/devise-dummy/app/views/devise/passwords/new.html.erb +12 -0
  353. data/spec/devise-dummy/app/views/devise/registrations/edit.html.erb +25 -0
  354. data/spec/devise-dummy/app/views/devise/registrations/new.html.erb +18 -0
  355. data/spec/devise-dummy/app/views/devise/sessions/new.html.erb +17 -0
  356. data/spec/devise-dummy/app/views/devise/shared/_links.erb +25 -0
  357. data/spec/devise-dummy/app/views/devise/unlocks/new.html.erb +12 -0
  358. data/spec/devise-dummy/app/views/layouts/application.html.erb +14 -0
  359. data/spec/devise-dummy/app/views/main/index.html.haml +1 -0
  360. data/spec/devise-dummy/app/views/posts/admin.html.haml +20 -0
  361. data/spec/devise-dummy/app/views/posts/admin_account.html.haml +20 -0
  362. data/spec/devise-dummy/app/views/posts/guest.html.haml +20 -0
  363. data/spec/devise-dummy/app/views/posts/index.html.haml +19 -0
  364. data/spec/devise-dummy/app/views/posts/show.html.haml +11 -0
  365. data/spec/devise-dummy/app/views/users/admin.html.haml +19 -0
  366. data/spec/devise-dummy/app/views/users/admin_account.html.haml +19 -0
  367. data/spec/devise-dummy/app/views/users/guest.html.haml +19 -0
  368. data/spec/devise-dummy/app/views/users/index.html.haml +19 -0
  369. data/spec/devise-dummy/app/views/users/show.html.haml +11 -0
  370. data/spec/devise-dummy/config.ru +4 -0
  371. data/spec/devise-dummy/config/application.rb +46 -0
  372. data/spec/devise-dummy/config/boot.rb +10 -0
  373. data/spec/devise-dummy/config/cantango_permissions.yml +50 -0
  374. data/spec/devise-dummy/config/categories.yml +10 -0
  375. data/spec/devise-dummy/config/database.yml +22 -0
  376. data/spec/devise-dummy/config/environment.rb +5 -0
  377. data/spec/devise-dummy/config/environments/development.rb +26 -0
  378. data/spec/devise-dummy/config/environments/production.rb +49 -0
  379. data/spec/devise-dummy/config/environments/test.rb +35 -0
  380. data/spec/devise-dummy/config/initializers/backtrace_silencers.rb +7 -0
  381. data/spec/devise-dummy/config/initializers/cantango.rb +8 -0
  382. data/spec/devise-dummy/config/initializers/devise.rb +204 -0
  383. data/spec/devise-dummy/config/initializers/inflections.rb +10 -0
  384. data/spec/devise-dummy/config/initializers/mime_types.rb +5 -0
  385. data/spec/devise-dummy/config/initializers/secret_token.rb +7 -0
  386. data/spec/devise-dummy/config/initializers/session_store.rb +8 -0
  387. data/spec/devise-dummy/config/initializers/simple_roles.rb +42 -0
  388. data/spec/devise-dummy/config/locales/devise.en.yml +53 -0
  389. data/spec/devise-dummy/config/locales/en.yml +5 -0
  390. data/spec/devise-dummy/config/routes.rb +88 -0
  391. data/spec/devise-dummy/db/migrate/002_create_comment.rb +13 -0
  392. data/spec/devise-dummy/db/migrate/003_create_post.rb +14 -0
  393. data/spec/devise-dummy/db/migrate/004_create_article.rb +14 -0
  394. data/spec/devise-dummy/db/migrate/005_create_account.rb +13 -0
  395. data/spec/devise-dummy/db/migrate/006_create_concerto.rb +14 -0
  396. data/spec/devise-dummy/db/migrate/007_devise_create_users.rb +31 -0
  397. data/spec/devise-dummy/db/schema.rb +75 -0
  398. data/spec/devise-dummy/db/seeds.rb +5 -0
  399. data/spec/devise-dummy/db/users.txt +7 -0
  400. data/spec/devise-dummy/public/404.html +26 -0
  401. data/spec/devise-dummy/public/422.html +26 -0
  402. data/spec/devise-dummy/public/500.html +26 -0
  403. data/spec/devise-dummy/public/favicon.ico +0 -0
  404. data/spec/devise-dummy/public/javascripts/application.js +2 -0
  405. data/spec/devise-dummy/public/javascripts/controls.js +965 -0
  406. data/spec/devise-dummy/public/javascripts/dragdrop.js +974 -0
  407. data/spec/devise-dummy/public/javascripts/effects.js +1123 -0
  408. data/spec/devise-dummy/public/javascripts/prototype.js +6001 -0
  409. data/spec/devise-dummy/public/javascripts/rails.js +191 -0
  410. data/spec/devise-dummy/public/stylesheets/.gitkeep +0 -0
  411. data/spec/devise-dummy/script/rails +6 -0
  412. data/spec/devise-dummy_spec_helper.rb +41 -0
  413. data/spec/devise-integration/concerto_spec.rb +80 -0
  414. data/spec/dummy/Rakefile +7 -0
  415. data/spec/dummy/app/controllers/accounts_controller.rb +23 -0
  416. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  417. data/spec/dummy/app/controllers/articles_controller.rb +55 -0
  418. data/spec/dummy/app/controllers/comments_controller.rb +38 -0
  419. data/spec/dummy/app/controllers/concertos_controller.rb +43 -0
  420. data/spec/dummy/app/controllers/main_controller.rb +8 -0
  421. data/spec/dummy/app/controllers/posts_controller.rb +47 -0
  422. data/spec/dummy/app/controllers/sessions_controller.rb +16 -0
  423. data/spec/dummy/app/controllers/users_controller.rb +23 -0
  424. data/spec/dummy/app/helpers/application_helper.rb +37 -0
  425. data/spec/dummy/app/models/account_setup.rb +41 -0
  426. data/spec/dummy/app/models/admin.rb +4 -0
  427. data/spec/dummy/app/models/article.rb +6 -0
  428. data/spec/dummy/app/models/comment.rb +5 -0
  429. data/spec/dummy/app/models/concerto.rb +6 -0
  430. data/spec/dummy/app/models/guest.rb +27 -0
  431. data/spec/dummy/app/models/improvisation.rb +2 -0
  432. data/spec/dummy/app/models/post.rb +5 -0
  433. data/spec/dummy/app/models/song.rb +3 -0
  434. data/spec/dummy/app/models/tune.rb +3 -0
  435. data/spec/dummy/app/models/user.rb +12 -0
  436. data/spec/dummy/app/permits/accounts/admin/roles/editor_permit.rb +15 -0
  437. data/spec/dummy/app/permits/licenses/bloggers_license.rb +12 -0
  438. data/spec/dummy/app/permits/licenses/musicians_license.rb +13 -0
  439. data/spec/dummy/app/permits/role_groups/editor_permit.rb +13 -0
  440. data/spec/dummy/app/permits/roles/admin_permit.rb +12 -0
  441. data/spec/dummy/app/permits/roles/guest_permit.rb +12 -0
  442. data/spec/dummy/app/permits/roles/user_permit.rb +18 -0
  443. data/spec/dummy/app/views/articles/admin.html.haml +20 -0
  444. data/spec/dummy/app/views/articles/admin_account.html.haml +20 -0
  445. data/spec/dummy/app/views/articles/guest.html.haml +20 -0
  446. data/spec/dummy/app/views/articles/index.html.haml +23 -0
  447. data/spec/dummy/app/views/articles/show.html.haml +10 -0
  448. data/spec/dummy/app/views/comments/guest.html.haml +20 -0
  449. data/spec/dummy/app/views/comments/index.html.haml +20 -0
  450. data/spec/dummy/app/views/concertos/admin.html.haml +20 -0
  451. data/spec/dummy/app/views/concertos/admin_account.html.haml +20 -0
  452. data/spec/dummy/app/views/concertos/guest.html.haml +20 -0
  453. data/spec/dummy/app/views/concertos/index.html.haml +19 -0
  454. data/spec/dummy/app/views/concertos/show.html.haml +10 -0
  455. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  456. data/spec/dummy/app/views/main/index.html.haml +1 -0
  457. data/spec/dummy/app/views/posts/admin.html.haml +20 -0
  458. data/spec/dummy/app/views/posts/admin_account.html.haml +20 -0
  459. data/spec/dummy/app/views/posts/guest.html.haml +20 -0
  460. data/spec/dummy/app/views/posts/index.html.haml +19 -0
  461. data/spec/dummy/app/views/posts/show.html.haml +11 -0
  462. data/spec/dummy/app/views/users/admin.html.haml +19 -0
  463. data/spec/dummy/app/views/users/admin_account.html.haml +19 -0
  464. data/spec/dummy/app/views/users/guest.html.haml +19 -0
  465. data/spec/dummy/app/views/users/index.html.haml +19 -0
  466. data/spec/dummy/app/views/users/show.html.haml +11 -0
  467. data/spec/dummy/config.ru +4 -0
  468. data/spec/dummy/config/application.rb +43 -0
  469. data/spec/dummy/config/boot.rb +10 -0
  470. data/spec/dummy/config/cantango_permissions.yml +50 -0
  471. data/spec/dummy/config/categories.yml +10 -0
  472. data/spec/dummy/config/database.yml +22 -0
  473. data/spec/dummy/config/environment.rb +5 -0
  474. data/spec/dummy/config/environments/development.rb +26 -0
  475. data/spec/dummy/config/environments/production.rb +49 -0
  476. data/spec/dummy/config/environments/test.rb +35 -0
  477. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  478. data/spec/dummy/config/initializers/cantango.rb +5 -0
  479. data/spec/dummy/config/initializers/inflections.rb +10 -0
  480. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  481. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  482. data/spec/dummy/config/initializers/session_store.rb +8 -0
  483. data/spec/dummy/config/initializers/simple_roles.rb +44 -0
  484. data/spec/dummy/config/locales/en.yml +5 -0
  485. data/spec/dummy/config/routes.rb +84 -0
  486. data/spec/dummy/db/migrate/001_create_user.rb +16 -0
  487. data/spec/dummy/db/migrate/002_create_comment.rb +13 -0
  488. data/spec/dummy/db/migrate/003_create_post.rb +14 -0
  489. data/spec/dummy/db/migrate/004_create_article.rb +14 -0
  490. data/spec/dummy/db/migrate/005_create_account.rb +13 -0
  491. data/spec/dummy/db/migrate/006_create_concerto.rb +14 -0
  492. data/spec/dummy/public/404.html +26 -0
  493. data/spec/dummy/public/422.html +26 -0
  494. data/spec/dummy/public/500.html +26 -0
  495. data/spec/dummy/public/favicon.ico +0 -0
  496. data/spec/dummy/public/javascripts/application.js +2 -0
  497. data/spec/dummy/public/javascripts/controls.js +965 -0
  498. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  499. data/spec/dummy/public/javascripts/effects.js +1123 -0
  500. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  501. data/spec/dummy/public/javascripts/rails.js +191 -0
  502. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  503. data/spec/dummy/script/rails +6 -0
  504. data/spec/dummy/tmp/pids/server.pid +1 -0
  505. data/spec/dummy_spec_helper.rb +43 -0
  506. data/spec/entire_suite_spec.rb +15 -0
  507. data/spec/factories.rb +8 -0
  508. data/spec/fixtures/config/cantango_permissions.yml +48 -0
  509. data/spec/fixtures/config/categories.yml +6 -0
  510. data/spec/fixtures/config/evaluator_fixtures.yml +18 -0
  511. data/spec/fixtures/config/licenses.yml +4 -0
  512. data/spec/fixtures/config/permissions.yml +19 -0
  513. data/spec/fixtures/config/role_group.yml +4 -0
  514. data/spec/fixtures/config/roles.yml +4 -0
  515. data/spec/fixtures/config/user_permissions.yml +8 -0
  516. data/spec/fixtures/models.rb +2 -0
  517. data/spec/fixtures/models/items.rb +8 -0
  518. data/spec/fixtures/models/simple_roles.rb +44 -0
  519. data/spec/fixtures/models/user.rb +22 -0
  520. data/spec/fixtures/models/user_account.rb +21 -0
  521. data/spec/fixtures/tango_fixtures.rb +29 -0
  522. data/spec/generators/cantango/account_role_permit_generator_spec.rb +35 -0
  523. data/spec/generators/cantango/account_role_permits_generator_spec.rb +59 -0
  524. data/spec/generators/cantango/license_generator_spec.rb +33 -0
  525. data/spec/generators/cantango/licenses_generator_spec.rb +58 -0
  526. data/spec/generators/cantango/role_permit_generator_spec.rb +35 -0
  527. data/spec/generators/cantango/role_permits_generator_spec.rb +58 -0
  528. data/spec/helpers/dummy_app_ability.rb +26 -0
  529. data/spec/integration/Design_notes.textile +30 -0
  530. data/spec/integration/admin_user/masquerade_spec.rb +22 -0
  531. data/spec/integration/cache_using_moneta_spec.rb +46 -0
  532. data/spec/integration/cache_using_session_spec.rb +46 -0
  533. data/spec/integration/main_spec.rb +16 -0
  534. data/spec/integration/performance/ability_initialize_performance.rb +54 -0
  535. data/spec/integration/performance/cache_performance.rb +31 -0
  536. data/spec/integration/performance/can_performance.rb +54 -0
  537. data/spec/integration/performance/helpers/ability.rb +44 -0
  538. data/spec/integration/performance/helpers/ability_api.rb +44 -0
  539. data/spec/integration/performance/helpers/ability_raw.rb +8 -0
  540. data/spec/integration/performance/helpers/cache.rb +37 -0
  541. data/spec/integration/performance/helpers/rules.rb +12 -0
  542. data/spec/integration/performance/integral_performance_caching_disabled.rb +33 -0
  543. data/spec/integration/performance/integral_performance_caching_enabled.rb +33 -0
  544. data/spec/integration/performance/raw_performance.rb +11 -0
  545. data/spec/integration/user/articles_spec.rb +39 -0
  546. data/spec/integration/user/concerto_spec.rb +39 -0
  547. data/spec/note_on_caching_and_dynamic.textile +114 -0
  548. data/spec/path_helper.rb +9 -0
  549. data/spec/simple_roles.rb +46 -0
  550. data/spec/spec_helper.rb +22 -0
  551. data/wiki/ability/initialize.markdown +45 -0
  552. data/wiki/api/user/api.markdown +88 -0
  553. data/wiki/api/user_account/api.markdown +88 -0
  554. data/wiki/config/ability.markdown +18 -0
  555. data/wiki/config/autoload.markdown +31 -0
  556. data/wiki/config/guest.markdown +49 -0
  557. data/wiki/config/models_registration.markdown +16 -0
  558. data/wiki/config/role_groups.markdown +1 -0
  559. data/wiki/config/roles.markdown +1 -0
  560. data/wiki/engines/cache/config.markdown +31 -0
  561. data/wiki/engines/cache/session_store.markdown +0 -0
  562. data/wiki/engines/cache/store.markdown +6 -0
  563. data/wiki/engines/permissions/categories.markdown +33 -0
  564. data/wiki/engines/permissions/config.markdown +60 -0
  565. data/wiki/engines/permissions/moneta_store.markdown +0 -0
  566. data/wiki/engines/permissions/store.markdown +0 -0
  567. data/wiki/engines/permissions/yaml_store.markdown +0 -0
  568. data/wiki/engines/permits/config.markdown +0 -0
  569. data/wiki/engines/permits/licenses.markdown +0 -0
  570. data/wiki/engines/permits/role_groups.markdown +0 -0
  571. data/wiki/engines/permits/roles.markdown +0 -0
  572. data/wiki/engines/permits/user_accounts.markdown +0 -0
  573. data/wiki/feature_list.markdown +39 -0
  574. data/wiki/rules_caching.markdown +17 -0
  575. data/wiki/users/masquerading.markdown +29 -0
  576. data/wiki/when_to_use.markdown +64 -0
  577. data/wiki/why_to_use.markdown +11 -0
  578. metadata +788 -0
@@ -0,0 +1,26 @@
1
+ module CanTango
2
+ class Ability
3
+ module RoleHelpers
4
+
5
+ include CanTango::Helpers::RoleMethods
6
+
7
+ # return list roles the user has
8
+ # TODO: should also fetch roles of all role_groups! (or is this responsibility of roles_list?)
9
+ def roles
10
+ raise "#{subject.inspect} should have a #{roles_list_meth} method" if !subject.respond_to?(roles_list_meth)
11
+ subj_roles = subject.send(roles_list_meth)
12
+ return [] if subj_roles.blank?
13
+ subj_roles.flatten
14
+ end
15
+
16
+ # return list of symbols for role groups the user belongs to
17
+ # TODO: use roles filter here? or better in #valid? of selector ?
18
+ def role_groups
19
+ raise "#{subject.inspect} should have a #{role_groups_list_meth} method" if !subject.respond_to?(role_groups_list_meth)
20
+ subj_role_groups = subject.send(role_groups_list_meth)
21
+ return [] if subj_role_groups.blank?
22
+ subj_role_groups.flatten
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ module CanTango
2
+ class Ability
3
+ class Scope
4
+ attr_accessor :ability
5
+
6
+ def initialize ability
7
+ @ability = ability
8
+ end
9
+
10
+ def can? *args
11
+ ability.can? *args
12
+ end
13
+
14
+ def cannot? *args
15
+ ability.cannot? *args
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,22 @@
1
+ module CanTango
2
+ class Ability
3
+ module UserHelpers
4
+ def user
5
+ return subject.user if subject.respond_to? :user
6
+ subject
7
+ end
8
+
9
+ def user_account
10
+ return subject.active_account if subject.respond_to? :active_account
11
+ subject
12
+ end
13
+
14
+ def user_key_field
15
+ key_field = config.user.unique_key_field
16
+ raise "\nModel <#{user.class}> has no ##{key_field} as defined in CanTango.config.user.unique_key_field" if !user.respond_to?(key_field)
17
+ key_field
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,5 @@
1
+ module CanTango
2
+ module Api
3
+ autoload_modules :User, :UserAccount, :Options, :Common
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'aliases/permit'
3
+ require 'aliases/role_permit'
4
+ require 'aliases/role_group_permit'
5
+ require 'aliases/license'
6
+ require 'aliases/user_permit'
7
+ require 'aliases/account_permit'
8
+
@@ -0,0 +1,8 @@
1
+ module CanTango
2
+ class AccountPermit < CanTango::PermitEngine::AccountPermit
3
+ def initialize ability
4
+ super
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,7 @@
1
+ module CanTango
2
+ class License < CanTango::PermitEngine::License
3
+ def initialize permit
4
+ super
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module CanTango
2
+ class Permit < CanTango::PermitEngine::Permit
3
+ def initialize ability
4
+ super
5
+ end
6
+ end
7
+ end
8
+
9
+
@@ -0,0 +1,7 @@
1
+ module CanTango
2
+ class RoleGroupPermit < CanTango::PermitEngine::RoleGroupPermit
3
+ def initialize ability
4
+ super
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module CanTango
2
+ class RolePermit < CanTango::PermitEngine::RolePermit
3
+ def initialize ability
4
+ super
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module CanTango
2
+ class UserPermit < CanTango::PermitEngine::UserPermit
3
+ def initialize ability
4
+ super
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,10 @@
1
+ module CanTango
2
+ module Api
3
+ module Common
4
+ def create_ability candidate, opts = {}
5
+ CanTango.config.ability.factory_build candidate, opts
6
+ end
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,16 @@
1
+ module CanTango
2
+ module Api
3
+ module Options
4
+
5
+ def ability_options
6
+ opts = {}
7
+ opts.merge!(:session => session) if respond_to? :session
8
+ opts.merge!(:request => request) if respond_to? :request
9
+ opts.merge!(:params => params) if respond_to? :params
10
+ opts.merge!(:controller => controller) if respond_to? :controller
11
+ # puts "CanTango::Ability options:" << opts.keys.inspect
12
+ opts
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ module CanTango
2
+ module Api
3
+ module User
4
+ autoload_modules :Ability, :Can, :Scope
5
+
6
+ module All
7
+ def self.included base
8
+ [:Ability, :Can, :Scope].each do |api|
9
+ base.send :include, clazz(api)
10
+ end
11
+ end
12
+
13
+ def clazz api
14
+ ("CanTango::Api::User::" << api.to_s.camelize).constantize
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,38 @@
1
+ module CanTango
2
+ module Api
3
+ module User
4
+ module Ability
5
+ def user_ability user, options = {}
6
+ @current_ability ||= create_ability(user, ability_options.merge(options))
7
+ end
8
+
9
+ def current_ability user_type = :user
10
+ user_ability get_ability_user(user_type)
11
+ end
12
+
13
+ protected
14
+
15
+ include CanTango::Api::Common
16
+
17
+ def get_ability_user user_type
18
+ user_meth = :"current_#{user_type}"
19
+ return AbilityUser.guest if !respond_to?(user_meth)
20
+
21
+ user = send user_meth
22
+ user ? user : AbilityUser.guest
23
+ end
24
+
25
+ module AbilityUser
26
+ def self.guest
27
+ user = CanTango.config.guest.user
28
+
29
+ raise "You must set the guest_user to a Proc or lambda in CanTango.config" if !user
30
+ user.respond_to?(:call) ? user.call : user
31
+ end
32
+ end
33
+
34
+ include CanTango::Api::Options
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,26 @@
1
+ module CanTango
2
+ module Api
3
+ module User
4
+ module Can
5
+ include Ability
6
+ # Example: generated from types of accounts! (see below)
7
+ # def admin_can?(*args)
8
+ # current_ability(:admin).can?(*args)
9
+ # end
10
+ def self.included(base)
11
+ ::CanTango.config.users.registered.each do |user|
12
+ base.class_eval %{
13
+ def #{user}_can? *args
14
+ current_ability(:#{user}).can?(*args)
15
+ end
16
+
17
+ def #{user}_cannot? *args
18
+ current_ability(:#{user}).cannot?(*args)
19
+ end
20
+ }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ module CanTango
2
+ module Api
3
+ module User
4
+ module Scope
5
+
6
+ def scope_user scope, options = {}, &block
7
+ user = scoped_user(scope)
8
+ ab_scope = user_ability_scope(user, options)
9
+ yield ab_scope if block
10
+ ab_scope
11
+ end
12
+
13
+ def real_user scope, options = {}, &block
14
+ scope_user scope, options.merge(:masquerade => false), &block
15
+ end
16
+
17
+ protected
18
+
19
+ def user_ability_scope user, options = {}
20
+ CanTango::Ability::Scope.new user_ability(user, options)
21
+ end
22
+
23
+ def scoped_user scope
24
+ send(:"current_#{scope}")
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ module CanTango
2
+ module Api
3
+ module UserAccount
4
+ autoload_modules :Ability, :Can, :Scope
5
+
6
+ module All
7
+ def self.included base
8
+ [:Ability, :Can, :Scope].each do |api|
9
+ base.send :include, clazz(api)
10
+ end
11
+ end
12
+
13
+ def clazz api
14
+ ("CanTango::Api::UserAccount::" << api.to_s.camelize).constantize
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,44 @@
1
+ module CanTango
2
+ module Api
3
+ module UserAccount
4
+ module Ability
5
+ def user_account_ability user_account, options = {}
6
+ @current_ability ||= create_ability(user_account, ability_options.merge(options))
7
+ end
8
+
9
+ def current_account_ability user_type = :user
10
+ account_meth = :"current_#{user_type}_account"
11
+ return guest_user_account if !respond_to?(account_meth)
12
+
13
+ user_account = send(account_meth)
14
+ return guest_user_account if !user_account
15
+
16
+ user_account_ability user_account
17
+ end
18
+
19
+ protected
20
+
21
+ include CanTango::Api::Common
22
+
23
+ def get_ability_user_acount user_type
24
+ user_account_meth = :"current_#{user_type}_account"
25
+ return AbilityAccount.guest if !respond_to?(user_account_meth)
26
+
27
+ user_account = send user_account_meth
28
+ user_account ? user_account : AbilityAccount.guest
29
+ end
30
+
31
+ module AbilityAccount
32
+ def self.guest
33
+ account = CanTango.config.guest.account
34
+
35
+ raise "You must set the guest_account to a Proc or lambda in CanTango.config" if !account
36
+ account.respond_to?(:call) ? account.call : account
37
+ end
38
+ end
39
+
40
+ include CanTango::Api::Options
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,26 @@
1
+ module CanTango
2
+ module Api
3
+ module UserAccount
4
+ module Can
5
+ include Ability
6
+ # Example: generated from types of accounts! (see below)
7
+ # def admin_account_can?(*args)
8
+ # current_account_ability(:admin).can?(*args)
9
+ # end
10
+ def self.included(base)
11
+ ::CanTango.config.user_accounts.registered.each do |account|
12
+ base.class_eval %{
13
+ def #{account}_account_can? *args
14
+ current_account_ability(:#{account}).can?(*args)
15
+ end
16
+
17
+ def #{account}_account_cannot? *args
18
+ current_account_ability(:#{account}).cannot?(*args)
19
+ end
20
+ }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ module CanTango
2
+ module Api
3
+ module UserAccount
4
+ module Scope
5
+
6
+ def account_scope scope, options = {}, &block
7
+ account = scoped_account(scope)
8
+ ab_scope = account_ability_scope(account, options)
9
+ yield ab_scope if block
10
+ ab_scope
11
+ end
12
+
13
+ def as_real_account scope, options = {}, &block
14
+ scope_account scope, options.merge(:masquerade => false), &block
15
+ end
16
+
17
+ protected
18
+
19
+ def account_ability_scope account, options = {}
20
+ CanTango::Ability::Scope.new user_account_ability(account, options)
21
+ end
22
+
23
+ def scoped_acount scope
24
+ send(:"current_#{scope}_account")
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ module CanTango
2
+ module Cache
3
+ autoload_modules :MonetaCache
4
+ end
5
+ end
6
+
@@ -0,0 +1,68 @@
1
+ module CanTango
2
+ module Cache
3
+ class MonetaCache
4
+ include Singleton
5
+
6
+ attr_reader :options
7
+
8
+ def configure_with options = {}
9
+ @options ||= options
10
+ @type ||= options[:type] || CanTango.config.cache.store.default_type
11
+ end
12
+
13
+ def load! key
14
+ cache[key]
15
+ end
16
+
17
+ def save! key, rules
18
+ cache.store key, rules
19
+ end
20
+
21
+ def delete key
22
+ cache.delete key
23
+ end
24
+
25
+ def cache
26
+ @cache ||= begin
27
+ moneta = eval(factory_statement)
28
+ moneta.clear
29
+ moneta
30
+ end
31
+ end
32
+
33
+ def factory_statement
34
+ %{
35
+ ::Moneta::Builder.build do
36
+ #{run_adapter}
37
+ end
38
+ }
39
+ end
40
+
41
+ def run_adapter
42
+ case type.to_sym
43
+ when :yaml
44
+ yaml_adapter
45
+ else
46
+ simple_adapter
47
+ end
48
+ end
49
+
50
+ def yaml_adapter
51
+ "run #{adapter}, #{options}"
52
+ end
53
+
54
+ def simple_adapter
55
+ "run #{adapter}"
56
+ end
57
+
58
+ def type
59
+ (@type == :yaml) ? :YAML : @type
60
+ end
61
+
62
+ def adapter
63
+ require "moneta/adapters/#{type}"
64
+ @adapter = "Moneta::Adapters::#{type.to_s.camelize}".constantize
65
+ end
66
+ end
67
+ end
68
+ end