cantango 0.8.9.5 → 0.9.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/README.textile +35 -7
  2. data/VERSION +1 -1
  3. data/cantango.gemspec +39 -12
  4. data/lib/cantango.rb +4 -3
  5. data/lib/cantango/ability.rb +17 -21
  6. data/lib/cantango/ability/cache/key.rb +32 -4
  7. data/lib/cantango/ability/cache/rules_cache.rb +9 -2
  8. data/lib/cantango/ability/cache_helpers.rb +1 -7
  9. data/lib/cantango/ability/engine_helpers.rb +27 -0
  10. data/lib/cantango/ability_executor.rb +41 -0
  11. data/lib/cantango/api/user/ability.rb +8 -12
  12. data/lib/cantango/api/user/session.rb +2 -1
  13. data/lib/cantango/api/user_account.rb +2 -2
  14. data/lib/cantango/api/user_account/ability.rb +19 -14
  15. data/lib/cantango/api/user_account/can.rb +8 -0
  16. data/lib/cantango/api/user_account/session.rb +33 -0
  17. data/lib/cantango/cached_ability.rb +26 -0
  18. data/lib/cantango/configuration.rb +3 -3
  19. data/lib/cantango/configuration/ability.rb +1 -0
  20. data/lib/cantango/configuration/candidate_registry.rb +51 -0
  21. data/lib/cantango/configuration/categories.rb +2 -2
  22. data/lib/cantango/configuration/engines.rb +7 -3
  23. data/lib/cantango/configuration/engines/permission.rb +5 -0
  24. data/lib/cantango/configuration/engines/permit.rb +1 -0
  25. data/lib/cantango/configuration/engines/user_ac.rb +19 -0
  26. data/lib/cantango/configuration/guest.rb +1 -1
  27. data/lib/cantango/configuration/modes.rb +21 -0
  28. data/lib/cantango/configuration/permits.rb +1 -1
  29. data/lib/cantango/configuration/role_groups.rb +1 -2
  30. data/lib/cantango/configuration/user_accounts.rb +1 -1
  31. data/lib/cantango/configuration/users.rb +1 -1
  32. data/lib/cantango/engine.rb +40 -0
  33. data/lib/cantango/helpers.rb +1 -1
  34. data/lib/cantango/helpers/debug.rb +9 -0
  35. data/lib/cantango/model.rb +6 -0
  36. data/lib/cantango/model/filter.rb +102 -0
  37. data/lib/cantango/model/scope.rb +57 -0
  38. data/lib/cantango/permission_engine.rb +14 -3
  39. data/lib/cantango/permission_engine/loader/base.rb +1 -6
  40. data/lib/cantango/permission_engine/loader/permissions.rb +10 -16
  41. data/lib/cantango/permission_engine/store.rb +1 -7
  42. data/lib/cantango/permission_engine/yaml_store.rb +3 -10
  43. data/lib/cantango/permit_engine.rb +17 -4
  44. data/lib/cantango/permit_engine/builder/base.rb +3 -1
  45. data/lib/cantango/permit_engine/executor/abstract.rb +2 -0
  46. data/lib/cantango/permit_engine/executor/base.rb +1 -1
  47. data/lib/cantango/permit_engine/factory.rb +5 -3
  48. data/lib/cantango/permit_engine/finder.rb +4 -6
  49. data/lib/cantango/permit_engine/util.rb +1 -1
  50. data/lib/cantango/permits/permit.rb +25 -0
  51. data/lib/cantango/permits/role_group_permit/builder.rb +23 -7
  52. data/lib/cantango/permits/role_permit.rb +1 -2
  53. data/lib/cantango/rails/helpers/rest_helper.rb +3 -2
  54. data/lib/cantango/user_ac_engine.rb +40 -0
  55. data/lib/cantango/user_ac_engine/executor.rb +59 -0
  56. data/lib/cantango/users/macros.rb +3 -0
  57. data/lib/cantango/users/user.rb +1 -1
  58. data/lib/cantango/users/user_account.rb +1 -1
  59. data/lib/generators/cantango/permission/permission_generator.rb +43 -0
  60. data/spec/active_record/migrations/008_create_permissions.rb +10 -0
  61. data/spec/cantango/ability_executor/cached_only_spec.rb +76 -0
  62. data/spec/cantango/ability_executor_spec.rb +75 -0
  63. data/spec/cantango/api/attributes_spec.rb +2 -1
  64. data/spec/cantango/api/current_user_accounts.rb +5 -1
  65. data/spec/cantango/api/user/ability_api_spec.rb +17 -4
  66. data/spec/cantango/api/user/can_api_spec.rb +9 -5
  67. data/spec/cantango/api/user/scope_api_spec.rb +15 -7
  68. data/spec/cantango/api/user_account/ability_api_spec.rb +12 -5
  69. data/spec/cantango/api/user_account/can_api_spec.rb +8 -4
  70. data/spec/cantango/cached_ability_spec.rb +0 -0
  71. data/spec/cantango/model/filter_spec.rb +168 -0
  72. data/spec/cantango/model/scope_spec.rb +107 -0
  73. data/spec/cantango/permission_engine/loader/permissions/{cantango_permissions_loader.rb → cantango_permissions_loader_spec.rb} +0 -0
  74. data/spec/cantango/permission_engine/loader/permissions/shared.rb +2 -2
  75. data/spec/cantango/permission_engine/yaml_store_spec.rb +0 -1
  76. data/spec/cantango/permit_engine/role_group_permit_spec.rb +2 -2
  77. data/spec/cantango/permits/permit_spec.rb +2 -2
  78. data/spec/cantango/rules_spec.rb +6 -6
  79. data/spec/cantango/user_ac_engine_spec.rb +53 -0
  80. data/spec/fixtures/config/cantango_permissions.yml +49 -0
  81. data/spec/fixtures/models/permission.rb +12 -0
  82. data/spec/fixtures/models/user.rb +8 -0
  83. data/spec/generators/cantango/permission_generator_spec.rb +44 -0
  84. metadata +59 -35
data/README.textile CHANGED
@@ -35,14 +35,42 @@ Run bundler in a terminal/console from the folder of your Gemfile (root folder o
35
35
 
36
36
  @$ bundle@
37
37
 
38
- h2. Update Oct 17, 2011
38
+ h2. Update Oct 29, 2011
39
39
 
40
- Version *0.8.9.5* has been released. Contains an important bug fix for permit options!
40
+ Versions *0.9+* have naming bug. Please use version 0.8.9 for now.
41
41
 
42
- Also the user _[user_class]_can?_ and _cannot?_ API methods have been updated to work correctly when _current_[user_class]_ and such methods (fx as generated by _Devise_) return an account and not a user instance.
43
- In this case CanTango will attempt to call the #user method on the account to get the user.
44
- In many cases for more advanced scenarios, it makes more sense to treat the devise models as accounts and have the user models defined separately and linked to one or more accounts.
45
- The accounts would then have the credentials for the user in that partiular context and the user only the user specific details.
42
+ New features:
43
+
44
+ * Model AC filters and scopes
45
+ * Engine _:user_ac_ (User Access Control)
46
+ * Cache and No-Cache modes for Ability, run in succession and rule results merged
47
+
48
+ The :user_ac engine is a port of the Permission system from the _Rails in Action_ book.
49
+ With this engine a user can have many permissions defined, where each such permission is a persisted Permission model instance that describes a 'can' action on a specific type of object.
50
+
51
+ The new modal Ability model allows you to define rules that are run in Cache mode and others that can be run in no-cache mode. This enables you to circumvent the previos restriction that didn't allow you to use normal conditional ruby logic outside blocks if you enabled caching.
52
+
53
+ <pre>
54
+ class UserPermit < CanTango::UserPermit
55
+ def static_rules
56
+ ...
57
+ end
58
+
59
+ module Cached
60
+ def permit_rules
61
+ end
62
+ end
63
+
64
+ module NonCached
65
+ def permit_rules
66
+ end
67
+ end
68
+ end
69
+ </pre>
70
+
71
+ Any rule method defined directly for the permit is run for any (or both) modes. To define rules specifically for cache or no-cache modes, you should place them in a nested module to signify this as shown in this example.
72
+
73
+ You can configure modes with the new config object @CanTango.config.ability.modes@ and set it via @CanTango.config.ability.mode = :no_cache@ . The valid modes are: :cache, :no_cache, and :both. You can similarly configure which modes each engine should participate in, fx via @CanTango.config.permit_engine.mode = :cache@
46
74
 
47
75
  h2. Quickstart
48
76
 
@@ -121,7 +149,7 @@ If you use any of these adapters, you must manually include the following in you
121
149
 
122
150
  @gem 'dkastner-moneta'@ for moneta adapter and @gem 'sourcify'@ for the compiler adapter.
123
151
 
124
- CanTango uses @autoload_modules@ from the "sweetloader":https://github.com/kristianmandrup/sweet_loader.git' gem.
152
+ CanTango uses @autoload_modules@ from the "sweetloader":https://github.com/kristianmandrup/sweet_loader.git gem.
125
153
  This ensures that all such modules are lazy-loaded. Thus if you configure CanTango to exclude an engine, the code for that engine will never be loaded, minimizing the load time and memory print.
126
154
 
127
155
  h2. You need help?
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.9.5
1
+ 0.9.3.2
data/cantango.gemspec CHANGED
@@ -4,14 +4,17 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = "cantango"
8
- s.version = "0.8.9.5"
7
+ s.name = %q{cantango}
8
+ s.version = "0.9.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Kristian Mandrup", "Stanislaw Pankevich"]
12
- s.date = "2011-10-17"
13
- s.description = "Define your permission rules as role- or role group specific permits.\nIntegrates well with multiple Devise user acounts.\nIncludes rules caching.\nStore permissions in yaml file or key-value store"
14
- s.email = "kmandrup@gmail.com, s.pankevich@gmail.com"
11
+ s.authors = [%q{Kristian Mandrup}, %q{Stanislaw Pankevich}]
12
+ s.date = %q{2011-10-29}
13
+ s.description = %q{Define your permission rules as role- or role group specific permits.
14
+ Integrates well with multiple Devise user acounts.
15
+ Includes rules caching.
16
+ Store permissions in yaml file or key-value store}
17
+ s.email = %q{kmandrup@gmail.com, s.pankevich@gmail.com}
15
18
  s.extra_rdoc_files = [
16
19
  "LICENSE.txt",
17
20
  "README.textile"
@@ -38,12 +41,14 @@ Gem::Specification.new do |s|
38
41
  "lib/cantango/ability/cache/session_cache.rb",
39
42
  "lib/cantango/ability/cache/writer.rb",
40
43
  "lib/cantango/ability/cache_helpers.rb",
44
+ "lib/cantango/ability/engine_helpers.rb",
41
45
  "lib/cantango/ability/masquerade_helpers.rb",
42
46
  "lib/cantango/ability/permission_helpers.rb",
43
47
  "lib/cantango/ability/permit_helpers.rb",
44
48
  "lib/cantango/ability/role_helpers.rb",
45
49
  "lib/cantango/ability/scope.rb",
46
50
  "lib/cantango/ability/user_helpers.rb",
51
+ "lib/cantango/ability_executor.rb",
47
52
  "lib/cantango/adapter/compiler.rb",
48
53
  "lib/cantango/adapter/moneta.rb",
49
54
  "lib/cantango/api.rb",
@@ -60,14 +65,17 @@ Gem::Specification.new do |s|
60
65
  "lib/cantango/api/user_account/ability.rb",
61
66
  "lib/cantango/api/user_account/can.rb",
62
67
  "lib/cantango/api/user_account/scope.rb",
68
+ "lib/cantango/api/user_account/session.rb",
63
69
  "lib/cantango/cache.rb",
64
70
  "lib/cantango/cache/hash_cache.rb",
65
71
  "lib/cantango/cache/moneta_cache.rb",
72
+ "lib/cantango/cached_ability.rb",
66
73
  "lib/cantango/cancan/rule.rb",
67
74
  "lib/cantango/configuration.rb",
68
75
  "lib/cantango/configuration/ability.rb",
69
76
  "lib/cantango/configuration/adapters.rb",
70
77
  "lib/cantango/configuration/autoload.rb",
78
+ "lib/cantango/configuration/candidate_registry.rb",
71
79
  "lib/cantango/configuration/categories.rb",
72
80
  "lib/cantango/configuration/debug.rb",
73
81
  "lib/cantango/configuration/engines.rb",
@@ -76,10 +84,12 @@ Gem::Specification.new do |s|
76
84
  "lib/cantango/configuration/engines/permission.rb",
77
85
  "lib/cantango/configuration/engines/permit.rb",
78
86
  "lib/cantango/configuration/engines/store.rb",
87
+ "lib/cantango/configuration/engines/user_ac.rb",
79
88
  "lib/cantango/configuration/factory.rb",
80
89
  "lib/cantango/configuration/guest.rb",
81
90
  "lib/cantango/configuration/hash_registry.rb",
82
91
  "lib/cantango/configuration/models.rb",
92
+ "lib/cantango/configuration/modes.rb",
83
93
  "lib/cantango/configuration/permit_registry.rb",
84
94
  "lib/cantango/configuration/permits.rb",
85
95
  "lib/cantango/configuration/registry.rb",
@@ -96,7 +106,11 @@ Gem::Specification.new do |s|
96
106
  "lib/cantango/filters/role_filter.rb",
97
107
  "lib/cantango/filters/role_group_filter.rb",
98
108
  "lib/cantango/helpers.rb",
109
+ "lib/cantango/helpers/debug.rb",
99
110
  "lib/cantango/helpers/role_methods.rb",
111
+ "lib/cantango/model.rb",
112
+ "lib/cantango/model/filter.rb",
113
+ "lib/cantango/model/scope.rb",
100
114
  "lib/cantango/permission_engine.rb",
101
115
  "lib/cantango/permission_engine/collector.rb",
102
116
  "lib/cantango/permission_engine/compiler.rb",
@@ -183,6 +197,8 @@ Gem::Specification.new do |s|
183
197
  "lib/cantango/rules/rule_class.rb",
184
198
  "lib/cantango/rules/scope.rb",
185
199
  "lib/cantango/rules/user_relation.rb",
200
+ "lib/cantango/user_ac_engine.rb",
201
+ "lib/cantango/user_ac_engine/executor.rb",
186
202
  "lib/cantango/users.rb",
187
203
  "lib/cantango/users/macros.rb",
188
204
  "lib/cantango/users/masquerade.rb",
@@ -201,6 +217,7 @@ Gem::Specification.new do |s|
201
217
  "lib/generators/cantango/license/templates/license.erb",
202
218
  "lib/generators/cantango/license_base.rb",
203
219
  "lib/generators/cantango/licenses/licenses_generator.rb",
220
+ "lib/generators/cantango/permission/permission_generator.rb",
204
221
  "lib/generators/cantango/permit_generator.rb",
205
222
  "lib/generators/cantango/role_permit/role_permit_generator.rb",
206
223
  "lib/generators/cantango/role_permit/templates/account_permit.erb",
@@ -227,6 +244,7 @@ Gem::Specification.new do |s|
227
244
  "spec/active_record/migrations/005_create_account.rb",
228
245
  "spec/active_record/migrations/006_create_todo.rb",
229
246
  "spec/active_record/migrations/007_create_user_todos.rb",
247
+ "spec/active_record/migrations/008_create_permissions.rb",
230
248
  "spec/active_record/scenarios/SCENARIOS README.textile",
231
249
  "spec/active_record/scenarios/engines/permission_engine/categories.yml",
232
250
  "spec/active_record/scenarios/engines/permission_engine/permissions.yml",
@@ -281,6 +299,8 @@ Gem::Specification.new do |s|
281
299
  "spec/cantango/ability/cache/session_cache_spec.rb",
282
300
  "spec/cantango/ability/cache/writer_spec.rb",
283
301
  "spec/cantango/ability/cache_spec.rb",
302
+ "spec/cantango/ability_executor/cached_only_spec.rb",
303
+ "spec/cantango/ability_executor_spec.rb",
284
304
  "spec/cantango/ability_filters_spec.rb",
285
305
  "spec/cantango/ability_spec.rb",
286
306
  "spec/cantango/api/attributes_spec.rb",
@@ -294,6 +314,7 @@ Gem::Specification.new do |s|
294
314
  "spec/cantango/api/user_account/scope_api_spec.rb",
295
315
  "spec/cantango/api/user_account_api_spec.rb",
296
316
  "spec/cantango/api/user_api_spec.rb",
317
+ "spec/cantango/cached_ability_spec.rb",
297
318
  "spec/cantango/configuration/ability_spec.rb",
298
319
  "spec/cantango/configuration/adapter_spec.rb",
299
320
  "spec/cantango/configuration/autoload_spec.rb",
@@ -323,6 +344,8 @@ Gem::Specification.new do |s|
323
344
  "spec/cantango/configuration/user_spec.rb",
324
345
  "spec/cantango/configuration_spec.rb",
325
346
  "spec/cantango/license/save_license_spec.rb",
347
+ "spec/cantango/model/filter_spec.rb",
348
+ "spec/cantango/model/scope_spec.rb",
326
349
  "spec/cantango/models/items.rb",
327
350
  "spec/cantango/models/users.rb",
328
351
  "spec/cantango/moneta_spec.rb",
@@ -332,7 +355,7 @@ Gem::Specification.new do |s|
332
355
  "spec/cantango/permission_engine/categories_store_spec.rb",
333
356
  "spec/cantango/permission_engine/compiler_spec.rb",
334
357
  "spec/cantango/permission_engine/loader/categories_spec.rb",
335
- "spec/cantango/permission_engine/loader/permissions/cantango_permissions_loader.rb",
358
+ "spec/cantango/permission_engine/loader/permissions/cantango_permissions_loader_spec.rb",
336
359
  "spec/cantango/permission_engine/loader/permissions/shared.rb",
337
360
  "spec/cantango/permission_engine/moneta_store_spec.rb",
338
361
  "spec/cantango/permission_engine/parser_spec.rb",
@@ -359,6 +382,7 @@ Gem::Specification.new do |s|
359
382
  "spec/cantango/permits/macros_spec.rb",
360
383
  "spec/cantango/permits/permit_spec.rb",
361
384
  "spec/cantango/rules_spec.rb",
385
+ "spec/cantango/user_ac_engine_spec.rb",
362
386
  "spec/cantango_spec.rb",
363
387
  "spec/devise-dummy/Rakefile",
364
388
  "spec/devise-dummy/app/controllers/accounts_controller.rb",
@@ -562,6 +586,7 @@ Gem::Specification.new do |s|
562
586
  "spec/entire_suite_spec.rb",
563
587
  "spec/factories/user.rb",
564
588
  "spec/factories/user_account.rb",
589
+ "spec/fixtures/config/cantango_permissions.yml",
565
590
  "spec/fixtures/config/categories.yml",
566
591
  "spec/fixtures/config/evaluator_fixtures.yml",
567
592
  "spec/fixtures/config/licenses.yml",
@@ -573,6 +598,7 @@ Gem::Specification.new do |s|
573
598
  "spec/fixtures/models/admin.rb",
574
599
  "spec/fixtures/models/admin_account.rb",
575
600
  "spec/fixtures/models/items.rb",
601
+ "spec/fixtures/models/permission.rb",
576
602
  "spec/fixtures/models/simple_roles.rb",
577
603
  "spec/fixtures/models/user.rb",
578
604
  "spec/fixtures/models/user_account.rb",
@@ -582,6 +608,7 @@ Gem::Specification.new do |s|
582
608
  "spec/generators/cantango/install_generator_spec.rb",
583
609
  "spec/generators/cantango/license_generator_spec.rb",
584
610
  "spec/generators/cantango/licenses_generator_spec.rb",
611
+ "spec/generators/cantango/permission_generator_spec.rb",
585
612
  "spec/generators/cantango/role_permit_generator_spec.rb",
586
613
  "spec/generators/cantango/role_permits_generator_spec.rb",
587
614
  "spec/helpers/dummy_app_ability.rb",
@@ -635,11 +662,11 @@ Gem::Specification.new do |s|
635
662
  "wiki/when_to_use.markdown",
636
663
  "wiki/why_to_use.markdown"
637
664
  ]
638
- s.homepage = "http://github.com/kristianmandrup/cantango"
639
- s.licenses = ["MIT"]
640
- s.require_paths = ["lib"]
641
- s.rubygems_version = "1.8.10"
642
- s.summary = "CanCan extension with role oriented permission management and more"
665
+ s.homepage = %q{http://github.com/kristianmandrup/cantango}
666
+ s.licenses = [%q{MIT}]
667
+ s.require_paths = [%q{lib}]
668
+ s.rubygems_version = %q{1.8.6}
669
+ s.summary = %q{CanCan extension with role oriented permission management and more}
643
670
 
644
671
  if s.respond_to? :specification_version then
645
672
  s.specification_version = 3
data/lib/cantango.rb CHANGED
@@ -10,9 +10,10 @@ require 'sweetloader'
10
10
  AutoLoader.namespaces = {:CanTango => 'cantango'}
11
11
 
12
12
  module CanTango
13
- autoload_modules :Ability, :Api, :Configuration, :Cache, :Permits
14
- autoload_modules :PermitEngine, :Rails, :Users
15
- autoload_modules :PermissionEngine, :Rules, :Api, :Helpers, :Filters, :Engine
13
+ autoload_modules :Ability, :CachedAbility, :AbilityExecutor
14
+ autoload_modules :Api, :Configuration, :Cache, :Permits
15
+ autoload_modules :PermitEngine, :PermissionEngine, :UserAcEngine
16
+ autoload_modules :Rails, :Users, :Rules, :Api, :Helpers, :Filters, :Model, :Engine
16
17
 
17
18
  class << self
18
19
  def configure &block
@@ -4,50 +4,39 @@ module CanTango
4
4
  class Ability
5
5
  autoload_modules :Scope, :Cache
6
6
  autoload_modules :MasqueradeHelpers, :PermitHelpers, :PermissionHelpers
7
- autoload_modules :UserHelpers, :RoleHelpers, :CacheHelpers
7
+ autoload_modules :UserHelpers, :RoleHelpers, :CacheHelpers, :EngineHelpers
8
8
 
9
9
  include CanCan::Ability
10
10
 
11
- attr_reader :options, :subject, :session, :candidate
11
+ attr_reader :options, :candidate
12
12
 
13
13
  # Equivalent to a CanCan Ability#initialize call
14
14
  # which executes all the permission logic
15
15
  def initialize candidate, options = {}
16
16
  raise "Candidate must be something!" if !candidate
17
17
  @candidate, @options = candidate, options
18
- @session = options[:session] || {} # seperate session cache for each type of user?
19
-
20
- return if cached_rules?
21
18
 
22
19
  clear_rules!
23
20
  permit_rules
24
- execute_engines!
25
21
 
26
- cache_rules! if caching_on?
22
+ execute_engines! if engines_on?
27
23
  end
28
24
 
29
25
  include CanTango::PermitEngine::Util
30
26
 
31
- def permit_rules
32
- end
33
-
34
- def clear_rules!
35
- @rules = []
27
+ def cached?
28
+ false
36
29
  end
37
30
 
38
- def execute_engines!
39
- each_engine {|engine| engine.new(self).execute! if engine }
31
+ def permit_rules
40
32
  end
41
33
 
42
- def each_engine &block
43
- engines.execution_order.each do |name|
44
-
45
- yield engines.registered[name] if engines.active? name
46
- end
34
+ def clear_rules!
35
+ @rules ||= default_rules
47
36
  end
48
37
 
49
- def engines
50
- CanTango.config.engines
38
+ def session
39
+ @session = options[:session] || {} # seperate session cache for each type of user?
51
40
  end
52
41
 
53
42
  def subject
@@ -60,11 +49,18 @@ module CanTango
60
49
  CanTango.config
61
50
  end
62
51
 
52
+ include EngineHelpers
63
53
  include CacheHelpers
64
54
  include MasqueradeHelpers
65
55
  include PermissionHelpers
66
56
  include PermitHelpers
67
57
  include UserHelpers
68
58
  include RoleHelpers
59
+
60
+ protected
61
+
62
+ def default_rules
63
+ []
64
+ end
69
65
  end
70
66
  end
@@ -4,9 +4,14 @@ module CanTango
4
4
  class Key
5
5
  attr_reader :user, :subject
6
6
 
7
- def initialize user, subject = nil
7
+ def initialize user, subject = nil, method_names = nil
8
8
  @user = user
9
9
  @subject = subject || user
10
+ @method_names = method_names
11
+ end
12
+
13
+ def method_names
14
+ @method_names ||= [:roles_list, :role_groups_list]
10
15
  end
11
16
 
12
17
  def self.create_for ability
@@ -26,7 +31,16 @@ module CanTango
26
31
  protected
27
32
 
28
33
  def hash_values
29
- @hash_values ||= [user_key, subject_roles_hash].compact
34
+ @hash_values ||= [user_key, subject_roles_hash, permissions_key].compact
35
+ end
36
+
37
+ def permissions_key
38
+ return subject.send(:permissions_hash) if permissions_key? && subject.respond_to?(:permissions_hash)
39
+ subject.send(:permissions) if permissions_key?
40
+ end
41
+
42
+ def permissions_key?
43
+ subject.respond_to?(:permissions) && permission_engine.modes.include?(:cache) && permission_engine.on?
30
44
  end
31
45
 
32
46
  def user_key
@@ -43,11 +57,25 @@ module CanTango
43
57
  end
44
58
 
45
59
  def role_hash_values
46
- @role_hash_values ||= [:roles_list, :role_groups_list].inject([]) do |result, meth|
47
- result << subject.send(meth) if subject.respond_to? meth
60
+ @role_hash_values ||= method_names.inject([]) do |result, meth_name|
61
+ result << subject.send(meth_name) if use_in_hash? meth_name
48
62
  result
49
63
  end
50
64
  end
65
+
66
+ private
67
+
68
+ def permission_engine
69
+ CanTango.config.engine(:user_ac)
70
+ end
71
+
72
+ def use_in_hash? meth_name
73
+ subject.respond_to?(meth_name) && CanTango.config.permits.enabled_types.include?(meth_map[meth_name])
74
+ end
75
+
76
+ def meth_map
77
+ {:roles_list => :role, :role_groups_list => :role_group }
78
+ end
51
79
  end
52
80
  end
53
81
  end
@@ -17,11 +17,18 @@ module CanTango
17
17
  end
18
18
 
19
19
  def cache_options
20
- CanTango.config.cache_engine.store.options || {}
20
+ cache_engine.store.options || {}
21
21
  end
22
22
 
23
23
  def clazz
24
- CanTango.config.cache_engine.store.default_class
24
+ cache_engine.store.default_class
25
+ end
26
+
27
+ protected
28
+
29
+ def cache_engine
30
+ raise "Cache engine not registered!" if !CanTango.config.engine(:cache)
31
+ CanTango.config.engine(:cache)
25
32
  end
26
33
  end
27
34
  end
@@ -3,7 +3,7 @@ module CanTango
3
3
  module CacheHelpers
4
4
 
5
5
  def cached_rules?
6
- caching_on? && cache.key.same?(session)
6
+ cache.key.same?(session)
7
7
  end
8
8
 
9
9
  def cache_rules!
@@ -17,12 +17,6 @@ module CanTango
17
17
  def cache
18
18
  @cache ||= Cache.new self
19
19
  end
20
-
21
- protected
22
-
23
- def caching_on?
24
- CanTango.config.cache_engine.on?
25
- end
26
20
  end
27
21
  end
28
22
  end
@@ -0,0 +1,27 @@
1
+ module CanTango
2
+ class Ability
3
+ module EngineHelpers
4
+ def execute_engines!
5
+ each_engine {|engine| engine.new(self).execute! if engine }
6
+ end
7
+
8
+ def each_engine &block
9
+ engines.execution_order.each do |name|
10
+ yield engines.registered[name] if engines.active? name
11
+ end
12
+ end
13
+
14
+ def opts_engines_off?
15
+ options[:engines] == :off
16
+ end
17
+
18
+ def engines_on?
19
+ CanTango.config.engines.any?(:on) && !opts_engines_off?
20
+ end
21
+
22
+ def engines
23
+ CanTango.config.engines
24
+ end
25
+ end
26
+ end
27
+ end