cantango 0.8.0 → 0.8.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (270) hide show
  1. data/Gemfile +32 -19
  2. data/README.textile +79 -131
  3. data/VERSION +1 -1
  4. data/cantango.gemspec +94 -61
  5. data/lib/cantango.rb +4 -6
  6. data/lib/cantango/ability.rb +28 -17
  7. data/lib/cantango/ability/cache.rb +30 -60
  8. data/lib/cantango/ability/cache/base_cache.rb +1 -1
  9. data/lib/cantango/ability/cache/key.rb +39 -0
  10. data/lib/cantango/ability/cache/kompiler.rb +22 -6
  11. data/lib/cantango/ability/cache/moneta_cache.rb +1 -1
  12. data/lib/cantango/ability/cache/reader.rb +32 -0
  13. data/lib/cantango/ability/cache/rules_cache.rb +31 -0
  14. data/lib/cantango/ability/cache/session_cache.rb +3 -2
  15. data/lib/cantango/ability/cache/writer.rb +42 -0
  16. data/lib/cantango/ability/cache_helpers.rb +28 -0
  17. data/lib/cantango/ability/masquerade_helpers.rb +7 -2
  18. data/lib/cantango/ability/permission_helpers.rb +0 -8
  19. data/lib/cantango/ability/permit_helpers.rb +0 -17
  20. data/lib/cantango/ability/role_helpers.rb +0 -2
  21. data/lib/cantango/ability/user_helpers.rb +1 -0
  22. data/lib/cantango/adapter/compiler.rb +9 -0
  23. data/lib/cantango/adapter/moneta.rb +23 -0
  24. data/lib/cantango/api.rb +1 -1
  25. data/lib/cantango/api/aliases.rb +4 -8
  26. data/lib/cantango/api/attributes.rb +17 -0
  27. data/lib/cantango/api/common.rb +6 -0
  28. data/lib/cantango/api/options.rb +9 -5
  29. data/lib/cantango/cache.rb +1 -1
  30. data/lib/cantango/cache/hash_cache.rb +34 -0
  31. data/lib/cantango/configuration.rb +13 -8
  32. data/lib/cantango/configuration/adapters.rb +25 -0
  33. data/lib/cantango/configuration/categories.rb +3 -1
  34. data/lib/cantango/configuration/engines.rb +83 -11
  35. data/lib/cantango/configuration/engines/cache.rb +12 -1
  36. data/lib/cantango/configuration/engines/engine.rb +5 -5
  37. data/lib/cantango/configuration/engines/permission.rb +1 -1
  38. data/lib/cantango/configuration/permit_registry.rb +17 -0
  39. data/lib/cantango/configuration/permits.rb +29 -0
  40. data/lib/cantango/configuration/registry.rb +5 -2
  41. data/lib/cantango/configuration/role_groups.rb +3 -0
  42. data/lib/cantango/configuration/role_registry.rb +4 -0
  43. data/lib/cantango/configuration/roles.rb +2 -0
  44. data/lib/cantango/configuration/user_accounts.rb +1 -0
  45. data/lib/cantango/configuration/users.rb +1 -0
  46. data/lib/cantango/engine.rb +13 -0
  47. data/lib/cantango/filters.rb +5 -0
  48. data/lib/cantango/filters/filter.rb +34 -0
  49. data/lib/cantango/filters/role_filter.rb +29 -0
  50. data/lib/cantango/filters/role_group_filter.rb +28 -0
  51. data/lib/cantango/permission_engine.rb +26 -1
  52. data/lib/cantango/permission_engine/collector.rb +7 -2
  53. data/lib/cantango/permission_engine/compiler.rb +8 -1
  54. data/lib/cantango/permission_engine/evaluator.rb +2 -2
  55. data/lib/cantango/permission_engine/factory.rb +8 -12
  56. data/lib/cantango/permission_engine/loader.rb +1 -1
  57. data/lib/cantango/permission_engine/loader/base.rb +1 -1
  58. data/lib/cantango/permission_engine/loader/categories.rb +3 -3
  59. data/lib/cantango/permission_engine/loader/permissions.rb +8 -5
  60. data/lib/cantango/permission_engine/moneta_store.rb +2 -2
  61. data/lib/cantango/permission_engine/parser.rb +1 -1
  62. data/lib/cantango/permission_engine/parser/categories.rb +1 -1
  63. data/lib/cantango/permission_engine/parser/category.rb +1 -1
  64. data/lib/cantango/permission_engine/parser/default.rb +1 -2
  65. data/lib/cantango/permission_engine/parser/ownership.rb +1 -1
  66. data/lib/cantango/permission_engine/parser/permissions.rb +1 -1
  67. data/lib/cantango/permission_engine/parser/regex.rb +2 -2
  68. data/lib/cantango/permission_engine/parser/relationship.rb +1 -1
  69. data/lib/cantango/permission_engine/parser/rule.rb +1 -1
  70. data/lib/cantango/permission_engine/permission.rb +2 -2
  71. data/lib/cantango/permission_engine/selector.rb +3 -3
  72. data/lib/cantango/permission_engine/selector/account_types.rb +24 -0
  73. data/lib/cantango/permission_engine/selector/base.rb +3 -3
  74. data/lib/cantango/permission_engine/selector/licenses.rb +2 -2
  75. data/lib/cantango/permission_engine/selector/role_groups.rb +7 -6
  76. data/lib/cantango/permission_engine/selector/roles.rb +10 -6
  77. data/lib/cantango/permission_engine/selector/user_types.rb +23 -0
  78. data/lib/cantango/permission_engine/selector/users.rb +2 -2
  79. data/lib/cantango/permission_engine/statement.rb +10 -9
  80. data/lib/cantango/permission_engine/statements.rb +27 -25
  81. data/lib/cantango/permission_engine/store.rb +1 -1
  82. data/lib/cantango/permission_engine/yaml_store.rb +2 -2
  83. data/lib/cantango/permit_engine.rb +29 -4
  84. data/lib/cantango/permit_engine/builder.rb +2 -3
  85. data/lib/cantango/permit_engine/builder/base.rb +9 -1
  86. data/lib/cantango/permit_engine/builder/special_permits.rb +7 -8
  87. data/lib/cantango/permit_engine/compatibility.rb +1 -1
  88. data/lib/cantango/permit_engine/executor.rb +1 -1
  89. data/lib/cantango/permit_engine/executor/abstract.rb +1 -1
  90. data/lib/cantango/permit_engine/executor/base.rb +1 -1
  91. data/lib/cantango/permit_engine/executor/system.rb +1 -1
  92. data/lib/cantango/permit_engine/factory.rb +2 -7
  93. data/lib/cantango/permit_engine/finder.rb +43 -9
  94. data/lib/cantango/permit_engine/role_matcher.rb +1 -1
  95. data/lib/cantango/permit_engine/util.rb +2 -1
  96. data/lib/cantango/permits.rb +9 -0
  97. data/lib/cantango/{permit_engine → permits}/account_permit.rb +15 -4
  98. data/lib/cantango/{permit_engine → permits}/account_permit/builder.rb +2 -6
  99. data/lib/cantango/{permit_engine → permits}/account_permit/finder.rb +2 -2
  100. data/lib/cantango/{permit_engine → permits}/license.rb +1 -1
  101. data/lib/cantango/{permit_engine → permits}/license/loader.rb +1 -1
  102. data/lib/cantango/{permit_engine → permits}/license/rules.rb +1 -1
  103. data/lib/cantango/permits/macros.rb +19 -0
  104. data/lib/cantango/{permit_engine → permits}/permit.rb +13 -1
  105. data/lib/cantango/{permit_engine → permits}/role_group_permit.rb +15 -3
  106. data/lib/cantango/{permit_engine → permits}/role_group_permit/builder.rb +10 -22
  107. data/lib/cantango/{permit_engine → permits}/role_group_permit/finder.rb +2 -2
  108. data/lib/cantango/{permit_engine → permits}/role_permit.rb +15 -3
  109. data/lib/cantango/permits/role_permit/builder.rb +27 -0
  110. data/lib/cantango/{permit_engine → permits}/role_permit/finder.rb +2 -2
  111. data/lib/cantango/{permit_engine → permits}/user_permit.rb +15 -3
  112. data/lib/cantango/{permit_engine → permits}/user_permit/builder.rb +2 -6
  113. data/lib/cantango/{permit_engine → permits}/user_permit/finder.rb +2 -2
  114. data/lib/cantango/rails.rb +3 -1
  115. data/lib/cantango/rails/engine.rb +11 -6
  116. data/lib/cantango/rails/helpers/base_helper.rb +28 -0
  117. data/lib/cantango/rails/helpers/controller_helper.rb +17 -0
  118. data/lib/cantango/rails/helpers/rest_helper.rb +44 -0
  119. data/lib/cantango/rails/helpers/view_helper.rb +17 -0
  120. data/lib/cantango/rails/railtie.rb +1 -1
  121. data/lib/cantango/rspec/config.rb +1 -1
  122. data/lib/cantango/rspec/matchers/be_allowed_to.rb +5 -3
  123. data/lib/cantango/rules/user_relation.rb +1 -1
  124. data/lib/cantango/users/macros.rb +8 -2
  125. data/lib/cantango/users/user.rb +1 -1
  126. data/lib/generators/cantango/account_permit/account_permit_generator.rb +37 -0
  127. data/lib/generators/cantango/account_permit/templates/account_permit.erb +13 -0
  128. data/lib/generators/cantango/base.rb +15 -18
  129. data/lib/generators/cantango/basic.rb +41 -0
  130. data/lib/generators/cantango/install/install_generator.rb +37 -0
  131. data/lib/generators/cantango/install/templates/cantango.rb +4 -0
  132. data/{spec/active_record/scenarios/user_accounts/config/account_permits.yml → lib/generators/cantango/install/templates/categories.yml} +0 -0
  133. data/lib/generators/cantango/install/templates/permissions.yml +4 -0
  134. data/lib/generators/cantango/license/license_generator.rb +6 -11
  135. data/lib/generators/cantango/license/templates/license.erb +1 -1
  136. data/lib/generators/cantango/license_base.rb +2 -2
  137. data/lib/generators/cantango/licenses/licenses_generator.rb +2 -7
  138. data/lib/generators/cantango/permit_generator.rb +31 -10
  139. data/lib/generators/cantango/role_permit/role_permit_generator.rb +11 -14
  140. data/lib/generators/cantango/role_permit/templates/account_permit.erb +2 -2
  141. data/lib/generators/cantango/role_permit/templates/role_group_permit.erb +2 -2
  142. data/lib/generators/cantango/role_permit/templates/role_permit.erb +2 -2
  143. data/lib/generators/cantango/role_permits/role_permits_generator.rb +16 -98
  144. data/lib/generators/cantango/user_permit/templates/account_permit.erb +5 -0
  145. data/lib/generators/cantango/user_permit/templates/user_permit.erb +13 -0
  146. data/lib/generators/cantango/user_permit/user_permit_generator.rb +36 -0
  147. data/spec/TODO +1 -6
  148. data/spec/active_record/helper/permits_config.rb +1 -1
  149. data/spec/active_record/scenarios/engines/permission_engine/{cantango_permissions.yml → permissions.yml} +2 -1
  150. data/spec/active_record/scenarios/engines/permission_engine/tango_permission_yml_spec.rb +8 -9
  151. data/spec/active_record/scenarios/engines/permit_engine/licenses_spec.rb +2 -2
  152. data/spec/active_record/scenarios/engines/permit_engine/role_groups_permits_spec.rb +2 -2
  153. data/spec/active_record/scenarios/shared/{can_tango.rb → cantango.rb} +1 -1
  154. data/spec/active_record/scenarios/shared/models/items.rb +0 -1
  155. data/spec/active_record/scenarios/shared/models/users.rb +6 -1
  156. data/spec/active_record/spec_helper.rb +6 -4
  157. data/spec/cantango/ability/cache/key_spec.rb +64 -0
  158. data/spec/cantango/ability/cache/{compiler_spec.rb → kompiler_spec.rb} +9 -21
  159. data/spec/cantango/ability/cache/reader_compile_spec.rb +42 -0
  160. data/spec/cantango/ability/cache/reader_spec.rb +33 -0
  161. data/spec/cantango/ability/cache/rules_cache_spec.rb +15 -0
  162. data/spec/cantango/ability/cache/session_cache_spec.rb +1 -1
  163. data/spec/cantango/ability/cache/writer_spec.rb +21 -0
  164. data/spec/cantango/ability/cache_spec.rb +6 -2
  165. data/spec/cantango/ability_filters_spec.rb +5 -10
  166. data/spec/cantango/ability_spec.rb +2 -3
  167. data/spec/cantango/api/attributes_spec.rb +27 -0
  168. data/spec/cantango/api/user/can_api_spec.rb +2 -2
  169. data/spec/cantango/api/user_account/can_api_spec.rb +2 -2
  170. data/spec/cantango/configuration/adapter_spec.rb +28 -0
  171. data/spec/cantango/configuration/engines/cache_spec.rb +2 -2
  172. data/spec/cantango/configuration/engines/permission_spec.rb +3 -3
  173. data/spec/cantango/configuration/engines/permit_spec.rb +1 -1
  174. data/spec/cantango/configuration/engines/store_shared.rb +3 -1
  175. data/spec/cantango/configuration/engines_spec.rb +106 -3
  176. data/spec/cantango/configuration/hash_registry_spec.rb +1 -1
  177. data/spec/cantango/configuration/permit_registry_spec.rb +14 -0
  178. data/spec/cantango/configuration/permits_spec.rb +25 -0
  179. data/spec/cantango/configuration/registry_spec.rb +1 -1
  180. data/spec/cantango/configuration/shared/registry_ex.rb +2 -1
  181. data/spec/cantango/configuration_spec.rb +5 -5
  182. data/spec/cantango/permission_engine/compiler_spec.rb +8 -0
  183. data/spec/cantango/permission_engine/permission_spec.rb +1 -1
  184. data/spec/cantango/permission_engine/yaml_store_spec.rb +14 -4
  185. data/spec/cantango/permission_engine_spec.rb +0 -0
  186. data/spec/cantango/permit_engine/account_permit_spec.rb +2 -4
  187. data/spec/cantango/permit_engine/builder/role_group_permits_spec.rb +4 -7
  188. data/spec/cantango/permit_engine/builder/role_permits_spec.rb +5 -6
  189. data/spec/cantango/permit_engine/builder/special_permits_spec.rb +3 -4
  190. data/spec/cantango/permit_engine/executor/system_spec.rb +2 -2
  191. data/spec/cantango/permit_engine/factory_spec.rb +2 -3
  192. data/spec/cantango/permit_engine/finder_spec.rb +144 -23
  193. data/spec/cantango/permit_engine/permit/permit_static_and_dynamic_rules_spec.rb +4 -5
  194. data/spec/cantango/permit_engine/role_group_permit_spec.rb +1 -1
  195. data/spec/cantango/permit_engine/role_permit_spec.rb +6 -7
  196. data/spec/cantango/permit_engine/user_permit_spec.rb +2 -3
  197. data/spec/cantango/permit_engine_spec.rb +2 -0
  198. data/spec/cantango/permits/macros_spec.rb +41 -0
  199. data/spec/cantango/permits/permit_spec.rb +46 -0
  200. data/spec/cantango_spec.rb +13 -0
  201. data/spec/devise-dummy/app/helpers/application_helper.rb +7 -0
  202. data/spec/devise-dummy/app/views/articles/admin.html.haml +1 -1
  203. data/spec/devise-dummy/app/views/articles/admin_account.html.haml +1 -1
  204. data/spec/devise-dummy/app/views/articles/guest.html.haml +1 -1
  205. data/spec/devise-dummy/app/views/articles/index.html.haml +1 -1
  206. data/spec/devise-dummy/app/views/comments/guest.html.haml +1 -1
  207. data/spec/devise-dummy/app/views/comments/index.html.haml +1 -1
  208. data/spec/devise-dummy/app/views/concertos/admin.html.haml +1 -1
  209. data/spec/devise-dummy/app/views/concertos/admin_account.html.haml +1 -1
  210. data/spec/devise-dummy/app/views/concertos/guest.html.haml +1 -1
  211. data/spec/devise-dummy/app/views/concertos/index.html.haml +1 -1
  212. data/spec/devise-dummy/app/views/users/index.html.haml +1 -1
  213. data/spec/devise-dummy/config/initializers/cantango.rb +3 -3
  214. data/spec/devise-dummy/config/{cantango_permissions.yml → permissions.yml} +2 -1
  215. data/spec/devise-integration/concerto_spec.rb +1 -1
  216. data/spec/dummy/app/models/user.rb +1 -0
  217. data/spec/dummy/app/views/articles/admin.html.haml +1 -1
  218. data/spec/dummy/app/views/articles/admin_account.html.haml +1 -1
  219. data/spec/dummy/app/views/articles/guest.html.haml +1 -1
  220. data/spec/dummy/app/views/articles/index.html.haml +1 -1
  221. data/spec/dummy/app/views/comments/guest.html.haml +1 -1
  222. data/spec/dummy/app/views/comments/index.html.haml +1 -1
  223. data/spec/dummy/app/views/concertos/admin.html.haml +1 -1
  224. data/spec/dummy/app/views/concertos/admin_account.html.haml +1 -1
  225. data/spec/dummy/app/views/concertos/guest.html.haml +1 -1
  226. data/spec/dummy/app/views/concertos/index.html.haml +1 -1
  227. data/spec/dummy/app/views/posts/admin.html.haml +1 -1
  228. data/spec/dummy/app/views/posts/admin_account.html.haml +1 -1
  229. data/spec/dummy/app/views/posts/guest.html.haml +1 -1
  230. data/spec/dummy/app/views/posts/index.html.haml +1 -1
  231. data/spec/dummy/app/views/users/admin.html.haml +1 -1
  232. data/spec/dummy/app/views/users/admin_account.html.haml +1 -1
  233. data/spec/dummy/app/views/users/guest.html.haml +1 -1
  234. data/spec/dummy/app/views/users/index.html.haml +1 -1
  235. data/spec/dummy/config/application.rb +1 -0
  236. data/spec/dummy/config/initializers/cantango.rb +1 -3
  237. data/spec/dummy/config/{cantango_permissions.yml → permissions.yml} +2 -2
  238. data/spec/dummy_spec_helper.rb +2 -0
  239. data/spec/entire_suite_spec.rb +2 -0
  240. data/spec/factories/user.rb +8 -0
  241. data/spec/factories/user_account.rb +6 -0
  242. data/spec/fixtures/config/permissions.yml +60 -19
  243. data/spec/fixtures/models/admin.rb +2 -0
  244. data/spec/fixtures/models/admin_account.rb +22 -0
  245. data/spec/fixtures/models/simple_roles.rb +5 -0
  246. data/spec/fixtures/models/user.rb +4 -0
  247. data/spec/helpers/dummy_app_ability.rb +2 -5
  248. data/spec/integration/cache_using_moneta_spec.rb +3 -1
  249. data/spec/integration/cache_using_session_spec.rb +2 -2
  250. data/spec/integration/user/articles_spec.rb +1 -1
  251. data/spec/integration/user/concerto_spec.rb +1 -1
  252. data/spec/spec_helper.rb +5 -5
  253. metadata +120 -95
  254. data/lib/cantango/ability/class_methods.rb +0 -27
  255. data/lib/cantango/api/aliases/account_permit.rb +0 -8
  256. data/lib/cantango/api/aliases/license.rb +0 -7
  257. data/lib/cantango/api/aliases/permit.rb +0 -9
  258. data/lib/cantango/api/aliases/role_group_permit.rb +0 -7
  259. data/lib/cantango/api/aliases/role_permit.rb +0 -7
  260. data/lib/cantango/api/aliases/user_permit.rb +0 -8
  261. data/lib/cantango/permission_engine/builder.rb +0 -6
  262. data/lib/cantango/permit_engine/role_permit/builder.rb +0 -46
  263. data/lib/cantango/rails/base_helpers.rb +0 -26
  264. data/lib/cantango/rails/controller_helpers.rb +0 -15
  265. data/lib/cantango/rails/view_helpers.rb +0 -15
  266. data/spec/active_record/scenarios/shared/permits/PERMITS README.textile +0 -3
  267. data/spec/active_record/scenarios/user_accounts/docs/USER_ACCOUNTS_SCENARIO.textile +0 -20
  268. data/spec/active_record/scenarios/user_accounts/docs/basic_rules_spec_possible_samples.txt +0 -84
  269. data/spec/factories.rb +0 -8
  270. data/spec/fixtures/config/cantango_permissions.yml +0 -48
@@ -1,27 +0,0 @@
1
- module CanTango
2
- class Ability
3
- mattr_accessor :orm, :strategy
4
-
5
- module ClassMethods
6
- # BAD!
7
- def orm= orm
8
- @orm = orm
9
- set_strategy orm
10
- end
11
-
12
- def set_strategy orm
13
- @strategy = relational_orm?(orm) ? :default : :string
14
- end
15
-
16
- private
17
-
18
- def relational_orm? orm
19
- relations_orms.include?(orm)
20
- end
21
-
22
- def relations_orms
23
- [:active_record, :generic]
24
- end
25
- end
26
- end
27
- end
@@ -1,8 +0,0 @@
1
- module CanTango
2
- class AccountPermit < CanTango::PermitEngine::AccountPermit
3
- def initialize ability
4
- super
5
- end
6
- end
7
- end
8
-
@@ -1,7 +0,0 @@
1
- module CanTango
2
- class License < CanTango::PermitEngine::License
3
- def initialize permit
4
- super
5
- end
6
- end
7
- end
@@ -1,9 +0,0 @@
1
- module CanTango
2
- class Permit < CanTango::PermitEngine::Permit
3
- def initialize ability
4
- super
5
- end
6
- end
7
- end
8
-
9
-
@@ -1,7 +0,0 @@
1
- module CanTango
2
- class RoleGroupPermit < CanTango::PermitEngine::RoleGroupPermit
3
- def initialize ability
4
- super
5
- end
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- module CanTango
2
- class RolePermit < CanTango::PermitEngine::RolePermit
3
- def initialize ability
4
- super
5
- end
6
- end
7
- end
@@ -1,8 +0,0 @@
1
- module CanTango
2
- class UserPermit < CanTango::PermitEngine::UserPermit
3
- def initialize ability
4
- super
5
- end
6
- end
7
- end
8
-
@@ -1,6 +0,0 @@
1
- module CanTango::Permit
2
- module Builder
3
- autoload :Base, 'tango/permit/builder/base'
4
- autoload :SpecialPermits, 'tango/permit/builder/special_permits'
5
- end
6
- end
@@ -1,46 +0,0 @@
1
- module CanTango
2
- module PermitEngine
3
- class RolePermit < CanTango::PermitEngine::Permit
4
- class Builder < CanTango::PermitEngine::Builder::Base
5
- # class NoAvailableRoles < StandardError; end
6
-
7
- # builds a list of Permits for each role of the current ability user (or account)
8
- # @return [Array<RoleGroupPermit::Base>] the role permits built for this ability
9
- def build
10
- # raise NoAvailableRoles, "no available roles are defined" if available_roles.empty?
11
- roles.inject([]) do |permits, role|
12
- (permits << create_permit(role)) if valid?(role.to_sym)
13
- permits
14
- end.compact
15
- end
16
-
17
- def finder
18
- CanTango::PermitEngine::RolePermit::Finder
19
- end
20
-
21
- protected
22
-
23
- def valid? role
24
- return false if not_only_role?(role)
25
- !excluded? role
26
- end
27
-
28
- def not_only_role? role
29
- !only_roles.empty? && !only_roles.include?(role)
30
- end
31
-
32
- def excluded? role
33
- excluded_roles.include? role
34
- end
35
-
36
- def only_roles
37
- CanTango.config.roles.onlies
38
- end
39
-
40
- def excluded_roles
41
- CanTango.config.roles.excluded
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,26 +0,0 @@
1
- module CanTango
2
- module Rails
3
- module BaseHelpers
4
- def self.included(base)
5
- include_apis(base)
6
- base.extend ClassMethods
7
- end
8
-
9
- module ClassMethods
10
- def include_apis(clazz)
11
- return if !respond_to?(:apis) || !apis
12
- apis.each do |api|
13
- clazz.send :include, "CanTango::Api::User::#{api}".constantize
14
- clazz.send :include, "CanTango::Api::UserAccount::#{api}".constantize
15
- end
16
- end
17
-
18
- def apis
19
- [:Can, :Scope]
20
- end
21
- end
22
- extend ClassMethods
23
- end
24
- end
25
- end
26
-
@@ -1,15 +0,0 @@
1
- module CanTango
2
- module Rails
3
- module ControllerHelpers
4
- include CanTango::Rails::BaseHelpers
5
-
6
- def self.included(base)
7
- include_apis(self)
8
- end
9
-
10
- def self.apis
11
- [] # [:Can, :Active, :Scope]
12
- end
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- module CanTango
2
- module Rails
3
- module ViewHelpers
4
- include CanTango::Rails::BaseHelpers
5
-
6
- def self.included(base)
7
- include_apis(self)
8
- end
9
-
10
- def self.apis
11
- [] # [:Can, :Active, :Scope]
12
- end
13
- end
14
- end
15
- end
@@ -1,3 +0,0 @@
1
- h1. Permits for scenarios
2
-
3
- Should be grouped into RolePermits and RoleGroupPermits. Some of each should be put in a UserAccount namespace, but only for specific scenario, not in shared!
@@ -1,20 +0,0 @@
1
- h1. Guest, Admin, User Accounts Scenario
2
-
3
- Blog model:
4
- * Article
5
- * Post
6
- * Comment
7
- * User
8
-
9
- GuestAcount Permissions:
10
- * Read all articles, posts and comments
11
- * No access to User
12
-
13
- UserAccount Permissions:
14
- * Read all articles, posts and comments
15
- * Manage all owned articles, posts and comments
16
- * Manage own User
17
-
18
- AdminAccount Permissions:
19
- * Manage all
20
-
@@ -1,84 +0,0 @@
1
- exit
2
- require 'active_record/spec_helper'
3
-
4
- describe Permits::Ability do
5
- include Config::Basic
6
-
7
- context "Guest user" do
8
- before :each do
9
- basic_config :guest
10
- end
11
-
12
- it "should be able to :read Comment and Post but NOT Article" do
13
- @ability.can?(:read, Comment).should be_true
14
- @ability.can?(:read, @comment).should be_true
15
-
16
- @ability.can?(:read, Post).should be_true
17
- @ability.can?(:read, @post).should be_true
18
-
19
- @ability.can?(:read, Article).should be_false
20
- @ability.can?(:read, @article).should be_false
21
- end
22
-
23
- it "should be not able to :update only Comment" do
24
- @ability.can?(:update, Comment).should be_true
25
- @ability.can?(:update, @comment).should be_true
26
-
27
- @ability.can?(:update, Post).should be_false
28
- @ability.can?(:update, @post).should be_false
29
- end
30
- end
31
-
32
- context "Admin user" do
33
- before do
34
- basic_config :admin
35
- end
36
-
37
- it "should be able to :read anything" do
38
- @ability.can?(:read, Comment).should be_true
39
- @ability.can?(:read, Post).should be_true
40
- end
41
-
42
- it "should be not able to :update everything" do
43
- @ability.can?(:update, Comment).should be_true
44
- @ability.can?(:update, Post).should be_true
45
- end
46
-
47
- it "should be not able to :create everything" do
48
- @ability.can?(:create, Comment).should be_true
49
- @ability.can?(:create, Post).should be_true
50
- end
51
-
52
- it "should be not able to :update everything" do
53
- @ability.can?(:destroy, Comment).should be_true
54
- @ability.can?(:destroy, Post).should be_true
55
- end
56
- end
57
-
58
- context "Admin Account having admin role" do
59
- before do
60
- basic_config :admin_account
61
- end
62
-
63
- it "should be able to :read anything" do
64
- @ability.can?(:read, Comment).should be_true
65
- @ability.can?(:read, Post).should be_true
66
- end
67
-
68
- it "should be not able to :update everything" do
69
- @ability.can?(:update, Comment).should be_true
70
- @ability.can?(:update, Post).should be_true
71
- end
72
-
73
- it "should be not able to :create everything" do
74
- @ability.can?(:create, Comment).should be_true
75
- @ability.can?(:create, Post).should be_true
76
- end
77
-
78
- it "should be not able to :update everything" do
79
- @ability.can?(:destroy, Comment).should be_true
80
- @ability.can?(:destroy, Post).should be_true
81
- end
82
- end
83
-
84
- end
data/spec/factories.rb DELETED
@@ -1,8 +0,0 @@
1
- Factory.define :user do |u|
2
- u.name 'kris'
3
- end
4
-
5
- Factory.define :user_account do |u|
6
- u.name 'susan'
7
- end
8
-
@@ -1,48 +0,0 @@
1
- roles:
2
- admin:
3
- can:
4
- manage:
5
- - all
6
-
7
- user:
8
- can:
9
- read:
10
- - Comment
11
- - Post
12
- - Article
13
- - User
14
- write:
15
- - Article
16
- manage:
17
- - Comment
18
- - Post
19
-
20
- role_groups:
21
- bloggers:
22
- can:
23
- read:
24
- - Article
25
- - Comment
26
- cannot:
27
- write:
28
- - Article
29
- - Post
30
- editors:
31
- can:
32
- read:
33
- - Article
34
- - Comment
35
- cannot:
36
- write:
37
- - Article
38
- - Post
39
-
40
- licenses:
41
- editors:
42
- can:
43
- manage:
44
- - all
45
- users:
46
- kris@gmail.com:
47
- can:
48
- cannot: